grape-doc 0.4.3 → 0.5.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: f091b08c9891f653ccf8135a7ed2acd82b9aab73
4
- data.tar.gz: abde91cc6fdf56b1a98a0a3d57f8cbdc50c70b5a
3
+ metadata.gz: 20c49ea385aee4168b325d4df3d75843c5fcd505
4
+ data.tar.gz: 7dfb74e1f420d008dc8ad3b66c7d262b026b8321
5
5
  SHA512:
6
- metadata.gz: 55f9cbb99cd28cef5a1de3ed71d3e644b41cef3d3aa3e843cb3205a08e8aeedf8375bdcea6d122289603f296ee22202b9a605a76d57a09d9eb77ddd245cf65dd
7
- data.tar.gz: 12dc7014a7b4022bffbd1bff1fb20929e1f2fe817d3010eec43858da5a1053c8d9b2ade4fad3558fe92d913928af3e32c2c5c7b3d4ba8fef56df6db88922cd41
6
+ metadata.gz: dd034ca8b87b1b77d87d5ae2f9db763babf1205d875722b975672155ef62ed1f318a09a61feb4a303ae7598392dad2885f4507872acab521c722ac991c998c3f
7
+ data.tar.gz: cedebfb30692dfe07801696fd2e65e567ae9c7f469ffb5ab8e1830ca19c04a2426f46fd99adf1f4e60013811fe49f58d309b280bf794fbd80785783479daedad
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.3
1
+ 0.5.0
data/grape-doc.gemspec CHANGED
@@ -2,27 +2,27 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
 
5
- spec.name = "grape-doc"
6
- spec.version = File.open(File.join(File.dirname(__FILE__),"VERSION")).read.split("\n")[0].chomp.gsub(' ','')
7
- spec.authors = ["Adam Luzsi"]
8
- spec.email = ["adamluzsi@gmail.com"]
5
+ spec.name = 'grape-doc'
6
+ spec.version = File.open(File.join(File.dirname(__FILE__),'VERSION')).read.split("\n")[0].chomp.gsub(' ','')
7
+ spec.authors = ['Adam Luzsi']
8
+ spec.email = ['adamluzsi@gmail.com']
9
9
 
10
- spec.description = %q{ Documentation generator for Grape module compatible with Redmine and Github formats }
10
+ spec.description = %q{ Documentation generator for Grape module compatible with Redmine/textile and Html formats }
11
11
  spec.summary = %q{ Documentation generator for Grape module }
12
12
 
13
13
  spec.homepage = "https://github.com/adamluzsi/#{__FILE__.split(File::Separator).last.split('.').first}"
14
14
  spec.files = `git ls-files`.split($/)
15
15
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
16
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
- spec.require_paths = ["lib"]
17
+ spec.require_paths = ['lib']
18
18
 
19
- spec.add_development_dependency "bundler"
20
- spec.add_development_dependency "rake"
19
+ spec.add_development_dependency 'bundler'
20
+ spec.add_development_dependency 'rake'
21
21
 
22
- spec.add_dependency "grape"
23
- spec.add_dependency "loader"
24
- spec.add_dependency "RedCloth"
25
- spec.add_dependency "rack-test"
26
- spec.add_dependency "rack-test-poc",">= 1.1.0"
22
+ spec.add_dependency 'grape'
23
+ spec.add_dependency 'loader'
24
+ spec.add_dependency 'RedCloth'
25
+ spec.add_dependency 'rack-test'
26
+ spec.add_dependency 'rack-test-poc','>= 1.1.0'
27
27
 
28
28
  end
data/lib/grape-doc.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  require 'loader'
2
+ require 'securerandom'
2
3
  require 'rack-test-poc'
3
4
  require_relative_directory_r 'grape/doc'
@@ -13,7 +13,7 @@ module GrapeDoc
13
13
 
14
14
  def to_textile
15
15
  require 'RedCloth'
16
- RedCloth.new(self.map{|e| e.to_textile }.join("\n\n"))
16
+ RedCloth.new(self.map{|e| e.respond_to?(:to_textile) ? e.to_textile : e.to_s }.join("\n\n"))
17
17
  end;alias to_s to_textile
18
18
 
19
19
  end
@@ -1,7 +1,35 @@
1
1
  module GrapeDoc
2
2
  class ApiDocParts
3
3
 
