ghost_writer 0.2.0 → 0.3.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 967ed54744c35d63d0a06e6665ae69ab314f6f34
4
+ data.tar.gz: 20c5650513d18bc21298317222409fd8986b7ad8
5
+ SHA512:
6
+ metadata.gz: 642ed40681a6b8a79aac3988029b8a96e347a4ab2d98809ef3bdbddd7af285114852a069aca3f2a21ffb871d21da1d2c4fd43bce2ccbdd4d91e3f10e33a47a30
7
+ data.tar.gz: e59c1e45a4bf4ce60770970c9c26d52f7a8d9bf30b111ed7385b8f22442cb52d30843f585c23506f361db6e747adc58e6247e134a34df50158c8a24cb232f046
data/README.md CHANGED
@@ -28,6 +28,7 @@ Write controller spec:
28
28
  RSpec.configure do |config|
29
29
  # The difference with previous version. already no need including Module and Defining after hook
30
30
  GhostWriter.output_dir = "api_docs" # Optional (default is "api_examples")
31
+ GhostWriter.output_format = :rst # Optional (default is :markdown)
31
32
  GhostWriter.github_base_url = "https://github.com/joker1007/ghost_writer/tree/master/output_examples" # Optional
32
33
  end
33
34
 
@@ -49,7 +50,7 @@ describe PostsController do
49
50
  end
50
51
  ```
51
52
 
52
- And set environment variable GENERATE_API_DOC at runtime
53
+ And set environment variable GENERATE\_API\_DOC at runtime
53
54
  ```
54
55
  bundle exec ghost_writer spec/controllers
55
56
  -> generate docs at [Rails.root]/doc/api_examples
data/bin/ghost_writer CHANGED
@@ -18,6 +18,7 @@ where [options] are:
18
18
  EOS
19
19
 
20
20
  opt :output, "Output directory", :type => String
21
+ opt :format, "Output doc format (default: markdown, availables: markdown, rst)", :type => String
21
22
  opt :clear, "[Caution] Clear Output directory before running specs", :default => false
22
23
  end
23
24
 
@@ -29,6 +30,7 @@ end
29
30
  RSpec.configure do |c|
30
31
  c.include GhostWriter
31
32
  GhostWriter.output_dir = opts[:output]
33
+ GhostWriter.output_format = opts[:format].to_sym if opts[:format]
32
34
  c.after(:suite) do
33
35
  GhostWriter.generate_api_doc
34
36
  end
data/ghost_writer.gemspec CHANGED
@@ -21,8 +21,8 @@ Gem::Specification.new do |gem|
21
21
  gem.add_dependency "rspec-rails", "~> 2.11"
22
22
  gem.add_dependency "trollop"
23
23
 
24
- gem.add_development_dependency "rspec", "~> 2.12"
24
+ gem.add_development_dependency "rspec-rails", "~> 2.12"
25
25
  gem.add_development_dependency 'rake', ['>= 0']
26
- gem.add_development_dependency 'rails', ['~> 3.2.9']
26
+ gem.add_development_dependency 'rails', ['>= 3.2.9', '< 5']
27
27
  gem.add_development_dependency 'tapp'
28
28
  end
data/lib/ghost_writer.rb CHANGED
@@ -8,13 +8,15 @@ module GhostWriter
8
8
 
9
9
  module Format
10
10
  autoload "Markdown", "ghost_writer/format/markdown"
11
+ autoload "Rst", "ghost_writer/format/rst"
11
12
  end
12
13
 
13
- DEFAULT_OUTPUT_DIR = "api_examples"
14
- DOCUMENT_INDEX_FILENAME = "document_index.markdown"
14
+ DEFAULT_OUTPUT_DIR = "api_examples".freeze
15
+ DEFAULT_FORMAT = :markdown
16
+ DOCUMENT_INDEX_FILENAME = "document_index".freeze
15
17
 
16
18
  class << self
17
- attr_writer :output_dir, :output_flag
19
+ attr_writer :output_dir, :output_flag, :output_format
18
20
  attr_accessor :github_base_url
19
21
 
20
22
  def document_group
@@ -27,7 +29,7 @@ module GhostWriter
27
29
  unless File.exist?(output_path)
28
30
  FileUtils.mkdir_p(output_path)
29
31
  end
30
- document_index = GhostWriter::DocumentIndex.new(output_path + DOCUMENT_INDEX_FILENAME, document_group)
32
+ document_index = GhostWriter::DocumentIndex.new(output_path + "#{DOCUMENT_INDEX_FILENAME}.#{output_format}", document_group, GhostWriter.output_format)
31
33
  document_index.write_file
