machined 0.7.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/Rakefile +2 -2
  2. data/bin/machined +3 -3
  3. data/lib/machined.rb +17 -17
  4. data/lib/machined/cli.rb +35 -35
  5. data/lib/machined/context.rb +4 -4
  6. data/lib/machined/environment.rb +57 -31
  7. data/lib/machined/helpers/asset_tag_helpers.rb +4 -4
  8. data/lib/machined/helpers/locals_helpers.rb +1 -1
  9. data/lib/machined/helpers/output_helpers.rb +15 -15
  10. data/lib/machined/helpers/page_helpers.rb +1 -1
  11. data/lib/machined/helpers/render_helpers.rb +16 -16
  12. data/lib/machined/index.rb +1 -1
  13. data/lib/machined/initializable.rb +9 -11
  14. data/lib/machined/processors/front_matter_processor.rb +2 -2
  15. data/lib/machined/processors/layout_processor.rb +1 -1
  16. data/lib/machined/server.rb +2 -2
  17. data/lib/machined/sprocket.rb +4 -4
  18. data/lib/machined/static_compiler.rb +2 -2
  19. data/lib/machined/templates/site/Gemfile.tt +4 -4
  20. data/lib/machined/templates/site/config.ru +1 -1
  21. data/lib/machined/templates/site/machined.rb +2 -2
  22. data/lib/machined/templates/site/views/layouts/application.html.erb +2 -2
  23. data/lib/machined/utils.rb +3 -3
  24. data/lib/machined/version.rb +1 -1
  25. data/machined.gemspec +29 -31
  26. data/spec/machined/cli_spec.rb +56 -56
  27. data/spec/machined/context_spec.rb +6 -6
  28. data/spec/machined/environment_spec.rb +94 -94
  29. data/spec/machined/helpers/asset_tag_helpers_spec.rb +42 -42
  30. data/spec/machined/helpers/locals_helper_spec.rb +17 -17
  31. data/spec/machined/helpers/output_helpers_spec.rb +27 -27
  32. data/spec/machined/helpers/page_helpers_spec.rb +32 -32
  33. data/spec/machined/helpers/render_helpers_spec.rb +42 -42
  34. data/spec/machined/initializable_spec.rb +9 -9
  35. data/spec/machined/processors/front_matter_processor_spec.rb +7 -7
  36. data/spec/machined/processors/layout_processor_spec.rb +19 -19
  37. data/spec/machined/server_spec.rb +36 -36
  38. data/spec/machined/sprocket_spec.rb +15 -15
  39. data/spec/machined/utils_spec.rb +14 -14
  40. data/spec/spec_helper.rb +7 -7
  41. data/spec/support/be_fresh_matcher.rb +2 -2
  42. data/spec/support/helpers.rb +6 -6
  43. metadata +177 -301
@@ -1,16 +1,16 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Machined::Context do
4
- describe "#machined" do
5
- it "returns a reference to the Machined environment" do
4
+ describe '#machined' do
5
+ it 'returns a reference to the Machined environment' do
6
6
  context.machined.should be(machined)
7
7
  end
8
8
  end
9
9
 
10
- describe "#config" do
10
+ describe '#config' do
11
11
  it "returns a reference to the Machined environment's configuration" do
12
- machined.config.layout = "application"
13
- context.config.layout.should == "application"
12
+ machined.config.layout = 'application'
13
+ context.config.layout.should == 'application'
14
14
  end
15
15
  end
16
16
  end
@@ -1,37 +1,37 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Machined::Environment do
4
- describe "#initialize" do
5
- it "loads configuration from a config file" do
4
+ describe '#initialize' do
5
+ it 'loads configuration from a config file' do
6
6
  within_construct do |c|
7
- c.file "machined.rb", <<-CONTENT.unindent
8
- config.output_path = "site"
7
+ c.file 'machined.rb', <<-CONTENT.unindent
8
+ config.output_path = 'site'
9
9
  append_sprocket :updates
10
10
  CONTENT
