Module: WCC::Contentful::App::SectionHelper
- Extended by:
- SectionHelper
- Included in:
- SectionHelper
- Defined in:
- app/helpers/wcc/contentful/app/section_helper.rb
Instance Method Summary collapse
- #markdown(text, options = {}) ⇒ Object
- #render_section(section, index) ⇒ Object
- #safe_line_break(text, options = {}) ⇒ Object
- #section_css_name(section) ⇒ Object
- #section_id(section) ⇒ Object
- #section_styles(section) ⇒ Object
- #section_template_name(section) ⇒ Object
- #split_content_for_mobile_view(visible_count, speakers) ⇒ Object
Instance Method Details
#markdown(text, options = {}) ⇒ Object
| 37 38 39 40 41 42 43 44 45 46 | # File 'app/helpers/wcc/contentful/app/section_helper.rb', line 37 def markdown(text, = {}) renderer = WCC::Contentful::App::MarkdownRenderer.new( ) html_to_render = renderer.markdown(text) content_tag(:div, CGI.unescapeHTML(html_to_render).html_safe, class: 'formatted-content') end | 
#render_section(section, index) ⇒ Object
| 8 9 10 | # File 'app/helpers/wcc/contentful/app/section_helper.rb', line 8 def render_section(section, index) render('components/section', section: section, index: index) end | 
#safe_line_break(text, options = {}) ⇒ Object
| 48 49 50 51 52 53 54 55 56 57 | # File 'app/helpers/wcc/contentful/app/section_helper.rb', line 48 def safe_line_break(text, = {}) return unless text.present? text = CGI.escapeHTML(text) text = text.gsub(/\&(nbsp|vert|\#\d+);/, '&\1;') .gsub(/\<br\/?\>/, '<br/>') content_tag(:span, text.html_safe, { class: 'safe-line-break' }.merge()) end | 
#section_css_name(section) ⇒ Object
| 16 17 18 | # File 'app/helpers/wcc/contentful/app/section_helper.rb', line 16 def section_css_name(section) section_template_name(section).dasherize end | 
#section_id(section) ⇒ Object
| 32 33 34 35 | # File 'app/helpers/wcc/contentful/app/section_helper.rb', line 32 def section_id(section) title = section.try(:bookmark_title) || section.try(:title) CGI.escape(title.gsub(/\W+/, '-')) if title.present? end | 
#section_styles(section) ⇒ Object
| 20 21 22 23 24 25 26 27 28 29 30 | # File 'app/helpers/wcc/contentful/app/section_helper.rb', line 20 def section_styles(section) section_styles = ['section-' + section_css_name(section)] if styles = section.try(:styles) section_styles.push(styles.map { |style| style.downcase.gsub(/[^\w]/, '-') }) elsif style = section.try(:style) section_styles.push(style.downcase.gsub(/[^\w]/, '-')) else section_styles.push('default') end section_styles end | 
#section_template_name(section) ⇒ Object
| 12 13 14 | # File 'app/helpers/wcc/contentful/app/section_helper.rb', line 12 def section_template_name(section) section.class.name.demodulize.underscore.sub('section_', '') end | 
#split_content_for_mobile_view(visible_count, speakers) ⇒ Object
| 59 60 61 62 63 | # File 'app/helpers/wcc/contentful/app/section_helper.rb', line 59 def split_content_for_mobile_view(visible_count, speakers) visible_count = visible_count.to_i speakers = [*speakers].compact [speakers.shift(visible_count), speakers] end |