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_button(element, options = {}) ⇒ Object
- #render_clickable_element(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(element, options = {}) ⇒ Object
- #render_img_srcset(element, options = {}) ⇒ Object
- #render_link(element, options = {}) ⇒ Object
- #render_picture_source(element, options = {}) ⇒ Object
- #render_video_element(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
62 63 64 |
# File 'lib/pulitzer/content_element_helper.rb', line 62 def render_body(element, = {}) content_tag(:span, element.body.html_safe, ) if element.body end |
#render_button(element, options = {}) ⇒ Object
54 55 56 |
# File 'lib/pulitzer/content_element_helper.rb', line 54 def (element, = {}) content_tag(:button, element.title, .merge('data-pulitzer-action' => element.content, class: element.style.css_class_name)) end |
#render_clickable_element(element, options = {}) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/pulitzer/content_element_helper.rb', line 42 def render_clickable_element(element, = {}) if element.custom_type? (element, ) else render_link(element, ) end end |
#render_cms_element(element, options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/pulitzer/content_element_helper.rb', line 8 def render_cms_element(element, = {}) if element.image_type? render_image_element(element,) elsif element.video_type? render_video_element(element,) elsif element.clickable_type? render_clickable_element(element,) else render_body(element,) end end |
#render_cms_html(element, options = {}) ⇒ Object
66 67 68 |
# File 'lib/pulitzer/content_element_helper.rb', line 66 def render_cms_html(element, = {}) content_tag(:span, element.html, ) if element.html end |
#render_cms_image_path(element, options = {}) ⇒ Object
38 39 40 |
# File 'lib/pulitzer/content_element_helper.rb', line 38 def render_cms_image_path(element, = {}) element.image_url(:cms) end |
#render_cms_section(version, section_name) ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'lib/pulitzer/content_element_helper.rb', line 74 def render_cms_section(version, section_name) section = version.section(section_name) fail SectionMissingError.new("Version #{version.inspect} is missing a section called '#{section_name}' but it's trying to render it.") unless section section.partials.collect do |partial| if partial.has_display? render partial: partial.full_view_path, locals: {partial: partial} end end.join.html_safe end |
#render_cms_url(element, options = {}) ⇒ Object
70 71 72 |
# File 'lib/pulitzer/content_element_helper.rb', line 70 def render_cms_url(element, ={}) element.body.html_safe if element.html end |
#render_image_element(element, options = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/pulitzer/content_element_helper.rb', line 20 def render_image_element(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
34 35 36 |
# File 'lib/pulitzer/content_element_helper.rb', line 34 def render_img_srcset(element, = {}) content_tag(:img, nil, .merge(srcset: element.image_url(:cms))) end |
#render_link(element, options = {}) ⇒ Object
50 51 52 |
# File 'lib/pulitzer/content_element_helper.rb', line 50 def render_link(element, = {}) content_tag(:a, element.title, .merge(href: element.content, class: element.style.css_class_name)) end |
#render_picture_source(element, options = {}) ⇒ Object
30 31 32 |
# File 'lib/pulitzer/content_element_helper.rb', line 30 def render_picture_source(element, = {}) content_tag(:source, nil, .merge(srcset: element.image_url(:cms))) end |
#render_video_element(element, options = {}) ⇒ Object
58 59 60 |
# File 'lib/pulitzer/content_element_helper.rb', line 58 def render_video_element(element, = {}) content_tag(:iframe, nil, .merge(src: element.video_link)) if element.video_link end |