class ComfortableMexicanSofa::Content::Tag::Datetime

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

Attributes

strftime[R]

Public Class Methods

new(context:, params: [], source: nil) click to toggle source
# File lib/comfortable_mexican_sofa/content/tags/datetime.rb, line 12
def initialize(context:, params: [], source: nil)
  super
  @strftime = options["strftime"]
end

Public Instance Methods

content() click to toggle source
# File lib/comfortable_mexican_sofa/content/tags/datetime.rb, line 17
def content
  fragment.datetime
end
form_field(object_name, view, index) { |input| ... } click to toggle source
# 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]"
  options = { 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, options)

  yield input
end
render() click to toggle source
# 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