ghost_writer 0.4.1 → 0.4.2

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: 876770396865698ba8324e5b1765edfeffaab4c1
4
- data.tar.gz: 7c8b0d88212c2985f6969e3a3fcf286db6135d8f
3
+ metadata.gz: 7aaf1da751c9da1f4bd95426076de33da3ed4bb8
4
+ data.tar.gz: 59d7e48cdf34b773da063196e78a6215c5dab391
5
5
  SHA512:
6
- metadata.gz: 61966afe8996ef69ffbc49133455adcfae3bb63dbd1ae1ed955ef884cc0e93f912d28127554b279a9eea76be9d6ee2c7dc97e7bf419c6166fd6957ac66e09f36
7
- data.tar.gz: ee9f5674274384cdcfaf14b6ef5cc4512cf83a2d572323546be75230e62f9ba2b1f951b436f6a98a48a878c9a8bcd25a31417eee080989db75cf4eb1ca6ed135
6
+ metadata.gz: 1473fc739dbbc1274784edb02e52948b67591be47ca3fa30fa7930555c254877968a544fe5f695594eb75c903ab7413b30cc2c7608f0fd9f1ad2b5d8e97c3a46
7
+ data.tar.gz: 14d93f8b53bfbb364a078f5bcfe7a86de4224fdc0e761113e227cfcd0351652ebc93d3ba66ca5ba90d9aabda70ddfaba828c9b5c11e878b9e4c47b16645fd3be
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # GhostWriter
2
2
  [![Build Status](https://travis-ci.org/joker1007/ghost_writer.png)](https://travis-ci.org/joker1007/ghost_writer)
3
3
  [![Gem Version](https://badge.fury.io/rb/ghost_writer.png)](http://badge.fury.io/rb/ghost_writer)
4
+ [![Code Climate](https://codeclimate.com/github/joker1007/ghost_writer.png)](https://codeclimate.com/github/joker1007/ghost_writer)
4
5
 
5
6
  Generate API examples from params and response of controller specs
6
7
 
data/lib/ghost_writer.rb CHANGED
@@ -31,11 +31,13 @@ module GhostWriter
31
31
  FileUtils.mkdir_p(output_path)
32
32
  end
33
33
  document_index = GhostWriter::DocumentIndex.new(output_path + "#{DOCUMENT_INDEX_FILENAME}", document_group, GhostWriter.output_format)
34
- document_index.write_index_file
34
+ document_index.write_file(format: output_format)
35
35
  document_group.each do |output, docs|
36
36
  docs.sort_by!(&:location)
37
- docs.shift.write_file(true)
38
- docs.each(&:write_file)
37
+ initial = docs.shift
38
+ initial.header = true
39
+ initial.write_file(format: output_format, overwrite: true)
40
+ docs.each {|d| d.write_file(format: output_format) }
39
41
  end
40
42
 
41
43
  document_group.clear
@@ -68,8 +70,8 @@ module GhostWriter
68
70
  request_method: request.env["REQUEST_METHOD"],
69
71
  path_info: request.env["PATH_INFO"],
70
72
  param_example: controller.params.reject {|key, val| key == "controller" || key == "action"},
71
- status_example: response.status.inspect,
72
- response_example: response.body,
73
+ status_code: response.status,
74
+ response_body: response.body,
73
75
  format: GhostWriter.output_format
74
76
  })
75
77
 
@@ -1,79 +1,59 @@
1
- class GhostWriter::Document
2
- attr_reader :title, :description, :location, :request_method, :path_info, :param_example, :status_example, :response_example, :output, :relative_path
1
+ require 'ghost_writer/writer'
3
2
 
4
- def initialize(output, attrs)
5
- format_module = "GhostWriter::Format::#{attrs[:format].to_s.classify}"
6
- extend(format_module.constantize)
3
+ class GhostWriter::Document
4
+ attr_reader :basename, :relative_path, :title, :description, :location, :request_method, :path_info, :response_format, :param_example, :status_code
5
+ attr_accessor :header
7
6
 
8
- @output = output
9
- @relative_path = Pathname.new(output).relative_path_from(GhostWriter.output_path)
7
+ def initialize(basename, attrs)
8
+ @basename = basename
9
+ @relative_path = Pathname.new(basename).relative_path_from(GhostWriter.output_path)
10
10
  @title = attrs[:title]
11
11
  @description = attrs[:description]
12
12
  @location = attrs[:location]
13
13
  @request_method = attrs[:request_method]
14
14
  @path_info = attrs[:path_info]
15
- @param_example = attrs[:param_example]
16
- @status_example = attrs[:status_example]
17
- @response_example = attrs[:response_example]
18
- end
19
-
20
- def write_file(overwrite = false)
21
- unless File.exist?(File.dirname(output))
22
- FileUtils.mkdir_p(File.dirname(output))
23
- end
24
-
25
- mode = overwrite ? "w" : "a"
26
- doc = File.open("#{output}.#{extname}", mode)
27
15
 
28
- if overwrite
29
- doc.write paragraph(document_header)
30
- end
31
-
32
- doc.write(document_body)
33
-
34
- doc.close
16
+ param_example = attrs[:param_example].stringify_keys
17
+ @response_format = param_example.delete("format").to_s
18
+ @param_example = param_example
19
+ @status_code = attrs[:status_code]
20
+ @response_body = attrs[:response_body]
35
21
  end
36
22
 
37
- def document_header
38
- <<EOP
39
- #{headword(title, 2)}
40
-
41
- EOP
23
+ def write_file(options = {})
24
+ writer = GhostWriter::Writer.new(self, options)
25
+ writer.write_file
42
26
  end
43
27
 
44
- def document_body
45
- <<EOP
46
- #{headword(description, 3)}
47
-
48
- #{headword("access path:", 4)}
49
- #{quote("#{request_method} #{path_info}")}
50
-
51
- #{headword("request params:", 4)}
52
- #{quote(param_example.inspect, :ruby)}
53
-
54
- #{headword("status code:", 4)}
55
- #{quote(status_example)}
56
-
57
- #{headword("response:", 4)}
58
- #{quote_response(response_example)}
59
-
60
- Generated by "#{description}\" at #{location}
28
+ def serialized_params
29
+ MultiJson.dump(param_example)
30
+ end
61
31
 
62
- #{separator(32)}
32
+ def response_body
33
+ arrange_json(@response_body)
34
+ end
63
35
 
64
- EOP
36
+ def response_format(json_convert_to_javascript = false)
37
+ if json_convert_to_javascript && @response_format == "json"
38
+ "javascript"
39
+ else
40
+ @response_format
41
+ end
65
42
  end
66
43
 
67
- private
68
- def quote_response(body)
69
- if param_example[:format] && param_example[:format].to_sym == :json
70
- quote(arrange_json(response_example), :javascript)
44
+ def content_type
45
+ if response_format == "json"
46
+ "application/json; charset=UTF-8"
71
47
  else
72
- quote(response_example, param_example[:format])
48
+ "text/html; charset=UTF-8"
73
49
  end
74
50
  end
75
51
 
52
+ private
53
+
76
54
  def arrange_json(body)
55
+ return body unless response_format == "json"
56
+
77
57
  data = ActiveSupport::JSON.decode(body)
78
58
  if data.is_a?(Array) || data.is_a?(Hash)
79
59
  JSON.pretty_generate(data)
@@ -1,34 +1,27 @@
1
+ require 'ghost_writer/index_writer'
2
+ require 'ghost_writer/index_writer/rack'
3
+
1
4
  class GhostWriter::DocumentIndex
2
- attr_reader :output, :documents
5
+ attr_reader :basename, :document_group
6
+
7
+ def initialize(basename, document_group, format)
8
+ @basename = basename
9
+ @document_group = document_group
10
+ end
3
11
 
4
- def initialize(output, documents, format)
5
- format_module = "GhostWriter::Format::#{format.to_s.classify}"
6
- extend(format_module.constantize)
12
+ def write_file(options = {})
13
+ writer = GhostWriter::IndexWriter.new(self, options)
14
+ writer.write_file
7
15
 
8
- @output = output
9
- @documents = documents
16
+ rack_writer = GhostWriter::IndexWriter::Rack.new(self)
17
+ rack_writer.write_file
10
18
  end
11
19
 
12
- def write_index_file
20
+ def base_url
13
21
  if GhostWriter.github_base_url
14
22
  base_url = GhostWriter.github_base_url + "/"
15
23
  else
16
24
  base_url = ""
17
25
  end
18
-
19
- document_list = documents.flat_map do |output, docs|
20
- docs.map do |d|
21
- list(
22
- link(d.description, base_url + "#{d.relative_path}")
23
- )
24
- end
25
- end
26
-
27
- index_file = File.open("#{output}.#{extname}", "w")
28
- index_file.write paragraph(<<EOP)
29
- #{headword("API Examples")}
30
- #{document_list.join("\n")}
31
- EOP
32
- index_file.close
33
26
  end
34
27
  end
@@ -0,0 +1,28 @@
1
+ require 'active_support/core_ext/string'
2
+
3
+ class GhostWriter::IndexWriter
4
+ autoload "Markdown", "ghost_writer/index_writer/markdown"
5
+ autoload "Rst", "ghost_writer/index_writer/rst"
6
+
7
+ def initialize(document_index, options = {})
8
+ @document_index = document_index
9
+ @format = options.delete(:format) || :markdown
10
+ end
11
+
12
+ def write_file
13
+ format_class = lookup_format_class
14
+ format = format_class.new(@document_index)
15
+ format.write_file
16
+ end
17
+
18
+ private
19
+
20
+ def lookup_format_class
21
+ case @format
22
+ when Class
23
+ @format
24
+ when String, Symbol
25
+ "GhostWriter::IndexWriter::#{@format.to_s.classify}".constantize
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,27 @@
1
+ class GhostWriter::IndexWriter
2
+ class Base
3
+ def initialize(document_index)
4
+ @document_index = document_index
5
+ end
6
+
7
+ def write_file
8
+ unless File.exist?(File.dirname(@document_index.basename))
9
+ FileUtils.mkdir_p(File.dirname(@document_index.basename))
10
+ end
11
+
12
+ File.open("#{@document_index.basename}.#{extname}", "w") do |f|
13
+ f.write template.result(@document_index.instance_eval { binding })
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def extname
20
+ raise NotImplementedError
21
+ end
22
+
23
+ def template
24
+ raise NotImplementedError
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,16 @@
1
+ require 'ghost_writer/index_writer/base'
2
+
3
+ class GhostWriter::IndexWriter
4
+ class Markdown < Base
5
+ private
6
+
7
+ def extname
8
+ "md"
9
+ end
10
+
11
+ def template
12
+ path = File.join(File.expand_path(File.dirname(__FILE__)), "templates", "markdown.erb")
13
+ ERB.new(File.read(path), nil, "%-")
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,39 @@
1
+ require 'ghost_writer/index_writer/base'
2
+
3
+ class GhostWriter::IndexWriter
4
+ class Rack < Base
5
+ def write_file
6
+ unless File.exist?(File.dirname(@document_index.basename))
7
+ FileUtils.mkdir_p(File.dirname(@document_index.basename))
8
+ end
9
+
10
+ File.open(app_path, "w") do |f|
11
+ f.write template.result(@document_index.instance_eval { binding })
12
+ end
13
+
14
+ File.open(configru_path, "w") do |f|
15
+ f.write "require_relative 'mock_server'\n"
16
+ f.write "run MockServer.new"
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def app_path
23
+ File.join(File.dirname(@document_index.basename), "mock_server.rb")
24
+ end
25
+
26
+ def configru_path
27
+ File.join(File.dirname(@document_index.basename), "config.ru")
28
+ end
29
+
30
+ def extname
31
+ "rb"
32
+ end
33
+
34
+ def template
35
+ path = File.join(File.expand_path(File.dirname(__FILE__)), "templates", "rack.erb")
36
+ ERB.new(File.read(path), nil, "%-")
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,16 @@
1
+ require 'ghost_writer/index_writer/base'
2
+
3
+ class GhostWriter::IndexWriter
4
+ class Rst < Base
5
+ private
6
+
7
+ def extname
8
+ "rst"
9
+ end
10
+
11
+ def template
12
+ path = File.join(File.expand_path(File.dirname(__FILE__)), "templates", "rst.erb")
13
+ ERB.new(File.read(path), nil, "%-")
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,7 @@
1
+ ## API Examples
2
+
3
+ <% document_group.each do |output, docs| -%>
4
+ <% docs.each do |d| -%>
5
+ - [<%= d.description %>](<%= base_url + d.relative_path.to_s %>)
6
+ <% end %>
7
+ <% end -%>
@@ -0,0 +1,36 @@
1
+ require 'rack'
2
+
3
+ class MockServer
4
+ def call(env)
5
+ request = Rack::Request.new(env)
6
+ params = recursive_to_s(request.params)
7
+ case [request.request_method, request.path_info, params]
8
+ <% document_group.each do |output, docs| -%>
9
+ <% docs.each do |d| -%>
10
+ when [<%= d.request_method.inspect %>, <%= d.path_info.inspect %>, recursive_to_s(<%= MultiJson.load(d.serialized_params).inspect %>)]
11
+ [200, {"Content-Type" => <%= d.content_type.inspect %>}, [(<<BODY)]]
12
+ <%= d.response_body %>
13
+ BODY
14
+ <% end %>
15
+ <% end -%>
16
+ else
17
+ [404, {"Content-Type" => "text/html"}, ['No match rule']]
18
+ end
19
+ end
20
+
21
+ def recursive_to_s(params)
22
+ case params
23
+ when Hash
24
+ params.each do |k, v|
25
+ params[k] = recursive_to_s(v)
26
+ end
27
+ when Array
28
+ params.map do |v|
29
+ recursive_to_s(v)
30
+ end
31
+ else
32
+ params.to_s
33
+ end
34
+ end
35
+ end
36
+
@@ -0,0 +1,8 @@
1
+ API Examples
2
+ *****************
3
+
4
+ <% document_group.each do |output, docs| -%>
5
+ <% docs.each do |d| -%>
6
+ * `<%= d.description %> <<%= base_url + d.relative_path.to_s %>>`_.
7
+ <% end %>
8
+ <% end -%>
@@ -1,3 +1,3 @@
1
1
  module GhostWriter
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
@@ -0,0 +1,29 @@
1
+ require 'active_support/core_ext/string'
2
+
3
+ class GhostWriter::Writer
4
+ autoload "Markdown", "ghost_writer/writer/markdown"
5
+ autoload "Rst", "ghost_writer/writer/rst"
6
+
7
+ def initialize(document, options = {})
8
+ @document = document
9
+ @format = options.delete(:format) || :markdown
10
+ @options = options
11
+ end
12
+
13
+ def write_file
14
+ format_class = lookup_format_class
15
+ format = format_class.new(@document, @options)
16
+ format.write_file
17
+ end
18
+
19
+ private
20
+
21
+ def lookup_format_class
22
+ case @format
23
+ when Class
24
+ @format
25
+ when String, Symbol
26
+ "GhostWriter::Writer::#{@format.to_s.classify}".constantize
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,31 @@
1
+ require 'erb'
2
+
3
+ class GhostWriter::Writer
4
+ class Base
5
+ def initialize(document, options = {})
6
+ @document = document
7
+ @overwrite = options[:overwrite] || false
8
+ end
9
+
10
+ def write_file
11
+ unless File.exist?(File.dirname(@document.basename))
12
+ FileUtils.mkdir_p(File.dirname(@document.basename))
13
+ end
14
+
15
+ mode = @overwrite ? "w" : "a"
16
+ File.open("#{@document.basename}.#{extname}", mode) do |f|
17
+ f.write template.result(@document.instance_eval { binding })
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def extname
24
+ raise NotImplementedError
25
+ end
26
+
27
+ def template
28
+ raise NotImplementedError
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,16 @@
1
+ require 'ghost_writer/writer/base'
2
+
3
+ class GhostWriter::Writer
4
+ class Markdown < Base
5
+ private
6
+
7
+ def extname
8
+ "md"
9
+ end
10
+
11
+ def template
12
+ path = File.join(File.expand_path(File.dirname(__FILE__)), "templates", "markdown.erb")
13
+ ERB.new(File.read(path))
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ require 'ghost_writer/writer/base'
2
+
3
+ class GhostWriter::Writer
4
+ class Rst < Base
5
+ private
6
+
7
+ def extname
8
+ "rst"
9
+ end
10
+
11
+ def template
12
+ path = File.join(File.expand_path(File.dirname(__FILE__)), "templates", "rst.erb")
13
+ ERB.new(File.read(path), nil, "%-")
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,33 @@
1
+ <% if header %>
2
+ ## <%= title %>
3
+ <% end %>
4
+
5
+ ### <%= description %>
6
+
7
+ #### access path:
8
+
9
+ ```
10
+ <%= "#{request_method} #{path_info}" %>
11
+ ```
12
+
13
+ #### request params:
14
+
15
+ ```json
16
+ <%= serialized_params %>
17
+ ```
18
+
19
+ #### status code:
20
+
21
+ ```
22
+ <%= status_code %>
23
+ ```
24
+
25
+ #### response:
26
+
27
+ ```<%= response_format %>
28
+ <%= response_body %>
29
+ ```
30
+
31
+ Generated by <%= description %> at <%= location %>
32
+
33
+ --------------------------------
@@ -0,0 +1,41 @@
1
+ <% if header -%>
2
+ <%= title %>
3
+ <%= "*" * title.length * 2 %>
4
+ <% end -%>
5
+
6
+ <%= description %>
7
+ <%= "=" * description.length * 2 %>
8
+
9
+
10
+ access path
11
+ ----------------
12
+
13
+ ::
14
+ <%= "#{request_method} #{path_info}" %>
15
+
16
+
17
+ request params
18
+ ----------------------
19
+
20
+ .. code-block:: javascript
21
+ <%= serialized_params.each_line.map{|line| line.chomp.empty? ? line : " " + line}.join %>
22
+
23
+
24
+ status code
25
+ ----------------------
26
+
27
+ ::
28
+ <%= status_code %>
29
+
30
+
31
+ response
32
+ ----------------------
33
+
34
+ .. code-block:: <%= response_format(true) %>
35
+ <%= response_body.each_line.map{|line| line.chomp.empty? ? line : " " + line}.join %>
36
+
37
+
38
+ Generated by <%= description %> at <%= location %>
39
+
40
+
41
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ghost_writer
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
  - joker1007
@@ -147,10 +147,21 @@ files:
147
147
  - lib/ghost_writer.rb
148
148
  - lib/ghost_writer/document.rb
149
149
  - lib/ghost_writer/document_index.rb
150
- - lib/ghost_writer/format/markdown.rb
151
- - lib/ghost_writer/format/rack.rb
152
- - lib/ghost_writer/format/rst.rb
150
+ - lib/ghost_writer/index_writer.rb
151
+ - lib/ghost_writer/index_writer/base.rb
152
+ - lib/ghost_writer/index_writer/markdown.rb
153
+ - lib/ghost_writer/index_writer/rack.rb
154
+ - lib/ghost_writer/index_writer/rst.rb
155
+ - lib/ghost_writer/index_writer/templates/markdown.erb
156
+ - lib/ghost_writer/index_writer/templates/rack.erb
157
+ - lib/ghost_writer/index_writer/templates/rst.erb
153
158
  - lib/ghost_writer/version.rb
159
+ - lib/ghost_writer/writer.rb
160
+ - lib/ghost_writer/writer/base.rb
161
+ - lib/ghost_writer/writer/markdown.rb
162
+ - lib/ghost_writer/writer/rst.rb
163
+ - lib/ghost_writer/writer/templates/markdown.erb
164
+ - lib/ghost_writer/writer/templates/rst.erb
154
165
  - output_examples/anonymous_controller/index.markdown
155
166
  - output_examples/anonymous_controller/show.markdown
156
167
  - output_examples/document_index.markdown
@@ -1,35 +0,0 @@
1
- module GhostWriter
2
- module Format
3
- module Markdown
4
- private
5
-
6
- def extname
7
- "md"
8
- end
9
-
10
- def headword(text, level = 1)
11
- "#{'#'*level} #{text}"
12
- end
13
-
14
- def paragraph(text)
15
- text + "\n"
16
- end
17
-
18
- def separator(length)
19
- "-" * length
20
- end
21
-
22
- def quote(text, quote_format = nil)
23
- "```#{quote_format}\n#{text}\n```"
24
- end
25
-
26
- def list(text, level = 1)
27
- "#{" " * (level - 1)}- #{text}"
28
- end
29
-
30
- def link(text, url)
31
- "[#{text}](#{url})"
32
- end
33
- end
34
- end
35
- end
@@ -1,99 +0,0 @@
1
- require 'multi_json'
2
-
3
- module GhostWriter
4
- module Format
5
- module Rack
6
- def write_index_file
7
- rack = <<RUBY
8
- require 'rack'
9
-
10
- class DummyApp
11
- def call(env)
12
- request = Rack::Request.new(env)
13
- case [request.request_method, request.path_info]
14
-
15
- RUBY
16
- documents.each do |output, docs|
17
- docs.each do |d|
18
- rack += <<RUBY
19
- when [#{d.request_method.inspect}, #{d.path_info.inspect}]
20
- if fuzzy_match(request.params, #{parameter_arranging(d.param_example.reject {|k, _| k == "format"}).inspect})
21
- [200, {"Content-Type" => #{d.content_type.inspect}}, [(<<BODY)]]
22
- #{d.response_example}
23
- BODY
24
- else
25
- [404, {"Content-Type" => "text/html"}, ['No match rule']]
26
- end
27
- RUBY
28
- end
29
- end
30
- rack += <<RUBY
31
- else
32
- [404, {"Content-Type" => "text/html"}, ['No match rule']]
33
- end
34
- end
35
-
36
- def fuzzy_match(params, other)
37
- params.all? do |k, v|
38
- case v
39
- when Hash
40
- return false unless other[k].instance_of?(Hash)
41
- fuzzy_match(v, other[k])
42
- when Array
43
- return false unless other[k].instance_of?(Array)
44
- fuzzy_match_array(v, other[k])
45
- else
46
- v.to_s == other[k].to_s
47
- end
48
- end
49
- end
50
-
51
- def fuzzy_match_array(array, other)
52
- array.each_with_index.all? do |v, i|
53
- case v
54
- when Hash
55
- fuzzy_match(v, other[i])
56
- when Array
57
- fuzzy_match_array(v, other[i])
58
- else
59
- v.to_s == other[i].to_s
60
- end
61
- end
62
- end
63
- end
64
- RUBY
65
- File.open("#{output}.#{extname}", "w") do |f|
66
- f.write rack
67
- end
68
-
69
- configru = File.join(File.dirname(output), "config.ru")
70
-
71
- File.open(configru, "w") do |f|
72
- f.write "require_relative '#{File.basename(output)}'\n"
73
- f.write "run DummyApp.new"
74
- end
75
- end
76
-
77
- def write_file(overwrite = false)
78
- end
79
-
80
- def content_type
81
- if param_example["format"] == "json"
82
- "application/json; charset=UTF-8"
83
- else
84
- "text/html; charset=UTF-8"
85
- end
86
- end
87
-
88
- private
89
-
90
- def extname
91
- "rb"
92
- end
93
-
94
- def parameter_arranging(params)
95
- MultiJson.load(MultiJson.dump(params))
96
- end
97
- end
98
- end
99
- end
@@ -1,50 +0,0 @@
1
- module GhostWriter
2
- module Format
3
- module Rst
4
- private
5
-
6
- def extname
7
- "rst"
8
- end
9
-
10
- def headword(text, level = 1)
11
- char = case level
12
- when 1
13
- "*"
14
- when 2
15
- "="
16
- when 3
17
- "-"
18
- when 4
19
- "^"
20
- end
21
- text + "\n" + char * text.length * 2
22
- end
23
-
24
- def paragraph(text)
25
- text + "\n"
26
- end
27
-
28
- def separator(length)
29
- ""
30
- end
31
-
32
- def quote(text, quote_format = nil)
33
- if quote_format
34
- marker = ".. code-block:: #{quote_format}" + "\n"
35
- else
36
- marker = "::" + "\n"
37
- end
38
- marker + "#{text.each_line.map{|line| line.chomp.empty? ? line : " " + line}.join}"
39
- end
40
-
41
- def list(text, level = 1)
42
- "#{" " * (level - 1)}* #{text}"
43
- end
44
-
45
- def link(text, url)
46
- "`#{text} #{url}`_"
47
- end
48
- end
49
- end
50
- end