smartgen 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/ChangeLog.md +4 -0
  2. data/Gemfile +11 -0
  3. data/Gemfile.lock +61 -0
  4. data/README.md +119 -0
  5. data/Rakefile +8 -0
  6. data/bin/smartgen +25 -0
  7. data/lib/smartgen.rb +21 -0
  8. data/lib/smartgen/configuration.rb +17 -0
  9. data/lib/smartgen/engines.rb +3 -0
  10. data/lib/smartgen/engines/base.rb +45 -0
  11. data/lib/smartgen/engines/markdown.rb +16 -0
  12. data/lib/smartgen/engines/textile.rb +16 -0
  13. data/lib/smartgen/generator.rb +104 -0
  14. data/lib/smartgen/markup_file.rb +47 -0
  15. data/lib/smartgen/object_hash.rb +41 -0
  16. data/lib/smartgen/renderers.rb +1 -0
  17. data/lib/smartgen/renderers/erb.rb +12 -0
  18. data/lib/smartgen/resource.rb +32 -0
  19. data/lib/smartgen/version.rb +4 -0
  20. data/spec/fixtures/expectations/common/another_index.html +13 -0
  21. data/spec/fixtures/expectations/common/index.html +8 -0
  22. data/spec/fixtures/expectations/common/other_index.html +13 -0
  23. data/spec/fixtures/expectations/with_layout/index.html +12 -0
  24. data/spec/fixtures/expectations/with_layout/index_with_metadata.html +43 -0
  25. data/spec/fixtures/expectations/with_layout/index_with_specific_metadata.html +44 -0
  26. data/spec/fixtures/src/assets/images/image.gif +0 -0
  27. data/spec/fixtures/src/assets/javascripts/somelib.js +2 -0
  28. data/spec/fixtures/src/assets/stylesheets/style.css +2 -0
  29. data/spec/fixtures/src/common/another_index.md +12 -0
  30. data/spec/fixtures/src/common/index.textile +10 -0
  31. data/spec/fixtures/src/common/other_index.markdown +12 -0
  32. data/spec/fixtures/src/layout.html.erb +5 -0
  33. data/spec/fixtures/src/layout_with_metadata.html.erb +22 -0
  34. data/spec/fixtures/src/layout_with_specific_metadata.html.erb +23 -0
  35. data/spec/fixtures/src/metadata.yml +43 -0
  36. data/spec/fixtures/src/with_layout/index.textile +10 -0
  37. data/spec/fixtures/src/with_layout/index_with_specific_metadata.textile +10 -0
  38. data/spec/lib/smartgen/configuration_spec.rb +30 -0
  39. data/spec/lib/smartgen/engines/base_spec.rb +71 -0
  40. data/spec/lib/smartgen/engines/markdown_spec.rb +23 -0
  41. data/spec/lib/smartgen/engines/textile_spec.rb +19 -0
  42. data/spec/lib/smartgen/generator_spec.rb +166 -0
  43. data/spec/lib/smartgen/markup_file_spec.rb +128 -0
  44. data/spec/lib/smartgen/object_hash_spec.rb +54 -0
  45. data/spec/lib/smartgen/renderers/erb_spec.rb +32 -0
  46. data/spec/lib/smartgen/resource_spec.rb +60 -0
  47. data/spec/lib/smartgen_spec.rb +18 -0
  48. data/spec/sandbox/.gitkeep +0 -0
  49. data/spec/spec_helper.rb +37 -0
  50. metadata +240 -0
