Module: Sibu::PagesHelper
- Defined in:
- app/helpers/sibu/pages_helper.rb
Instance Method Summary collapse
- #available_docs ⇒ Object
- #available_links ⇒ Object
- #elements(id = nil) ⇒ Object
- #elt_id(elt) ⇒ Object
- #elts(id) ⇒ Object
- #embed(elt, 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.shared + 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 |
#elements(id = nil) ⇒ Object
61 62 63 64 |
# File 'app/helpers/sibu/pages_helper.rb', line 61 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
174 175 176 |
# File 'app/helpers/sibu/pages_helper.rb', line 174 def elt_id(elt) elt.is_a?(Hash) ? (elt["data-id"] || elt["id"]) : elt end |
#elts(id) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'app/helpers/sibu/pages_helper.rb', line 133 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
99 100 101 102 103 104 |
# File 'app/helpers/sibu/pages_helper.rb', line 99 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 |
#form_label(elt, html_opts = {}, &block) ⇒ Object
86 87 88 89 90 91 |
# File 'app/helpers/sibu/pages_helper.rb', line 86 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
76 77 78 79 80 81 82 83 84 |
# File 'app/helpers/sibu/pages_helper.rb', line 76 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
66 67 68 69 70 71 72 73 74 |
# File 'app/helpers/sibu/pages_helper.rb', line 66 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 = {}) ⇒ Object
167 168 169 170 171 172 |
# File 'app/helpers/sibu/pages_helper.rb', line 167 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
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'app/helpers/sibu/pages_helper.rb', line 146 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?('/') 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 # 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) : "/#{p.path}") : "#" end |
#link_type(val) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'app/helpers/sibu/pages_helper.rb', line 26 def link_type(val) if val.blank? || val == '#' || /^\d+$/.match(val.to_s) 'internal' elsif (Sibu::Document.shared + Sibu::Document.for_user(sibu_user)).map {|d| d.file_url}.include?(val) 'document' else 'external' end end |
#p(elt, opts = {}) ⇒ Object
45 46 47 48 49 50 51 |
# File 'app/helpers/sibu/pages_helper.rb', line 45 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
53 54 55 |
# File 'app/helpers/sibu/pages_helper.rb', line 53 def sb self end |
#sb_page ⇒ Object Also known as: page
Note : see ActionView::OutputBuffer
107 108 109 110 |
# File 'app/helpers/sibu/pages_helper.rb', line 107 def sb_page @sb_entity = @page self end |
#sb_site ⇒ Object Also known as: site
113 114 115 116 |
# File 'app/helpers/sibu/pages_helper.rb', line 113 def sb_site @sb_entity = @site self end |
#section(id, tag, html_opts = {}, &block) ⇒ Object
119 120 121 122 123 |
# File 'app/helpers/sibu/pages_helper.rb', line 119 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
125 126 127 128 129 130 131 |
# File 'app/helpers/sibu/pages_helper.rb', line 125 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_templates end |
#select_element(id) ⇒ Object
57 58 59 |
# File 'app/helpers/sibu/pages_helper.rb', line 57 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.empty] + Sibu::Image.shared + Sibu::Image.for_user(sibu_user)).uniq end |
#widget(elt, widget_type, opts = {}, &block) ⇒ Object
93 94 95 96 97 |
# File 'app/helpers/sibu/pages_helper.rb', line 93 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 |