Module: TemplateHelper

Defined in:
app/helpers/template_helper.rb

Instance Method Summary collapse

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, options = {})
  check_box_tag name, value, checked, options.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 (element, attribute = nil, object = nil, content_or_options_with_block = nil, options = {}, escape = true, &block)
  (element, nil, options.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, options = {})
  hidden_field_tag name, value, options.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, option_tags = nil, options = {})
  select_tag name, option_tags, options.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, options={})
  text_field_tag attribute, nil, options.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_dataObject



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