Class: Occams::Content::Tag::Datetime
- Inherits:
-
Fragment
- Object
- Occams::Content::Tag
- Fragment
- Occams::Content::Tag::Datetime
- Defined in:
- lib/occams/content/tags/datetime.rb
Overview
Tag for text content that is going to be rendered using text input with datetime widget
{{ cms:datetime identifier, strftime: "at %I:%M%p" }}
‘strftime` - Format datetime string during rendering
Direct Known Subclasses
Instance Attribute Summary collapse
-
#strftime ⇒ Object
readonly
Returns the value of attribute strftime.
Attributes inherited from Fragment
#identifier, #namespace, #options, #renderable
Attributes inherited from Occams::Content::Tag
Instance Method Summary collapse
- #content ⇒ Object
- #form_field(object_name, view, index) {|input| ... } ⇒ Object
-
#initialize(context:, params: [], source: nil) ⇒ Datetime
constructor
A new instance of Datetime.
- #render ⇒ Object
Methods inherited from Fragment
Methods inherited from Occams::Content::Tag
Constructor Details
#initialize(context:, params: [], source: nil) ⇒ Datetime
Returns a new instance of Datetime.
11 12 13 14 |
# File 'lib/occams/content/tags/datetime.rb', line 11 def initialize(context:, params: [], source: nil) super @strftime = ['strftime'] end |
Instance Attribute Details
#strftime ⇒ Object (readonly)
Returns the value of attribute strftime.
9 10 11 |
# File 'lib/occams/content/tags/datetime.rb', line 9 def strftime @strftime end |
Instance Method Details
#content ⇒ Object
16 17 18 |
# File 'lib/occams/content/tags/datetime.rb', line 16 def content fragment.datetime end |
#form_field(object_name, view, index) {|input| ... } ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/occams/content/tags/datetime.rb', line 30 def form_field(object_name, view, index) name = "#{object_name}[fragments_attributes][#{index}][datetime]" = { id: form_field_id, class: 'form-control', data: { 'cms-datetime' => true } } value = content.present? ? content.to_s(:db) : '' input = view.send(:text_field_tag, name, value, ) yield input end |
#render ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/occams/content/tags/datetime.rb', line 20 def render return '' unless renderable if strftime.present? content.strftime(strftime) else content.to_s end end |