Class: Trifle::Docs::Harvester::Markdown::Conveyor

Inherits:
Conveyor
  • Object
show all
Defined in:
lib/trifle/docs/harvester/markdown.rb

Instance Attribute Summary

Attributes inherited from Conveyor

#cache, #file, #namespace, #url

Instance Method Summary collapse

Methods inherited from Conveyor

#data, #initialize

Constructor Details

This class inherits a constructor from Trifle::Docs::Harvester::Conveyor

Instance Method Details

#contentObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/trifle/docs/harvester/markdown.rb', line 29

def content
  @content = nil unless cache

  @content ||= Redcarpet::Markdown.new(
    Render.new(with_toc_data: true),
    fenced_code_blocks: true,
    disable_indented_code_blocks: true,
    footnotes: true
  ).render(data.sub(/^---(.*?)---(\s*)/m, ''))
rescue StandardError => e
  puts "Markdown: Failed to parse CONTENT for #{file}: #{e}"
end

#default_metaObject



42
43
44
45
46
47
48
49
# File 'lib/trifle/docs/harvester/markdown.rb', line 42

def default_meta
  {
    'url' => "/#{[namespace, url].compact.join('/')}",
    'breadcrumbs' => url.split('/'),
    'toc' => toc,
    'updated_at' => ::File.stat(file).mtime
  }
end

#metaObject



51
52
53
54
55
56
57
58
59
# File 'lib/trifle/docs/harvester/markdown.rb', line 51

def meta
  @meta = nil unless cache

  @meta ||= (YAML.safe_load(data[/^---(.*?)---(\s*)/m].to_s) || {}).merge(default_meta)
rescue StandardError => e
  puts "Markdown: Failed to parse META for #{file}: #{e}"

  default_meta
end

#tocObject



61
62
63
64
65
66
67
68
69
# File 'lib/trifle/docs/harvester/markdown.rb', line 61

def toc
  @toc = nil unless cache

  @toc ||= Redcarpet::Markdown.new(
    Redcarpet::Render::HTML_TOC
  ).render(data.sub(/^---(.*?)---(\s*)/m, ''))
rescue StandardError => e
  puts "Markdown: Failed to parse TOC for #{file}: #{e}"
end