Class: Filch::Templates
- Inherits:
-
Object
- Object
- Filch::Templates
- Defined in:
- lib/filch.rb
Overview
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#templates ⇒ Object
readonly
Returns the value of attribute templates.
Instance Method Summary collapse
-
#build_templates ⇒ Object
def button_attrs attrs = { } if @model.methods.include?(:button_attrs) attrs = attrs.merge(@model.button_attrs) || attrs end attrs end.
- #html_attrs ⇒ Object
- #html_attrs_values ⇒ Object
-
#initialize(model) ⇒ Templates
constructor
A new instance of Templates.
- #model_html_attrs ⇒ Object
-
#template_keys ⇒ Object
will generate forms based on the list of templates in the Array YourModel.template_keys.
Constructor Details
#initialize(model) ⇒ Templates
Returns a new instance of Templates.
63 64 65 66 |
# File 'lib/filch.rb', line 63 def initialize(model) @model = model @templates = build_templates end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
67 68 69 |
# File 'lib/filch.rb', line 67 def model @model end |
#templates ⇒ Object (readonly)
Returns the value of attribute templates.
67 68 69 |
# File 'lib/filch.rb', line 67 def templates @templates end |
Instance Method Details
#build_templates ⇒ Object
def button_attrs
attrs = {
}
if @model.methods.include?(:button_attrs)
attrs = attrs.merge(@model.) || attrs
end
attrs
end
113 114 115 116 117 118 119 120 |
# File 'lib/filch.rb', line 113 def build_templates templates = {} templates.default = Template.new(@model, 'default') template_keys.each do |template| templates[template] = Template.new(@model, template) end templates end |
#html_attrs ⇒ Object
94 95 96 97 98 99 100 101 |
# File 'lib/filch.rb', line 94 def html_attrs attrs = html_attrs_values attrs.default = {} attrs.each_key do |key| attrs[key] = attrs[key].merge(model_html_attrs[key]) end attrs end |
#html_attrs_values ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/filch.rb', line 69 def html_attrs_values { assocs: { click: 'filchColClick', load: 'toggleShowHide' }, attrs: { click: 'filchColClick', load: 'toggleShowHide' }, button: { click: 'toggleShowHide', shId: 'filch', load: 'toggleShowHide' }, datalist: { updateInner_path: '/filch/datalist', class: 'js', update: 'dlUpdate' }, field: { class: 'js form-control', input: 'filchDataList' }, label: { class: 'cheese'} } end |
#model_html_attrs ⇒ Object
84 85 86 87 88 89 90 91 92 |
# File 'lib/filch.rb', line 84 def model_html_attrs model_attrs = if @model.methods.include?(:filch_html_attrs) @model.filch_html_attrs else {} end model_attrs.default = {} model_attrs end |
#template_keys ⇒ Object
will generate forms based on the list of templates in the Array YourModel.template_keys. defaults to [‘all’]
125 126 127 128 129 130 131 |
# File 'lib/filch.rb', line 125 def template_keys if @model.methods.include?(:template_keys) @model.template_keys || ['all'] else ['all'] end end |