Module: Sunrise::WidgetsHelper
- Defined in:
- app/helpers/sunrise/widgets_helper.rb
Instance Method Summary collapse
- #render_accordion_widget(content, _args = {}) ⇒ Object
- #render_content_widget(widget, content, params = {}) ⇒ Object
- #render_widgets(content, params = {}) ⇒ Object
Instance Method Details
#render_accordion_widget(content, _args = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/helpers/sunrise/widgets_helper.rb', line 27 def (content, _args = {}) return content unless content.include?('[WIDGET:ACCORDION:START]') content.gsub(/\[WIDGET:ACCORDION:START\](.+)\[WIDGET:ACCORDION:END\]/m) do |text| items = [] text.gsub(/\[WIDGET:ACCORDION:ITEM:START\](.+?)\[WIDGET:ACCORDION:ITEM:END\]/m) do |item_text| items << { title: item_text.gsub(/.*\[WIDGET:ACCORDION:TITLE:START\](.+)\[WIDGET:ACCORDION:TITLE:END\].*/m, '\1'), content: item_text.gsub(/.*\[WIDGET:ACCORDION:CONTENT:START\](.+)\[WIDGET:ACCORDION:CONTENT:END\].*/m, '\1') } '' end render_cell(:widgets, :accordion, text: text, items: items) end end |
#render_content_widget(widget, content, params = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'app/helpers/sunrise/widgets_helper.rb', line 5 def (, content, params = {}) content.gsub(.regexp) do |sub| if .cells? render_cell :widgets, .code, matcher: .regexp.match(sub), params: params else render file: .file, locals: { matcher: .regexp.match(sub), params: params } end end.html_safe end |
#render_widgets(content, params = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/helpers/sunrise/widgets_helper.rb', line 15 def (content, params = {}) return if content.blank? ContentWidget.all.each do || content = (, content, params[.code]) end content = (content, params) content end |