Module: Pulitzer::ContentElementHelper

Defined in:
lib/pulitzer/content_element_helper.rb

Instance Method Summary collapse

Instance Method Details

#render_body(element, options = {}) ⇒ Object



38
39
40
# File 'lib/pulitzer/content_element_helper.rb', line 38

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

#render_cms_element(element, options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/pulitzer/content_element_helper.rb', line 4

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

#render_cms_html(element, options = {}) ⇒ Object



42
43
44
# File 'lib/pulitzer/content_element_helper.rb', line 42

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

#render_cms_image_path(element, options = {}) ⇒ Object



30
31
32
# File 'lib/pulitzer/content_element_helper.rb', line 30

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

#render_cms_section(post_type, section_name) ⇒ Object



50
51
52
53
54
# File 'lib/pulitzer/content_element_helper.rb', line 50

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

#render_cms_url(element, options = {}) ⇒ Object



46
47
48
# File 'lib/pulitzer/content_element_helper.rb', line 46

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

#render_image(element, options = {}) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/pulitzer/content_element_helper.rb', line 14

def render_image(element,options = {})
  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

#render_img_srcset(element, options = {}) ⇒ Object



26
27
28
# File 'lib/pulitzer/content_element_helper.rb', line 26

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

#render_picture_source(element, options = {}) ⇒ Object



22
23
24
# File 'lib/pulitzer/content_element_helper.rb', line 22

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

#render_video(element, options = {}) ⇒ Object



34
35
36
# File 'lib/pulitzer/content_element_helper.rb', line 34

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