Module: Sibu::PagesHelper
- Defined in:
- app/helpers/sibu/pages_helper.rb
Instance Method Summary collapse
- #available_links ⇒ Object
- #elements(id = nil) ⇒ Object
- #elt_id(elt) ⇒ Object
- #elts(id) ⇒ Object
- #grp(elt, opts = {}, &block) ⇒ Object
- #img(elt, opts = {}) ⇒ Object
- #interactive_map(elt, html_opts = {}, &block) ⇒ Object
- #is_internal(val) ⇒ Object
- #link(elt, html_opts = {}, &block) ⇒ Object
- #link_path(page_id) ⇒ Object
- #p(elt, opts = {}) ⇒ Object
- #page_languages ⇒ Object
- #page_templates ⇒ Object
- #sb ⇒ Object
-
#sb_page ⇒ Object
(also: #page)
Note : see ActionView::OutputBuffer.
- #sb_site ⇒ Object (also: #site)
- #section(id, tag, html_opts = {}, &block) ⇒ Object
-
#sections(id, tag, html_opts = {}, &block) ⇒ Object
Todo : voir comment générer une section par défaut en mode liste des sections et insertion d’un bloc avec sections.
- #sections_templates ⇒ Object
- #select_element(id) ⇒ Object
- #site_images ⇒ Object
Instance Method Details
#available_links ⇒ Object
27 28 29 |
# File 'app/helpers/sibu/pages_helper.rb', line 27 def available_links (@site.pages, :id, :name, @element["value"]) end |
#elements(id = nil) ⇒ Object
60 61 62 63 |
# File 'app/helpers/sibu/pages_helper.rb', line 60 def elements(id = nil) items = id ? select_element(id)["elements"] : @sb_entity.find_or_init(*@sb_section)["elements"] items.blank? ? [{"id" => "#{@sb_section.last}*"}] : items end |
#elt_id(elt) ⇒ Object
153 154 155 |
# File 'app/helpers/sibu/pages_helper.rb', line 153 def elt_id(elt) elt.is_a?(Hash) ? (elt["data-id"] || elt["id"]) : elt end |
#elts(id) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'app/helpers/sibu/pages_helper.rb', line 113 def elts(id) items = [] element_id = elt_id(id) elemnts = @sb_entity.elements(*(@sb_section + element_id.split("|")).uniq) if elemnts elemnts.each do |e| e["data-id"] = [element_id, e["id"]].join("|") items << e end end items.blank? ? [{"id" => element_id.split("|").last, "data-id" => [element_id, "#{element_id}0"].join("|")}] : items end |
#grp(elt, opts = {}, &block) ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'app/helpers/sibu/pages_helper.rb', line 75 def grp(elt, opts = {}, &block) wrapper = opts.delete(:wrapper) || :div repeat = opts.delete(:repeat) children = opts.delete(:children) defaults = {"id" => elt.is_a?(Hash) ? elt["id"] : elt} opts = defaults.merge(opts) opts.merge!({data: {id: elt_id(elt), type: "group", repeat: repeat, children: children}}) if action_name != 'show' content_tag(wrapper, capture(self, &block), opts) end |
#img(elt, opts = {}) ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'app/helpers/sibu/pages_helper.rb', line 65 def img(elt, opts = {}) wrapper = opts.delete(:wrapper) repeat = opts.delete(:repeat) size = opts.delete(:size) defaults = {"id" => elt.is_a?(Hash) ? elt["id"] : elt, "src" => DEFAULT_IMG} content = defaults.merge(elt.is_a?(Hash) ? elt : (select_element(elt) || {})) opts.merge!({data: {id: elt_id(elt), type: "media", repeat: repeat, size: size}}) if action_name != 'show' wrapper ? content_tag(wrapper, content_tag(:img, nil, content.except("id")), opts) : content_tag(:img, nil, content.except("id").merge(opts)) end |
#interactive_map(elt, html_opts = {}, &block) ⇒ Object
146 147 148 149 150 151 |
# File 'app/helpers/sibu/pages_helper.rb', line 146 def interactive_map(elt, html_opts = {}, &block) defaults = {"data-lat" => "45.68854", "data-lng" => "5.91587", "data-title" => DEFAULT_TEXT} content = elt.is_a?(Hash) ? defaults.merge(elt) : (select_element(elt) || {"id" => elt}).merge(defaults) html_opts.merge!({data: {id: elt_id(elt), type: "map"}}) if action_name != 'show' content_tag(:div, nil, content.merge(html_opts)) end |
#is_internal(val) ⇒ Object
31 32 33 |
# File 'app/helpers/sibu/pages_helper.rb', line 31 def is_internal(val) val.blank? || val == '#' || /^\d{1,3}$/.match(val.to_s) end |
#link(elt, html_opts = {}, &block) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'app/helpers/sibu/pages_helper.rb', line 126 def link(elt, html_opts = {}, &block) repeat = html_opts.delete(:repeat) children = html_opts.delete(:children) defaults = {"id" => elt_id(elt), "value" => "", "text" => DEFAULT_TEXT} content = defaults.merge(elt.is_a?(Hash) ? elt : (select_element(elt) || {})) val = content.delete("value") || "" text = content.delete("text"); html_opts.merge!({data: {id: elt_id(elt), type: "link", repeat: repeat, children: children}}) if action_name != 'show' if val.to_s.include?('http') content["href"] = val else content["href"] = @links.keys.include?(val.to_s) ? (action_name == 'show' ? link_path(val) : site_page_edit_content_path(@site.id, val)) : '#' end if block_given? content_tag(:a, content.merge(html_opts).except("elements"), &block) else content_tag(:a, text, content.merge(html_opts).except("elements")) end end |
#link_path(page_id) ⇒ Object
5 6 7 8 |
# File 'app/helpers/sibu/pages_helper.rb', line 5 def link_path(page_id) p = @site.page_by_id(page_id) p ? (@site.domain.blank? ? site_page_path(@site.id, p.id) : "/#{p.path}") : "#" end |
#p(elt, opts = {}) ⇒ Object
44 45 46 47 48 49 50 |
# File 'app/helpers/sibu/pages_helper.rb', line 44 def p(elt, opts = {}) repeat = opts.delete(:repeat) defaults = {"id" => elt.is_a?(Hash) ? elt["id"] : elt, "text" => DEFAULT_PARAGRAPH} content = defaults.merge(elt.is_a?(Hash) ? elt : (select_element(elt) || {})) opts.merge!({data: {id: elt_id(elt), repeat: repeat, type: "paragraph"}}) if action_name != 'show' content_tag(:div, content_tag(:p, raw(content["text"]).html_safe), opts) end |
#page_languages ⇒ Object
19 20 21 |
# File 'app/helpers/sibu/pages_helper.rb', line 19 def page_languages [['Français', 'fr'], ['Anglais', 'en']] end |
#page_templates ⇒ Object
10 11 12 |
# File 'app/helpers/sibu/pages_helper.rb', line 10 def page_templates [['Accueil', 'home'], ['Offre', 'offer'], ['Galerie', 'gallery'], ['Destination', 'destination'], ['Mentions légales', 'text']] end |
#sb ⇒ Object
52 53 54 |
# File 'app/helpers/sibu/pages_helper.rb', line 52 def sb self end |
#sb_page ⇒ Object Also known as: page
Note : see ActionView::OutputBuffer
86 87 88 89 |
# File 'app/helpers/sibu/pages_helper.rb', line 86 def sb_page @sb_entity = @page self end |
#sb_site ⇒ Object Also known as: site
92 93 94 95 |
# File 'app/helpers/sibu/pages_helper.rb', line 92 def sb_site @sb_entity = @site self end |
#section(id, tag, html_opts = {}, &block) ⇒ Object
98 99 100 101 102 |
# File 'app/helpers/sibu/pages_helper.rb', line 98 def section(id, tag, html_opts = {}, &block) @sb_section = [id] opts = action_name != 'show' ? html_opts.merge({"data-sb-id" => id, "data-sb-repeat" => @sb_entity != @site, "data-sb-entity" => @sb_entity == @site ? 'site' : 'page'}) : html_opts content_tag(tag, capture(self, &block), opts) end |
#sections(id, tag, html_opts = {}, &block) ⇒ Object
Todo : voir comment générer une section par défaut en mode liste des sections et insertion d’un bloc avec sections
105 106 107 108 109 110 111 |
# File 'app/helpers/sibu/pages_helper.rb', line 105 def sections(id, tag, html_opts = {}, &block) (@sb_entity.find_or_init(id)["elements"].map.with_index do |elt, i| @sb_section = [id, elt["id"]] opts = action_name != 'show' ? html_opts.merge({"data-sb-id" => @sb_section.join('|'), "data-sb-repeat" => true, "data-sb-entity" => @sb_entity == @site ? 'site' : 'page'}) : html_opts content_tag(tag, capture(self, i, &block), opts) end).join('').html_safe end |
#sections_templates ⇒ Object
14 15 16 17 |
# File 'app/helpers/sibu/pages_helper.rb', line 14 def sections_templates Dir.glob(File.join(Rails.root, "app/views/shared/#{@site.site_template.path}/*.erb")).map {|f| f.split('/').last} .map {|f| f[1..-1].gsub('.html.erb', '')}.select {|f| f != 'site'}.map {|f| {"id" => "sibu_template_#{f}", "template" => f}} end |
#select_element(id) ⇒ Object
56 57 58 |
# File 'app/helpers/sibu/pages_helper.rb', line 56 def select_element(id) @sb_entity.element(*@sb_section, id) end |