Module: LadyJosephine::SirTrevorHelper
- Included in:
- Renderer::SirTrevorRenderer
- Defined in:
- app/helpers/lady_josephine/sir_trevor_helper.rb
Instance Method Summary collapse
- #component_attributes_for(block, classes) ⇒ Object
- #image_with_srcset_tag(srcset, sizes, options = {}) ⇒ Object
- #protocol_relative(path) ⇒ Object
- #render_sir_trevor(json, without_notes = true, image_type = 'large') ⇒ Object
- #sir_trevor_markdown(text) ⇒ Object
- #sir_trevor_video(block) ⇒ Object
Instance Method Details
#component_attributes_for(block, classes) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/helpers/lady_josephine/sir_trevor_helper.rb', line 25 def component_attributes_for(block, classes) classes = [classes].flatten(1).map do |klass| if klass.is_a? Hash key = block[klass.keys.first.to_s] [klass.values.first, key].reject(&:blank?).join("--") else klass end end if block["note"] != "yes" {"data-article_component" => block["uuid"], "notes_count" => block["references_count"], "ng-class" => "{'is-active': active}", "class" => classes} else {} end end |
#image_with_srcset_tag(srcset, sizes, options = {}) ⇒ Object
47 48 49 50 51 |
# File 'app/helpers/lady_josephine/sir_trevor_helper.rb', line 47 def image_with_srcset_tag(srcset, sizes, = {}) src = protocol_relative path_to_image(srcset.split(', ').first.split(' ').first) tag "img", .merge(:src => src, :srcset => srcset, :sizes => sizes) end |
#protocol_relative(path) ⇒ Object
53 54 55 |
# File 'app/helpers/lady_josephine/sir_trevor_helper.rb', line 53 def protocol_relative(path) path.gsub(/\Ahttps?:/, '') end |
#render_sir_trevor(json, without_notes = true, image_type = 'large') ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/helpers/lady_josephine/sir_trevor_helper.rb', line 6 def render_sir_trevor(json, without_notes = true, image_type = 'large') if hash = parse_sir_trevor(json) first_definition_block = true hash.map { |object| if object["data"]["note"] != "yes" || !without_notes if object["type"] == "definition" = {first: first_definition_block} first_definition_block = false render_sir_trevor_block(object, image_type, ) else render_sir_trevor_block(object, image_type) end end }.compact.join.html_safe else '' end end |
#sir_trevor_markdown(text) ⇒ Object
42 43 44 45 |
# File 'app/helpers/lady_josephine/sir_trevor_helper.rb', line 42 def sir_trevor_markdown(text) markdown = ::Redcarpet::Markdown.new(LadyJosephine::Redcarpet::CustomMarkdownFormatter.new(escape_html: true, safe_links_only: true)) markdown.render(text).html_safe end |
#sir_trevor_video(block) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'app/helpers/lady_josephine/sir_trevor_helper.rb', line 57 def sir_trevor_video(block) if block["source"] == "youtube" = { frameborder: 0, wmode: nil, autoplay: false, hide_related: true, showinfo: 0, color: "white", modestbranding: 1, iv_load_policy: 3, theme: "light", fullscreen: block["note"] == "yes" ? 0 : 1 } src = "//www.youtube.com/embed/#{block['remote_id']}" params = [] params << "wmode=#{options[:wmode]}" if [:wmode] params << "autoplay=1" if [:autoplay] params << "rel=0" if [:hide_related] params << "showinfo=#{options[:showinfo]}" if [:showinfo] params << "modestbranding=#{options[:modestbranding]}" if [:modestbranding] params << "color=#{options[:color]}" if [:color] params << "iv_load_policy=#{options[:iv_load_policy]}" if [:iv_load_policy] params << "theme=#{options[:theme]}" if [:theme] params << "fs=#{options[:fullscreen]}" if [:fullscreen] src += "?#{params.join '&'}" unless params.empty? %{<div class="ratio-container youtube-block" data-youtube-url=#{src} data-video-id=#{block['remote_id']}></div>} elsif block["source"] == "vimeo" = { show_title: false, show_byline: false, show_portrait: false, frameborder: 0 } frameborder = [:frameborder] || 0 src = "//player.vimeo.com/video/#{block['remote_id']}" params = [] params << "title=0" unless [:show_title] params << "byline=0" if [:autoplay] params << "portrait=0" if [:hide_related] src += "?#{params.join '&'}" unless params.empty? %{<div class="ratio-container vimeo-block" data-vimeo-url=#{src} data-video-id=#{block['remote_id']}></div>} else "" end end |