Module: Kea::ApplicationHelper
- Defined in:
- app/helpers/kea/application_helper.rb
Instance Method Summary collapse
- #body_class ⇒ Object
- #body_id ⇒ Object
- #cache_json(object, path = nil, options = {}) ⇒ Object
- #json_for(target, options = {}) ⇒ Object
- #knockout_template(name, partial: nil, &block) ⇒ Object
- #overlay_template(name, partial: nil, &block) ⇒ Object
Instance Method Details
#body_class ⇒ Object
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_id ⇒ Object
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, = {}) unless path path = polymorphic_path(object) end content = json_for(object, ) 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, = {}) [:scope] ||= self [:url_options] ||= serializer = [: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, ).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 content_tag :script, type: "text/html", id: name do render partial: partial end else content_tag :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 (name, partial: nil, &block) content_for :knockout_templates do if partial content_tag :script, type: "text/html", id: name, "data-bind" => "overlayTemplate: '#{name}'" do render partial: partial end else content_tag :script, type: "text/html", id: name, "data-bind" => "overlayTemplate: '#{name}'" do capture(&block) end end end end |