double_doc 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,8 @@
1
1
  module DoubleDoc
2
2
  class DocExtractor
3
3
  TYPES = {
4
- 'rb' => /\s*##\s?(.*)$/
4
+ 'rb' => /\s*##\s?(.*)$/,
5
+ 'js' => %r{\s*///\s?(.*)$}
5
6
  }.freeze
6
7
 
7
8
  def self.extract(source, options = {})
@@ -3,8 +3,22 @@ require 'double_doc/doc_extractor'
3
3
 
4
4
  module DoubleDoc
5
5
  class ImportHandler
6
- def initialize(root)
6
+ attr_reader :root, :load_paths
7
+
8
+ def initialize(root, options = {})
7
9
  @root = Pathname.new(root)
10
+ @load_paths = [@root]
11
+
12
+ if options[:gemfile]
13
+ gemfile = @root + "Gemfile"
14
+
15
+ unless gemfile.exist?
16
+ raise LoadError, "missing Gemfile inside #{@root}"
17
+ end
18
+
19
+ @load_paths.concat(load_paths_from_gemfile(gemfile))
20
+ end
21
+
8
22
  @docs = {}
9
23
  end
10
24
 
@@ -23,6 +37,20 @@ module DoubleDoc
23
37
 
24
38
  protected
25
39
 
40
+ def load_paths_from_gemfile(gemfile)
41
+ with_gemfile(gemfile) do
42
+ puts "Loading paths from #{gemfile}"
43
+
44
+ defn = Bundler::Definition.build(gemfile, @root + "Gemfile.lock", nil)
45
+ defn.validate_ruby!
46
+ defn.resolve_with_cache!
47
+
48
+ defn.specs.inject([]) do |paths, spec|
49
+ paths.concat(spec.load_paths.map {|p| Pathname.new(p)})
50
+ end
51
+ end
52
+ end
53
+
26
54
  def resolve_imports_from_lines(lines)
27
55
  doc = []
28
56
 
@@ -40,7 +68,7 @@ module DoubleDoc
40
68
  def get_doc(path)
41
69
  return @docs[path] if @docs[path]
42
70
 
43
- file = File.new(@root + path)
71
+ file = find_file(path)
44
72
 
45
73
  if path =~ /\.md$/
46
74
  @docs[path] = resolve_imports(file)
@@ -48,5 +76,24 @@ module DoubleDoc
48
76
  @docs[path] = resolve_imports(DocExtractor.extract(file))
49
77
  end
50
78
  end
79
+
80
+ def find_file(path)
81
+ load_path = @load_paths.detect do |load_path|
82
+ (load_path + path).exist?
83
+ end
84
+
85
+ unless load_path
86
+ raise LoadError, "No such file or directory: #{path}"
87
+ end
88
+
89
+ File.new(load_path + path)
90
+ end
91
+
92
+ def with_gemfile(gemfile)
93
+ ENV["BUNDLE_GEMFILE"], orig_gemfile = gemfile.to_s, ENV["BUNDLE_GEMFILE"]
94
+ yield
95
+ ensure
96
+ ENV["BUNDLE_GEMFILE"] = orig_gemfile
97
+ end
51
98
  end
52
99
  end
@@ -57,7 +57,7 @@ module DoubleDoc
57
57
 
58
58
  desc "Generate markdown #{html_dst ? 'and HTML ' : ''}DoubleDoc documentation from #{sources.join(', ')}"
59
59
  generated_task = task(task_name => destinations) do |t, args|
60
- import_handler = DoubleDoc::ImportHandler.new(options[:root] || Rake.original_dir)
60
+ import_handler = DoubleDoc::ImportHandler.new(options[:root] || Rake.original_dir, options.fetch(:import, {}))
61
61
 
62
62
  generated_md_files = []
63
63
 
@@ -1,4 +1,4 @@
1
- ## ## DoubleDoc 1.2
1
+ ## ## DoubleDoc 1.3
2
2
  module DoubleDoc
3
- VERSION = "1.2.1"
3
+ VERSION = "1.3.0"
4
4
  end
@@ -1,4 +1,4 @@
1
- ## DoubleDoc 1.2
1
+ ## DoubleDoc 1.3
2
2
 
3
3
  One of the challenges you face when writing public documention for code or APIs, is that you have to remember to update the documentation
4
4
  when ever you change the API. The main reason why this is a problem is that very often the documentation lives very for from your code.
@@ -1,31 +1,49 @@
1
1
  require 'test_helper'
2
2
 
3
3
  describe "the doc extractor" do
4
- describe "on ruby files" do
5
- ## this line should be extracted
6
- # this line should not be extracted
7
- ## this line should also be extracted
8
4
 
9
- before do
10
- @doc = DoubleDoc::DocExtractor.extract(File.new(__FILE__))
5
+ def self.it_acts_like_an_extractor
6
+ it "extracts documentation" do
7
+ subject.must_match(/this line should be extracted/)
8
+ subject.must_match(/this line should also be extracted/)
11
9
  end
12
10
 
13
- it "should extract documentation from ruby files" do
14
- @doc.must_match(/this line should be extracted/)
15
- @doc.must_match(/this line should also be extracted/)
11
+ it "doesn't extract regular comments" do
12
+ subject.wont_match(/this line should not be extracted/)
16
13
  end
17
14
 
18
- it "should not extract regular comments" do
19
- @doc.wont_match(/this line should not be extracted/)
15
+ it "doesn't add any extra new-lines" do
16
+ subject.must_match(/^this/m)
17
+ subject.must_match(/extracted\n$/m)
20
18
  end
21
19
 
22
- it "should not add any extra new-lines" do
23
- @doc.must_match(/^this/m)
24
- @doc.must_match(/extracted\n$/m)
20
+ it "adds an empty line between documentation sections" do
21
+ subject.must_match(/extracted\n\nthis/m)
25
22
  end
23
+ end
26
24
 
27
- it "add an empty line between documentation sections" do
28
- @doc.must_match(/extracted\n\nthis/m)
25
+ describe "on .rb files" do
26
+ ## this line should be extracted
27
+ # this line should not be extracted
28
+ ## this line should also be extracted
29
+
30
+ subject do
31
+ DoubleDoc::DocExtractor.extract(File.new(__FILE__))
32
+ end
33
+
34
+ it_acts_like_an_extractor
35
+ end
36
+
37
+ describe 'on .js files' do
38
+ subject do
39
+ source = <<-EOS
40
+ /// this line should be extracted
41
+ // this line should not be extracted
42
+ /// this line should also be extracted
43
+ EOS
44
+ DoubleDoc::DocExtractor.extract(source, :type => 'js')
29
45
  end
46
+
47
+ it_acts_like_an_extractor
30
48
  end
31
49
  end
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "double_doc", :path => File.join(File.expand_path(File.dirname(__FILE__)), "..", "..")
4
+ gem "mime-types", :git => "https://github.com/halostatue/mime-types.git", :ref => "v1.22"
@@ -0,0 +1,34 @@
1
+ GIT
2
+ remote: https://github.com/halostatue/mime-types.git
3
+ revision: b8d2208cc34e9b9ca6456182742dcb3bfc47daf6
4
+ ref: v1.22
5
+ specs:
6
+ mime-types (1.20.1)
7
+
8
+ PATH
9
+ remote: /Users/staugaard/code/double_doc
10
+ specs:
11
+ double_doc (1.3.0)
12
+ erubis
13
+ pygments.rb (~> 0.2)
14
+ rake
15
+ redcarpet (~> 2.1)
16
+
17
+ GEM
18
+ remote: https://rubygems.org/
19
+ specs:
20
+ erubis (2.7.0)
21
+ posix-spawn (0.3.6)
22
+ pygments.rb (0.5.0)
23
+ posix-spawn (~> 0.3.6)
24
+ yajl-ruby (~> 1.1.0)
25
+ rake (10.0.4)
26
+ redcarpet (2.2.2)
27
+ yajl-ruby (1.1.0)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ double_doc!
34
+ mime-types!
@@ -0,0 +1,61 @@
1
+ require 'test_helper'
2
+
3
+ describe "import handler" do
4
+ subject do
5
+ DoubleDoc::ImportHandler.new(root, options)
6
+ end
7
+
8
+ after do
9
+ ENV["BUNDLE_GEMFILE"] = Bundler.root.join("Gemfile").to_s
10
+ end
11
+
12
+ describe "with gemfile" do
13
+ let(:root) { Bundler.root }
14
+ let(:options) {{ :gemfile => true }}
15
+
16
+ describe "when root has no tmpfile" do
17
+ let(:root) { Bundler.root + "lib" }
18
+
19
+ describe "initialization" do
20
+ it "should raise" do
21
+ lambda { subject }.must_raise LoadError
22
+ end
23
+ end
24
+ end
25
+
26
+ describe "rubygems" do
27
+ describe "load_paths" do
28
+ it "should add Gemfile load paths" do
29
+ subject.load_paths.must_include subject.root
30
+ subject.load_paths.size.must_be :>, 1
31
+ end
32
+ end
33
+
34
+ describe "find_file" do
35
+ it "should resolve files" do
36
+ subject.send(:find_file, "bundler.rb").must_be_instance_of File
37
+ end
38
+
39
+ it "should raise if unable to find file" do
40
+ lambda do
41
+ subject.send(:find_file, "nope.rb")
42
+ end.must_raise LoadError
43
+ end
44
+ end
45
+ end
46
+
47
+ describe "path, git" do
48
+ let(:root) { File.join(File.expand_path(File.dirname(__FILE__)), "fixtures") }
49
+
50
+ describe "find_file" do
51
+ it "should resolve files from path" do
52
+ subject.send(:find_file, "double_doc.rb").must_be_instance_of File
53
+ end
54
+
55
+ it "should resolve file from git" do
56
+ subject.send(:find_file, "mime-types.rb").must_be_instance_of File
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
metadata CHANGED
@@ -1,118 +1,120 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: double_doc
3
- version: !ruby/object:Gem::Version
4
- hash: 29
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.0
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 2
9
- - 1
10
- version: 1.2.1
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Mick Staugaard
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-04-16 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2013-05-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: guard
22
- version_requirements: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
23
17
  none: false
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- hash: 3
28
- segments:
29
- - 0
30
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
31
22
  type: :development
32
23
  prerelease: false
33
- requirement: *id001
34
- - !ruby/object:Gem::Dependency
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
35
31
  name: minitest
36
- version_requirements: &id002 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
37
33
  none: false
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- hash: 3
42
- segments:
43
- - 0
44
- version: "0"
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
45
38
  type: :development
46
39
  prerelease: false
47
- requirement: *id002
48
- - !ruby/object:Gem::Dependency
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
49
47
  name: rake
50
- version_requirements: &id003 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
51
49
  none: false
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- hash: 3
56
- segments:
57
- - 0
58
- version: "0"
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
59
54
  type: :runtime
60
55
  prerelease: false
61
- requirement: *id003
62
- - !ruby/object:Gem::Dependency
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
63
  name: erubis
64
- version_requirements: &id004 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
65
65
  none: false
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- hash: 3
70
- segments:
71
- - 0
72
- version: "0"
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
73
70
  type: :runtime
74
71
  prerelease: false
75
- requirement: *id004
76
- - !ruby/object:Gem::Dependency
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
77
79
  name: redcarpet
78
- version_requirements: &id005 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
79
81
  none: false
80
- requirements:
82
+ requirements:
81
83
  - - ~>
82
- - !ruby/object:Gem::Version
83
- hash: 1
84
- segments:
85
- - 2
86
- - 1
87
- version: "2.1"
84
+ - !ruby/object:Gem::Version
85
+ version: '2.1'
88
86
  type: :runtime
89
87
  prerelease: false
90
- requirement: *id005
91
- - !ruby/object:Gem::Dependency
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '2.1'
94
+ - !ruby/object:Gem::Dependency
92
95
  name: pygments.rb
93
- version_requirements: &id006 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
94
97
  none: false
95
- requirements:
98
+ requirements:
96
99
  - - ~>
97
- - !ruby/object:Gem::Version
98
- hash: 15
99
- segments:
100
- - 0
101
- - 2
102
- version: "0.2"
100
+ - !ruby/object:Gem::Version
101
+ version: '0.2'
103
102
  type: :runtime
104
103
  prerelease: false
105
- requirement: *id006
106
- description: A simple framework for writing and generating beautiful documentation for your code
107
- email:
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '0.2'
110
+ description: A simple framework for writing and generating beautiful documentation
111
+ for your code
112
+ email:
108
113
  - mick@staugaard.com
109
114
  executables: []
110
-
111
115
  extensions: []
112
-
113
116
  extra_rdoc_files: []
114
-
115
- files:
117
+ files:
116
118
  - lib/double_doc/doc_extractor.rb
117
119
  - lib/double_doc/html_generator.rb
118
120
  - lib/double_doc/html_renderer.rb
@@ -124,44 +126,59 @@ files:
124
126
  - lib/guard/doubledoc.rb
125
127
  - templates/default.html.erb
126
128
  - templates/screen.css
127
- - README.md
129
+ - readme.md
128
130
  - test/doc_extractor_test.rb
131
+ - test/fixtures/Gemfile
132
+ - test/fixtures/Gemfile.lock
133
+ - test/fixtures/vendor/cache/erubis-2.7.0.gem
134
+ - test/fixtures/vendor/cache/posix-spawn-0.3.6.gem
135
+ - test/fixtures/vendor/cache/pygments.rb-0.5.0.gem
136
+ - test/fixtures/vendor/cache/rake-10.0.4.gem
137
+ - test/fixtures/vendor/cache/redcarpet-2.2.2.gem
138
+ - test/fixtures/vendor/cache/yajl-ruby-1.1.0.gem
129
139
  - test/html_generator_test.rb
140
+ - test/import_handler_test.rb
130
141
  - test/test_helper.rb
131
142
  homepage: http://staugaard.github.com/double_doc
132
143
  licenses: []
133
-
134
144
  post_install_message:
135
145
  rdoc_options: []
136
-
137
- require_paths:
146
+ require_paths:
138
147
  - lib
139
- required_ruby_version: !ruby/object:Gem::Requirement
148
+ required_ruby_version: !ruby/object:Gem::Requirement
140
149
  none: false
141
- requirements:
142
- - - ">="
143
- - !ruby/object:Gem::Version
144
- hash: 3
145
- segments:
150
+ requirements:
151
+ - - ! '>='
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ segments:
146
155
  - 0
147
- version: "0"
148
- required_rubygems_version: !ruby/object:Gem::Requirement
156
+ hash: -1537526380922081734
157
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
158
  none: false
150
- requirements:
151
- - - ">="
152
- - !ruby/object:Gem::Version
153
- hash: 3
154
- segments:
159
+ requirements:
160
+ - - ! '>='
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ segments:
155
164
  - 0
156
- version: "0"
165
+ hash: -1537526380922081734
157
166
  requirements: []
158
-
159
167
  rubyforge_project:
160
- rubygems_version: 1.8.21
168
+ rubygems_version: 1.8.25
161
169
  signing_key:
162
170
  specification_version: 3
163
171
  summary: Documentation right where you want it
164
- test_files:
172
+ test_files:
165
173
  - test/doc_extractor_test.rb
174
+ - test/fixtures/Gemfile
175
+ - test/fixtures/Gemfile.lock
176
+ - test/fixtures/vendor/cache/erubis-2.7.0.gem
177
+ - test/fixtures/vendor/cache/posix-spawn-0.3.6.gem
178
+ - test/fixtures/vendor/cache/pygments.rb-0.5.0.gem
179
+ - test/fixtures/vendor/cache/rake-10.0.4.gem
180
+ - test/fixtures/vendor/cache/redcarpet-2.2.2.gem
181
+ - test/fixtures/vendor/cache/yajl-ruby-1.1.0.gem
166
182
  - test/html_generator_test.rb
183
+ - test/import_handler_test.rb
167
184
  - test/test_helper.rb