Class: CML::Tags::Hours
Constant Summary collapse
- DAYS =
[ { :key => 'mon', :label => "Monday" }, { :key => 'tue', :label => "Tuesday" }, { :key => 'wed', :label => "Wednesday" }, { :key => 'thu', :label => "Thursday" }, { :key => 'fri', :label => "Friday" }, { :key => 'sat', :label => "Saturday" }, # { :key => 'cat', :label => "Caturday" }, { :key => 'sun', :label => "Sunday" } ]
- Template =
Templates =
<<-HTML.freeze {{label}} <table class="cml_hours cml_row {{classes}}"> {{rows_html}} </table> HTML
- RowTemplate =
Liquid::Template.parse(<<-HTML.freeze) <tr class="cml_hours_{{day_key}}"> <td class="cml_hours_day">{{day_label}}</td> <td class="cml_hours_hours"> <p class="cml_hours_1"> <span class="cml_hours_selects">{{hours_open_1}}</span> <span class="cml_hours_to">to</span> <span class="cml_hours_selects">{{hours_close_1}}</span> </p> <p class="cml_hours_2"> <span class="cml_hours_selects">{{hours_open_2}}</span> <span class="cml_hours_to">to</span> <span class="cml_hours_selects">{{hours_close_2}}</span> </p> </td> <td class="cml_hours_open_close"> <p class="cml_hours_openallday"> {{open_checkbox}} </p> <p class="cml_hours_closedallday"> {{closed_checkbox}} </p> </td> </tr> HTML
- TrueFalseCheckboxTemplate =
Liquid::Template.parse(<<-HTML) <input type="hidden" name="{{name}}" value="FALSE" /> <input {{checked}}type="checkbox" name="{{name}}" id="{{id}}" value="TRUE" /> <label for="{{id}}">{{label}}</label> HTML
- TimeSelectTemplate =
Liquid::Template.parse( TimeSelect.build( "{{name}}", false ) )
- TimeSelectTemplateAllowUnlisted =
Liquid::Template.parse( TimeSelect.build( "{{name}}", false, :allow_unlisted => true ) )
Constants included from CML::TagLogic
CML::TagLogic::And, CML::TagLogic::AndPhraseExp, CML::TagLogic::CombinatorDefault, CML::TagLogic::CombinatorDict, CML::TagLogic::CombinatorExp, CML::TagLogic::GroupExp, CML::TagLogic::Or, CML::TagLogic::OrCombinatorExp, CML::TagLogic::PrecedenceRegexp, CML::TagLogic::TokenExp, CML::TagLogic::TokenRegexp
Instance Attribute Summary
Attributes inherited from CML::Tag
#attrs, #cml, #data, #opts, #tag
Attributes included from CML::TagLogic
#errors, #has_grouped_logic, #has_liquid_logic, #logic_tree
Instance Method Summary collapse
-
#field_name(day, field_suffix) ⇒ Object
Builds a field name for the given day and suffix.
- #finite_value? ⇒ Boolean
-
#initialize(cml, opts = {}) ⇒ Hours
constructor
A new instance of Hours.
-
#normalize? ⇒ Boolean
= Normalize = =============.
-
#normalized_data_value(name) ⇒ Object
Returns data value as array of values or nil, if none.
- #raw_data ⇒ Object
-
#to_html ⇒ Object
= Rendering = =============.
-
#truthy_checkbox_value?(value) ⇒ Boolean
“true”, true, “coolio” –> true “false”, false, “”, nil –> false.
Methods inherited from CML::Tag
#cacheable?, #children, #classes, #convert, #ensure_resolved, #gold=, #gold?, #gold_class, #gold_reason, #instructions, #iterating?, #label, #legend, memoize, #multi_type, #name, #parent_multiples, #prefix, #preloaded_data, #raw_label, #to_liquid, #to_s, #validate?, #validations, #validators, #value, #wrapper, #wrapper_classes
Methods included from CML::TagLogic
#dependencies_on_fields, #dependencies_through_cml_group, #depends_on_fields, #describe_logic_token, #detect_grouped_logic, #detect_liquid_logic, #each_logic_token_in, #expand_logic, #expand_parsed_expression, #in_logic_graph?, #keep_merge!, #only_if, parse_expression, resolve_combinator
Constructor Details
#initialize(cml, opts = {}) ⇒ Hours
Returns a new instance of Hours.
124 125 126 127 128 129 |
# File 'lib/cml/tags/hours.rb', line 124 def initialize(cml, opts = {}) super( cml, opts ) @attrs["matcher"] = "hours" @attrs["validates"] = @attrs["validates"].to_s + " hours" @attrs["allowunlisted"] = !(@attrs["allowunlisted"].to_s =~ /^t/i).nil? end |
Instance Method Details
#field_name(day, field_suffix) ⇒ Object
Builds a field name for the given day and suffix. e.g:
field_name( <tue>, "open_1" ) --> "u123[my_field_tue_open_1]"
182 183 184 |
# File 'lib/cml/tags/hours.rb', line 182 def field_name( day, field_suffix ) prefix( name( true, "#{day[:key]}_#{field_suffix}" ) ) end |
#finite_value? ⇒ Boolean
131 132 133 |
# File 'lib/cml/tags/hours.rb', line 131 def finite_value? true end |
#normalize? ⇒ Boolean
Normalize =
151 152 153 |
# File 'lib/cml/tags/hours.rb', line 151 def normalize? @opts[:normalize] end |
#normalized_data_value(name) ⇒ Object
Returns data value as array of values or nil, if none.
160 161 162 163 164 165 166 167 |
# File 'lib/cml/tags/hours.rb', line 160 def normalized_data_value( name ) val = raw_data[name] if val && !val.empty? Array( val ) else nil end end |
#raw_data ⇒ Object
155 156 157 |
# File 'lib/cml/tags/hours.rb', line 155 def raw_data @opts[:data] || {} end |
#to_html ⇒ Object
Rendering =
139 140 141 142 143 144 145 |
# File 'lib/cml/tags/hours.rb', line 139 def to_html data = self.data.merge({ "rows_html" => rows_html }) rendered = Liquid::Template.parse( Template ).render( data ) wrapper( rendered ) end |
#truthy_checkbox_value?(value) ⇒ Boolean
“true”, true, “coolio” –> true “false”, false, “”, nil –> false
171 172 173 174 |
# File 'lib/cml/tags/hours.rb', line 171 def truthy_checkbox_value?( value ) value = value.is_a?(Array) ? value[0].to_s : value.to_s !( value.empty? || value =~ /^f/i ) end |