Sha256: d7eb7388a915a764610052bd25d5d5ad81b7607905b81d94b225c468635fe35f
Contents?: true
Size: 1018 Bytes
Versions: 2
Compression:
Stored size: 1018 Bytes
Contents
module Headmin module DocumentationHelper def extract_documentation(text) # Get content inside documentation block starts_with = '<% documentation do %>\n' ends_with = '\n<% end %>' between = text[/#{starts_with}(.*?)#{ends_with}/m, 1] # Remove leading whitespaces from each line between.lines.map { |line| line.sub(' ', '') }.join end def markdown_to_html(text) renderer = Headmin::DocumentationRenderer.new(escape_html: true) markdown = Redcarpet::Markdown.new(renderer, tables: true, fenced_code_blocks: true) markdown.render(text) end def documentation(template = nil) # Disable rendering inside block return if block_given? # Read contents of template content = @lookup_context.find_template(template, nil, true).encode! # Extract documentation content = extract_documentation(content) # Convert markdown into HTML html = markdown_to_html(content) raw html end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
headmin-0.3.2 | app/helpers/headmin/documentation_helper.rb |
headmin-0.3.1 | app/helpers/headmin/documentation_helper.rb |