11
- machined.config.output_path.should == "site"
11
+ machined.config.output_path.should == 'site'
12
12
  machined.updates.should be_a(Machined::Sprocket)
13
13
  end
14
14
  end
15
15
  end
16
16
 
17
- describe "#append_sprocket" do
18
- it "creates a new Sprockets environment" do
17
+ describe '#append_sprocket' do
18
+ it 'creates a new Sprockets environment' do
19
19
  sprocket = machined.append_sprocket :updates
20
20
  sprocket.should be_a(Sprockets::Environment)
21
21
  end
22
22
 
23
- it "appends the sprocket to #sprockets" do
23
+ it 'appends the sprocket to #sprockets' do
24
24
  sprocket = machined.append_sprocket :updates
25
25
  machined.sprockets.last.should be(sprocket)
26
26
  end
27
27
 
28
- it "adds a method with the given name which returns the sprocket" do
28
+ it 'adds a method with the given name which returns the sprocket' do
29
29
  sprocket = machined.append_sprocket :updates
30
30
  machined.updates.should be(sprocket)
31
31
  Machined::Environment.method_defined?(:updates).should be_false
32
32
  end
33
33
 
34
- it "yields the sprocket for configuration" do
34
+ it 'yields the sprocket for configuration' do
35
35
  yielded_sprocket = nil
36
36
  sprocket = machined.append_sprocket :updates do |updates|
37
37
  yielded_sprocket = updates
@@ -39,73 +39,73 @@ describe Machined::Environment do
39
39
  yielded_sprocket.should be(sprocket)
40
40
  end
41
41
 
42
- it "initializes the sprocket with a reference to the Machined environment" do
42
+ it 'initializes the sprocket with a reference to the Machined environment' do
43
43
  sprocket = machined.append_sprocket :updates
44
44
  sprocket.machined.should be(machined)
45
45
  end
46
46
 
47
- it "initializes the sprocket with configuration" do
48
- sprocket = machined.append_sprocket :updates, :root => "spec/machined"
49
- sprocket.root.should == File.expand_path("spec/machined")
47
+ it 'initializes the sprocket with configuration' do
48
+ sprocket = machined.append_sprocket :updates, :root => 'spec/machined'
49
+ sprocket.root.should == File.expand_path('spec/machined')
50
50
  end
51
51
  end
52
52
 
53
- describe "#prepend_sprocket" do
54
- it "creates a new Sprockets environment" do
53
+ describe '#prepend_sprocket' do
54
+ it 'creates a new Sprockets environment' do
55
55
  sprocket = machined.prepend_sprocket :updates
56
56
  sprocket.should be_a(Sprockets::Environment)
57
57
  end
58
58
 
59
- it "prepends the sprocket to #sprockets" do
59
+ it 'prepends the sprocket to #sprockets' do
60
60
  sprocket = machined.prepend_sprocket :updates
61
61
  machined.sprockets.first.should be(sprocket)
62
62
  end
63
63
  end
64
64
 
65
- describe "#remove_sprocket" do
66
- it "sets the accessor method to return nil" do
65
+ describe '#remove_sprocket' do
66
+ it 'sets the accessor method to return nil' do
67
67
  machined.remove_sprocket :pages
68
68
  machined.pages.should be_nil
69
69
  end
70
70
 
71
- it "removes the sprockets from the sprockets list" do
71
+ it 'removes the sprockets from the sprockets list' do
72
72
  views = machined.views
73
73
  machined.remove_sprocket :views
74
74
  machined.sprockets.should_not include(views)
75
75
  end
76
76
  end
77
77
 
78
- describe "#helpers" do
79
- it "adds methods defined in the given block to the Context" do
78
+ describe '#helpers' do
79
+ it 'adds methods defined in the given block to the Context' do
80
80
  machined.helpers do
81
81
  def hello
82
- "world"
82
+ 'world'
83
83
  end
84
84
  end
85
85
 
86
- context.hello.should == "world"
86
+ context.hello.should == 'world'
87
87
  end
88
88
 
89
- it "adds methods defined in the given module to the Context" do
89
+ it 'adds methods defined in the given module to the Context' do
90
90
  helper = Module.new do
