Module: Pulitzer::ContentElementHelper
- Defined in:
- lib/pulitzer/content_element_helper.rb
Instance Method Summary collapse
- #cms_content_present?(element) ⇒ Boolean
- #render_body(element, options = {}) ⇒ Object
- #render_cms_element(element, options = {}) ⇒ Object
- #render_cms_html(element, options = {}) ⇒ Object
- #render_cms_image_path(element, options = {}) ⇒ Object
- #render_cms_section(version, section_name) ⇒ Object
- #render_cms_url(element, options = {}) ⇒ Object
- #render_image(element, options = {}) ⇒ Object
- #render_img_srcset(element, options = {}) ⇒ Object
- #render_picture_source(element, options = {}) ⇒ Object
- #render_video(element, options = {}) ⇒ Object
Instance Method Details
#cms_content_present?(element) ⇒ Boolean
4 5 6 |
# File 'lib/pulitzer/content_element_helper.rb', line 4 def cms_content_present?(element) element.present? && element.has_content? end |
#render_body(element, options = {}) ⇒ Object
44 45 46 |
# File 'lib/pulitzer/content_element_helper.rb', line 44 def render_body(element, = {}) content_tag(:span, element.body.html_safe, ) if element.body end |
#render_cms_element(element, options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/pulitzer/content_element_helper.rb', line 8 def render_cms_element(element, = {}) if element.image_type? render_image(element,) elsif element.video_type? render_video(element,) else render_body(element,) end end |
#render_cms_html(element, options = {}) ⇒ Object
48 49 50 |
# File 'lib/pulitzer/content_element_helper.rb', line 48 def render_cms_html(element, = {}) content_tag(:span, element.html, ) if element.html end |
#render_cms_image_path(element, options = {}) ⇒ Object
36 37 38 |
# File 'lib/pulitzer/content_element_helper.rb', line 36 def render_cms_image_path(element, = {}) element.image_url(:cms) end |
#render_cms_section(version, section_name) ⇒ Object
56 57 58 59 60 |
# File 'lib/pulitzer/content_element_helper.rb', line 56 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 |
#render_cms_url(element, options = {}) ⇒ Object
52 53 54 |
# File 'lib/pulitzer/content_element_helper.rb', line 52 def render_cms_url(element, ={}) element.body.html_safe if element.html end |
#render_image(element, options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/pulitzer/content_element_helper.rb', line 18 def render_image(element, = {}) if element.image? = {'data-pulitzer-element' => element.id} if .is_a? Hash .merge!() end image_tag element.image_url(:cms), end end |
#render_img_srcset(element, options = {}) ⇒ Object
32 33 34 |
# File 'lib/pulitzer/content_element_helper.rb', line 32 def render_img_srcset(element, = {}) content_tag(:img, nil, .merge(srcset: element.image_url(:cms))) end |
#render_picture_source(element, options = {}) ⇒ Object
28 29 30 |
# File 'lib/pulitzer/content_element_helper.rb', line 28 def render_picture_source(element, = {}) content_tag(:source, nil, .merge(srcset: element.image_url(:cms))) end |
#render_video(element, options = {}) ⇒ Object
40 41 42 |
# File 'lib/pulitzer/content_element_helper.rb', line 40 def render_video(element, = {}) content_tag(:iframe, nil, .merge(src: element.video_link)) if element.video_link end |