autodoc 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd7ea52b3a87c93556f1cbf9be2a363c462eb3ec
4
- data.tar.gz: 4e87fecba92d019d63430317add3423fb6fcc2b7
3
+ metadata.gz: 3398b87997facd945fc411efcad5b7fe4bd1ea0a
4
+ data.tar.gz: 86726fc12df1d0e7564edb712b7e9ea3c430dd42
5
5
  SHA512:
6
- metadata.gz: 6d9d22983853069fca27ed5fa21b81d59ad81b2123a618e88973d81c6dd6873130bf7f7a27aba5a1d89aab36e8f2ecc60e6324c214d59212ffc8e6ee268c216f
7
- data.tar.gz: 5b29b67396ca361c9501fef5a84a5091ab6c09c7ceacdd2d5640ef48ff55bae0e84734f2365a662458388ac5718f6895a5c0b19b7991f6b4f57e21558faf1d04
6
+ metadata.gz: b6bf838b4dfe9f2616ff1220189c14b67567dfc8088c2d226f223c1ca2122984666236ae752884098261d67159ebc051ac2d941019b25dc61ff4a4a1538d4597
7
+ data.tar.gz: e3db0ce08099d05159c6f85921a06232d295a67ebb7c30e34f078f0ce653f6431681fecbecc4d27dbaa84a189add4637619e339ba16b6212d16db1ea8f1cd6a9
@@ -1,3 +1,6 @@
1
+ ## 0.4.2
2
+ - Add HTML Documentation support (Thx @daviddening)
3
+
1
4
  ## 0.4.1
2
5
  - Support RSpec 2.99 (Thx @dex1t)
3
6
 
data/Gemfile CHANGED
@@ -14,4 +14,5 @@ group :test do
14
14
  gem "weak_parameters"
15
15
  gem "protected_attributes"
16
16
  gem "rack-test"
17
+ gem "redcarpet"
17
18
  end
