Sha256: b4b383067fcea70974814db8131cd45fb7d7d9bc176ed3df89067b506f83b2c3
Contents?: true
Size: 1.7 KB
Versions: 1
Compression:
Stored size: 1.7 KB
Contents
# frozen_string_literal: true require 'redcarpet' require '../wcc-contentful-app/lib/wcc/contentful/app/markdown_renderer' module WCC::Contentful::App::SectionHelper extend self def render_section(section, index) render('components/section', section: section, index: index) end def section_template_name(section) section.class.name.demodulize.underscore.sub('section_', '') end def section_css_name(section) section_template_name(section).dasherize end 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 def section_id(section) title = section.try(:bookmark_title) || section.try(:title) CGI.escape(title.gsub(/\W+/, '-')) if title.present? end def markdown(text) html_to_render = WCC::Contentful::App::MarkdownRenderer.new.markdown(text) content_tag(:div, CGI.unescapeHTML(html_to_render).html_safe, class: 'formatted-content') end def safe_line_break(text, options = {}) 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(options)) end def split_content_for_mobile_view(visible_count, speakers) visible_count = visible_count.to_i speakers = [*speakers].compact [speakers.shift(visible_count), speakers] end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
wcc-contentful-app-1.0.6 | app/helpers/wcc/contentful/app/section_helper.rb |