32
34
  document_group.each do |output, docs|
33
35
  docs.sort_by!(&:description)
@@ -50,10 +52,14 @@ module GhostWriter
50
52
  def output_path
51
53
  Rails.root + "doc" + output_dir
52
54
  end
55
+
56
+ def output_format
57
+ @output_format || DEFAULT_FORMAT
58
+ end
53
59
  end
54
60
 
55
61
  def collect_example
56
- output = File.join(doc_dir, "#{doc_name}.markdown")
62
+ output = File.join(doc_dir, "#{doc_name}.#{GhostWriter.output_format}")
57
63
  document = GhostWriter::Document.new(output, {
58
64
  title: "#{described_class} #{doc_name.titleize}",
59
65
  description: example.full_description.dup,
@@ -62,7 +68,9 @@ module GhostWriter
62
68
  param_example: controller.params.reject {|key, val| key == "controller" || key == "action"},
63
69
  status_example: response.status.inspect,
64
70
  response_example: response.body,
71
+ format: GhostWriter.output_format
65
72
  })
73
+
66
74
  GhostWriter.document_group[output] ||= []
67
75
  GhostWriter.document_group[output] << document
68
76
  end
@@ -82,7 +90,7 @@ module GhostWriter
82
90
 
83
91
  included do
84
92
  after do
85
- if example.metadata[:type] == :controller && example.metadata[:generate_api_doc]
93
+ if (example.metadata[:type] == :controller || example.metadata[:type] == :request) && example.metadata[:generate_api_doc]
86
94
  collect_example if GhostWriter.output_flag
87
95
  end
88
96
  end
@@ -2,7 +2,9 @@ class GhostWriter::Document
2
2
  attr_reader :title, :description, :location, :url_example, :param_example, :status_example, :response_example, :output, :relative_path
3
3
 
4
4
  def initialize(output, attrs)
5
- extend(GhostWriter::Format::Markdown)
5
+ format_module = "GhostWriter::Format::#{attrs[:format].to_s.classify}"
6
+ extend(format_module.constantize)
7
+
6
8
  @output = output
7
9
  @relative_path = Pathname.new(output).relative_path_from(GhostWriter.output_path)
8
10
  @title = attrs[:title]
@@ -23,46 +25,44 @@ class GhostWriter::Document
23
25
  doc = File.open(output, mode)
24
26
 
25
27
  if overwrite
26
- doc.write paragraph(<<EOP)
28
+ doc.write paragraph(document_header)
29
+ end
30
+
31
+ doc.write(document_body)
32
+
33
+ doc.close
34
+ end
35
+
36
+ def document_header
37
+ <<EOP
27
38
  #{headword(title, 1)}
28
39
 
29
- --------------------------------
40
+ #{separator(32)}
30
41
 
31
42
  EOP
32
- end
43
+ end
33
44
 
34
- doc.write paragraph(<<EOP)
45
+ def document_body
46
+ <<EOP
35
47
  #{headword(description, 2)}
36
- EOP
37
48
 
38
- doc.write paragraph(<<EOP)
39
49
  #{headword("access path:", 3)}
40
50
  #{quote(url_example)}
41
- EOP
42
51
 
43
- doc.write paragraph(<<EOP)
44
52
  #{headword("request params:", 3)}
45
53
  #{quote(param_example.inspect, :ruby)}
46
- EOP
47
54
 
48
- doc.write paragraph(<<EOP)
49
55
  #{headword("status code:", 3)}
50
56
  #{quote(status_example)}
51
- EOP
52
57
 
53
- doc.write paragraph(<<EOP)
54
58
  #{headword("response:", 3)}
55
59
  #{quote_response(response_example)}
56
- EOP
57
60
 
58
- doc.write paragraph(<<EOP)
59
61
  Generated by "#{description}\" at #{location}
60
62
 
61
- --------------------------------
63
+ #{separator(32)}
62
64
 
63
65
  EOP
64
-
65
- doc.close
66
66
  end
67
67
 
68
68
  private
@@ -1,8 +1,10 @@
1
1
  class GhostWriter::DocumentIndex
2
2
  attr_reader :output, :documents
3
3
 
4
- def initialize(output, documents)
5
- extend(GhostWriter::Format::Markdown)
4
+ def initialize(output, documents, format)
5
+ format_module = "GhostWriter::Format::#{format.to_s.classify}"
6
+ extend(format_module.constantize)
7
+
6
8
  @output = output
