jdoc 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 272ba27b2c8096ee1cd29cf122bc4a3ad0ab1ce7
4
- data.tar.gz: 132c4ab5391930817097b13e3e98a66fbe8c7ff6
3
+ metadata.gz: caa1e9494adadf0a14d5697e39c49856d0fc78b0
4
+ data.tar.gz: d79c705955a92c5e28b586ffd79abb797644c4ff
5
5
  SHA512:
6
- metadata.gz: 9366989f68722a5a3cbe9f1b43ae5dc1b59453e461d7196f46a85feacdd1318e3a7cb2f1abfca5550bc0991fe1b48588ac3d6272a98f709368c50f7c71667859
7
- data.tar.gz: 07e0d09dc49e06766e90a3066698a3ce8def4f1e8956906cb5d666a1d1d7b6c9c003d40b6d7cc7122e245a9f8449d4741505a94f04c333835f151ed6e738e1b1
6
+ metadata.gz: 03930f9cf0de98043b16cdbeb6ebbef9025e1f68d6d6f5892928147aa23846cfb6c4b15d92d737bb3c21f570a6a77de685215b5b53531ebf00972cb43ddfdb9e
7
+ data.tar.gz: a1c9263e15fe42ce0cf3355b730bcacfb6c8122c852a3275242b34fb468f419875a217e177c0e30e8c6b86a44af8c66b7e3337540a71dc46bed31411033f09f1
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.1.4
2
+ * Provide :html option to render docs in HTML
3
+
1
4
  ## 0.1.3
2
5
  * Use its pointer name if a resource has no title property
3
6
 
data/jdoc.gemspec CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.add_dependency "activesupport"
20
20
  spec.add_dependency "erubis"
21
21
  spec.add_dependency "json_schema"
22
+ spec.add_dependency "redcarpet"
22
23
  spec.add_development_dependency "bundler", "~> 1.6"
23
24
  spec.add_development_dependency "pry"
24
25
  spec.add_development_dependency "rake"
@@ -1,6 +1,37 @@
1
1
  module Jdoc
2
2
  class Generator
3
- TEMPLATE_PATH = File.expand_path("../../../template.md.erb", __FILE__)
3
+ HTML_TEMPLATE_PATH = File.expand_path("../../../template.html.erb", __FILE__)
4
+ MARKDOWN_TEMPLATE_PATH = File.expand_path("../../../template.md.erb", __FILE__)
5
+
6
+ class << self
7
+ # @return [Erubis::Eruby]
8
+ def markdown_renderer
9
+ @markdown_renderer ||= Erubis::Eruby.new(markdown_template)
10
+ end
11
+
12
+ # @return [Erubis::Eruby]
13
+ def html_renderer
14
+ @html_renderer ||= Erubis::Eruby.new(html_template)
15
+ end
16
+
17
+ def redcarpet
18
+ @redcarpet ||= Redcarpet::Markdown.new(
19
+ Redcarpet::Render::HTML.new(hard_wrap: true, filter_html: true),
20
+ autolink: true,
21
+ fenced_code_blocks: true,
22
+ )
23
+ end
24
+
25
+ # @return [String] ERB template
26
+ def markdown_template
27
+ File.read(MARKDOWN_TEMPLATE_PATH)
28
+ end
29
+
30
+ # @return [String] ERB template
31
+ def html_template
32
+ File.read(HTML_TEMPLATE_PATH)
33
+ end
34
+ end
4
35
 
5
36
  # Utility wrapper for Jdoc::Generator#call
6
37
  # @return [String]
@@ -9,37 +40,26 @@ module Jdoc
9
40
  end
10
41
 
11
42
  # @param schema [Hash] JSON Schema represented as a Hash
12
- def initialize(schema)
43
+ # @param html [true, false] Pass true to render HTML docs
44
+ def initialize(schema, html: false)
13
45
  @raw_schema = schema
46
+ @html = html
14
47
  end
15
48
 
16
- # Generates documentation in Markdown format from JSON schema
17
- # @return [String] Text of generated markdown document
49
+ # Generates Markdown or HTML documentation from JSON schema
50
+ # @return [String]
18
51
  def call
19
- eruby.result(context)
52
+ result = self.class.markdown_renderer.result(schema: schema)
53
+ result = self.class.html_renderer.result(body: self.class.redcarpet.render(result)) if @html
54
+ result
20
55
  end
21
56
 
22
57
  private
23
58
 
24
- # @return [Hash] Context object used as a set of local variables for rendering template
25
- def context
26
- { schema: schema }
27
- end
28
-
29
59
  # @return [Jdoc::Schema]
30
60
  # @raise [JsonSchema::SchemaError] Raises if given invalid JSON Schema
31
61
  def schema
32
62
  @schema ||= Jdoc::Schema.new(@raw_schema)
33
63
  end
34
-
35
- # @return [Erubis::Eruby]
36
- def eruby
37
- Erubis::Eruby.new(template)
38
- end
39
-
40
- # @return [String] ERB template
41
- def template
42
- File.read(TEMPLATE_PATH)
43
- end
44
64
  end
45
65
  end
data/lib/jdoc/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jdoc
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
data/lib/jdoc.rb CHANGED
@@ -2,6 +2,7 @@ require "active_support/core_ext/string/inflections"
2
2
  require "cgi"
3
3
  require "erubis"
4
4
  require "json_schema"
5
+ require "redcarpet"
5
6
  require "uri"
6
7
 
7
8
  require "jdoc/generator"
data/template.html.erb ADDED
@@ -0,0 +1,43 @@
1
+ <!DOCTYPE HTML>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>API Docs</title>
6
+ <style>
7
+ body {
8
+ width: 920px;
9
+ margin: 0 auto;
10
+ font-size: 14px;
11
+ }
12
+
13
+ a {
14
+ color: #4183C4;
15
+ }
16
+
17
+ pre {
18
+ color: #393939;
19
+ background-color: #fafafb;
20
+ padding: 10px;
21
+ margin: 2em 0;
22
+ border: 1px solid #cacaca;
23
+ border-radius: 3px;
24
+ font: 12px/1.4em Consolas, 'Liberation Mono', Courier, monospace;
25
+ overflow: auto;
26
+ }
27
+
28
+ ol code,
29
+ ul code,
30
+ p code {
31
+ font-size: 12px;
32
+ margin: 0;
33
+ border: 1px solid #ddd;
34
+ background-color: #f8f8f8;
35
+ border-radius: 3px;
36
+ padding: 0;
37
+ }
38
+ </style>
39
+ </head>
40
+ <body>
41
+ <%= body %>
42
+ </body>
43
+ </html>
data/template.md.erb CHANGED
@@ -1,4 +1,4 @@
1
- # <%= schema.title %>
1
+ # <%= schema.title || "API" %>
2
2
  <% schema.resources.each do |resource| %>
3
3
  * <%= resource.hyperlink %>
4
4
  <% resource.links.each do |link| %>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jdoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: redcarpet
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: bundler
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -135,6 +149,7 @@ files:
135
149
  - spec/fixtures/schema.yml
136
150
  - spec/jdoc/generator_spec.rb
137
151
  - spec/spec_helper.rb
152
+ - template.html.erb
138
153
  - template.md.erb
139
154
  homepage: https://github.com/r7kamura/jdoc
140
155
  licenses: