smartgen 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +0 -8
- data/Gemfile.lock +25 -31
- data/lib/smartgen/object_hash.rb +2 -2
- data/lib/smartgen/version.rb +1 -1
- metadata +138 -194
- 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/erb/index.html +0 -15
- data/spec/fixtures/expectations/erb/with_layout/index.html +0 -19
- 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/erb/index.html.erb +0 -7
- data/spec/fixtures/src/erb/with_layout/index.html.erb +0 -7
- data/spec/fixtures/src/erb/with_layout/layout.html.erb +0 -5
- 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 -5
- data/spec/lib/smartgen/engines/base_spec.rb +0 -92
- data/spec/lib/smartgen/engines/erb_spec.rb +0 -37
- 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 -272
- data/spec/lib/smartgen/indexer_spec.rb +0 -122
- data/spec/lib/smartgen/markup_file_spec.rb +0 -168
- data/spec/lib/smartgen/object_hash_spec.rb +0 -91
- data/spec/lib/smartgen/renderers/erb_spec.rb +0 -38
- data/spec/lib/smartgen/resource_spec.rb +0 -73
- 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,92 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Smartgen::Engine::Base do
|
4
|
-
describe "processing" do
|
5
|
-
describe "pre processing" do
|
6
|
-
before do
|
7
|
-
Smartgen::Engine::Base.pre_processors = []
|
8
|
-
end
|
9
|
-
|
10
|
-
context "without pre processors" do
|
11
|
-
it "should just return body" do
|
12
|
-
body = 'body'
|
13
|
-
subject.process(body).should == body
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context "with pre processors" do
|
18
|
-
class PreProcessor
|
19
|
-
def process(body, metadata=Smartgen::ObjectHash.new) # just needs to respond_to?(:process)
|
20
|
-
"<pre_processed>#{body}#{metadata[:name]}</pre_processed>"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should pre process body" do
|
25
|
-
Smartgen::Engine::Base.register(PreProcessor.new)
|
26
|
-
|
27
|
-
body = 'body'
|
28
|
-
subject.process(body).should == "<pre_processed>#{body}</pre_processed>"
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should pre process body with metadata" do
|
32
|
-
Smartgen::Engine::Base.register(PreProcessor.new)
|
33
|
-
|
34
|
-
body = 'body'
|
35
|
-
subject.process(body, Smartgen::ObjectHash.new({:name => " John"})).should == "<pre_processed>body John</pre_processed>"
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should do run pre processors in the order they were registered" do
|
39
|
-
class AnotherPreProcessor
|
40
|
-
def process(body, metadata={})
|
41
|
-
body.gsub(/pre_processed/, 'another')
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
Smartgen::Engine::Base.register(PreProcessor.new)
|
46
|
-
Smartgen::Engine::Base.register(AnotherPreProcessor.new)
|
47
|
-
|
48
|
-
body = 'body'
|
49
|
-
subject.process(body).should == "<another>#{body}</another>"
|
50
|
-
end
|
51
|
-
|
52
|
-
context "when pre processor has engine setter" do
|
53
|
-
class PreProcessor
|
54
|
-
attr_accessor :engine
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should set engine on pre processor after initializing the engine" do
|
58
|
-
pre_processor = PreProcessor.new
|
59
|
-
Smartgen::Engine::Base.register(pre_processor)
|
60
|
-
subject
|
61
|
-
pre_processor.engine.should == subject
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
context "when forcing processing without pre processors" do
|
66
|
-
it "should return just body" do
|
67
|
-
subject.process_without_pre_processors('some body').should == 'some body'
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
context "of a subclass" do
|
72
|
-
class OtherPreProcessor
|
73
|
-
def process(body, metadata={})
|
74
|
-
"<another>#{body}</another>"
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
class MyCustomEngine < Smartgen::Engine::Base
|
79
|
-
end
|
80
|
-
|
81
|
-
it "should pre process body with different processor of ancestor" do
|
82
|
-
Smartgen::Engine::Base.register(PreProcessor.new)
|
83
|
-
MyCustomEngine.register(OtherPreProcessor.new)
|
84
|
-
|
85
|
-
body = 'body'
|
86
|
-
MyCustomEngine.new.process(body).should == "<another>#{body}</another>"
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Smartgen::Engine::ERB do
|
4
|
-
let :body do
|
5
|
-
"2 + 2 = <%= 2 * 2 %>"
|
6
|
-
end
|
7
|
-
|
8
|
-
let :contents do
|
9
|
-
"2 + 2 = 4"
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should process body using ERB" do
|
13
|
-
subject.process(body).should == contents
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should support .erb extension" do
|
17
|
-
should be_supported('.erb')
|
18
|
-
end
|
19
|
-
|
20
|
-
context "with metadata" do
|
21
|
-
let :body do
|
22
|
-
"Some metadata: <%= metadata.name %>"
|
23
|
-
end
|
24
|
-
|
25
|
-
let :contents do
|
26
|
-
"Some metadata: #{metadata.name}"
|
27
|
-
end
|
28
|
-
|
29
|
-
let :metadata do
|
30
|
-
Smartgen::ObjectHash.new :name => 'Vicente'
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should process body using ERB" do
|
34
|
-
subject.process(body, metadata).should == contents
|
35
|
-
end
|
36
|
-
end
|
37
|
-
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,272 +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
|
-
capture(:stdout) { subject.invoke_all }
|
95
|
-
File.should_not be_file(output_folder_file("inexistent_file.html"))
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
describe "with ERB files" do
|
100
|
-
def src_files
|
101
|
-
[fixture('src/erb/index.html.erb')]
|
102
|
-
end
|
103
|
-
|
104
|
-
it "should generate index file" do
|
105
|
-
capture(:stdout) { subject.invoke_all }
|
106
|
-
read_output("index.html").should == read_fixture("expectations/erb/index.html")
|
107
|
-
end
|
108
|
-
|
109
|
-
describe "with layout" do
|
110
|
-
def src_files
|
111
|
-
[fixture('src/erb/with_layout/index.html.erb')]
|
112
|
-
end
|
113
|
-
|
114
|
-
def options
|
115
|
-
{ :layout => fixture('src/layout.html.erb') }
|
116
|
-
end
|
117
|
-
|
118
|
-
it "should use the layout when generating" do
|
119
|
-
capture(:stdout) { subject.invoke_all }
|
120
|
-
read_output("index.html").should == read_fixture("expectations/erb/with_layout/index.html")
|
121
|
-
end
|
122
|
-
|
123
|
-
context "inside the src_files pattern" do
|
124
|
-
def src_files
|
125
|
-
[fixture('src/erb/with_layout/**/*')]
|
126
|
-
end
|
127
|
-
|
128
|
-
def options
|
129
|
-
{ :layout => fixture('src/erb/with_layout/layout.html.erb') }
|
130
|
-
end
|
131
|
-
|
132
|
-
it "should use the layout when generating" do
|
133
|
-
capture(:stdout) { subject.invoke_all }
|
134
|
-
read_output("index.html").should == read_fixture("expectations/erb/with_layout/index.html")
|
135
|
-
end
|
136
|
-
|
137
|
-
it "should not attempt to render layout using ERB engine" do
|
138
|
-
capture(:stdout) { subject.invoke_all }
|
139
|
-
read_output("index.html").should == read_fixture("expectations/erb/with_layout/index.html")
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
describe "with layout" do
|
146
|
-
def src_files
|
147
|
-
[fixture('src/with_layout/index.textile')]
|
148
|
-
end
|
149
|
-
|
150
|
-
def options
|
151
|
-
{ :layout => fixture('src/layout.html.erb') }
|
152
|
-
end
|
153
|
-
|
154
|
-
it "should use the layout when generating" do
|
155
|
-
capture(:stdout) { subject.invoke_all }
|
156
|
-
read_output("index.html").should == read_fixture("expectations/with_layout/index.html")
|
157
|
-
end
|
158
|
-
|
159
|
-
describe "and metadata" do
|
160
|
-
def options
|
161
|
-
{ :layout => fixture('src/layout_with_metadata.html.erb'), :metadata_file => fixture('src/metadata.yml') }
|
162
|
-
end
|
163
|
-
|
164
|
-
it "should load metadata from file and expose it when rendering files" do
|
165
|
-
capture(:stdout) { subject.invoke_all }
|
166
|
-
read_output("index.html").should == read_fixture("expectations/with_layout/index_with_metadata.html")
|
167
|
-
end
|
168
|
-
|
169
|
-
describe "using conventions" do
|
170
|
-
def src_files
|
171
|
-
[fixture('src/with_layout/index_with_specific_metadata.textile')]
|
172
|
-
end
|
173
|
-
|
174
|
-
def options
|
175
|
-
{ :layout => fixture('src/layout_with_specific_metadata.html.erb'), :metadata_file => fixture('src/metadata.yml') }
|
176
|
-
end
|
177
|
-
|
178
|
-
it "should expose metadata for current page data for each file in metadata.current_page" do
|
179
|
-
capture(:stdout) { subject.invoke_all }
|
180
|
-
read_output("index_with_specific_metadata.html").should == read_fixture("expectations/with_layout/index_with_specific_metadata.html")
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
describe "assets" do
|
187
|
-
def assets
|
188
|
-
[fixture("src/assets/images"), fixture("src/assets/javascripts"), fixture("src/assets/stylesheets")]
|
189
|
-
end
|
190
|
-
|
191
|
-
def options
|
192
|
-
{ :assets => assets }
|
193
|
-
end
|
194
|
-
|
195
|
-
it "should copy directories to output folder" do
|
196
|
-
capture(:stdout) { subject.invoke_all }
|
197
|
-
|
198
|
-
File.should be_directory(output_folder_file('images'))
|
199
|
-
File.should be_directory(output_folder_file('javascripts'))
|
200
|
-
end
|
201
|
-
|
202
|
-
it "should copy the contents of the given directories to output folder" do
|
203
|
-
capture(:stdout) { subject.invoke_all }
|
204
|
-
|
205
|
-
File.should be_file(output_folder_file('images/image.gif'))
|
206
|
-
File.should be_file(output_folder_file('javascripts/somelib.js'))
|
207
|
-
File.should be_file(output_folder_file('stylesheets/style.css'))
|
208
|
-
end
|
209
|
-
|
210
|
-
it "should force copy of the contents of the given directories to output folder" do
|
211
|
-
FileUtils.mkdir_p(output_folder_file('javascripts'))
|
212
|
-
File.open(output_folder_file('javascripts/somelib.js'), 'w') { |f| f.write('//some code') }
|
213
|
-
|
214
|
-
capture(:stdout) { subject.invoke_all }
|
215
|
-
read_output('javascripts/somelib.js').should == read_fixture('src/assets/javascripts/somelib.js')
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
219
|
-
describe "with indexer" do
|
220
|
-
def src_files
|
221
|
-
[fixture('src/indexer/index_with_indexer.textile')]
|
222
|
-
end
|
223
|
-
|
224
|
-
def options
|
225
|
-
{ :use_indexer => true }
|
226
|
-
end
|
227
|
-
|
228
|
-
it "should add IDs to each <h> tag" do
|
229
|
-
capture(:stdout) { subject.invoke_all }
|
230
|
-
|
231
|
-
actual_src_filenames.each do |src_filename, src_ext|
|
232
|
-
read_output("#{src_filename}.html").should == read_fixture("expectations/indexer/#{src_filename}.html")
|
233
|
-
end
|
234
|
-
end
|
235
|
-
|
236
|
-
context "and numbered_index" do
|
237
|
-
def src_files
|
238
|
-
[fixture('src/indexer/index_with_indexer_and_numbered_index.textile')]
|
239
|
-
end
|
240
|
-
|
241
|
-
def options
|
242
|
-
{ :use_indexer => true, :numbered_index => true }
|
243
|
-
end
|
244
|
-
|
245
|
-
it "should add numbered indexes on each <h> tag" do
|
246
|
-
capture(:stdout) { subject.invoke_all }
|
247
|
-
|
248
|
-
actual_src_filenames.each do |src_filename, src_ext|
|
249
|
-
read_output("#{src_filename}.html").should == read_fixture("expectations/indexer/#{src_filename}.html")
|
250
|
-
end
|
251
|
-
end
|
252
|
-
end
|
253
|
-
end
|
254
|
-
end
|
255
|
-
|
256
|
-
describe "renderer registration" do
|
257
|
-
it "should register ERB renderer by default" do
|
258
|
-
Smartgen::Generator.renderer.should be_an_instance_of(Smartgen::Renderer::ERB)
|
259
|
-
end
|
260
|
-
|
261
|
-
it "should allow the registration of a custom renderer" do
|
262
|
-
class MyRenderer
|
263
|
-
def render(layout, markup_file)
|
264
|
-
"do some rendering stuff"
|
265
|
-
end
|
266
|
-
end
|
267
|
-
|
268
|
-
Smartgen::Generator.renderer = MyRenderer.new
|
269
|
-
Smartgen::Generator.renderer.render('some_layout', mock(Smartgen::MarkupFile)).should == "do some rendering stuff"
|
270
|
-
end
|
271
|
-
end
|
272
|
-
end
|