smartgen 0.6.0 → 0.6.1

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.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +0 -8
  3. data/Gemfile.lock +25 -31
  4. data/lib/smartgen/object_hash.rb +2 -2
  5. data/lib/smartgen/version.rb +1 -1
  6. metadata +138 -194
  7. data/spec/fixtures/expectations/common/another_index.html +0 -13
  8. data/spec/fixtures/expectations/common/index.html +0 -8
  9. data/spec/fixtures/expectations/common/other_index.html +0 -13
  10. data/spec/fixtures/expectations/erb/index.html +0 -15
  11. data/spec/fixtures/expectations/erb/with_layout/index.html +0 -19
  12. data/spec/fixtures/expectations/indexer/index_with_indexer.html +0 -16
  13. data/spec/fixtures/expectations/indexer/index_with_indexer_and_numbered_index.html +0 -16
  14. data/spec/fixtures/expectations/with_layout/index.html +0 -12
  15. data/spec/fixtures/expectations/with_layout/index_with_metadata.html +0 -43
  16. data/spec/fixtures/expectations/with_layout/index_with_specific_metadata.html +0 -44
  17. data/spec/fixtures/src/assets/images/image.gif +0 -0
  18. data/spec/fixtures/src/assets/javascripts/somelib.js +0 -2
  19. data/spec/fixtures/src/assets/stylesheets/style.css +0 -2
  20. data/spec/fixtures/src/common/another_index.md +0 -12
  21. data/spec/fixtures/src/common/index.textile +0 -10
  22. data/spec/fixtures/src/common/other_index.markdown +0 -12
  23. data/spec/fixtures/src/common/somefile +0 -10
  24. data/spec/fixtures/src/erb/index.html.erb +0 -7
  25. data/spec/fixtures/src/erb/with_layout/index.html.erb +0 -7
  26. data/spec/fixtures/src/erb/with_layout/layout.html.erb +0 -5
  27. data/spec/fixtures/src/indexer/index_with_indexer.textile +0 -26
  28. data/spec/fixtures/src/indexer/index_with_indexer_and_numbered_index.textile +0 -26
  29. data/spec/fixtures/src/layout.html.erb +0 -5
  30. data/spec/fixtures/src/layout_with_metadata.html.erb +0 -22
  31. data/spec/fixtures/src/layout_with_specific_metadata.html.erb +0 -23
  32. data/spec/fixtures/src/metadata.yml +0 -43
  33. data/spec/fixtures/src/with_layout/index.textile +0 -10
  34. data/spec/fixtures/src/with_layout/index_with_specific_metadata.textile +0 -10
  35. data/spec/lib/smartgen/configuration_spec.rb +0 -5
  36. data/spec/lib/smartgen/engines/base_spec.rb +0 -92
  37. data/spec/lib/smartgen/engines/erb_spec.rb +0 -37
  38. data/spec/lib/smartgen/engines/markdown_spec.rb +0 -23
  39. data/spec/lib/smartgen/engines/textile_spec.rb +0 -19
  40. data/spec/lib/smartgen/generator_spec.rb +0 -272
  41. data/spec/lib/smartgen/indexer_spec.rb +0 -122
  42. data/spec/lib/smartgen/markup_file_spec.rb +0 -168
  43. data/spec/lib/smartgen/object_hash_spec.rb +0 -91
  44. data/spec/lib/smartgen/renderers/erb_spec.rb +0 -38
  45. data/spec/lib/smartgen/resource_spec.rb +0 -73
  46. data/spec/lib/smartgen/watcher_spec.rb +0 -71
  47. data/spec/lib/smartgen_spec.rb +0 -18
  48. data/spec/sandbox/.gitkeep +0 -0
  49. data/spec/spec_helper.rb +0 -37