91
91
  def hello
92
- "world"
92
+ 'world'
93
93
  end
94
94
  end
95
95
  machined.helpers helper
96
- context.hello.should == "world"
96
+ context.hello.should == 'world'
97
97
  end
98
98
  end
99
99
 
100
- describe "default assets sprocket" do
101
- it "appends the standard asset paths" do
100
+ describe 'default assets sprocket' do
101
+ it 'appends the standard asset paths' do
102
102
  within_construct do |c|
103
- c.directory "assets/images"
104
- c.directory "assets/javascripts"
105
- c.directory "assets/stylesheets"
106
- c.directory "vendor/assets/images"
107
- c.directory "vendor/assets/javascripts"
108
- c.directory "vendor/assets/stylesheets"
103
+ c.directory 'assets/images'
104
+ c.directory 'assets/javascripts'
105
+ c.directory 'assets/stylesheets'
106
+ c.directory 'vendor/assets/images'
107
+ c.directory 'vendor/assets/javascripts'
108
+ c.directory 'vendor/assets/stylesheets'
109
109
 
110
110
  machined.assets.paths.should match_paths(%w(
111
111
  assets/images
@@ -118,12 +118,12 @@ describe Machined::Environment do
118
118
  end
119
119
  end
120
120
 
121
- it "appends the available asset paths" do
121
+ it 'appends the available asset paths' do
122
122
  within_construct do |c|
123
- c.directory "assets/css"
124
- c.directory "assets/img"
125
- c.directory "assets/js"
126
- c.directory "assets/plugins"
123
+ c.directory 'assets/css'
124
+ c.directory 'assets/img'
125
+ c.directory 'assets/js'
126
+ c.directory 'assets/plugins'
127
127
 
128
128
  machined.assets.paths.should match_paths(%w(
129
129
  assets/css
@@ -134,21 +134,21 @@ describe Machined::Environment do
134
134
  end
135
135
  end
136
136
 
137
- it "appends Rails::Engine paths" do
138
- require "rails"
139
- require "jquery-rails"
140
- machined.assets.paths.first.should =~ %r(/jquery-rails-[\d\.]+/vendor/assets/javascripts)
141
- Rails::Engine.subclasses.delete Jquery::Rails::Engine
142
- end
137
+ # it 'appends Rails::Engine paths' do
138
+ # require 'rails'
139
+ # require 'jquery-rails'
140
+ # machined.assets.paths.first.should =~ %r(/jquery-rails-[\d\.]+/vendor/assets/javascripts)
141
+ # Rails::Engine.subclasses.delete Jquery::Rails::Engine
142
+ # end
143
143
 
144
- it "appends Sprockets::Plugin paths" do
145
- require "sprockets-plugin"
144
+ it 'appends Sprockets::Plugin paths' do
145
+ require 'sprockets-plugin'
146
146
 
147
147
  within_construct do |c|
148
- plugin_dir = c.directory "plugin/assets"
149
- plugin_dir.directory "images"
150
- plugin_dir.directory "javascripts"
151
- plugin_dir.directory "stylesheets"
148
+ plugin_dir = c.directory 'plugin/assets'
149
+ plugin_dir.directory 'images'
150
+ plugin_dir.directory 'javascripts'
151
+ plugin_dir.directory 'stylesheets'
152
152
 
153
153
  plugin = Class.new(Sprockets::Plugin)
154
154
  plugin.append_paths_in plugin_dir
@@ -162,36 +162,36 @@ describe Machined::Environment do
162
162
  end
163
163
  end
164
164
 
165
- it "compiles web assets" do
165
+ it 'compiles web assets' do
166
166
  within_construct do |c|
167
- c.file "assets/javascripts/main.js", "//= require dep"
168
- c.file "assets/javascripts/dep.js", "var app = {};"
169
- c.file "assets/stylesheets/main.css.scss", "@import 'dep';\nbody { color: $color; }"
170
- c.file "assets/stylesheets/_dep.scss", "$color: red;"
167
+ c.file 'assets/javascripts/main.js', '//= require dep'
168
+ c.file 'assets/javascripts/dep.js', 'var app = {};'
169
+ c.file 'assets/stylesheets/main.css.scss', "@import 'dep';\nbody { color: $color; }"
170
+ c.file 'assets/stylesheets/_dep.scss', '$color: red;'
171
171
 
172
- machined.assets["main.js"].to_s.should == "var app = {};\n"
173
- machined.assets["main.css"].to_s.should == "body {\n color: red; }\n"
172
+ machined.assets['main.js'].to_s.should == "var app = {};\n"
173
+ machined.assets['main.css'].to_s.should == "body {\n color: red; }\n"
174
174
  end
175
175
  end
176
176
  end
177
177
 
178
- describe "default pages sprocket" do
179
- it "appends the pages path" do
178
+ describe 'default pages sprocket' do
179
+ it 'appends the pages path' do
180
180
  within_construct do |c|
181
- c.directory "pages"
181
+ c.directory 'pages'
182
182
  machined.pages.paths.should match_paths(%w(pages)).with_root(c)
183
183
  end
184
184
  end
185
185
 
186
- it "compiles html pages" do
186
+ it 'compiles html pages' do
187
187
  within_construct do |c|
188
- c.file "pages/index.html.haml", "%h1 Hello World"
189
- machined.pages["index.html"].to_s.should == "<h1>Hello World</h1>\n"
188
+ c.file 'pages/index.html.haml', '%h1 Hello World'
189
+ machined.pages['index.html'].to_s.should == "<h1>Hello World</h1>\n"
190
190
  end
191
191
  end
192
192
 
193
- context "when :assets_only is set in constructor" do
194
- it "is never created" do
193
+ context 'when :assets_only is set in constructor' do
194
+ it 'is never created' do
195
195
  machined :assets_only => true
196
196
  machined.respond_to?(:pages).should be_false
197
197
  machined.sprockets.should == [ machined.assets, machined.views ]
@@ -199,10 +199,10 @@ describe Machined::Environment do
199
199
 
200
200
  end
201
201
 
202
- context "when :assets_only is set in the config file" do
203
- it "is removed" do
202
+ context 'when :assets_only is set in the config file' do
203
+ it 'is removed' do
204
204
  within_construct do |c|
205
- c.file "machined.rb", "config.assets_only = true"
205
+ c.file 'machined.rb', 'config.assets_only = true'
206
206
 
207
207
  machined
208
208
  machined.pages.should be_nil
@@ -212,49 +212,49 @@ describe Machined::Environment do
212
212
  end
213
213
  end
214
214
 
215
- describe "default views sprocket" do
216
- it "appends the views path" do
215
+ describe 'default views sprocket' do
216
+ it 'appends the views path' do
217
217
  within_construct do |c|
218
- c.directory "views"
218
+ c.directory 'views'
219
219
  machined.views.paths.should match_paths(%w(views)).with_root(c)
220
220
  end
221
221
  end
222
222
 
223
- it "compiles html pages" do
223
+ it 'compiles html pages' do
224
224
  within_construct do |c|
225
- c.file "views/layouts/main.html.haml", "%h1 Hello World"
226
- machined.views["layouts/main.html"].to_s.should == "<h1>Hello World</h1>\n"
225
+ c.file 'views/layouts/main.html.haml', '%h1 Hello World'
226
+ machined.views['layouts/main.html'].to_s.should == "<h1>Hello World</h1>\n"
227
227
  end
228
228
  end
229
229
  end
230
230
 
231
- describe "compression" do
232
- context "with compress set to true" do
233
- it "compresses javascripts and stylesheets" do
231
+ describe 'compression' do
232
+ context 'with compress set to true' do
233
+ it 'compresses javascripts and stylesheets' do
234
234
  within_construct do |c|
235
- c.file "assets/javascripts/main.js", "//= require dep"
236
- c.file "assets/javascripts/dep.js", "var app = {};"
237
- c.file "assets/stylesheets/main.css.scss", "@import 'dep';\nbody { color: $color; }"
238
- c.file "assets/stylesheets/_dep.scss", "$color: red;"
235
+ c.file 'assets/javascripts/main.js', '//= require dep'
236
+ c.file 'assets/javascripts/dep.js', 'var app = {};'
237
+ c.file 'assets/stylesheets/main.css.scss', "@import 'dep';\nbody { color: $color; }"
238
+ c.file 'assets/stylesheets/_dep.scss', '$color: red;'
239
239
 
240
- Crush::Uglifier.should_receive(:compress).with("var app = {};\n").and_return("compressed")
241
- Crush::Sass::Engine.should_receive(:compress).with("body {\n color: red; }\n").and_return("compressed")
240
+ Crush::Uglifier.should_receive(:compress).with("var app = {};\n").and_return('compressed')
241
+ Crush::Sass::Engine.should_receive(:compress).with("body {\n color: red; }\n").and_return('compressed')
242
242
 
243
243
  machined :compress => true
244
- machined.assets["main.js"].to_s.should == "compressed"
245
- machined.assets["main.css"].to_s.should == "compressed"
244
+ machined.assets['main.js'].to_s.should == 'compressed'
245
+ machined.assets['main.css'].to_s.should == 'compressed'
246
246
  end
247
247
  end
248
248
  end
249
249
  end
250
250
 
251
- context "with a js_compressor set" do
252
- it "compresses using that compressor" do
251
+ context 'with a js_compressor set' do
252
+ it 'compresses using that compressor' do
253
253
  within_construct do |c|
254
- c.file "assets/javascripts/main.js", "var app = {};"
255
- c.file "machined.rb", "config.js_compressor = :packr"
256
- Crush::Packr.should_receive(:compress).with("var app = {};\n").and_return("compressed")
257
- machined.assets["main.js"].to_s.should == "compressed"
254
+ c.file 'assets/javascripts/main.js', 'var app = {};'
255
+ c.file 'machined.rb', 'config.js_compressor = :packr'
256
+ Crush::Packr.should_receive(:compress).with("var app = {};\n").and_return('compressed')
257
+ machined.assets['main.js'].to_s.should == 'compressed'
258
258
  end
259
259
  end
260
260
  end
@@ -1,77 +1,77 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Machined::Helpers::AssetTagHelpers do
4
- describe "#asset_path" do
5
- context "with URIs" do
6
- it "returns URIs untouched" do
7
- context.asset_path(:js, "https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js").should ==
8
- "https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"
9
- context.asset_path(:js, "http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js").should ==
10
- "http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"
11
- context.asset_path(:js, "//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js").should ==
12
- "//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"
4
+ describe '#asset_path' do
5
+ context 'with URIs' do
6
+ it 'returns URIs untouched' do
7
+ context.asset_path(:js, 'https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js').should ==
8
+ 'https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js'
9
+ context.asset_path(:js, 'http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js').should ==
10
+ 'http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js'
11
+ context.asset_path(:js, '//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js').should ==
12
+ '//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js'
13
13
  end
14
14
  end
15
15
 
16
- context "with regular files" do
17
- it "returns absolute paths" do
18
- context.asset_path(:js, "/path/to/file.js").should == "/path/to/file.js"
19
- context.asset_path(:images, "/path/to/file.jpg").should == "/path/to/file.jpg"
16
+ context 'with regular files' do
17
+ it 'returns absolute paths' do
18
+ context.asset_path(:js, '/path/to/file.js').should == '/path/to/file.js'
19
+ context.asset_path(:images, '/path/to/file.jpg').should == '/path/to/file.jpg'
20
20
  end
21
21
 
22
- it "appends the extension for javascripts and stylesheets" do
23
- context.asset_path(:js, "/path/to/file").should == "/path/to/file.js"
24
- context.asset_path(:css, "/path/to/file").should == "/path/to/file.css"
25
- context.asset_path(:images, "/path/to/file").should_not == "/path/to/file.jpg"
22
+ it 'appends the extension for javascripts and stylesheets' do
23
+ context.asset_path(:js, '/path/to/file').should == '/path/to/file.js'
24
+ context.asset_path(:css, '/path/to/file').should == '/path/to/file.css'
25
+ context.asset_path(:images, '/path/to/file').should_not == '/path/to/file.jpg'
26
26
  end
27
27
 
28
- it "prepends a base URL if missing" do
29
- context.asset_path(:css, "main").should == "/stylesheets/main.css"
30
- context.asset_path(:js, "main").should == "/javascripts/main.js"
31
- context.asset_path(:images, "logo.jpg").should == "/images/logo.jpg"
28
+ it 'prepends a base URL if missing' do
29
+ context.asset_path(:css, 'main').should == '/stylesheets/main.css'
30
+ context.asset_path(:js, 'main').should == '/javascripts/main.js'
31
+ context.asset_path(:images, 'logo.jpg').should == '/images/logo.jpg'
32
32
  end
33
33
 
34
- it "appends a timestamp if the file exists in the output path" do
34
+ it 'appends a timestamp if the file exists in the output path' do
35
35
  within_construct do |c|
36
- c.file "public/javascripts/main.js"
37
- c.file "public/favicon.ico"
36
+ c.file 'public/javascripts/main.js'
37
+ c.file 'public/favicon.ico'
38
38
 
39
- context.asset_path(:js, "main").should =~ %r(/javascripts/main.js\?\d+)
40
- context.asset_path(:images, "/favicon.ico").should =~ %r(/favicon.ico\?\d+)
39
+ context.asset_path(:js, 'main').should =~ %r(/javascripts/main.js\?\d+)
40
+ context.asset_path(:images, '/favicon.ico').should =~ %r(/favicon.ico\?\d+)
41
41
  end
42
42
  end
43
43
  end
44
44
 
45
- context "with assets" do
46
- it "prepends a base URL if missing" do
45
+ context 'with assets' do
46
+ it 'prepends a base URL if missing' do
47
47
  within_construct do |c|
48
- c.file "assets/images/logo.jpg"
49
- c.file "assets/javascripts/main.js"
50
- c.file "assets/stylesheets/main.css"
48
+ c.file 'assets/images/logo.jpg'
49
+ c.file 'assets/javascripts/main.js'
50
+ c.file 'assets/stylesheets/main.css'
51
51
 
52
- context.asset_path(:css, "main").should == "/assets/main.css"
53
- context.asset_path(:js, "main").should == "/assets/main.js"
54
- context.asset_path(:images, "logo.jpg").should == "/assets/logo.jpg"
52
+ context.asset_path(:css, 'main').should == '/assets/main.css'
53
+ context.asset_path(:js, 'main').should == '/assets/main.js'
54
+ context.asset_path(:images, 'logo.jpg').should == '/assets/logo.jpg'
55
55
  end
56
56
  end
57
57
 
58
- it "uses the digest path if configured" do
58
+ it 'uses the digest path if configured' do
59
59
  within_construct do |c|
60
- c.file "assets/javascrtips/main.js"
60
+ c.file 'assets/javascrtips/main.js'
61
61
 
62
62
  machined :digest_assets => true
63
- context.asset_path(:js, "main").should =~ %r(/assets/main-[0-9a-f]+.js)
63
+ context.asset_path(:js, 'main').should =~ %r(/assets/main-[0-9a-f]+.js)
64
64
  end
65
65
  end
66
66
  end
67
67
  end
68
68
 
69
- describe "#asset_path" do
70
- it "is compatible with the Sprockets::Helpers API" do
69
+ describe '#asset_path' do
70
+ it 'is compatible with the Sprockets::Helpers API' do
71
71
  within_construct do |c|
72
- c.file "assets/images/logo.jpg"
72
+ c.file 'assets/images/logo.jpg'
73
73
 
74
- context.image_path("logo.jpg", :digest => true).should =~ %r(/assets/logo-[0-9a-f]+.jpg)
74
+ context.image_path('logo.jpg', :digest => true).should =~ %r(/assets/logo-[0-9a-f]+.jpg)
75
75
  end
76
76
  end
77
77
  end