Module: Sibu::PagesHelper
- Defined in:
- app/helpers/sibu/pages_helper.rb
Instance Method Summary collapse
- #available_docs ⇒ Object
- #available_links ⇒ Object
- #default_content(type) ⇒ Object
- #elements(id = nil) ⇒ Object
- #elt_id(elt) ⇒ Object
- #elts(id) ⇒ Object
- #embed(elt, opts = {}) ⇒ Object
- #empty_tag(elt, tag, type, opts = {}) ⇒ Object
- #form_label(elt, html_opts = {}, &block) ⇒ Object
- #grp(elt, opts = {}, &block) ⇒ Object
- #img(elt, opts = {}) ⇒ Object
- #interactive_map(elt, html_opts = {}) ⇒ Object
- #link(elt, html_opts = {}, &block) ⇒ Object
- #link_path(page_id) ⇒ Object
- #link_type(val) ⇒ Object
- #p(elt, opts = {}) ⇒ 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
- #sections_templates ⇒ Object
- #select_element(id) ⇒ Object
- #site_images ⇒ Object
- #widget(elt, widget_type, opts = {}, &block) ⇒ Object
Instance Method Details
#available_docs ⇒ Object
22 23 24 |
# File 'app/helpers/sibu/pages_helper.rb', line 22 def available_docs (Sibu::Document.for_user(sibu_user), :file_url, :file_name, @element["value"]) end |
#available_links ⇒ Object
18 19 20 |
# File 'app/helpers/sibu/pages_helper.rb', line 18 def available_links (@site.pages.order(:name), :id, :name, @element["value"]) end |
#default_content(type) ⇒ Object
202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'app/helpers/sibu/pages_helper.rb', line 202 def default_content(type) case type when "text" {"text" => DEFAULT_TEXT} when "link" {"value" => "", "text" => DEFAULT_TEXT} when "paragraph" {"text" => DEFAULT_PARAGRAPH} when "media" {"src" => DEFAULT_IMG} when "embed" {"code" => '<p>Contenu HTML personnalisé (iframe, etc...)</p>'} end end |
#elements(id = nil) ⇒ Object
63 64 65 66 |
# File 'app/helpers/sibu/pages_helper.rb', line 63 def elements(id = nil) items = id ? select_element(id)["elements"] : @sb_entity.find_or_init(*@sb_section)["elements"] items.blank? ? [{"id" => "el#{Time.current.to_i}"}] : items end |
#elt_id(elt) ⇒ Object
198 199 200 |
# File 'app/helpers/sibu/pages_helper.rb', line 198 def elt_id(elt) elt.is_a?(Hash) ? (elt["data-id"] || elt["id"]) : elt end |
#elts(id) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'app/helpers/sibu/pages_helper.rb', line 150 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 |
#embed(elt, opts = {}) ⇒ Object
114 115 116 117 118 119 |
# File 'app/helpers/sibu/pages_helper.rb', line 114 def (elt, opts = {}) defaults = {"id" => elt.is_a?(Hash) ? elt["id"] : elt, "code" => '<p>Contenu HTML personnalisé (iframe, etc...)</p>'} content = defaults.merge(elt.is_a?(Hash) ? elt : (select_element(elt) || {})) opts.merge!({data: {id: elt_id(elt), type: "embed"}}) if action_name != 'show' content_tag(:div, content_tag(:p, raw(content["code"]).html_safe), opts) end |
#empty_tag(elt, tag, type, opts = {}) ⇒ Object
93 94 95 96 97 98 99 |
# File 'app/helpers/sibu/pages_helper.rb', line 93 def empty_tag(elt, tag, type, opts = {}) repeat = opts.delete(:repeat) defaults = {"id" => elt.is_a?(Hash) ? elt["id"] : elt}.merge!(default_content(type)) opts = defaults.merge(opts) opts.merge!({data: {id: elt_id(elt), type: type, repeat: repeat}}) if action_name != 'show' content_tag(tag, nil, opts) end |
#form_label(elt, html_opts = {}, &block) ⇒ Object
101 102 103 104 105 106 |
# File 'app/helpers/sibu/pages_helper.rb', line 101 def form_label(elt, html_opts = {}, &block) defaults = {"id" => elt.is_a?(Hash) ? elt["id"] : elt, "text" => DEFAULT_TEXT} content = defaults.merge(elt.is_a?(Hash) ? elt : (select_element(elt) || {})) html_opts.merge!({data: {id: elt_id(elt), type: "text"}}) if action_name != 'show' content_tag(:label, raw(content["text"]).html_safe, html_opts) end |
#grp(elt, opts = {}, &block) ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'app/helpers/sibu/pages_helper.rb', line 83 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(*elts(elt), &block), opts) end |
#img(elt, opts = {}) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/helpers/sibu/pages_helper.rb', line 68 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) || {})) if action_name == 'show' content["src"] = ("/#{conf[:deployment_path]}" + content["src"]) if @online && conf[:deployment_path] else opts.merge!({data: {id: elt_id(elt), type: "media", repeat: repeat, size: size}}) end wrapper ? content_tag(wrapper, content_tag(:img, nil, content.except("id")), opts) : content_tag(:img, nil, content.except("id").merge(opts.stringify_keys) {|k, old, new| k == 'class' ? [old, new].join(' ') : new}) end |
#interactive_map(elt, html_opts = {}) ⇒ Object
191 192 193 194 195 196 |
# File 'app/helpers/sibu/pages_helper.rb', line 191 def interactive_map(elt, html_opts = {}) defaults = {"data-lat" => "45.68854", "data-lng" => "5.91587", "data-title" => DEFAULT_TEXT} content = defaults.merge(elt.is_a?(Hash) ? elt : (select_element(elt) || {"id" => elt})) html_opts.merge!({data: {id: elt_id(elt), type: "map"}}) if action_name != 'show' content_tag(:div, nil, content.merge(html_opts)) end |
#link(elt, html_opts = {}, &block) ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'app/helpers/sibu/pages_helper.rb', line 163 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.start_with?('http') content["href"] = val elsif val.to_s.start_with?('#') content["href"] = val content.delete("target") elsif val.to_s.start_with?('/') content["href"] = val elsif val.to_s.include?('@') content["href"] = 'mailto:' + 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 # Note : sends elts in given order if block_given? content_tag(:a, capture(*([raw(text)] + elts(elt)), &block), content.merge(html_opts).except("elements")) else content_tag(:a, raw(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 ? (request.host == conf[:host] ? site_page_path(@site.id, p.id) : (conf[:deployment_path] ? "/#{conf[:deployment_path]}/#{p.path}" : "/#{p.path}")) : "#" end |
#link_type(val) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/helpers/sibu/pages_helper.rb', line 26 def link_type(val) if val.blank? || /^\d+$/.match(val.to_s) 'internal' elsif Sibu::Document.for_user(sibu_user).map {|d| d.file_url}.include?(val) 'document' elsif val.to_s.start_with?('http', '#', '/') 'external' else 'email' end end |
#p(elt, opts = {}) ⇒ Object
47 48 49 50 51 52 53 |
# File 'app/helpers/sibu/pages_helper.rb', line 47 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 |
#sb ⇒ Object
55 56 57 |
# File 'app/helpers/sibu/pages_helper.rb', line 55 def sb self end |
#sb_page ⇒ Object Also known as: page
Note : see ActionView::OutputBuffer
122 123 124 125 |
# File 'app/helpers/sibu/pages_helper.rb', line 122 def sb_page @sb_entity = @page self end |
#sb_site ⇒ Object Also known as: site
129 130 131 132 |
# File 'app/helpers/sibu/pages_helper.rb', line 129 def sb_site @sb_entity = @site self end |
#section(id, tag, html_opts = {}, &block) ⇒ Object
136 137 138 139 140 |
# File 'app/helpers/sibu/pages_helper.rb', line 136 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
142 143 144 145 146 147 148 |
# File 'app/helpers/sibu/pages_helper.rb', line 142 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
10 11 12 |
# File 'app/helpers/sibu/pages_helper.rb', line 10 def sections_templates @site.site_template.available_sections end |
#select_element(id) ⇒ Object
59 60 61 |
# File 'app/helpers/sibu/pages_helper.rb', line 59 def select_element(id) @sb_entity.element(*@sb_section, id) end |
#site_images ⇒ Object
14 15 16 |
# File 'app/helpers/sibu/pages_helper.rb', line 14 def site_images Sibu::Image.for_user(sibu_user).uniq end |
#widget(elt, widget_type, opts = {}, &block) ⇒ Object
108 109 110 111 112 |
# File 'app/helpers/sibu/pages_helper.rb', line 108 def (elt, , opts = {}, &block) content = elt.is_a?(Hash) ? elt : (select_element(elt) || {}) opts.merge!({data: {id: elt_id(elt), type: "widget_#{.to_s.split('::').last.underscore}"}}) if action_name != 'show' content_tag(:div, capture(.new(content), &block), opts) end |