class MediumExport::Content
Constants
- Image
Attributes
article[R]
template[R]
Public Class Methods
new(article:, template: nil)
click to toggle source
# File lib/middleman-medium_export/content.rb, line 8 def initialize(article:, template: nil) @article = article @template = template end
Public Instance Methods
html()
click to toggle source
# File lib/middleman-medium_export/content.rb, line 13 def html @content ||= begin template ? body_with_template : article.body end end
local_images()
click to toggle source
# File lib/middleman-medium_export/content.rb, line 31 def local_images @images ||= Nokogiri::HTML(html).search('img').map do |img| src = img.attributes['src'].value next if src.start_with?('http') Image.new(src, File.join(source_dir, src)) end.compact end
markdown()
click to toggle source
# File lib/middleman-medium_export/content.rb, line 19 def markdown @markdown ||= File.read(article.source_file) end
title()
click to toggle source
# File lib/middleman-medium_export/content.rb, line 23 def title article.title end
Private Instance Methods
app()
click to toggle source
# File lib/middleman-medium_export/content.rb, line 55 def app @app ||= article.blog_data.controller.app end
body_with_template()
click to toggle source
# File lib/middleman-medium_export/content.rb, line 42 def body_with_template template_html = template_context.render(nil, template.path, { locals: {}}) template.position == :top ? "#{template_html}#{article.body}" : "#{article.body}#{template_html}" end
source_dir()
click to toggle source
# File lib/middleman-medium_export/content.rb, line 47 def source_dir @source_dir ||= app.source_dir end
template_context()
click to toggle source
# File lib/middleman-medium_export/content.rb, line 51 def template_context @template_context ||= app.generic_template_context end