grape-doc 0.3.4 → 0.4.0

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: aaecb438259bbda6c0f52ef2d1e7a027cd686b27
4
- data.tar.gz: ab25877beee8e7315d34b2fca1f5ca15f2b3743a
3
+ metadata.gz: b3ef112f1cfda8c0f2aeaea8a6e6bf31ec205c70
4
+ data.tar.gz: 3e3ba46f60a0a3f42e323d84335ab4e56ebf850e
5
5
  SHA512:
6
- metadata.gz: fcb4dfccecef9025b1877ab84a12fed26489201d660ac5faf932d8a98eed0a19d01103e6ce48c59153a238bdf728c490c5eeda3d5a6b7787b95680cefbfc401c
7
- data.tar.gz: 44205c82703e4b7176fc49255c0d50489c0b4387ffe1e07302b1a793f5ab494cecd45e6f221c7b752bb048cca94332f502f140532ba7a760b7fa8f584509bc09
6
+ metadata.gz: 610f14fea4beb9067955f13308491583cbb101d1984dff76c536b565cc93c26152ad4db64938e8549b83b32829784676900ca9a5d679f33765f28328e822a81a
7
+ data.tar.gz: ce10b1cbd6fed21329bf10e21f50b73da442262bb916adc0ee38a0a1f951149f530396db725ec7697253207d589b2121030196fbe87f18ef24c856cabe66d573
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.4
1
+ 0.4.0
@@ -2,23 +2,18 @@ module GrapeDoc
2
2
 
3
3
  class ApiDocumentation < Array
4
4
 
5
- def create(type,*args)
5
+ def build(type,*args)
6
6
  raise(ArgumentError,'invalid type') unless [String,Symbol].any?{ |klass| type.class <= klass }
7
7
  return Helpers.constantize("GrapeDoc::ApiDocParts::#{Helpers.camelize(type)}").new(*args)
8
- end
8
+ end;alias create build
9
9
 
10
10
  def add(type,*args)
11
11
  self.push(create(type,*args))
12
12
  end
13
13
 
14
- def br(int=1)
15
- raise unless int.class <= Integer
16
- int.times{self.push(ApiDocParts::Br.new("\n"))}
17
- end
18
-
19
14
  def to_textile
20
15
  require 'RedCloth'
21
- RedCloth.new(self.map{|e| e.to_textile }.join("\n"))
16
+ RedCloth.new(self.map{|e| e.to_textile }.join("\n\n"))
22
17
  end;alias to_s to_textile
23
18
 
24
19
  end
@@ -8,7 +8,7 @@ module GrapeDoc
8
8
  raise(ArgumentError,'invalid options given') unless opts.class <= Hash
9
9
  @options = {
10
10
  'format' => 'html',
11
- 'path' => File.join(Helpers.doc_folder_path,'api_doc.html')
11
+ 'path' => File.join(Helpers.doc_folder_path,'api_doc.html')
12
12
  }.merge(opts.reduce({}){|m,o| m.merge!(o[0].to_s => o[1]) ;m})
13
13
 
14
14
  process_head
@@ -23,8 +23,18 @@ module GrapeDoc
23
23
 
24
24
  def save
25
25
 
26
- File.write self.options['path'],
27
- document.to_textile.to_html
26
+ case @options['format'].to_s.downcase
27
+
28
+ when /redmine/,/textile/
29
+ File.write self.options['path'].sub(/\..*$/,'.textile'),
30
+ document.to_textile
31
+
32
+ else
33
+ File.write self.options['path'].sub(/\..*$/,'.html'),
34
+ document.to_textile.to_html
35
+
36
+
37
+ end
28
38
 
29
39
  true;rescue;false
30
40
  end;alias save! save
@@ -28,7 +28,7 @@ module GrapeDoc
28
28
  class StringObject < StringBasic
29
29
 
30
30
  def to_textile
31
- "#{markdown}. #{self.to_s}\n"
31
+ "#{markdown}. #{self.to_s}"
32
32
  end
33
33
 
