smartgen 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,148 +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
|
-
it "should have an extension" do
|
59
|
-
subject.extension.should == File.extname(path)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe "contents" do
|
64
|
-
it "should returns its raw contents" do
|
65
|
-
subject.raw_contents.should == File.read(path)
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should return its contents" do
|
69
|
-
subject.contents.should == File.read(fixture('expectations/common/index.html'))
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
context "engines usage" do
|
74
|
-
context "using default engine" do
|
75
|
-
it "should use textile as markup engine when using defaults for files without extension" do
|
76
|
-
def path
|
77
|
-
fixture('src/common/somefile')
|
78
|
-
end
|
79
|
-
|
80
|
-
subject.engine.should be_an_instance_of(Smartgen::Engine::Textile)
|
81
|
-
end
|
82
|
-
|
83
|
-
it "should use the engine with the highest priority for files without extension" do
|
84
|
-
class MyEngine
|
85
|
-
def process(body)
|
86
|
-
"some processing"
|
87
|
-
end
|
88
|
-
|
89
|
-
def supported?(extension)
|
90
|
-
['.something'].include?(extension)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
def path
|
95
|
-
fixture('src/common/somefile')
|
96
|
-
end
|
97
|
-
|
98
|
-
Smartgen::MarkupFile.register(MyEngine)
|
99
|
-
subject.engine.should be_an_instance_of(MyEngine)
|
100
|
-
Smartgen::MarkupFile.engines.clear
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
context "using textile engine" do
|
105
|
-
it "should use textile as markup engine" do
|
106
|
-
subject.engine.should be_an_instance_of(Smartgen::Engine::Textile)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
context "using markdown template" do
|
111
|
-
it "should use textile as markup engine for files with .markdown" do
|
112
|
-
def path
|
113
|
-
fixture('src/common/other_index.markdown')
|
114
|
-
end
|
115
|
-
|
116
|
-
subject.engine.should be_an_instance_of(Smartgen::Engine::Markdown)
|
117
|
-
end
|
118
|
-
|
119
|
-
it "should use textile as markup engine for files with .md" do
|
120
|
-
def path
|
121
|
-
fixture('src/common/another_index.md')
|
122
|
-
end
|
123
|
-
|
124
|
-
subject.engine.should be_an_instance_of(Smartgen::Engine::Markdown)
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
describe "indexer" do
|
130
|
-
subject { Smartgen::MarkupFile.new path, :indexer => true }
|
131
|
-
|
132
|
-
it "should be accessible when using indexer" do
|
133
|
-
subject.indexer.should be_an_instance_of(Smartgen::Indexer)
|
134
|
-
end
|
135
|
-
|
136
|
-
it "should use indexer" do
|
137
|
-
mock_indexer = mock(Smartgen::Indexer, :result => 'result')
|
138
|
-
Smartgen::Indexer.should_receive(:new).and_return(mock_indexer)
|
139
|
-
subject
|
140
|
-
end
|
141
|
-
|
142
|
-
it "should return indexer result as contents" do
|
143
|
-
mock_indexer = mock(Smartgen::Indexer, :result => 'result')
|
144
|
-
Smartgen::Indexer.should_receive(:new).and_return(mock_indexer)
|
145
|
-
subject.contents.should == 'result'
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
@@ -1,64 +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 respond to all of its keys" do
|
11
|
-
subject.merge!({:foo => 'foo', 'bar' => 'bar'})
|
12
|
-
|
13
|
-
subject.keys.each do |key|
|
14
|
-
should respond_to(key)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "inexistent key" do
|
19
|
-
it "should not respond to" do
|
20
|
-
subject.should_not respond_to("invalid_key")
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should return an empty ObjectHash" do
|
24
|
-
subject.invalid_key.should be_an_instance_of(Smartgen::ObjectHash)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should respond to ancestor methods" do
|
29
|
-
ancestor = Smartgen::ObjectHash.ancestors.first
|
30
|
-
ancestor.instance_methods.each do |method|
|
31
|
-
should respond_to(method)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should fetch key when calling method with the same name directly" do
|
36
|
-
subject.merge!({:foo => 'foo'})
|
37
|
-
subject.foo.should == 'foo'
|
38
|
-
end
|
39
|
-
|
40
|
-
describe "nested hashes" do
|
41
|
-
subject { Smartgen::ObjectHash.new({:nested_hash => {:some_key => 'value'}})}
|
42
|
-
|
43
|
-
it "should accept calling nested methods" do
|
44
|
-
subject.nested_hash.some_key.should == 'value'
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe "nested array with hashes" do
|
49
|
-
subject { Smartgen::ObjectHash.new({:array => [{:some_key => 'value'}]})}
|
50
|
-
|
51
|
-
it "should accept calling nested methods" do
|
52
|
-
subject.array.first.some_key.should == 'value'
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe Hash do
|
57
|
-
subject { Hash.new }
|
58
|
-
|
59
|
-
it "should return an object hash" do
|
60
|
-
subject.with_object_hash.should be_an_instance_of(Smartgen::ObjectHash)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
@@ -1,32 +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 with metadata variable" do
|
19
|
-
layout = "<html><body><%= markup_file.contents %><div><%= metadata[:some_key] %></div></body></html>"
|
20
|
-
subject.render(layout, markup_file, :some_key => 'some_value').should == "<html><body>#{contents}<div>some_value</div></body></html>"
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should render the given layout with metadata variable, using methods instead of accessing keys" do
|
24
|
-
layout = "<html><body><%= markup_file.contents %><div><%= metadata.some_key %></div></body></html>"
|
25
|
-
subject.render(layout, markup_file, :some_key => 'some_value').should == "<html><body>#{contents}<div>some_value</div></body></html>"
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should render the given layout with metadata variable, using nested methods instead of accessing keys" do
|
29
|
-
layout = "<html><body><%= markup_file.contents %><div><%= metadata.nested_hash.some_key %></div></body></html>"
|
30
|
-
subject.render(layout, markup_file, :nested_hash => {:some_key => 'some_value'}).should == "<html><body>#{contents}<div>some_value</div></body></html>"
|
31
|
-
end
|
32
|
-
end
|
@@ -1,60 +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
|
-
it "should generate files using the configuration" do
|
24
|
-
expected_arguments = [subject.config.src_files, subject.config.output_folder]
|
25
|
-
expected_options = {
|
26
|
-
:layout => subject.config.layout,
|
27
|
-
:assets => subject.config.assets,
|
28
|
-
:metadata_file => subject.config.metadata_file
|
29
|
-
}
|
30
|
-
|
31
|
-
mock_generator = mock(Smartgen::Generator)
|
32
|
-
Smartgen::Generator.
|
33
|
-
should_receive(:new).
|
34
|
-
with(expected_arguments, expected_options).
|
35
|
-
and_return(mock_generator)
|
36
|
-
|
37
|
-
mock_generator.should_receive(:invoke_all)
|
38
|
-
subject.generate!
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context "with default options" do
|
43
|
-
it_should_behave_like "generation with configuration"
|
44
|
-
end
|
45
|
-
|
46
|
-
context "with customized options" do
|
47
|
-
before do
|
48
|
-
subject.configure do |c|
|
49
|
-
c.src_files = ['help/**/*', 'ChangeLog', 'doc_src/**/*']
|
50
|
-
c.output_folder = 'public/docs'
|
51
|
-
c.layout = 'doc_src/layout.html.erb'
|
52
|
-
c.assets = ['doc_src/javascript/*.js', 'doc_src/stylesheets/*.css', 'doc_src/images/*.*']
|
53
|
-
c.metadata_file = 'doc_src/metadata.yml'
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
it_should_behave_like "generation with configuration"
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Smartgen::Watcher do
|
4
|
-
it "should create a resource and yield its configuration" do
|
5
|
-
expected_config = nil
|
6
|
-
Smartgen::Watcher.new(:my_resource) { |config| expected_config = config }
|
7
|
-
expected_config.should == Smartgen[:my_resource].config
|
8
|
-
end
|
9
|
-
|
10
|
-
context "when it will start watching" do
|
11
|
-
def src_files
|
12
|
-
['doc/**/*']
|
13
|
-
end
|
14
|
-
|
15
|
-
def directory_watcher
|
16
|
-
return @directory_watcher if @directory_watcher
|
17
|
-
|
18
|
-
@directory_watcher = mock(DirectoryWatcher, :add_observer => 'observer', :interval= => '2')
|
19
|
-
@directory_watcher.stub!(:start).and_return(@directory_watcher)
|
20
|
-
@directory_watcher.stub!(:join).and_return(@directory_watcher)
|
21
|
-
@directory_watcher
|
22
|
-
end
|
23
|
-
|
24
|
-
before do
|
25
|
-
DirectoryWatcher.stub!(:new).and_return(directory_watcher)
|
26
|
-
end
|
27
|
-
|
28
|
-
subject do
|
29
|
-
Smartgen::Watcher.new(:my_resource) do |config|
|
30
|
-
config.src_files = src_files
|
31
|
-
config.output_folder = 'public/docs'
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should create a directory watcher, pre loading src_files" do
|
36
|
-
DirectoryWatcher.should_receive(:new).with('.', :glob => src_files).and_return(directory_watcher)
|
37
|
-
capture(:stdout) { subject.start }
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should add itself as an observer, with :generate method as the callback" do
|
41
|
-
directory_watcher.should_receive(:add_observer).with(subject, :generate)
|
42
|
-
capture(:stdout) { subject.start }
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should start watching" do
|
46
|
-
directory_watcher.should_receive(:start)
|
47
|
-
directory_watcher.should_receive(:join)
|
48
|
-
capture(:stdout) { subject.start }
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should set interval to 2 seconds" do
|
52
|
-
directory_watcher.should_receive(:interval=).with(2)
|
53
|
-
capture(:stdout) { subject.start }
|
54
|
-
end
|
55
|
-
|
56
|
-
context "when generating" do
|
57
|
-
it "should generate files" do
|
58
|
-
Smartgen[:my_resource].should_receive(:generate!)
|
59
|
-
capture(:stdout) { subject.generate }
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context "when user hits ctrl+c" do
|
64
|
-
it "should exit gracefully" do
|
65
|
-
directory_watcher.should_receive(:stop)
|
66
|
-
Kernel.should_receive(:trap).with('INT').and_yield
|
67
|
-
capture(:stdout) { subject.start }
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
data/spec/lib/smartgen_spec.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe Smartgen do
|
5
|
-
describe "resources" do
|
6
|
-
it "should create a resource the first time it is accessed" do
|
7
|
-
Smartgen[:foo].should be_an_instance_of(Smartgen::Resource)
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should use the same resource when it is accessed in the future" do
|
11
|
-
Smartgen[:foo].should be_equal(Smartgen[:foo])
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should create different resource for each given name" do
|
15
|
-
Smartgen[:foo].should_not be_equal(Smartgen[:bar])
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
data/spec/sandbox/.gitkeep
DELETED
File without changes
|
data/spec/spec_helper.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
$:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
3
|
-
require 'rspec'
|
4
|
-
require 'smartgen'
|
5
|
-
|
6
|
-
RSpec.configure do |config|
|
7
|
-
def fixture(path)
|
8
|
-
File.join(fixtures_dir, path)
|
9
|
-
end
|
10
|
-
|
11
|
-
def fixtures_dir
|
12
|
-
File.expand_path('fixtures', File.dirname(__FILE__))
|
13
|
-
end
|
14
|
-
|
15
|
-
def sandbox(path)
|
16
|
-
File.join(sandbox_dir, path)
|
17
|
-
end
|
18
|
-
|
19
|
-
def sandbox_dir
|
20
|
-
File.expand_path('sandbox', File.dirname(__FILE__))
|
21
|
-
end
|
22
|
-
|
23
|
-
def capture(stream)
|
24
|
-
begin
|
25
|
-
stream = stream.to_s
|
26
|
-
eval "$#{stream} = StringIO.new"
|
27
|
-
yield
|
28
|
-
result = eval("$#{stream}").string
|
29
|
-
ensure
|
30
|
-
eval("$#{stream} = #{stream.upcase}")
|
31
|
-
end
|
32
|
-
|
33
|
-
result
|
34
|
-
end
|
35
|
-
|
36
|
-
alias silence capture
|
37
|
-
end
|