Module: Spina::Admin::PagesHelper
- Defined in:
- app/helpers/spina/admin/pages_helper.rb
Instance Method Summary collapse
- #build_structure_parts(name, item) ⇒ Object
- #flatten_nested_hash(hash) ⇒ Object
- #link_to_add_structure_item_fields(f, &block) ⇒ Object
- #option_label(part, value) ⇒ Object
- #page_ancestry_options(page) ⇒ Object
- #partable_partial_namespace(partable) ⇒ Object
- #partable_type_partial_namespace(partable_type) ⇒ Object
Instance Method Details
#build_structure_parts(name, item) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'app/helpers/spina/admin/pages_helper.rb', line 15 def build_structure_parts(name, item) structure = current_theme.structures.find { |structure| structure[:name] == name } return item.parts unless structure.present? structure[:structure_parts].map do |attributes| part = item.parts.where(name: attributes[:name]).first_or_initialize(attributes) part.partable = part.partable_type.constantize.new if part.partable.blank? part. = attributes[:options] part end end |
#flatten_nested_hash(hash) ⇒ Object
34 35 36 |
# File 'app/helpers/spina/admin/pages_helper.rb', line 34 def flatten_nested_hash(hash) hash.flat_map{|k, v| [k, *flatten_nested_hash(v)]} end |
#link_to_add_structure_item_fields(f, &block) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'app/helpers/spina/admin/pages_helper.rb', line 4 def link_to_add_structure_item_fields(f, &block) item = StructureItem.new fields = f.fields_for(:structure_items, item, child_index: item.object_id) do |builder| build_structure_parts(f.object.page_part.name, item) render("spina/admin/structure_items/fields", f: builder) end link_to '#', class: "add_structure_item_fields button button-link", data: {id: item.object_id, fields: fields.gsub("\n", "")} do icon('plus') end end |
#option_label(part, value) ⇒ Object
49 50 51 |
# File 'app/helpers/spina/admin/pages_helper.rb', line 49 def option_label(part, value) t(['options',part.name,value].compact.join('.')) end |
#page_ancestry_options(page) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'app/helpers/spina/admin/pages_helper.rb', line 38 def (page) pages = Spina::Page.active.regular_pages pages = pages.where.not(id: page.subtree.ids) unless page.new_record? || !page.methods.include?(:subtree) (flatten_nested_hash(pages.arrange(order: :position)).map do |page| next if page.depth >= Spina.config.max_page_depth - 1 = page.depth.zero? ? page. : " #{page.}".indent(page.depth, '-') [, page.id] end << [page.parent&., page&.parent_id].compact).uniq.compact end |
#partable_partial_namespace(partable) ⇒ Object
26 27 28 |
# File 'app/helpers/spina/admin/pages_helper.rb', line 26 def partable_partial_namespace(partable) partable_type_partial_namespace(partable.model_name.to_s) end |
#partable_type_partial_namespace(partable_type) ⇒ Object
30 31 32 |
# File 'app/helpers/spina/admin/pages_helper.rb', line 30 def partable_type_partial_namespace(partable_type) partable_type.tableize.sub(/\Aspina\//, '') end |