Class: ComfortableMexicanSofa::Content::Tag::Datetime
- Inherits:
-
Fragment
- Object
- ComfortableMexicanSofa::Content::Tag
- Fragment
- ComfortableMexicanSofa::Content::Tag::Datetime
- Defined in:
- lib/comfortable_mexican_sofa/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 ComfortableMexicanSofa::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 ComfortableMexicanSofa::Content::Tag
Constructor Details
#initialize(context:, params: [], source: nil) ⇒ Datetime
Returns a new instance of Datetime.
12 13 14 15 |
# File 'lib/comfortable_mexican_sofa/content/tags/datetime.rb', line 12 def initialize(context:, params: [], source: nil) super @strftime = ["strftime"] end |
Instance Attribute Details
#strftime ⇒ Object (readonly)
Returns the value of attribute strftime.
10 11 12 |
# File 'lib/comfortable_mexican_sofa/content/tags/datetime.rb', line 10 def strftime @strftime end |
Instance Method Details
#content ⇒ Object
17 18 19 |
# File 'lib/comfortable_mexican_sofa/content/tags/datetime.rb', line 17 def content fragment.datetime end |
#form_field(object_name, view, index) {|input| ... } ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/comfortable_mexican_sofa/content/tags/datetime.rb', line 31 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
21 22 23 24 25 26 27 28 29 |
# File 'lib/comfortable_mexican_sofa/content/tags/datetime.rb', line 21 def render return "" unless renderable if strftime.present? content.strftime(strftime) else content.to_s end end |