Sha256: 3602d990df66f4ce3328a89f066c8a717dfb5cd0a334229e8bd58d1c38e8514c

Contents?: true

Size: 1.74 KB

Versions: 1

Compression:

Stored size: 1.74 KB

Contents

module Pulitzer
  module ContentElementHelper

    def cms_content_present?(element)
      element.present? && element.has_content?
    end

    def render_cms_element(element,options = {})
      if element.image_type?
        render_image(element,options)
      elsif element.video_type?
        render_video(element,options)
      else
        render_body(element,options)
      end
    end

    def render_image(element,options = {})
      if element.image?
        pulitzer_options = {'data-pulitzer-element' => element.id}
        if options.is_a? Hash
          pulitzer_options.merge!(options)
        end
        image_tag element.image_url(:cms), pulitzer_options
      end
    end

    def render_picture_source(element,options = {})
      content_tag(:source, nil, options.merge(srcset: element.image_url(:cms)))
    end

    def render_img_srcset(element,options = {})
      content_tag(:img, nil, options.merge(srcset: element.image_url(:cms)))
    end

    def render_cms_image_path(element,options = {})
      element.image_url(:cms)
    end

    def render_video(element, options = {})
      content_tag(:iframe, nil, options.merge(src: element.video_link)) if element.video_link
    end

    def render_body(element, options = {})
      content_tag(:span, element.body.html_safe, options) if element.body
    end

    def render_cms_html(element, options = {})
      content_tag(:span, element.html, options) if element.html
    end

    def render_cms_url(element, options ={})
       element.body.html_safe if element.html
    end

    def render_cms_section(version, section_name)
      version.section(section_name).partials.collect do |partial|
        render partial: partial.full_view_path, locals: {partial: partial}
      end.join.html_safe
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pulitzer-0.13.0 lib/pulitzer/content_element_helper.rb