Class: MediumExport::Content

Inherits:
Object
  • Object
show all
Defined in:
lib/middleman-medium_export/content.rb

Defined Under Namespace

Classes: Image

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(article:, template: nil) ⇒ Content

Returns a new instance of Content.



8
9
10
11
# File 'lib/middleman-medium_export/content.rb', line 8

def initialize(article:, template: nil)
  @article = article
  @template = template
end

Instance Attribute Details

#articleObject (readonly)

Returns the value of attribute article.



6
7
8
# File 'lib/middleman-medium_export/content.rb', line 6

def article
  @article
end

#templateObject (readonly)

Returns the value of attribute template.



6
7
8
# File 'lib/middleman-medium_export/content.rb', line 6

def template
  @template
end

Instance Method Details

#htmlObject



13
14
15
16
17
# File 'lib/middleman-medium_export/content.rb', line 13

def html
  @content ||= begin
    template ? body_with_template : article.body
  end
end

#local_imagesObject



31
32
33
34
35
36
37
38
# 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

#markdownObject



19
20
21
# File 'lib/middleman-medium_export/content.rb', line 19

def markdown
  @markdown ||= File.read(article.source_file)
end

#tagsObject



27
28
29
# File 'lib/middleman-medium_export/content.rb', line 27

def tags
  article.tags
end

#titleObject



23
24
25
# File 'lib/middleman-medium_export/content.rb', line 23

def title
  article.title
end