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
- #content_for(id) ⇒ Object
- #editable(id, tag = :div, options = {}, &block) ⇒ Object
- #editable_image(id, default = nil) ⇒ Object
- #find_type_for_tag(tag) ⇒ Object
- #format_content(content) ⇒ Object
- #set_mercury_options(options, type) ⇒ Object
- #template_path(path) ⇒ Object
- #title ⇒ Object
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, ={}, &block) content = content_for(id) type = [:type] || find_type_for_tag(tag) if tag.is_a?(Hash) = tag if tag.is_a?(Hash) tag = :div end [:id] = id (, type) if type == :simple if content content_tag(tag, content, .except(:type)) else content_tag(tag, .except(:type), &block) end else content_tag(tag, .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 = {id: id} (, :image) image_tag(source, ) 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 (, type) if params[:mercury_frame] [:data] ||= {} [: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 |
#title ⇒ Object
46 47 48 |
# File 'app/helpers/pages_helper.rb', line 46 def title editable(:title, :h1) { @page.content[:title] } end |