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
41
# 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,
    tables: true
  ).render(data.sub(/^---(.*?)---(\s*)/m, ''))
rescue StandardError => e
  puts "Markdown: Failed to parse CONTENT for #{file}: #{e}"
end

#default_metaObject



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

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

#metaObject



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

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

#raw_contentObject



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

def raw_content
  @raw_content = nil unless cache

  @raw_content ||= data.sub(/^---(.*?)---(\s*)/m, '').strip
rescue StandardError => e
  puts "Markdown: Failed to load RAW CONTENT for #{file}: #{e}"
end

#tocObject



70
71
72
73
74
75
76
77
78
# File 'lib/trifle/docs/harvester/markdown.rb', line 70

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