Module: Trifle::Docs::Helper::MarkdownLayout
- Defined in:
- lib/trifle/docs/helper/markdown_layout.rb
Class Method Summary collapse
- .derive_title_from_url(url) ⇒ Object
-
.navigation_toc(sitemap, depth: 0) ⇒ Object
rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity.
- .render(meta:, raw_content:) ⇒ Object
Class Method Details
.derive_title_from_url(url) ⇒ Object
40 41 42 43 44 |
# File 'lib/trifle/docs/helper/markdown_layout.rb', line 40 def derive_title_from_url(url) return 'Untitled' if url.nil? || url.empty? url.split('/').last.to_s.gsub(/[-_]/, ' ').split.map(&:capitalize).join(' ') end |
.navigation_toc(sitemap, depth: 0) ⇒ Object
rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/trifle/docs/helper/markdown_layout.rb', line 22 def (sitemap, depth: 0) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity return '' unless sitemap.is_a?(Hash) sitemap.keys.reject { |k| k == '_meta' }.sort.map do |key| node = sitemap[key] = node['_meta'] || {} title = ['title'] || derive_title_from_url(['url'] || key) url = ['url'] || "/#{key}" indent = ' ' * depth children = node.reject { |child_key, _| child_key == '_meta' } [ "#{indent}- [#{title}](#{url})", (children, depth: depth + 1) ].reject(&:empty?).join("\n") end.join("\n") end |
.render(meta:, raw_content:) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/trifle/docs/helper/markdown_layout.rb', line 9 def render(meta:, raw_content:) lines = [] title = ['title'] || derive_title_from_url(['url']) lines << "# #{title}" lines << '' lines << '## Content' lines << raw_content.to_s.strip lines << '' lines.join("\n") end |