smartgen 0.3.0 → 0.4.0
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.
- data/Gemfile.lock +12 -12
- data/README.md +3 -2
- data/lib/smartgen/engines/base.rb +10 -10
- data/lib/smartgen/generator.rb +36 -33
- data/lib/smartgen/markup_file.rb +22 -21
- data/lib/smartgen/version.rb +1 -1
- metadata +14 -98
- data/spec/fixtures/expectations/common/another_index.html +0 -13
- data/spec/fixtures/expectations/common/index.html +0 -8
- data/spec/fixtures/expectations/common/other_index.html +0 -13
- data/spec/fixtures/expectations/indexer/index_with_indexer.html +0 -16
- data/spec/fixtures/expectations/indexer/index_with_indexer_and_numbered_index.html +0 -16
- data/spec/fixtures/expectations/with_layout/index.html +0 -12
- data/spec/fixtures/expectations/with_layout/index_with_metadata.html +0 -43
- data/spec/fixtures/expectations/with_layout/index_with_specific_metadata.html +0 -44
- data/spec/fixtures/src/assets/images/image.gif +0 -0
- data/spec/fixtures/src/assets/javascripts/somelib.js +0 -2
- data/spec/fixtures/src/assets/stylesheets/style.css +0 -2
- data/spec/fixtures/src/common/another_index.md +0 -12
- data/spec/fixtures/src/common/index.textile +0 -10
- data/spec/fixtures/src/common/other_index.markdown +0 -12
- data/spec/fixtures/src/common/somefile +0 -10
- data/spec/fixtures/src/indexer/index_with_indexer.textile +0 -26
- data/spec/fixtures/src/indexer/index_with_indexer_and_numbered_index.textile +0 -26
- data/spec/fixtures/src/layout.html.erb +0 -5
- data/spec/fixtures/src/layout_with_metadata.html.erb +0 -22
- data/spec/fixtures/src/layout_with_specific_metadata.html.erb +0 -23
- data/spec/fixtures/src/metadata.yml +0 -43
- data/spec/fixtures/src/with_layout/index.textile +0 -10
- data/spec/fixtures/src/with_layout/index_with_specific_metadata.textile +0 -10
- data/spec/lib/smartgen/configuration_spec.rb +0 -38
- data/spec/lib/smartgen/engines/base_spec.rb +0 -71
- data/spec/lib/smartgen/engines/markdown_spec.rb +0 -23
- data/spec/lib/smartgen/engines/textile_spec.rb +0 -19
- data/spec/lib/smartgen/generator_spec.rb +0 -226
- data/spec/lib/smartgen/indexer_spec.rb +0 -122
- data/spec/lib/smartgen/markup_file_spec.rb +0 -148
- data/spec/lib/smartgen/object_hash_spec.rb +0 -64
- data/spec/lib/smartgen/renderers/erb_spec.rb +0 -32
- data/spec/lib/smartgen/resource_spec.rb +0 -60
- data/spec/lib/smartgen/watcher_spec.rb +0 -71
- data/spec/lib/smartgen_spec.rb +0 -18
- data/spec/sandbox/.gitkeep +0 -0
- data/spec/spec_helper.rb +0 -37
@@ -1,71 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Smartgen::Engine::Base do
|
4
|
-
describe "processing" do
|
5
|
-
it "should just return body" do
|
6
|
-
body = 'body'
|
7
|
-
subject.process(body).should == body
|
8
|
-
end
|
9
|
-
|
10
|
-
describe "pre processing" do
|
11
|
-
before do
|
12
|
-
Smartgen::Engine::Base.pre_processors = []
|
13
|
-
end
|
14
|
-
|
15
|
-
context "without pre processors" do
|
16
|
-
it "should just return body" do
|
17
|
-
body = 'body'
|
18
|
-
subject.process(body).should == body
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
context "with pre processors" do
|
23
|
-
class PreProcessor
|
24
|
-
def process(body) # just needs to respond_to?(:process)
|
25
|
-
"<pre_processed>#{body}</pre_processed>"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should pre process body" do
|
30
|
-
Smartgen::Engine::Base.register(PreProcessor.new)
|
31
|
-
|
32
|
-
body = 'body'
|
33
|
-
subject.process(body).should == "<pre_processed>#{body}</pre_processed>"
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should do run pre processors in the order they were registered" do
|
37
|
-
class AnotherPreProcessor
|
38
|
-
def process(body)
|
39
|
-
body.gsub(/pre_processed/, 'another')
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
Smartgen::Engine::Base.register(PreProcessor.new)
|
44
|
-
Smartgen::Engine::Base.register(AnotherPreProcessor.new)
|
45
|
-
|
46
|
-
body = 'body'
|
47
|
-
subject.process(body).should == "<another>#{body}</another>"
|
48
|
-
end
|
49
|
-
|
50
|
-
context "of a subclass" do
|
51
|
-
class OtherPreProcessor
|
52
|
-
def process(body)
|
53
|
-
"<another>#{body}</another>"
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
class MyCustomEngine < Smartgen::Engine::Base
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should pre process body with different processor of ancestor" do
|
61
|
-
Smartgen::Engine::Base.register(PreProcessor.new)
|
62
|
-
MyCustomEngine.register(OtherPreProcessor.new)
|
63
|
-
|
64
|
-
body = 'body'
|
65
|
-
MyCustomEngine.new.process(body).should == "<another>#{body}</another>"
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Smartgen::Engine::Markdown do
|
4
|
-
def body
|
5
|
-
"# Some Header\n\nSome paragraph"
|
6
|
-
end
|
7
|
-
|
8
|
-
def contents
|
9
|
-
"<h1>Some Header</h1>\n\n<p>Some paragraph</p>"
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should process body using BlueCloth" do
|
13
|
-
subject.process(body).should == contents
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should support .md extension" do
|
17
|
-
should be_supported('.md')
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should support .markdown extension" do
|
21
|
-
should be_supported('.markdown')
|
22
|
-
end
|
23
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Smartgen::Engine::Textile do
|
4
|
-
def body
|
5
|
-
"h1. Some Header\n\nSome paragraph"
|
6
|
-
end
|
7
|
-
|
8
|
-
def contents
|
9
|
-
"<h1>Some Header</h1>\n<p>Some paragraph</p>"
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should process body using RedCloth" do
|
13
|
-
subject.process(body).should == contents
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should support .textile extension" do
|
17
|
-
should be_supported('.textile')
|
18
|
-
end
|
19
|
-
end
|
@@ -1,226 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'fileutils'
|
3
|
-
|
4
|
-
describe Smartgen::Generator do
|
5
|
-
def src_files
|
6
|
-
[fixture('src/common/**/*')]
|
7
|
-
end
|
8
|
-
|
9
|
-
def output_folder
|
10
|
-
sandbox('doc')
|
11
|
-
end
|
12
|
-
|
13
|
-
def output_folder_file(path)
|
14
|
-
File.join(output_folder, path)
|
15
|
-
end
|
16
|
-
|
17
|
-
def actual_src_files
|
18
|
-
Dir[*src_files].select { |f| ['.textile', '.markdown', '.md'].include?(File.extname(f)) }
|
19
|
-
end
|
20
|
-
|
21
|
-
def actual_src_filenames
|
22
|
-
actual_src_files.map { |f| [File.basename(f, File.extname(f)), File.extname(f)] }
|
23
|
-
end
|
24
|
-
|
25
|
-
def read_output(filename)
|
26
|
-
File.read(output_folder_file(filename))
|
27
|
-
end
|
28
|
-
|
29
|
-
def read_fixture(filename)
|
30
|
-
File.read(fixture(filename))
|
31
|
-
end
|
32
|
-
|
33
|
-
def arguments
|
34
|
-
[src_files, output_folder]
|
35
|
-
end
|
36
|
-
|
37
|
-
def options
|
38
|
-
{}
|
39
|
-
end
|
40
|
-
|
41
|
-
subject { Smartgen::Generator.new arguments, options, { :verbose => false } }
|
42
|
-
|
43
|
-
before do
|
44
|
-
FileUtils.rm_rf output_folder
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "generation" do
|
48
|
-
it "should create the output folder" do
|
49
|
-
capture(:stdout) { subject.invoke_all }
|
50
|
-
File.should be_directory(output_folder)
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should create HTML files for each markup template in src_files" do
|
54
|
-
capture(:stdout) { subject.invoke_all }
|
55
|
-
|
56
|
-
actual_src_filenames.each do |src_filename, src_ext|
|
57
|
-
File.should be_file(output_folder_file("#{src_filename}.html"))
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should convert markup files into HTML files when generating" do
|
62
|
-
capture(:stdout) { subject.invoke_all }
|
63
|
-
actual_src_filenames.each do |src_filename, src_ext|
|
64
|
-
read_output("#{src_filename}.html").should == read_fixture("expectations/common/#{src_filename}.html")
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should always force generation of each file, even if it exists" do
|
69
|
-
FileUtils.mkdir_p(output_folder)
|
70
|
-
File.open(output_folder_file("index.html"), 'w') { |f| f.write('old contents') }
|
71
|
-
capture(:stdout) { subject.invoke_all }
|
72
|
-
read_output("index.html").should == read_fixture("expectations/common/index.html")
|
73
|
-
end
|
74
|
-
|
75
|
-
context "with nil layout" do
|
76
|
-
def options
|
77
|
-
{ :layout => nil }
|
78
|
-
end
|
79
|
-
|
80
|
-
it "should not use layout" do
|
81
|
-
capture(:stdout) { subject.invoke_all }
|
82
|
-
actual_src_filenames.each do |src_filename, src_ext|
|
83
|
-
read_output("#{src_filename}.html").should == read_fixture("expectations/common/#{src_filename}.html")
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
describe "inexistent file" do
|
89
|
-
def src_files
|
90
|
-
[fixture('src/common/inexistent_file.textile')]
|
91
|
-
end
|
92
|
-
|
93
|
-
it "should not generate html" do
|
94
|
-
subject.invoke_all
|
95
|
-
File.should_not be_file(output_folder_file("inexistent_file.html"))
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
describe "with layout" do
|
100
|
-
def src_files
|
101
|
-
[fixture('src/with_layout/index.textile')]
|
102
|
-
end
|
103
|
-
|
104
|
-
def options
|
105
|
-
{ :layout => fixture('src/layout.html.erb') }
|
106
|
-
end
|
107
|
-
|
108
|
-
it "should use the layout when generating" do
|
109
|
-
capture(:stdout) { subject.invoke_all }
|
110
|
-
read_output("index.html").should == read_fixture("expectations/with_layout/index.html")
|
111
|
-
end
|
112
|
-
|
113
|
-
describe "and metadata" do
|
114
|
-
def options
|
115
|
-
{ :layout => fixture('src/layout_with_metadata.html.erb'), :metadata_file => fixture('src/metadata.yml') }
|
116
|
-
end
|
117
|
-
|
118
|
-
it "should load metadata from file and expose it when rendering files" do
|
119
|
-
capture(:stdout) { subject.invoke_all }
|
120
|
-
read_output("index.html").should == read_fixture("expectations/with_layout/index_with_metadata.html")
|
121
|
-
end
|
122
|
-
|
123
|
-
describe "using conventions" do
|
124
|
-
def src_files
|
125
|
-
[fixture('src/with_layout/index_with_specific_metadata.textile')]
|
126
|
-
end
|
127
|
-
|
128
|
-
def options
|
129
|
-
{ :layout => fixture('src/layout_with_specific_metadata.html.erb'), :metadata_file => fixture('src/metadata.yml') }
|
130
|
-
end
|
131
|
-
|
132
|
-
it "should expose metadata for current page data for each file in metadata.current_page" do
|
133
|
-
capture(:stdout) { subject.invoke_all }
|
134
|
-
read_output("index_with_specific_metadata.html").should == read_fixture("expectations/with_layout/index_with_specific_metadata.html")
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
describe "assets" do
|
141
|
-
def assets
|
142
|
-
[fixture("src/assets/images"), fixture("src/assets/javascripts"), fixture("src/assets/stylesheets")]
|
143
|
-
end
|
144
|
-
|
145
|
-
def options
|
146
|
-
{ :assets => assets }
|
147
|
-
end
|
148
|
-
|
149
|
-
it "should copy directories to output folder" do
|
150
|
-
capture(:stdout) { subject.invoke_all }
|
151
|
-
|
152
|
-
File.should be_directory(output_folder_file('images'))
|
153
|
-
File.should be_directory(output_folder_file('javascripts'))
|
154
|
-
end
|
155
|
-
|
156
|
-
it "should copy the contents of the given directories to output folder" do
|
157
|
-
capture(:stdout) { subject.invoke_all }
|
158
|
-
|
159
|
-
File.should be_file(output_folder_file('images/image.gif'))
|
160
|
-
File.should be_file(output_folder_file('javascripts/somelib.js'))
|
161
|
-
File.should be_file(output_folder_file('stylesheets/style.css'))
|
162
|
-
end
|
163
|
-
|
164
|
-
it "should force copy of the contents of the given directories to output folder" do
|
165
|
-
FileUtils.mkdir_p(output_folder_file('javascripts'))
|
166
|
-
File.open(output_folder_file('javascripts/somelib.js'), 'w') { |f| f.write('//some code') }
|
167
|
-
|
168
|
-
capture(:stdout) { subject.invoke_all }
|
169
|
-
read_output('javascripts/somelib.js').should == read_fixture('src/assets/javascripts/somelib.js')
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
describe "with indexer" do
|
174
|
-
def src_files
|
175
|
-
[fixture('src/indexer/index_with_indexer.textile')]
|
176
|
-
end
|
177
|
-
|
178
|
-
def options
|
179
|
-
{ :use_indexer => true }
|
180
|
-
end
|
181
|
-
|
182
|
-
it "should add IDs to each <h> tag" do
|
183
|
-
capture(:stdout) { subject.invoke_all }
|
184
|
-
|
185
|
-
actual_src_filenames.each do |src_filename, src_ext|
|
186
|
-
read_output("#{src_filename}.html").should == read_fixture("expectations/indexer/#{src_filename}.html")
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
context "and numbered_index" do
|
191
|
-
def src_files
|
192
|
-
[fixture('src/indexer/index_with_indexer_and_numbered_index.textile')]
|
193
|
-
end
|
194
|
-
|
195
|
-
def options
|
196
|
-
{ :use_indexer => true, :numbered_index => true }
|
197
|
-
end
|
198
|
-
|
199
|
-
it "should add numbered indexes on each <h> tag" do
|
200
|
-
capture(:stdout) { subject.invoke_all }
|
201
|
-
|
202
|
-
actual_src_filenames.each do |src_filename, src_ext|
|
203
|
-
read_output("#{src_filename}.html").should == read_fixture("expectations/indexer/#{src_filename}.html")
|
204
|
-
end
|
205
|
-
end
|
206
|
-
end
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
describe "renderer registration" do
|
211
|
-
it "should register ERB renderer by default" do
|
212
|
-
Smartgen::Generator.renderer.should be_an_instance_of(Smartgen::Renderer::ERB)
|
213
|
-
end
|
214
|
-
|
215
|
-
it "should allow the registration of a custom renderer" do
|
216
|
-
class MyRenderer
|
217
|
-
def render(layout, markup_file)
|
218
|
-
"do some rendering stuff"
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
Smartgen::Generator.renderer = MyRenderer.new
|
223
|
-
Smartgen::Generator.renderer.render('some_layout', mock(Smartgen::MarkupFile)).should == "do some rendering stuff"
|
224
|
-
end
|
225
|
-
end
|
226
|
-
end
|
@@ -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
|