Module: Redditor::ApplicationHelper

Defined in:
app/helpers/redditor/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#real_name(content_block) ⇒ Object


5
6
7
# File 'app/helpers/redditor/application_helper.rb', line 5

def real_name content_block
  content_block.class.name.underscore.sub('redditor/', '')
end

#redditor_form(f, &block) ⇒ Object


13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/helpers/redditor/application_helper.rb', line 13

def redditor_form(f, &block)
  id = "#{real_name(f.object)}_"
  id += f.object.id.nil? ? "#{f.object.object_id}" : "#{f.object.id}"
  f.object_name.sub!(/\[\d*\]/, "[#{f.object.object_id}]") if f.object.object_id.present?
  index = if f.object.object_id.present?
    f.object.object_id
  else
    f.index
  end
  data = { 'object-name' => f.object_name, 'object-id' => index }
  (:div, capture(&block), class: 'redditor__form', id: id, data: data)
end

#redditor_slider_block_kind(f, slider_block) ⇒ Object


26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/helpers/redditor/application_helper.rb', line 26

def redditor_slider_block_kind f, slider_block
  if @content_block
    kind = params.try(:[], 'content_block').try(:[], 'kind')
  else
    params_array = f.object_name.split(/(?:[\[\]]{1,2})/)
    par = params
    params_array.each do |p|
      par = par.try(:[], p)
    end
    kind = par.try(:[], 'kind')
  end
  return kind == 'description'
end

#redditor_validate(f) ⇒ Object


9
10
11
# File 'app/helpers/redditor/application_helper.rb', line 9

def redditor_validate f
  render "redditor/admin/validate", {f: f} 
end