data/README.md CHANGED
@@ -75,10 +75,14 @@ You can configure `Autodoc.configuration` to change its behavior:
75
75
  * template - [String] ERB template for each document (default: [document.md.erb](https://github.com/r7kamura/autodoc/blob/master/lib/autodoc/templates/document.md.erb))
76
76
  * toc_template - [String] ERB template for ToC (default: [toc.md.erb](https://github.com/r7kamura/autodoc/blob/master/lib/autodoc/templates/toc.md.erb))
77
77
  * toc - [Boolean] whether to generate toc.md (default: false)
78
+ * toc_html_template - [String] ERB template for html ToC (default: [toc.html.erb](https://github.com/r7kamura/autodoc/blob/master/lib/autodoc/templates/toc.html.erb))
79
+ * toc_html - [Boolean] whether to generate toc.html - a single page documentation with a toc (default: false)
78
80
 
79
81
  ```ruby
80
82
  # example
81
83
  Autodoc.configuration.path = "doc/api"
82
84
  Autodoc.configuration.toc = true
85
+ Autodoc.configuration.toc_html = true
83
86
  Autodoc.configuration.template = File.read(File.expand_path("../autodoc/templates/document.md.erb", __FILE__))
87
+
84
88
  ```
@@ -34,6 +34,14 @@ module Autodoc
34
34
  File.read(File.expand_path("../templates/toc.md.erb", __FILE__))
35
35
  end
36
36
 
37
+ property :toc_html do
38
+ false
39
+ end
40
+
41
+ property :toc_html_template do
42
+ File.read(File.expand_path("../templates/toc.html.erb", __FILE__))
43
+ end
44
+
37
45
  property :toc do
38
46
  false
39
47
  end
@@ -13,6 +13,8 @@ module Autodoc
13
13
 
14
14
  def write
15
15
  write_toc if Autodoc.configuration.toc
16
+ write_toc_html if Autodoc.configuration.toc_html
17
+
16
18
  write_documents
17
19
  end
18
20
 
@@ -34,8 +36,21 @@ module Autodoc
34
36
  ERB.new(Autodoc.configuration.toc_template, nil, "-").result(binding)
35
37
  end
36
38
 
39
+ def write_toc_html
40
+ toc_html_path.parent.mkpath
41
+ toc_html_path.open("w") {|file| file << render_toc_html }
42
+ end
43
+
44
+ def render_toc_html
45
+ ERB.new(Autodoc.configuration.toc_html_template, nil, "-").result(binding)
46
+ end
47
+
37
48
  def toc_path
38
49
  Autodoc.configuration.pathname + "toc.md"
39
50
  end
51
+
52
+ def toc_html_path
53
+ Autodoc.configuration.pathname + "toc.html"
54
+ end
40
55
  end
41
56
  end
@@ -0,0 +1,82 @@
1
+ <%# coding: UTF-8 -%>
2
+ <head>
3
+ <style>
4
+ .api-docs {
5
+ left: 210px;
6
+ }
7
+
8
+ .api-docs, .api-docs-toc {
9
+ width: 66%;
10
+ }
11
+
12
+ .api-action {
13
+ padding: 10px;
14
+ }
15
+
16
+ .tocify-wrapper {
17
+ overflow-y: auto;
18
+ overflow-x: hidden;
19
+ position: fixed;
20
+ width: 210px;
21
+ float: left;
22
+ font-size: 16px;
23
+ background-color: #AAAADD;
24
+ top: 1px;
25
+ bottom: -1px;
26
+ padding: 10px;
27
+ }
28
+
29
+ .generated-at {
30
+ position: fixed;
31
+ bottom: 10px;
32
+ }
33
+
34
+ .api-resource {
35
+ border-bottom: black 1px solid;
36
+ }
37
+
38
+ pre {
39
+ padding: 10px;
40
+ background-color: #CCCCEE;
41
+ }
42
+
43
+ .page-wrapper {
44
+ margin-left: 240px;
45
+ min-width: 700px;
46
+ position: relative;
47
+ z-index: 10;
48
+ }
49
+ </style>
50
+ </head>
51
+ <% markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, {fenced_code_blocks: true}) %>
52
+ <% document_markdown = '' %>
53
+ <html>
54
+ <div class='tocify-wrapper'>
55
+ <h1> Table of Contents </h1>
56
+ <% @table.sort.each do |pathname, documents| -%>
57
+ <% title = pathname.cleanpath.to_s.sub(/^.*doc\//,'') -%>
58
+ <% link = pathname.to_s.html_safe -%>
59
+ <li>
60
+ <a href="#<%= link -%>"><%= title -%></a>
61
+ </li>
62
+ <%
63
+ document_markdown += '<div id="' + pathname.to_s.html_safe + '" class="api-resource">'
64
+ documents.each do |document|
65
+ document_markdown += '<div class="api-action">'
66
+ document_markdown += markdown.render(document.render)
67
+ document_markdown += '</div>'
68
+ end
69
+ document_markdown += '</div>'
70
+ %>
71
+ <% end -%>
72
+ <div class='generated-at'>
73
+ Generated at:
74
+ <br>
75
+ <%= Time.now.to_s -%>
76
+ </div>
77
+ </div>
78
+
79
+ <div class='page-wrapper'>
80
+ <%= document_markdown -%>
81
+ </div>
82
+ </html>
@@ -1,3 +1,3 @@
1
1
  module Autodoc
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe "Recipes", type: :request do
4
- let(:env) do
4
+ let(:env_hash) do
5
5
  { "ACCEPT" => "application/json", "CONTENT_TYPE" => "application/json" }
6
6
  end
7
7
 
@@ -16,13 +16,13 @@ describe "Recipes", type: :request do
16
16
 
17
17
  context "with valid condition (using Rack::Test)", autodoc: true do
18
18
  before do
19
- env["Content-Type"] = "application/json"
19
+ env_hash["Content-Type"] = "application/json"
20
20
  end
21
21
 
22
22
  include Rack::Test::Methods
23
23
 
24
24
  it "returns the recipe" do
25
- get "/recipes/#{recipe.id}", params, env
25
+ get "/recipes/#{recipe.id}", params, env_hash
26
26
  expect(last_response.status).to eq(200)
27
27
  end
28
28
  end
@@ -40,7 +40,7 @@ describe "Recipes", type: :request do
40
40
  end
41
41
 
42
42
  it "returns 400" do
43
- post "/recipes", params.to_json, env
43
+ post "/recipes", params.to_json, env_hash
44
44
  expect(response.status).to eq(400)
45
45
  end
46
46
  end
@@ -51,7 +51,7 @@ describe "Recipes", type: :request do
51
51
  end
52
52
 
53
53
  it "returns 400" do
54
- post "/recipes", params.to_json, env
54
+ post "/recipes", params.to_json, env_hash
55
55
  expect(response.status).to eq(400)
56
56
  end
57
57
  end
@@ -62,7 +62,7 @@ describe "Recipes", type: :request do
62
62
  end
63
63
 
64
64
  it "creates a new recipe" do
65
- post "/recipes", params.to_json, env
65
+ post "/recipes", params.to_json, env_hash
66
66
  expect(response.status).to eq(201)
67
67
  end
68
68
  end
@@ -78,7 +78,7 @@ describe "Recipes", type: :request do
78
78
  end
79
79
 
80
80
  it "creates a new recipe" do
81
- post "/recipes", params.to_json, env
81
+ post "/recipes", params.to_json, env_hash
82
82
  expect(response.status).to eq(201)
83
83
  end
84
84
  end
@@ -3,6 +3,7 @@ require File.expand_path("../../spec/dummy/config/environment", __FILE__)
3
3
  require "rspec/rails"
4
4
 
5
5
  Autodoc.configuration.toc = true
6
+ Autodoc.configuration.toc_html = true
6
7
  Autodoc.configuration.path = "spec/dummy/doc"
7
8
 
8
9
  RSpec.configure do |config|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autodoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-13 00:00:00.000000000 Z
11
+ date: 2015-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -128,6 +128,7 @@ files:
128
128
  - lib/autodoc/documents.rb
129
129
  - lib/autodoc/rspec.rb
130
130
  - lib/autodoc/templates/document.md.erb
131
+ - lib/autodoc/templates/toc.html.erb
131
132
  - lib/autodoc/templates/toc.md.erb
132
133
  - lib/autodoc/version.rb
133
134
  - spec/autodoc/documents_spec.rb