4
+ module TOC
5
+ class << self
6
+
7
+ def add_header(header_obj)
8
+ if [H1,H2].include? header_obj.class
9
+ (@headers ||= []).push(header_obj)
10
+ end
11
+ end
12
+
13
+ def create_toc
14
+ @headers.map { |header_obj|
15
+ [
16
+ '*' * header_obj.markdown.scan(/\d+$/)[0].to_i,
17
+ " \"#{header_obj.to_s}\":##{header_obj.instance_variable_get(:@opts)['id']}"
18
+ ].join
19
+ }.join("\n") + "\n\n"
20
+ end
21
+
22
+ end
23
+ end
24
+
4
25
  class H1 < StringObject
26
+
27
+ def initialize(*args)
28
+ super
29
+ @opts['id']= SecureRandom.uuid
30
+ TOC.add_header(self)
31
+ end
32
+
5
33
  end
6
34
 
7
35
  class H2 < H1
@@ -13,8 +13,8 @@ module GrapeDoc
13
13
  self.options['path'] = self.options['path'].to_s.sub(/\..*$/,'')
14
14
 
15
15
  process_head
16
- process_table_of_content
17
16
  process_endpoints
17
+ process_table_of_content
18
18
 
19
19
  end
20
20
 
@@ -48,6 +48,7 @@ module GrapeDoc
48
48
 
49
49
  def process_table_of_content
50
50
  #TODO: Table of content here!
51
+ document.insert 1, ApiDocParts::TOC.create_toc
51
52
  end
52
53
 
53
54
  def process_endpoints
@@ -21,7 +21,7 @@ module GrapeDoc
21
21
 
22
22
  def poc_file_path
23
23
  return Dir.glob(
24
- File.join(RackTestPoc.root,'test','poc','*.{yml,yaml}')
24
+ File.join(::RackTestPoc.root,'test','poc','*.{yml,yaml}')
25
25
  ).max_by(&File.method(:ctime))
26
26
  end
27
27
 
@@ -13,6 +13,12 @@ module GrapeDoc
13
13
  end
14
14
 
15
15
  def initialize(*args)
16
+
17
+ @opts = args.select{|e| e.class <= ::Hash }
18
+ args -= @opts
19
+
20
+ @opts = @opts.reduce({}){|m,o| m.merge!(o[0].to_s => o[1]) ;m}
21
+
16
22
  args[0] = Parser.parse(args[0])
17
23
  self.replace(args[0].to_s)
18
24
  end
@@ -21,27 +27,49 @@ module GrapeDoc
21
27
  self.class.markdown
22
28
  end
23
29
 
24
- alias to_textile to_s
30
+ def to_textile
31
+ case @opts['style'].to_s.downcase
25
32
 
26
- end
33
+ when /^mirror/
34
+ "#{markdown}#{self}#{markdown}"
27
35
 
28
- class StringObject < StringBasic
36
+ when /^start/,/^begin/
29
37
 
30
- def to_textile
31
- "#{markdown}. #{self.to_s}"
38
+ options = [
39
+ @opts['class'] ? "#{@opts['class']}" : nil,
40
+ @opts['id'] ? "##{@opts['id']}" : nil
41
+ ].compact
42
+
43
+ [
44
+ markdown,
45
+ options.empty? ? nil : "(#{options.join(' ')})",
46
+ '. ',
47
+ self.to_s
48
+ ].compact.join
49
+
50
+ else
51
+ self.to_s
52
+
53
+ end
32
54
  end
33
55
 
34
56
  end
35
57
 
36
- class StringObjectEnded < StringObject
37
-
38
- def to_textile
39
- "#{markdown}#{self}#{markdown}"
58
+ class StringObject < StringBasic
59
+ def initialize(*args)
60
+ super
61
+ @opts['style']= 'start'
40
62
  end
63
+ end
41
64
 
65
+ class StringObjectEnded < StringObject
66
+ def initialize(*args)
67
+ super
68
+ @opts['style']= 'mirror'
69
+ end
42
70
  end
43
71
 
44
- class ArrayObject < Array
72
+ class ArrayBasic < Array
45
73
 
46
74
  class << self
47
75
  def markdown=(obj)
@@ -87,5 +115,8 @@ module GrapeDoc
87
115
 
88
116
  end
89
117
 
118
+ class ArrayObject < ArrayBasic
119
+ end
120
+
90
121
  end
91
122
  end
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.4.3
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Luzsi
@@ -108,8 +108,8 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: 1.1.0
111
- description: " Documentation generator for Grape module compatible with Redmine and
112
- Github formats "
111
+ description: " Documentation generator for Grape module compatible with Redmine/textile
112
+ and Html formats "
113
113
  email:
114
114
  - adamluzsi@gmail.com
115
115
  executables: []