Module: Kea::ApplicationHelper

Defined in:
app/helpers/kea/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#body_classObject



7
8
9
# File 'app/helpers/kea/application_helper.rb', line 7

def body_class
  controller.class.to_s.gsub('Controller', '').underscore.dasherize.gsub('/', '-')
end

#body_idObject



3
4
5
# File 'app/helpers/kea/application_helper.rb', line 3

def body_id
  content_for?(:body_id) ? content_for(:body_id) : [body_class, params[:action]].join('-')
end

#cache_json(object, path = nil, options = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'app/helpers/kea/application_helper.rb', line 24

def cache_json(object, path = nil, options = {})
  unless path
    path = polymorphic_path(object)
  end

  content = json_for(object, options)

  content_for :json_cache, "window.app.cache['#{path}'] = #{content};\n".html_safe
end

#json_for(target, options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/helpers/kea/application_helper.rb', line 11

def json_for(target, options = {})
  options[:scope]       ||= self
  options[:url_options] ||= url_options
  
  serializer = options[:serializer] || target.active_model_serializer
  
  if target.is_a?(ActiveRecord::Relation)
    ActiveModel::ArraySerializer.new(target, each_serializer: serializer, scope: self).to_json
  else
    serializer.new(target, options).to_json
  end
end

#knockout_template(name, partial: nil, &block) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/helpers/kea/application_helper.rb', line 34

def knockout_template(name, partial: nil, &block)
  content_for :knockout_templates do
    if partial
       :script, type: "text/html", id: name do
        render partial: partial
      end
    else
       :script, type: "text/html", id: name do
        capture(&block)
      end
    end
  end
end

#overlay_template(name, partial: nil, &block) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/helpers/kea/application_helper.rb', line 48

def overlay_template(name, partial: nil, &block)
  content_for :knockout_templates do
    if partial
       :script, type: "text/html", id: name, "data-bind" => "overlayTemplate: '#{name}'" do
        render partial: partial
      end
    else
       :script, type: "text/html", id: name, "data-bind" => "overlayTemplate: '#{name}'" do
        capture(&block)
      end
    end
  end
end