Class: Jdoc::Generator
- Inherits:
-
Object
- Object
- Jdoc::Generator
- Defined in:
- lib/jdoc/generator.rb
Constant Summary collapse
- HTML_TEMPLATE_PATH =
File.("../../../template.html.erb", __FILE__)
- MARKDOWN_TEMPLATE_PATH =
File.("../../../template.md.erb", __FILE__)
Class Method Summary collapse
-
.call(*args) ⇒ String
Utility wrapper for Jdoc::Generator#call.
- .html_renderer ⇒ Erubis::Eruby
-
.html_template ⇒ String
ERB template.
- .markdown_renderer ⇒ Erubis::Eruby
-
.markdown_template ⇒ String
ERB template.
- .redcarpet ⇒ Object
Instance Method Summary collapse
-
#call ⇒ String
Generates Markdown or HTML documentation from JSON schema.
-
#initialize(schema, html: false) ⇒ Generator
constructor
A new instance of Generator.
Constructor Details
#initialize(schema, html: false) ⇒ Generator
Returns a new instance of Generator.
49 50 51 52 |
# File 'lib/jdoc/generator.rb', line 49 def initialize(schema, html: false) @raw_schema = schema @html = html end |
Class Method Details
.call(*args) ⇒ String
Utility wrapper for Jdoc::Generator#call
43 44 45 |
# File 'lib/jdoc/generator.rb', line 43 def self.call(*args) new(*args).call end |
.html_renderer ⇒ Erubis::Eruby
13 14 15 |
# File 'lib/jdoc/generator.rb', line 13 def html_renderer @html_renderer ||= Erubis::Eruby.new(html_template) end |
.html_template ⇒ String
Returns ERB template.
36 37 38 |
# File 'lib/jdoc/generator.rb', line 36 def html_template File.read(HTML_TEMPLATE_PATH) end |
.markdown_renderer ⇒ Erubis::Eruby
8 9 10 |
# File 'lib/jdoc/generator.rb', line 8 def markdown_renderer @markdown_renderer ||= Erubis::Eruby.new(markdown_template) end |
.markdown_template ⇒ String
Returns ERB template.
31 32 33 |
# File 'lib/jdoc/generator.rb', line 31 def markdown_template File.read(MARKDOWN_TEMPLATE_PATH) end |
.redcarpet ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/jdoc/generator.rb', line 17 def redcarpet @redcarpet ||= Redcarpet::Markdown.new( Redcarpet::Render::HTML.new( filter_html: true, hard_wrap: true, with_toc_data: true, ), autolink: true, fenced_code_blocks: true, no_intra_emphasis: true, ) end |
Instance Method Details
#call ⇒ String
Note:
Add some fix to adapt to GitHub anchor style
Generates Markdown or HTML documentation from JSON schema
57 58 59 60 61 62 63 64 65 |
# File 'lib/jdoc/generator.rb', line 57 def call result = self.class.markdown_renderer.result(schema: schema) if @html result = self.class.html_renderer.result(body: self.class.redcarpet.render(result)) result.gsub(/id="(.+)"/) {|text| text.tr("/:", "") } else result end end |