Sha256: f505445e3a9fdd58341332b1ee44427fc9b599f7dec40d03f835d007a882ad63

Contents?: true

Size: 1.11 KB

Versions: 13

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

# 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
#
class ComfortableMexicanSofa::Content::Tag::Datetime < ComfortableMexicanSofa::Content::Tag::Fragment

  attr_reader :strftime

  def initialize(context:, params: [], source: nil)
    super
    @strftime = options["strftime"]
  end

  def content
    fragment.datetime
  end

  def render
    return "" unless renderable

    if strftime.present?
      content.strftime(strftime)
    else
      content.to_s
    end
  end

  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

end

ComfortableMexicanSofa::Content::Renderer.register_tag(
  :datetime, ComfortableMexicanSofa::Content::Tag::Datetime
)

Version data entries

13 entries across 13 versions & 6 rubygems

Version Path
comfortable_mexican_sofa-2.0.19 lib/comfortable_mexican_sofa/content/tags/datetime.rb
PixelForce_ETS-0.0.2 lib/comfortable_mexican_sofa/content/tags/datetime.rb
PixelForce_ETS-0.0.1 lib/comfortable_mexican_sofa/content/tags/datetime.rb
kcyEtsTest2-0.0.4 lib/comfortable_mexican_sofa/content/tags/datetime.rb
kcyEtsTest2-0.0.3 lib/comfortable_mexican_sofa/content/tags/datetime.rb
kcyEtsTest2-0.0.2 lib/comfortable_mexican_sofa/content/tags/datetime.rb
kcyEtsTest2-0.0.1 lib/comfortable_mexican_sofa/content/tags/datetime.rb
kcyEtsTest-0.0.1 lib/comfortable_mexican_sofa/content/tags/datetime.rb
kcyEtsTest-2.2.19 lib/comfortable_mexican_sofa/content/tags/datetime.rb
ComfortableMexicanSofa-2.0.18 lib/comfortable_mexican_sofa/content/tags/datetime.rb
kcy1-1.0 lib/comfortable_mexican_sofa/content/tags/datetime.rb
comfortable_mexican_sofa-2.0.18 lib/comfortable_mexican_sofa/content/tags/datetime.rb
comfortable_mexican_sofa-2.0.17 lib/comfortable_mexican_sofa/content/tags/datetime.rb