@@ -0,0 +1,54 @@
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
+ it "should respond to ancestor methods" do
19
+ ancestor = Smartgen::ObjectHash.ancestors.first
20
+ ancestor.instance_methods.each do |method|
21
+ should respond_to(method)
22
+ end
23
+ end
24
+
25
+ it "should fetch key when calling method with the same name directly" do
26
+ subject.merge!({:foo => 'foo'})
27
+ subject.foo.should == 'foo'
28
+ end
29
+
30
+ describe "nested hashes" do
31
+ subject { Smartgen::ObjectHash.new({:nested_hash => {:some_key => 'value'}})}
32
+
33
+ it "should accept calling nested methods" do
34
+ subject.nested_hash.some_key.should == 'value'
35
+ end
36
+ end
37
+
38
+ describe "nested array with hashes" do
39
+ subject { Smartgen::ObjectHash.new({:array => [{:some_key => 'value'}]})}
40
+
41
+ it "should accept calling nested methods" do
42
+ subject.array.first.some_key.should == 'value'
43
+ end
44
+ end
45
+
46
+ describe Hash do
47
+ subject { Hash.new }
48
+
49
+ it "should return an object hash" do
50
+ subject.with_object_hash.should be_an_instance_of(Smartgen::ObjectHash)
51
+ end
52
+ end
53
+ end
54
+
@@ -0,0 +1,32 @@
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
@@ -0,0 +1,60 @@
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
@@ -0,0 +1,18 @@
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
File without changes
@@ -0,0 +1,37 @@
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
metadata ADDED
@@ -0,0 +1,240 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smartgen
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Vicente Mundim
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-24 00:00:00 -02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: thor
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 43
30
+ segments:
31
+ - 0
32
+ - 14
33
+ - 6
34
+ version: 0.14.6
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: i18n
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 11
46
+ segments:
47
+ - 0
48
+ - 5
49
+ - 0
50
+ version: 0.5.0
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: activesupport
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 9
62
+ segments:
63
+ - 2
64
+ - 3
65
+ - 5
66
+ version: 2.3.5
67
+ type: :runtime
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: RedCloth
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 49
78
+ segments:
79
+ - 4
80
+ - 2
81
+ - 3
82
+ version: 4.2.3
83
+ type: :runtime
84
+ version_requirements: *id004
85
+ - !ruby/object:Gem::Dependency
86
+ name: bluecloth
87
+ prerelease: false
88
+ requirement: &id005 !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ hash: 29
94
+ segments:
95
+ - 2
96
+ - 0
97
+ - 9
98
+ version: 2.0.9
99
+ type: :runtime
100
+ version_requirements: *id005
101
+ - !ruby/object:Gem::Dependency
102
+ name: rspec
103
+ prerelease: false
104
+ requirement: &id006 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ hash: 3
110
+ segments:
111
+ - 2
112
+ - 3
113
+ - 0
114
+ version: 2.3.0
115
+ type: :development
116
+ version_requirements: *id006
117
+ description: Smartgen generates static HTML files from markup files, using textile or markdown, and ERB to create layout templates
118
+ email:
119
+ - vicente.mundim@gmail.com
120
+ executables:
121
+ - smartgen
122
+ extensions: []
123
+
124
+ extra_rdoc_files: []
125
+
126
+ files:
127
+ - lib/smartgen/configuration.rb
128
+ - lib/smartgen/engines/base.rb
129
+ - lib/smartgen/engines/markdown.rb
130
+ - lib/smartgen/engines/textile.rb
131
+ - lib/smartgen/engines.rb
132
+ - lib/smartgen/generator.rb
133
+ - lib/smartgen/markup_file.rb
134
+ - lib/smartgen/object_hash.rb
135
+ - lib/smartgen/renderers/erb.rb
136
+ - lib/smartgen/renderers.rb
137
+ - lib/smartgen/resource.rb
138
+ - lib/smartgen/version.rb
139
+ - lib/smartgen.rb
140
+ - Gemfile
141
+ - Gemfile.lock
142
+ - Rakefile
143
+ - README.md
144
+ - ChangeLog.md
145
+ - spec/fixtures/expectations/common/another_index.html
146
+ - spec/fixtures/expectations/common/index.html
147
+ - spec/fixtures/expectations/common/other_index.html
148
+ - spec/fixtures/expectations/with_layout/index.html
149
+ - spec/fixtures/expectations/with_layout/index_with_metadata.html
150
+ - spec/fixtures/expectations/with_layout/index_with_specific_metadata.html
151
+ - spec/fixtures/src/assets/images/image.gif
152
+ - spec/fixtures/src/assets/javascripts/somelib.js
153
+ - spec/fixtures/src/assets/stylesheets/style.css
154
+ - spec/fixtures/src/common/another_index.md
155
+ - spec/fixtures/src/common/index.textile
156
+ - spec/fixtures/src/common/other_index.markdown
157
+ - spec/fixtures/src/layout.html.erb
158
+ - spec/fixtures/src/layout_with_metadata.html.erb
159
+ - spec/fixtures/src/layout_with_specific_metadata.html.erb
160
+ - spec/fixtures/src/metadata.yml
161
+ - spec/fixtures/src/with_layout/index.textile
162
+ - spec/fixtures/src/with_layout/index_with_specific_metadata.textile
163
+ - spec/lib/smartgen/configuration_spec.rb
164
+ - spec/lib/smartgen/engines/base_spec.rb
165
+ - spec/lib/smartgen/engines/markdown_spec.rb
166
+ - spec/lib/smartgen/engines/textile_spec.rb
167
+ - spec/lib/smartgen/generator_spec.rb
168
+ - spec/lib/smartgen/markup_file_spec.rb
169
+ - spec/lib/smartgen/object_hash_spec.rb
170
+ - spec/lib/smartgen/renderers/erb_spec.rb
171
+ - spec/lib/smartgen/resource_spec.rb
172
+ - spec/lib/smartgen_spec.rb
173
+ - spec/sandbox/.gitkeep
174
+ - spec/spec_helper.rb
175
+ - bin/smartgen
176
+ has_rdoc: true
177
+ homepage: ""
178
+ licenses: []
179
+
180
+ post_install_message:
181
+ rdoc_options: []
182
+
183
+ require_paths:
184
+ - lib
185
+ required_ruby_version: !ruby/object:Gem::Requirement
186
+ none: false
187
+ requirements:
188
+ - - ">="
189
+ - !ruby/object:Gem::Version
190
+ hash: 3
191
+ segments:
192
+ - 0
193
+ version: "0"
194
+ required_rubygems_version: !ruby/object:Gem::Requirement
195
+ none: false
196
+ requirements:
197
+ - - ">="
198
+ - !ruby/object:Gem::Version
199
+ hash: 3
200
+ segments:
201
+ - 0
202
+ version: "0"
203
+ requirements: []
204
+
205
+ rubyforge_project: smartgen
206
+ rubygems_version: 1.3.7
207
+ signing_key:
208
+ specification_version: 3
209
+ summary: A static HTML markup generator
210
+ test_files:
211
+ - spec/fixtures/expectations/common/another_index.html
212
+ - spec/fixtures/expectations/common/index.html
213
+ - spec/fixtures/expectations/common/other_index.html
214
+ - spec/fixtures/expectations/with_layout/index.html
215
+ - spec/fixtures/expectations/with_layout/index_with_metadata.html
216
+ - spec/fixtures/expectations/with_layout/index_with_specific_metadata.html
217
+ - spec/fixtures/src/assets/images/image.gif
218
+ - spec/fixtures/src/assets/javascripts/somelib.js
219
+ - spec/fixtures/src/assets/stylesheets/style.css
220
+ - spec/fixtures/src/common/another_index.md
221
+ - spec/fixtures/src/common/index.textile
222
+ - spec/fixtures/src/common/other_index.markdown
223
+ - spec/fixtures/src/layout.html.erb
224
+ - spec/fixtures/src/layout_with_metadata.html.erb
225
+ - spec/fixtures/src/layout_with_specific_metadata.html.erb
226
+ - spec/fixtures/src/metadata.yml
227
+ - spec/fixtures/src/with_layout/index.textile
228
+ - spec/fixtures/src/with_layout/index_with_specific_metadata.textile
229
+ - spec/lib/smartgen/configuration_spec.rb
230
+ - spec/lib/smartgen/engines/base_spec.rb
231
+ - spec/lib/smartgen/engines/markdown_spec.rb
232
+ - spec/lib/smartgen/engines/textile_spec.rb
233
+ - spec/lib/smartgen/generator_spec.rb
234
+ - spec/lib/smartgen/markup_file_spec.rb
235
+ - spec/lib/smartgen/object_hash_spec.rb
236
+ - spec/lib/smartgen/renderers/erb_spec.rb
237
+ - spec/lib/smartgen/resource_spec.rb
238
+ - spec/lib/smartgen_spec.rb
239
+ - spec/sandbox/.gitkeep
240
+ - spec/spec_helper.rb