Module: Puffer::Helpers::PufferHelper
- Defined in:
- lib/puffer/helpers/puffer_helper.rb
Instance Method Summary collapse
- #puffer_groups_navigation(namespace = puffer_namespace) ⇒ Object
- #puffer_resources_navigation(namespace = puffer_namespace, group = configuration.group) ⇒ Object
- #puffer_scopes_navigation ⇒ Object
- #render_field(field, record) ⇒ Object
- #render_head(field) ⇒ Object
Instance Method Details
#puffer_groups_navigation(namespace = puffer_namespace) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/puffer/helpers/puffer_helper.rb', line 13 def namespace = puffer_namespace Rails.application.routes.resources_tree.roots.select {|node| node.scope == namespace}.uniq_by(&:group).each do |resource_node| if resource_node.group path = send("#{resource_node.scope}_#{resource_node.url_segment}_path") current = resource.resource_node ? resource.root.resource_node.group == resource_node.group : false yield resource_node.group, path, current end end end |
#puffer_resources_navigation(namespace = puffer_namespace, group = configuration.group) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/puffer/helpers/puffer_helper.rb', line 24 def namespace = puffer_namespace, group = configuration.group Rails.application.routes.resources_tree.roots.select {|node| node.scope == namespace && node.group == group}.each do |resource_node| title = resource_node.controller.model.model_name.human path = send("#{resource_node.scope}_#{resource_node.url_segment}_path") current = resource.resource_node ? resource.root.resource_node == resource_node : false yield title, path, current end end |
#puffer_scopes_navigation ⇒ Object
7 8 9 10 11 |
# File 'lib/puffer/helpers/puffer_helper.rb', line 7 def Rails.application.routes.resources_tree.map(&:scope).uniq.each do |scope| yield scope, send("#{scope}_root_path"), scope == puffer_namespace end end |
#render_field(field, record) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/puffer/helpers/puffer_helper.rb', line 44 def render_field field, record if field.[:render] case field.[:render] when Symbol then res = send(field.[:render], record) when Proc then res = field.[:render].bind(self).call(record) else '' end else res = record.call_chain(field.to_s) end unless field.native? url = edit_polymorphic_path [resource.scope, record.call_chain(field.path)] rescue nil res = link_to res, url if url end res end |
#render_head(field) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/puffer/helpers/puffer_helper.rb', line 34 def render_head field head = [] if field.column head.push link_to_unless(puffer_filters.puffer_order == field.to_s, "▼", resource.collection_path(:page => params[:page], Puffer::Filters.model_name.param_key => puffer_filters.query.merge(:puffer_order => field))) head.push link_to_unless(puffer_filters.puffer_order == [field, :desc].join(' '), "▲", resource.collection_path(:page => params[:page], Puffer::Filters.model_name.param_key => puffer_filters.query.merge(:puffer_order => [field, :desc].join(' ')))) end head.push field.human head.join(' ').html_safe end |