Class: Releaf::Content::Nodes::FormBuilder
- Inherits:
-
Builders::FormBuilder
- Object
- Builders::FormBuilder
- Releaf::Content::Nodes::FormBuilder
- Defined in:
- app/builders/releaf/content/nodes/form_builder.rb
Instance Method Summary collapse
- #content_builder_class ⇒ Object
- #field_names ⇒ Object
- #item_position_options ⇒ Object
- #item_position_select_options ⇒ Object
- #node_fields ⇒ Object
- #render_content_fields_block ⇒ Object
- #render_content_fields_block? ⇒ Boolean
- #render_content_type ⇒ Object
- #render_item_position ⇒ Object
- #render_locale ⇒ Object
- #render_locale_options ⇒ Object
- #render_node_fields_block ⇒ Object
- #render_parent_id ⇒ Object
- #render_slug ⇒ Object
- #slug_base_url ⇒ Object
- #slug_button ⇒ Object
- #slug_link ⇒ Object
Instance Method Details
#content_builder_class ⇒ Object
34 35 36 |
# File 'app/builders/releaf/content/nodes/form_builder.rb', line 34 def content_builder_class Releaf::Content::Nodes::ContentFormBuilder end |
#field_names ⇒ Object
3 4 5 |
# File 'app/builders/releaf/content/nodes/form_builder.rb', line 3 def field_names %w(node_fields_block content_fields_block) end |
#item_position_options ⇒ Object
71 72 73 74 75 76 |
# File 'app/builders/releaf/content/nodes/form_builder.rb', line 71 def { include_blank: false, select_options: (, object.item_position) } end |
#item_position_select_options ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'app/builders/releaf/content/nodes/form_builder.rb', line 78 def after_text = t("After") list = [[t("First"), 0]] order_nodes = object.self_and_siblings.reorder(:item_position).to_a order_nodes.each_with_index do |node, index| next if node == object if index == order_nodes.size - 1 next_position = node.item_position + 1 else next_position = order_nodes[index + 1].item_position end list.push [after_text + ' ' + node.name, next_position ] end list end |
#node_fields ⇒ Object
7 8 9 |
# File 'app/builders/releaf/content/nodes/form_builder.rb', line 7 def node_fields [:parent_id, :name, :content_type, :slug, :item_position, :active, :locale] end |
#render_content_fields_block ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'app/builders/releaf/content/nodes/form_builder.rb', line 25 def render_content_fields_block return unless render_content_fields_block? tag(:div, class: ["section", "content-fields"]) do fields_for(:content, object.content, builder: content_builder_class) do |form| form.releaf_fields(form.field_names.to_a) end end end |
#render_content_fields_block? ⇒ Boolean
21 22 23 |
# File 'app/builders/releaf/content/nodes/form_builder.rb', line 21 def render_content_fields_block? object.content_class.respond_to?(:acts_as_node_fields) end |
#render_content_type ⇒ Object
49 50 51 52 53 54 |
# File 'app/builders/releaf/content/nodes/form_builder.rb', line 49 def render_content_type input = {disabled: true, value: t(object.content_type.underscore, scope: 'admin.content_types')} releaf_text_field(:content_type, input: input) do hidden_field_tag(:content_type, params[:content_type]) if object.new_record? end end |
#render_item_position ⇒ Object
67 68 69 |
# File 'app/builders/releaf/content/nodes/form_builder.rb', line 67 def render_item_position releaf_item_field(:item_position, options: ) end |
#render_locale ⇒ Object
38 39 40 |
# File 'app/builders/releaf/content/nodes/form_builder.rb', line 38 def render_locale releaf_item_field(:locale, options: ) if object.locale_selection_enabled? end |
#render_locale_options ⇒ Object
42 43 44 45 46 47 |
# File 'app/builders/releaf/content/nodes/form_builder.rb', line 42 def { select_options: I18n.available_locales, include_blank: object.locale.blank? } end |
#render_node_fields_block ⇒ Object
11 12 13 14 15 |
# File 'app/builders/releaf/content/nodes/form_builder.rb', line 11 def render_node_fields_block tag(:div, class: ["section", "node-fields"]) do releaf_fields(node_fields) end end |
#render_parent_id ⇒ Object
17 18 19 |
# File 'app/builders/releaf/content/nodes/form_builder.rb', line 17 def render_parent_id hidden_field(:parent_id) if object.new_record? end |
#render_slug ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'app/builders/releaf/content/nodes/form_builder.rb', line 56 def render_slug url = url_for(controller: controller.controller_path, action: "generate_url", parent_id: object.parent_id, id: object.id) input = { data: {'generator-url' => url} } releaf_field(:slug, input: input) do << wrapper(slug_link, class: "link") end end |
#slug_base_url ⇒ Object
98 99 100 |
# File 'app/builders/releaf/content/nodes/form_builder.rb', line 98 def slug_base_url "#{request.protocol}#{request.host_with_port}#{object.parent.try(:path)}" + (object.trailing_slash_for_path? ? "" : "/") end |
#slug_button ⇒ Object
110 111 112 |
# File 'app/builders/releaf/content/nodes/form_builder.rb', line 110 def (nil, "keyboard-o", title: t('Suggest slug'), class: "secondary generate") end |
#slug_link ⇒ Object
102 103 104 105 106 107 108 |
# File 'app/builders/releaf/content/nodes/form_builder.rb', line 102 def slug_link link_to(object.path) do safe_join do [slug_base_url, tag(:span, object.slug), (object.trailing_slash_for_path? ? "/" : "")] end end end |