Module: PagesHelper

Included in:
PagesController
Defined in:
app/helpers/pages_helper.rb

Constant Summary collapse

SIMPLE_TAGS =
%w(h1 h2 h3 h4 h5 h6 a span label)

Instance Method Summary collapse

Instance Method Details

#content_for(id) ⇒ Object



50
51
52
# File 'app/helpers/pages_helper.rb', line 50

def content_for(id)
  @page.content[id.to_s] if @page
end

#editable(id, tag = :div, options = {}, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/helpers/pages_helper.rb', line 11

def editable(id, tag=:div, options={}, &block)
  content        = content_for(id)
  type           = options[:type] || find_type_for_tag(tag)

  if tag.is_a?(Hash)
    options = tag if tag.is_a?(Hash)
    tag = :div
  end

  options[:id] = id

  set_mercury_options(options, type)

  if type == :simple
    if content
      (tag, content, options.except(:type))
    else
      (tag, options.except(:type), &block)
    end
  else
    (tag, options.except(:type), false) do
      raw(content || (block.call if block))
    end
  end
end

#editable_image(id, default = nil) ⇒ Object



37
38
39
40
41
42
43
44
# File 'app/helpers/pages_helper.rb', line 37

def editable_image(id, default=nil)
  source  = content_for(id) || default
  options = {id: id}

  set_mercury_options(options, :image)

  image_tag(source, options)
end

#find_type_for_tag(tag) ⇒ Object



61
62
63
64
65
66
67
# File 'app/helpers/pages_helper.rb', line 61

def find_type_for_tag(tag)
  if SIMPLE_TAGS.include?(tag.to_s)
    :simple
  else
    :full
  end
end

#format_content(content) ⇒ Object



4
5
6
7
8
9
# File 'app/helpers/pages_helper.rb', line 4

def format_content(content)
  content.reduce({}) do |hash, (key, data)|
    hash[key.to_s] = data[:value] || data[:attributes][:src]
    hash
  end
end

#set_mercury_options(options, type) ⇒ Object



54
55
56
57
58
59
# File 'app/helpers/pages_helper.rb', line 54

def set_mercury_options(options, type)
  if params[:mercury_frame]
    options[:data] ||= {}
    options[:data][:mercury] = type
  end
end

#template_path(path) ⇒ Object



69
70
71
72
73
74
75
76
77
# File 'app/helpers/pages_helper.rb', line 69

def template_path(path)
  return 'index' if path.blank?

  if template_exists?(path + '/index', %w(pages))
    path + '/index'
  else
    path
  end
end

#titleObject



46
47
48
# File 'app/helpers/pages_helper.rb', line 46

def title
  editable(:title, :h1) { @page.content[:title] }
end