Module: TemplateHelper
- Defined in:
- app/helpers/template_helper.rb
Instance Method Summary collapse
- #error_for(object, attribute) ⇒ Object
- #k_check_box_tag(object, name, value = nil, checked = false, options = {}) ⇒ Object
- #k_content_tag(element, attribute = nil, object = nil, content_or_options_with_block = nil, options = {}, escape = true, &block) ⇒ Object
- #k_hidden_field_tag(name, value = nil, object = nil, delegate_to = nil, options = {}) ⇒ Object
- #k_select_tag(object, name, option_tags = nil, options = {}) ⇒ Object
- #k_text_field_tag(object, attribute, options = {}) ⇒ Object
- #k_try(object, method) ⇒ Object
- #kindred_model_data ⇒ Object
- #target(object) ⇒ Object
- #template(model: nil, collection: nil, target_uuid: nil, &block) ⇒ Object
Instance Method Details
#error_for(object, attribute) ⇒ Object
45 46 47 |
# File 'app/helpers/template_helper.rb', line 45 def error_for(object, attribute) tag("small", data: {error: "", k_uuid: '', attr: attribute}, class: "error") end |
#k_check_box_tag(object, name, value = nil, checked = false, options = {}) ⇒ Object
37 38 39 |
# File 'app/helpers/template_helper.rb', line 37 def k_check_box_tag(object, name, value=nil, checked = false, = {}) check_box_tag name, value, checked, .merge({data: { attr: name, k_uuid: k_try(object, :uuid), val: ""} }) end |
#k_content_tag(element, attribute = nil, object = nil, content_or_options_with_block = nil, options = {}, escape = true, &block) ⇒ Object
25 26 27 |
# File 'app/helpers/template_helper.rb', line 25 def k_content_tag(element, attribute = nil, object = nil, = nil, = {}, escape = true, &block) content_tag(element, nil, .merge({data: { attr: attribute, k_uuid: k_try(object, :uuid), val: ""} })) end |
#k_hidden_field_tag(name, value = nil, object = nil, delegate_to = nil, options = {}) ⇒ Object
29 30 31 |
# File 'app/helpers/template_helper.rb', line 29 def k_hidden_field_tag(name, value=nil, object=nil, delegate_to=nil, = {}) hidden_field_tag name, value, .merge({data: { attr: name, k_uuid: k_try(object, :uuid), val: value } }) end |
#k_select_tag(object, name, option_tags = nil, options = {}) ⇒ Object
41 42 43 |
# File 'app/helpers/template_helper.rb', line 41 def k_select_tag(object, name, = nil, = {}) select_tag name, , .merge(data: { attr: name, k_uuid: k_try(object, :uuid), val: "" }) end |
#k_text_field_tag(object, attribute, options = {}) ⇒ Object
33 34 35 |
# File 'app/helpers/template_helper.rb', line 33 def k_text_field_tag(object, attribute, ={}) text_field_tag attribute, nil, .merge({data: { attr: attribute, k_uuid: k_try(object, :uuid), val: "" } }) end |
#k_try(object, method) ⇒ Object
53 54 55 56 57 |
# File 'app/helpers/template_helper.rb', line 53 def k_try(object, method) unless object.is_a?(Symbol) object.try method end end |
#kindred_model_data ⇒ Object
49 50 51 |
# File 'app/helpers/template_helper.rb', line 49 def kindred_model_data "<div data-kindred-model style='display:none;'></div>".html_safe end |
#target(object) ⇒ Object
21 22 23 |
# File 'app/helpers/template_helper.rb', line 21 def target(object) "data-target data-target-uuid=" + k_try(object, :uuid).to_s end |
#template(model: nil, collection: nil, target_uuid: nil, &block) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/helpers/template_helper.rb', line 2 def template(model: nil, collection: nil, target_uuid: nil, &block) model_name = if collection.present? ActiveModel::Naming.singular(collection.first) else model end @kindred_hash ||= {} @kindred_hash.merge!({ model_name => { template: capture(&block), collection: collection, target_uuid: target_uuid, } }) self.controller.instance_variable_set(:@kindred_hash, @kindred_hash) return nil end |