Module: Pageflow::WidgetsHelper

Defined in:
app/helpers/pageflow/widgets_helper.rb

Instance Method Summary collapse

Instance Method Details

#present_widgets_css_class(entry) ⇒ Object


19
20
21
22
23
# File 'app/helpers/pageflow/widgets_helper.rb', line 19

def present_widgets_css_class(entry)
  entry.widgets.resolve.map do |widget|
    "widget_#{widget.widget_type.name}_present"
  end.join(' ')
end

#render_widget_head_fragments(entry, options = {}) ⇒ Object


3
4
5
6
7
8
9
# File 'app/helpers/pageflow/widgets_helper.rb', line 3

def render_widget_head_fragments(entry, options = {})
  fragments = entry.widgets.resolve(options).map do |widget|
    widget.widget_type.render_head_fragment(self, entry)
  end

  safe_join(fragments)
end

#render_widgets(entry, options = {}) ⇒ Object


11
12
13
14
15
16
17
# File 'app/helpers/pageflow/widgets_helper.rb', line 11

def render_widgets(entry, options = {})
  fragments = entry.widgets.resolve(options).map do |widget|
    widget.widget_type.render(self, entry)
  end

  safe_join(fragments)
end

#widget_types_collection_for_role(role) ⇒ Object


37
38
39
40
41
# File 'app/helpers/pageflow/widgets_helper.rb', line 37

def widget_types_collection_for_role(role)
  Pageflow.config.widget_types.find_all_by_role(role).each_with_object({}) do |widget_type, result|
    result[I18n.t(widget_type.translation_key)] = widget_type.name
  end
end

#widget_types_json_seedsObject


25
26
27
28
29
30
31
32
33
34
35
# File 'app/helpers/pageflow/widgets_helper.rb', line 25

def widget_types_json_seeds
  Pageflow.config.widget_types.each_with_object({}) do |widget_type, result|
    widget_type.roles.each do |role|
      result[role] ||= []
      result[role] << {
        name: widget_type.name,
        translationKey: widget_type.translation_key
      }
    end
  end.to_json.html_safe
end