lib/brief/document/transformer.rb in brief-1.11.8 vs lib/brief/document/transformer.rb in brief-1.11.9

- old
+ new

@@ -1,5 +1,8 @@ +# The Document Transformer allows for special usage of markdown +# link and image embedding syntax. This lets us piggy back on these syntax +# and use them as include directives to embed other documents, or SVG diagrams. module Brief class Document::Transformer attr_reader :document, :fragment def initialize(fragment, document) @@ -10,10 +13,14 @@ def all transform_dynamic_links inline_svg_content end + def briefcase + @briefcase ||= document.briefcase + end + def inline_svg_content inline_svg_images.each do |img| src = img['src'].to_s if src.match(/=/) @@ -21,11 +28,11 @@ else value = src end begin - if asset = document.briefcase.find_asset(value) + if asset = briefcase.find_asset(value) img.replace("<div class='svg-wrapper'>#{ asset.read }</div>") end rescue nil end @@ -37,18 +44,18 @@ attribute, value = node['href'].to_s.split("=") instruction, strategy = node.text.to_s.split(':') if instruction == "link" && attribute == "path" begin - link_to_doc = document.briefcase.document_at(value) + link_to_doc = briefcase.document_at(value) if link_to_doc.exist? text = link_to_doc.send(strategy) node.inner_html = text - node['href'] = "brief://#{ link_to_doc.path }" + node['href'] = briefcase.get_href_for("brief://#{ link_to_doc.path }") else - node['href'] = "brief://document-not-found" + node['href'] = briefcase.get_href_for("brief://document-not-found") end rescue nil end end @@ -57,10 +64,10 @@ include_link_elements.each do |node| attribute, value = node['href'].to_s.split("=") instruction, strategy = node.text.to_s.split(':') if instruction == "include" && attribute == "path" - include_doc = document.briefcase.document_at(value) + include_doc = briefcase.document_at(value) replacement = nil if strategy == "raw_content" replacement = include_doc.unwrapped_html