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:, sitemap:) ⇒ Object
rubocop:disable Metrics/MethodLength.
Class Method Details
.derive_title_from_url(url) ⇒ Object
43 44 45 46 47 |
# File 'lib/trifle/docs/helper/markdown_layout.rb', line 43 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
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/trifle/docs/helper/markdown_layout.rb', line 25 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:, sitemap:) ⇒ Object
rubocop:disable Metrics/MethodLength
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/trifle/docs/helper/markdown_layout.rb', line 9 def render(meta:, raw_content:, sitemap:) # rubocop:disable Metrics/MethodLength lines = [] title = ['title'] || derive_title_from_url(['url']) lines << "# #{title}" lines << '' lines << '## Navigation' lines << (sitemap) lines << '' lines << '## Content' lines << raw_content.to_s.strip lines << '' lines.join("\n") end |