Module: PagesCore::Admin::PageBlocksHelper

Included in:
Admin::PagesHelper
Defined in:
app/helpers/pages_core/admin/page_blocks_helper.rb

Instance Method Summary collapse

Instance Method Details

#page_block_field(form, block_name, block_options) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/helpers/pages_core/admin/page_blocks_helper.rb', line 6

def page_block_field(form, block_name, block_options)
  labelled_field(
    if block_options[:type] == :select
      page_block_select(form, block_name, block_options)
    else
      page_block_text_field(form, block_name, block_options)
    end,
    block_options[:title],
    errors: form.object.errors[block_name],
    description: block_options[:description]
  )
end

#page_block_select(form, block_name, block_options) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'app/helpers/pages_core/admin/page_blocks_helper.rb', line 19

def page_block_select(form, block_name, block_options)
  opts = localize_page_select_options(form, block_options)
  opts = opts.call if opts.is_a?(Proc)
  opts = opts.map { |v| [v, v] } unless nested_array?(opts)
  opts = ([["", nil]] + opts).uniq

  value = form.object.send(block_name)
  opts << [value, value] unless opts.map(&:last).include?(value)

  form.send(:select, block_name, opts)
end

#page_block_text_field(form, block_name, block_options) ⇒ Object



31
32
33
34
35
36
37
# File 'app/helpers/pages_core/admin/page_blocks_helper.rb', line 31

def page_block_text_field(form, block_name, block_options)
  form.send(
    block_options[:size] == :field ? :text_field : :rich_text_area,
    block_name,
    page_block_field_options(block_options)
  )
end