@@ -1,122 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Smartgen::Indexer do
4
- matcher :have_tag do |tag, attributes|
5
- match do |actual|
6
- tags = Nokogiri::HTML(actual).css(tag.to_s)
7
- tags.present? && tags.any? do |tag|
8
- attributes.all? do |attribute, value|
9
- tag.has_attribute?(attribute.to_s) && tag[attribute.to_s] == value
10
- end
11
- end
12
- end
13
- end
14
-
15
- matcher :have_tag_with_contents do |tag, content|
16
- match do |actual|
17
- tags = Nokogiri::HTML(actual).css(tag.to_s)
18
- tags.present? && tags.any? do |tag|
19
- tag.content == content
20
- end
21
- end
22
- end
23
-
24
- def html
25
- "<h1>Some header</h1>"
26
- end
27
-
28
- subject { Smartgen::Indexer.new html }
29
-
30
- describe "addition of IDs" do
31
- def html
32
- return <<-HTML
33
- <html>
34
- <body>
35
- <h1>A h1 header</h1>
36
- <h2>A h2 header</h2>
37
- <h3>A h3 header</h3>
38
- <h4>A h4 header</h4>
39
- <h5>A h5 header</h5>
40
- <h6>A h6 header</h6>
41
- </body>
42
- </html>
43
- HTML
44
- end
45
-
46
- 1.upto(6).each do |header_level|
47
- it "should add IDs for each <h#{header_level}> tag in the result" do
48
- subject.result.should have_tag("h#{header_level}", :id => "a-h#{header_level}-header")
49
- end
50
- end
51
- end
52
-
53
- describe "index" do
54
- def html
55
- return <<-HTML
56
- <html>
57
- <body>
58
- <h1>A h1 header</h1>
59
- <h2>A h2 header</h2>
60
- <h3>A h3 header</h3>
61
- <h3>Some other h3 header</h3>
62
- <h2>Another h2 header</h2>
63
- <h5>A h5 header</h5>
64
- <h2>Yet Another h2 header</h2>
65
- <h3>Yet Another h3 header</h3>
66
- <h1>Other h1 header</h1>
67
- </body>
68
- </html>
69
- HTML
70
- end
71
-
72
- it "should return an index with headers data hierarquically distributed" do
73
- expected_index = [
74
- { :text => 'A h1 header', :id => 'a-h1-header', :level => 1, :children => [
75
- { :text => 'A h2 header', :id => 'a-h2-header', :level => 2, :children => [
76
- { :text => 'A h3 header', :id => 'a-h3-header', :level => 3, :children => [] },
77
- { :text => 'Some other h3 header', :id => 'some-other-h3-header', :level => 3, :children => [] }
78
- ] },
79
- { :text => 'Another h2 header', :id => 'another-h2-header', :level => 2, :children => [
80
- { :text => 'A h5 header', :id => 'a-h5-header', :level => 5, :children => [] }
81
- ] },
82
- { :text => 'Yet Another h2 header', :id => 'yet-another-h2-header', :level => 2, :children => [
83
- { :text => 'Yet Another h3 header', :id => 'yet-another-h3-header', :level => 3, :children => [] }
84
- ] },
85
- ]},
86
- { :text => 'Other h1 header', :id => 'other-h1-header', :level => 1, :children => [] }
87
- ]
88
-
89
- subject.index.should == expected_index
90
- end
91
-
92
- context "when numbered_index options is given" do
93
- subject { Smartgen::Indexer.new html, :numbered_index => true }
94
-
95
- it "should add the numbered index to header contents" do
96
- subject.result.should have_tag_with_contents("h1", "1 A h1 header")
97
- subject.result.should have_tag_with_contents("h2", "1.1 A h2 header")
98
- subject.result.should have_tag_with_contents("h3", "1.1.2 Some other h3 header")
99
- end
100
-
101
- it "should return an index with headers data hierarquically distributed with numbered index" do
102
- expected_index = [
103
- { :text => 'A h1 header', :id => 'a-h1-header', :level => 1, :numbered_index => '1', :children => [
104
- { :text => 'A h2 header', :id => 'a-h2-header', :level => 2, :numbered_index => '1.1', :children => [
105
- { :text => 'A h3 header', :id => 'a-h3-header', :level => 3, :numbered_index => '1.1.1', :children => [] },
106
- { :text => 'Some other h3 header', :id => 'some-other-h3-header', :level => 3, :numbered_index => '1.1.2', :children => [] }
107
- ] },
108
- { :text => 'Another h2 header', :id => 'another-h2-header', :level => 2, :numbered_index => '1.2', :children => [
109
- { :text => 'A h5 header', :id => 'a-h5-header', :level => 5, :numbered_index => '1.2.1', :children => [] }
110
- ] },
111
- { :text => 'Yet Another h2 header', :id => 'yet-another-h2-header', :level => 2, :numbered_index => '1.3', :children => [
112
- { :text => 'Yet Another h3 header', :id => 'yet-another-h3-header', :level => 3, :numbered_index => '1.3.1', :children => [] }
113
- ] },
114
- ]},
115
- { :text => 'Other h1 header', :id => 'other-h1-header', :level => 1, :numbered_index => '2', :children => [] }
116
- ]
117
-
118
- subject.index.should == expected_index
119
- end
120
- end
121
- end
122
- end
@@ -1,168 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Smartgen::MarkupFile do
4
- def path
5
- fixture('src/common/index.textile')
6
- end
7
-
8
- subject { Smartgen::MarkupFile.new path }
9
-
10
- describe "engine registration" do
11
- before do
12
- Smartgen::MarkupFile.engines.clear
13
- end
14
-
15
- after do
16
- Smartgen::MarkupFile.engines.clear
17
- end
18
-
19
- it "should register textile engine by default" do
20
- Smartgen::MarkupFile.engines.one? { |engine| engine.instance_of?(Smartgen::Engine::Textile) }.should be_true, "Textile was not registered as engine"
21
- end
22
-
23
- it "should register markdown engine by default" do
24
- Smartgen::MarkupFile.engines.one? { |engine| engine.instance_of?(Smartgen::Engine::Markdown) }.should be_true, "Markdown was not registered as engine"
25
- end
26
-
27
- class MyEngine < Smartgen::Engine::Base
28
- protected
29
- def parse(body)
30
- "some processing"
31
- end
32
-
33
- def extensions
34
- ['.something', '.otherext']
35
- end
36
- end
37
-
38
- it "should register an engine" do
39
- Smartgen::MarkupFile.register(MyEngine)
40
- Smartgen::MarkupFile.engines.one? { |engine| engine.instance_of?(MyEngine) }.should be_true, "MyEngine was not registered as engine"
41
- end
42
-
43
- it "should register the engine with high priority" do
44
- Smartgen::MarkupFile.register(MyEngine)
45
- Smartgen::MarkupFile.engines.first.should be_an_instance_of(MyEngine)
46
- end
47
- end
48
-
49
- describe "attributes" do
50
- it "should have a file path" do
51
- subject.path.should == path
52
- end
53
-
54
- it "should have a filename" do
55
- subject.filename.should == File.basename(path, File.extname(path))
56
- end
57
-
58
- context "when filename ends with .html" do
59
- def path
60
- fixture('src/erb/index.html.erb')
61
- end
62
-
63
- it "should not have .html in filename" do
64
- subject.filename.should == File.basename(path, ".html#{File.extname(path)}")
65
- end
66
- end
67
-
68
- it "should have an extension" do
69
- subject.extension.should == File.extname(path)
70
- end
71
- end
72
-
73
- describe "contents" do
74
- it "should returns its raw contents" do
75
- subject.raw_contents.should == File.read(path)
76
- end
77
-
78
- it "should return its contents" do
79
- subject.contents.should == File.read(fixture('expectations/common/index.html'))
80
- end
81
- end
82
-
83
- context "engines usage" do
84
- context "using default engine" do
85
- it "should use textile as markup engine when using defaults for files without extension" do
86
- def path
87
- fixture('src/common/somefile')
88
- end
89
-
90
- subject.engine.should be_an_instance_of(Smartgen::Engine::Textile)
91
- end
92
-
93
- it "should use the engine with the highest priority for files without extension" do
94
- class MyEngine
95
- def process(body, metadata={})
96
- "some processing"
97
- end
98
-
99
- def supported?(extension)
100
- ['.something'].include?(extension)
101
- end
102
- end
103
-
104
- def path
105
- fixture('src/common/somefile')
106
- end
107
-
108
- Smartgen::MarkupFile.register(MyEngine)
109
- subject.engine.should be_an_instance_of(MyEngine)
110
- Smartgen::MarkupFile.engines.clear
111
- end
112
- end
113
-
114
- context "using textile engine" do
115
- it "should use textile as markup engine" do
116
- subject.engine.should be_an_instance_of(Smartgen::Engine::Textile)
117
- end
118
- end
119
-
120
- context "using markdown engine" do
121
- it "should use markdown as markup engine for files with .markdown" do
122
- def path
123
- fixture('src/common/other_index.markdown')
124
- end
125
-
126
- subject.engine.should be_an_instance_of(Smartgen::Engine::Markdown)
127
- end
128
-
129
- it "should use markdown as markup engine for files with .md" do
130
- def path
131
- fixture('src/common/another_index.md')
132
- end
133
-
134
- subject.engine.should be_an_instance_of(Smartgen::Engine::Markdown)
135
- end
136
- end
137
-
138
- context "using erb engine" do
139
- it "should use markdown as markup engine for files with .md" do
140
- def path
141
- fixture('src/erb/index.html.erb')
142
- end
143
-
144
- subject.engine.should be_an_instance_of(Smartgen::Engine::ERB)
145
- end
146
- end
147
- end
148
-
149
- describe "indexer" do
150
- subject { Smartgen::MarkupFile.new path, :indexer => true }
151
-
152
- it "should be accessible when using indexer" do
153
- subject.indexer.should be_an_instance_of(Smartgen::Indexer)
154
- end
155
-
156
- it "should use indexer" do
157
- mock_indexer = mock(Smartgen::Indexer, :result => 'result')
158
- Smartgen::Indexer.should_receive(:new).and_return(mock_indexer)
159
- subject
160
- end
161
-
162
- it "should return indexer result as contents" do
163
- mock_indexer = mock(Smartgen::Indexer, :result => 'result')
164
- Smartgen::Indexer.should_receive(:new).and_return(mock_indexer)
165
- subject.contents.should == 'result'
166
- end
167
- end
168
- end
@@ -1,91 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Smartgen::ObjectHash do
4
- it { should be_a_kind_of(HashWithIndifferentAccess) }
5
-
6
- it "should be duped as an Smartgen::ObjectHash" do
7
- subject.dup.should be_an_instance_of(Smartgen::ObjectHash)
8
- end
9
-
10
- it "should differentiate itself when its inspected" do
11
- subject.inspect.should == "ObjectHash({})"
12
- end
13
-
14
- it "should respond to all of its keys" do
15
- subject.merge!({:foo => 'foo', 'bar' => 'bar'})
16
-
17
- subject.keys.each do |key|
18
- should respond_to(key)
19
- end
20
- end
21
-
22
- it "should respond to all of its keys with setter methods" do
23
- subject.merge!({:foo => 'foo', 'bar' => 'bar'})
24
-
25
- subject.keys.map { |k| "#{k}=" }.each do |key|
26
- should respond_to(key)
27
- end
28
- end
29
-
30
- describe "inexistent key" do
31
- it "should not respond to" do
32
- capture(:stderr) { subject.should_not respond_to("invalid_key") }
33
- end
34
-
35
- it "should return an empty ObjectHash" do
36
- capture(:stderr) { subject.invalid_key.should be_an_instance_of(Smartgen::ObjectHash) }
37
- end
38
-
39
- it "should print a warn" do
40
- capture(:stderr) { subject.invalid_key }.should == "warning: key invalid_key not found on #{subject.inspect}\n"
41
- end
42
- end
43
-
44
- it "should respond to ancestor methods" do
45
- ancestor = Smartgen::ObjectHash.ancestors.first
46
- ancestor.instance_methods.each do |method|
47
- should respond_to(method)
48
- end
49
- end
50
-
51
- it "should fetch key when calling method with the same name directly" do
52
- subject.merge!({:foo => 'foo'})
53
- subject.foo.should == 'foo'
54
- end
55
-
56
- it "should set a new key when any setter method is called" do
57
- subject.foo = 'foo'
58
- subject.foo.should == 'foo'
59
- end
60
-
61
- it "should update an existing key when setter method is called" do
62
- subject.merge!({:foo => 'foo'})
63
- subject.foo = 'bar'
64
- subject.foo.should == 'bar'
65
- end
66
-
67
- describe "nested hashes" do
68
- subject { Smartgen::ObjectHash.new({:nested_hash => {:some_key => 'value'}})}
69
-
70
- it "should accept calling nested methods" do
71
- subject.nested_hash.some_key.should == 'value'
72
- end
73
- end
74
-
75
- describe "nested array with hashes" do
76
- subject { Smartgen::ObjectHash.new({:array => [{:some_key => 'value'}]})}
77
-
78
- it "should accept calling nested methods" do
79
- subject.array.first.some_key.should == 'value'
80
- end
81
- end
82
-
83
- describe Hash do
84
- subject { Hash.new }
85
-
86
- it "should return an object hash" do
87
- subject.with_object_hash.should be_an_instance_of(Smartgen::ObjectHash)
88
- end
89
- end
90
- end
91
-
@@ -1,38 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Smartgen::Renderer::ERB do
4
- def contents
5
- "<p>Some HTML content</p>"
6
- end
7
-
8
- def markup_file
9
- @markup_file ||= mock(Smartgen::MarkupFile, :contents => contents)
10
- end
11
-
12
- it "should render the given layout with markup_file variable" do
13
- layout = "<html><body><%= markup_file.contents %></body></html>"
14
-
15
- subject.render(layout, markup_file).should == "<html><body>#{contents}</body></html>"
16
- end
17
-
18
- it "should render the given layout without setting metadata, but using methods to access metadata in template" do
19
- layout = "<html><body><%= markup_file.contents %><div><%= metadata.some_key %></div></body></html>"
20
-
21
- capture(:stderr) { subject.render(layout, markup_file).should == "<html><body>#{contents}<div>{}</div></body></html>" }
22
- end
23
-
24
- it "should render the given layout with metadata variable" do
25
- layout = "<html><body><%= markup_file.contents %><div><%= metadata[:some_key] %></div></body></html>"
26
- subject.render(layout, markup_file, Smartgen::ObjectHash.new(:some_key => 'some_value')).should == "<html><body>#{contents}<div>some_value</div></body></html>"
27
- end
28
-
29
- it "should render the given layout with metadata variable, using methods instead of accessing keys" do
30
- layout = "<html><body><%= markup_file.contents %><div><%= metadata.some_key %></div></body></html>"
31
- subject.render(layout, markup_file, Smartgen::ObjectHash.new(:some_key => 'some_value')).should == "<html><body>#{contents}<div>some_value</div></body></html>"
32
- end
33
-
34
- it "should render the given layout with metadata variable, using nested methods instead of accessing keys" do
35
- layout = "<html><body><%= markup_file.contents %><div><%= metadata.nested_hash.some_key %></div></body></html>"
36
- subject.render(layout, markup_file, Smartgen::ObjectHash.new(:nested_hash => {:some_key => 'some_value'})).should == "<html><body>#{contents}<div>some_value</div></body></html>"
37
- end
38
- end
@@ -1,73 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Smartgen::Resource do
4
- describe "configuration" do
5
- it "should yield a configuration when configuring" do
6
- subject.configure do |config|
7
- config.should be_an_instance_of(Smartgen::Configuration)
8
- end
9
- end
10
-
11
- it "should use the same configuration on later accesses" do
12
- configuration = nil
13
- subject.configure { |config| configuration = config }
14
-
15
- subject.configure do |config|
16
- config.should be_equal(configuration)
17
- end
18
- end
19
- end
20
-
21
- describe "generating" do
22
- shared_examples_for "generation with configuration" do
23
- let :expected_arguments do
24
- [subject.config.src_files, subject.config.output_folder]
25
- end
26
-
27
- it "should generate files using the configuration" do
28
- mock_generator = mock(Smartgen::Generator)
29
- Smartgen::Generator.
30
- should_receive(:new).
31
- with(expected_arguments, expected_options).
32
- and_return(mock_generator)
33
-
34
- mock_generator.should_receive(:invoke_all)
35
- subject.generate!
36
- end
37
- end
38
-
39
- context "with default options" do
40
- let :expected_options do
41
- Smartgen::ObjectHash.new
42
- end
43
-
44
- it_should_behave_like "generation with configuration"
45
- end
46
-
47
- context "with customized options" do
48
- before do
49
- subject.configure do |c|
50
- c.src_files = ['help/**/*', 'ChangeLog', 'doc_src/**/*']
51
- c.output_folder = 'public/docs'
52
- c.layout = 'doc_src/layout.html.erb'
53
- c.assets = ['doc_src/javascript/*.js', 'doc_src/stylesheets/*.css', 'doc_src/images/*.*']
54
- c.metadata_file = 'doc_src/metadata.yml'
55
- c.some_other_option = true
56
- c.and_another_one = 'some-value'
57
- end
58
- end
59
-
60
- let :expected_options do
61
- Smartgen::ObjectHash.new({
62
- :layout => subject.config.layout,
63
- :assets => subject.config.assets,
64
- :metadata_file => subject.config.metadata_file,
65
- :some_other_option => subject.config.some_other_option,
66
- :and_another_one => subject.config.and_another_one
67
- })
68
- end
69
-
70
- it_should_behave_like "generation with configuration"
71
- end
72
- end
73
- end