7
9
  @documents = documents
8
10
  end
@@ -2,7 +2,6 @@ module GhostWriter
2
2
  module Format
3
3
  module Markdown
4
4
  private
5
- # TODO: outputのフォーマットを選択可能に
6
5
  def headword(text, level = 1)
7
6
  "#{'#'*level} #{text}"
8
7
  end
@@ -11,6 +10,10 @@ module GhostWriter
11
10
  text + "\n"
12
11
  end
13
12
 
13
+ def separator(length)
14
+ "-" * length
15
+ end
16
+
14
17
  def quote(text, quote_format = nil)
15
18
  "```#{quote_format}\n#{text}\n```"
16
19
  end
@@ -0,0 +1,45 @@
1
+ module GhostWriter
2
+ module Format
3
+ module Rst
4
+ private
5
+ def headword(text, level = 1)
6
+ char = case level
7
+ when 1
8
+ "*"
9
+ when 2
10
+ "="
11
+ when 3
12
+ "-"
13
+ when 4
14
+ "^"
15
+ end
16
+ text + "\n" + char * text.length * 2
17
+ end
18
+
19
+ def paragraph(text)
20
+ text + "\n"
21
+ end
22
+
23
+ def separator(length)
24
+ ""
25
+ end
26
+
27
+ def quote(text, quote_format = nil)
28
+ if quote_format
29
+ marker = ".. code-block:: #{quote_format}" + "\n"
30
+ else
31
+ marker = "::" + "\n"
32
+ end
33
+ marker + "#{text.each_line.map{|line| line.chomp.empty? ? line : " " + line}.join}"
34
+ end
35
+
36
+ def list(text, level = 1)
37
+ "#{" " * (level - 1)}* #{text}"
38
+ end
39
+
40
+ def link(text, url)
41
+ "`#{text} #{url}`_"
42
+ end
43
+ end
44
+ end
45
+ end
@@ -1,3 +1,3 @@
1
1
  module GhostWriter
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -94,7 +94,7 @@ describe GhostWriter do
94
94
  GhostWriter.github_base_url = github_base_url
95
95
  group.run(NullObject.new)
96
96
  GhostWriter.generate_api_doc
97
- File.read(Rails.root + "doc" + "api_examples" + GhostWriter::DOCUMENT_INDEX_FILENAME).should =~ /#{github_base_url}/
97
+ File.read(Rails.root + "doc" + "api_examples" + "#{GhostWriter::DOCUMENT_INDEX_FILENAME}.#{GhostWriter.output_format}").should =~ /#{github_base_url}/
98
98
  end
99
99
  end
100
100
  end
@@ -6,9 +6,6 @@ RailsApp::Application.configure do
6
6
  # since you don't have to restart the web server when you make code changes.
7
7
  config.cache_classes = false
8
8
 
9
- # Log error messages when you accidentally call methods on nil.
10
- config.whiny_nils = true
11
-
12
9
  # Show full error reports and disable caching
13
10
  config.consider_all_requests_local = true
14
11
  config.action_controller.perform_caching = false
@@ -34,4 +31,6 @@ RailsApp::Application.configure do
34
31
 
35
32
  # Expands the lines which load the assets
36
33
  config.assets.debug = true
34
+
35
+ config.eager_load = false
37
36
  end
@@ -64,4 +64,6 @@ RailsApp::Application.configure do
64
64
  # Log the query plan for queries taking more than this (works
65
65
  # with SQLite, MySQL, and PostgreSQL)
66
66
  # config.active_record.auto_explain_threshold_in_seconds = 0.5
67
+
68
+ config.eager_load = true
67
69
  end
@@ -11,9 +11,6 @@ RailsApp::Application.configure do
11
11
  config.serve_static_assets = true
12
12
  config.static_cache_control = "public, max-age=3600"
13
13
 
14
- # Log error messages when you accidentally call methods on nil
15
- config.whiny_nils = true
16
-
17
14
  # Show full error reports and disable caching
18
15
  config.consider_all_requests_local = true
19
16
  config.action_controller.perform_caching = false
@@ -34,4 +31,6 @@ RailsApp::Application.configure do
34
31
 
35
32
  # Print deprecation notices to the stderr
36
33
  config.active_support.deprecation = :stderr
34
+
35
+ config.eager_load = false
37
36
  end
