Class: Playbook::HTMLBlockCode
- Inherits:
-
Redcarpet::Render::HTML
- Object
- Redcarpet::Render::HTML
- Playbook::HTMLBlockCode
- Includes:
- ActionView::Helpers::AssetTagHelper
- Defined in:
- app/helpers/playbook/redcarpet_helper.rb
Instance Method Summary collapse
- #header(title, level) ⇒ Object
- #image(link, title, alt_text) ⇒ Object
- #list(contents, _list_type) ⇒ Object
- #preprocess(full_document) ⇒ Object
Instance Method Details
#header(title, level) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'app/helpers/playbook/redcarpet_helper.rb', line 73 def header(title, level) if level == 7 @headers ||= [] permalink = title.gsub(/\W+/, "-") if @headers.include?(permalink) permalink += "_1" loop do break unless @headers.include?(permalink) permalink.gsub!(/\_(\d+)$/, "_#{Regexp.last_match(1).to_i + 1}") end end @headers << permalink %(\n<a name="#{permalink}" class="markdown-header-anchor anchor" href="##{permalink}"><span class="fa fa-link anchor-icon"></span></a><h#{level} id=\"#{permalink}\">#{title}</h#{level}>\n) else %(\n<h#{level}>#{title}</h#{level}>\n) end end |
#image(link, title, alt_text) ⇒ Object
92 93 94 |
# File 'app/helpers/playbook/redcarpet_helper.rb', line 92 def image(link, title, alt_text) image_tag(link, title: title, alt: alt_text, class: "imageloader lazyload") end |
#list(contents, _list_type) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'app/helpers/playbook/redcarpet_helper.rb', line 116 def list(contents, _list_type) @contents = contents @list_items = contents.split("\n") if @list_items[0].include?("[do]") || @list_items[0].include?("[dont]") @element_items = [] @list_items.each do |item, _index| item.gsub(%r{\<li>(.*)\</li>}) do @element_items.push(Regexp.last_match(1)) end end # Doing both because we could have either/both # clean up @dont_items, @trash_items_dont = @element_items.partition { |x, _i| x.include? "[dont]" } @do_items, @trash_items_do = @element_items.partition { |x, _i| x.include? "[do]" } @do_list = [] @do_items.each do |item, _index| @do_list.push("<li>#{item.sub('[do] ', '')}</li>") end @do_list = "<ul class='uix-ruleset do-list'>#{@do_list.join('')}</ul>" @dont_list = [] @dont_items.each do |item, _index| @dont_list.push("<li>#{item.sub('[dont] ', '')}</li>") end @dont_list = "<ul class='uix-ruleset dont-list'>#{@dont_list.join('')}</ul>" "<div class='row uix-ruleset-block'><div class='col-sm-6'>#{@do_list}</div><div class='col-sm-6'>#{@dont_list}</div></div>" else @contents end end |
#preprocess(full_document) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'app/helpers/playbook/redcarpet_helper.rb', line 96 def preprocess(full_document) full_document.gsub(/\[component (.*)\]/) do @string = Regexp.last_match(1) @default_height = "160" @attr = ["", @default_height] # Set src from attributes @string.gsub(/src="(.*?)"/) do @attr[0] = Regexp.last_match(1) end # Set height from attributes @string.gsub(/height="(.*?)"/) do @attr[1] = (Regexp.last_match(1) || @default_height) end %(\n<div class="uix-component-frame"><iframe scrolling="no" id="component-preview" src="#{@attr[0]}" width="100%" height="#{@attr[1]}"></iframe><a href="#{@attr[0]}" target="_blank" class="uix-component-link">View component</a></div>\n) end end |