Sha256: d14a432cc2d1683ab8e31bab32149c18ee6285d36738d2551044c44ef03b0506
Contents?: true
Size: 1.04 KB
Versions: 1
Compression:
Stored size: 1.04 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 Occams::Content::Tag::Datetime < Occams::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 Occams::Content::Renderer.register_tag( :datetime, Occams::Content::Tag::Datetime )
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
occams-1.0.1 | lib/occams/content/tags/datetime.rb |