34
34
  end
@@ -36,7 +36,7 @@ module GrapeDoc
36
36
  class StringObjectEnded < StringObject
37
37
 
38
38
  def to_textile
39
- "#{markdown}#{self}#{markdown}\n"
39
+ "#{markdown}#{self}#{markdown}"
40
40
  end
41
41
 
42
42
  end
@@ -82,7 +82,7 @@ module GrapeDoc
82
82
  "#{markdown} #{e}"
83
83
 
84
84
  end
85
- }.push('').join("\n")
85
+ }.join("\n")
86
86
  end
87
87
 
88
88
  end
data/test/sample.html CHANGED
@@ -22,7 +22,7 @@
22
22
  <li>status code: 200</li>
23
23
  <li>format type: json</li>
24
24
  </ul>
25
- <h6>raw body</h6>
25
+ <h6>raw response body</h6>
26
26
  <pre>{"hello":"world!"}</pre>
27
27
  <h6>json formatted body with Class types</h6>
28
28
  <pre>{
@@ -34,7 +34,7 @@
34
34
  <li>status code: 200</li>
35
35
  <li>format type: json</li>
36
36
  </ul>
37
- <h6>raw body</h6>
37
+ <h6>raw response body</h6>
38
38
  <pre>{"hello":"world!"}</pre>
39
39
  <h6>json formatted body with Class types</h6>
40
40
  <pre>{
@@ -0,0 +1,54 @@
1
+ h1. Rest Api Documentation (grape-doc)
2
+
3
+ h2. GET: /hello(.:format)
4
+
5
+ h3. Request
6
+
7
+ h4. description
8
+
9
+ * Hello world!
10
+
11
+ h4. params
12
+
13
+ * test
14
+ ** required: false
15
+ ** type: String
16
+ ** desc: it's a test string
17
+
18
+ h3. Response
19
+
20
+ h4. example
21
+
22
+ h5. curl sample with /hello
23
+
24
+ <pre>$ curl -X GET "http://example.org/hello?test=hy" -H "Accept-Version: v1" -H "X-Token: blabla"</pre>
25
+
26
+ * status code: 200
27
+ * format type: json
28
+
29
+ h6. raw response body
30
+
31
+ <pre>{"hello":"world!"}</pre>
32
+
33
+ h6. json formatted body with Class types
34
+
35
+ <pre>{
36
+ "hello": "String"
37
+ }</pre>
38
+
39
+ h5. curl sample with /hello.json
40
+
41
+ <pre>$ curl -X GET "http://example.org/hello.json?" -H "Accept-Version: v1" -H "X-Token: blabla"</pre>
42
+
43
+ * status code: 200
44
+ * format type: json
45
+
46
+ h6. raw response body
47
+
48
+ <pre>{"hello":"world!"}</pre>
49
+
50
+ h6. json formatted body with Class types
51
+
52
+ <pre>{
53
+ "hello": "String"
54
+ }</pre>
@@ -4,7 +4,7 @@ describe 'Doc generating' do
4
4
  specify 'test documentation generator' do
5
5
 
6
6
  var = GrapeDoc.new
7
- GrapeDoc.generate path: File.join(__dir__,'sample.html')
7
+ GrapeDoc.generate path: File.join(__dir__,'sample.html'),format: 'redmine'
8
8
 
9
9
  end
10
10
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-doc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Luzsi
@@ -136,6 +136,7 @@ files:
136
136
  - lib/grape/doc/parser.rb
137
137
  - lib/grape/doc/prototype.rb
138
138
  - test/sample.html
139
+ - test/sample.textile
139
140
  - test/test_all.rb
140
141
  - test/test_collector.rb
141
142
  - test/test_generator.rb
@@ -166,6 +167,7 @@ specification_version: 4
166
167
  summary: Documentation generator for Grape module
167
168
  test_files:
168
169
  - test/sample.html
170
+ - test/sample.textile
169
171
  - test/test_all.rb
170
172
  - test/test_collector.rb
171
173
  - test/test_generator.rb