Module: RubberRing::CmsHelper

Defined in:
app/helpers/rubber_ring/cms_helper.rb

Instance Method Summary collapse

Instance Method Details

#build_key_prefix(page_content, key) ⇒ Object



101
102
103
# File 'app/helpers/rubber_ring/cms_helper.rb', line 101

def build_key_prefix(page_content, key)
  "#{page_content.id}_#{key}_#{page_content.template}"
end


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/helpers/rubber_ring/cms_helper.rb', line 37

def compose_link(block, options, page)
  key = options[:key]
  content_value = nil
  content_value = page.content[key] unless page.content.nil?
  href_attribute = nil
  href_attribute = page.content["#{key}_href"] unless page.content.nil?

   = {
    :class     => options[:class],
    :id        => options[:id],
    :href      => href_attribute || options[:href]
  }
  ['data-cms'] = key if page and page.edit_mode?

  content_value = capture(&block) if content_value.nil?
  return , content_value
end

#editable_field(tag, options = {}, page, &block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/helpers/rubber_ring/cms_helper.rb', line 4

def editable_field(tag, options = {}, page, &block)
  key = options[:key]
  content_value = nil
  content_value = page.content[key] unless page.content.nil?

   = {
    :class            => options[:class],
    :id               => options[:id]
  }

  if page and page.edit_mode?
    ['data-cms']        = key
    ['contenteditable'] = 'true'
  end

  # if no content passed from @content (view - controller - model)
  # this means it is not yet in database and we will create tag with
  # content which is defined in a block of this editable_field helper
  content_value = capture(&block) if content_value.nil?

  (tag, raw(content_value), )
end

#editable_image(options = {}, page) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/helpers/rubber_ring/cms_helper.rb', line 55

def editable_image(options = {}, page)
  key = options[:key]
  image_source = nil
  image_source = page.content[key] unless page.content.nil?

   = {
    :class     => "rubber_ring_image #{options[:class]}",
    :src       => image_source || options[:src]
  }
  ['data-cms'] = key if page and page.edit_mode?

  unless options[:width].nil?
    .merge!({width: options[:width]})
  end

  unless options[:height].nil?
    .merge!({height: options[:height]})
  end

  tag(:img, )
end


31
32
33
34
35
# File 'app/helpers/rubber_ring/cms_helper.rb', line 31

def editable_link(options = {}, page, &block)
  , content_value = compose_link(block, options, page)
  ['contenteditable'] = 'true' if page and page.edit_mode?
  (:a, raw(content_value), )
end

#template(templates, options = {}, page) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'app/helpers/rubber_ring/cms_helper.rb', line 77

def template(templates, options = {}, page)
  key = options[:key]
  page_templates = page.page_templates.where(key: key)

  # if nothing is saved yet, use templates from helper defined in erb
  # convert array of hashes to open struct which will provide template and index methods like AR
  if page_templates.empty?
    page_templates = templates.inject([]) { |pt, t| pt << OpenStruct.new(t) }
    grouped_templates = page_templates
    from_db = false
  else
    grouped_templates = page_templates.group(:template)
    from_db = true
  end

  concat(render 'rubber_ring/template_control', key: key, template_types: grouped_templates, from_db: from_db)

   = { class: "#{options[:wrap_class]}" }
  ['data-cms'] = key if page and page.edit_mode?
  built_templates = build_templates(page_templates, page, key)

  concat((options[:wrap_element], raw(built_templates), ))
end

#title(page, &block) ⇒ Object



27
28
29
# File 'app/helpers/rubber_ring/cms_helper.rb', line 27

def title(page, &block)
  editable_field(:span, {key: 'page_title'}, page, &block)
end