Sha256: aa373a3119079d90aea4c38118b850ea911e3be70d8622461633a04bd6a7330e

Contents?: true

Size: 1.68 KB

Versions: 16

Compression:

Stored size: 1.68 KB

Contents

# frozen_string_literal: true

require 'redcarpet'

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, options = {})
    renderer = WCC::Contentful::App::MarkdownRenderer.new(
      options
    )
    html_to_render = renderer.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(/&lt;br\/?&gt;/, '<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

16 entries across 16 versions & 1 rubygems

Version Path
wcc-contentful-app-1.7.1 app/helpers/wcc/contentful/app/section_helper.rb
wcc-contentful-app-1.7.0 app/helpers/wcc/contentful/app/section_helper.rb
wcc-contentful-app-1.6.2 app/helpers/wcc/contentful/app/section_helper.rb
wcc-contentful-app-1.6.1 app/helpers/wcc/contentful/app/section_helper.rb
wcc-contentful-app-1.6.0 app/helpers/wcc/contentful/app/section_helper.rb
wcc-contentful-app-1.5.1 app/helpers/wcc/contentful/app/section_helper.rb
wcc-contentful-app-1.5.0 app/helpers/wcc/contentful/app/section_helper.rb
wcc-contentful-app-1.5.0.rc1 app/helpers/wcc/contentful/app/section_helper.rb
wcc-contentful-app-1.4.0 app/helpers/wcc/contentful/app/section_helper.rb
wcc-contentful-app-1.4.0.rc3 app/helpers/wcc/contentful/app/section_helper.rb
wcc-contentful-app-1.4.0.rc2 app/helpers/wcc/contentful/app/section_helper.rb
wcc-contentful-app-1.3.2 app/helpers/wcc/contentful/app/section_helper.rb
wcc-contentful-app-1.4.0.rc1 app/helpers/wcc/contentful/app/section_helper.rb
wcc-contentful-app-1.3.1 app/helpers/wcc/contentful/app/section_helper.rb
wcc-contentful-app-1.3.0 app/helpers/wcc/contentful/app/section_helper.rb
wcc-contentful-app-1.2.1 app/helpers/wcc/contentful/app/section_helper.rb