@@ -4,4 +4,4 @@
4
4
  # If you change this key, all old signed cookies will become invalid!
5
5
  # Make sure the secret is at least 30 characters and all random,
6
6
  # no regular words or you'll be exposed to dictionary attacks.
7
- RailsApp::Application.config.secret_token = '98e50fa60d0ddcf9c64b8b87e0dfd8c247885c4cbcaeecf37d24fc4b5fb2cd36c9744a5165653efc77d5ced8cb4a6c7157d3752721b0acc2e7b69b7f2b915b9a'
7
+ RailsApp::Application.config.secret_key_base = '98e50fa60d0ddcf9c64b8b87e0dfd8c247885c4cbcaeecf37d24fc4b5fb2cd36c9744a5165653efc77d5ced8cb4a6c7157d3752721b0acc2e7b69b7f2b915b9a'
metadata CHANGED
@@ -1,36 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ghost_writer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
5
- prerelease:
4
+ version: 0.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - joker1007
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-06 00:00:00.000000000 Z
11
+ date: 2013-08-06 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activesupport
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: 3.0.0
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: 3.0.0
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec-rails
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,23 +41,20 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: trollop
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
- name: rspec
56
+ name: rspec-rails
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ~>
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ~>
76
67
  - !ruby/object:Gem::Version
@@ -78,49 +69,49 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rake
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - '>='
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: rails
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ~>
87
+ - - '>='
100
88
  - !ruby/object:Gem::Version
101
89
  version: 3.2.9
90
+ - - <
91
+ - !ruby/object:Gem::Version
92
+ version: '5'
102
93
  type: :development
103
94
  prerelease: false
104
95
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
96
  requirements:
107
- - - ~>
97
+ - - '>='
108
98
  - !ruby/object:Gem::Version
109
99
  version: 3.2.9
100
+ - - <
101
+ - !ruby/object:Gem::Version
102
+ version: '5'
110
103
  - !ruby/object:Gem::Dependency
111
104
  name: tapp
112
105
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
106
  requirements:
115
- - - ! '>='
107
+ - - '>='
116
108
  - !ruby/object:Gem::Version
117
109
  version: '0'
118
110
  type: :development
119
111
  prerelease: false
120
112
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
113
  requirements:
123
- - - ! '>='
114
+ - - '>='
124
115
  - !ruby/object:Gem::Version
125
116
  version: '0'
126
117
  description: Generate API examples from params and response of controller specs
@@ -143,6 +134,7 @@ files:
143
134
  - lib/ghost_writer/document.rb
144
135
  - lib/ghost_writer/document_index.rb
145
136
  - lib/ghost_writer/format/markdown.rb
137
+ - lib/ghost_writer/format/rst.rb
146
138
  - lib/ghost_writer/version.rb
147
139
  - output_examples/anonymous_controller/index.markdown
148
140
  - output_examples/anonymous_controller/show.markdown
@@ -189,33 +181,26 @@ files:
189
181
  - spec/spec_helper.rb
190
182
  homepage: https://github.com/joker1007/ghost_writer
191
183
  licenses: []
184
+ metadata: {}
192
185
  post_install_message:
193
186
  rdoc_options: []
194
187
  require_paths:
195
188
  - lib
196
189
  required_ruby_version: !ruby/object:Gem::Requirement
197
- none: false
198
190
  requirements:
199
- - - ! '>='
191
+ - - '>='
200
192
  - !ruby/object:Gem::Version
201
193
  version: '0'
202
- segments:
203
- - 0
204
- hash: 885870710401004349
205
194
  required_rubygems_version: !ruby/object:Gem::Requirement
206
- none: false
207
195
  requirements:
208
- - - ! '>='
196
+ - - '>='
209
197
  - !ruby/object:Gem::Version
210
198
  version: '0'
211
- segments:
212
- - 0
213
- hash: 885870710401004349
214
199
  requirements: []
215
200
  rubyforge_project:
216
- rubygems_version: 1.8.23
201
+ rubygems_version: 2.0.3
217
202
  signing_key:
218
- specification_version: 3
203
+ specification_version: 4
219
204
  summary: Generate API examples from params and response of controller specs
220
205
  test_files:
221
206
  - spec/lib/ghost_writer_spec.rb
@@ -258,3 +243,4 @@ test_files:
258
243
  - spec/rails_app/test/test_helper.rb
259
244
  - spec/rails_app/test/unit/.gitkeep
260
245
  - spec/spec_helper.rb
246
+ has_rdoc: