machined 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,6 +4,7 @@ module Machined
4
4
  autoload :CLI, "machined/cli"
5
5
  autoload :Context, "machined/context"
6
6
  autoload :Environment, "machined/environment"
7
+ autoload :Index, "machined/index"
7
8
  autoload :Initializable, "machined/initializable"
8
9
  autoload :Server, "machined/server"
9
10
  autoload :Sprocket, "machined/sprocket"
@@ -3,22 +3,6 @@ require "active_support/core_ext/string/inflections"
3
3
  module Machined
4
4
  module Helpers
5
5
  module PageHelpers
6
- # Returns the context of the given path. This is useful
7
- # if you want to get the information from the front matter
8
- # of a specific page.
9
- def context_for(path, environment = self.environment)
10
- pathname = environment.resolve path, :base_path => self.pathname.dirname
11
-
12
- contexts_cache[pathname] ||= begin
13
- if pathname == self.pathname
14
- self
15
- else
16
- depend_on_asset pathname
17
- environment.find_asset(pathname).send :dependency_context
18
- end
19
- end
20
- end
21
-
22
6
  # Returns the default layout, unless overridden by
23
7
  # the YAML front matter.
24
8
  def layout
@@ -0,0 +1,23 @@
1
+ require "sprockets"
2
+
3
+ module Machined
4
+ # We need to add accessors for the Machined
5
+ # environment and the Sprocket's config to the
6
+ # index, so the Context has access.
7
+ class Index < Sprockets::Index
8
+ # A reference to the Machined environment which
9
+ # created this instance.
10
+ attr_reader :machined
11
+
12
+ # A reference to the configuration.
13
+ attr_reader :config
14
+
15
+ #
16
+ def initialize(environment)
17
+ @machined = environment.machined
18
+ @config = environment.config
19
+
20
+ super
21
+ end
22
+ end
23
+ end
@@ -29,7 +29,6 @@ module Machined
29
29
  super config.root
30
30
 
31
31
  @context_class = Class.new Context
32
- use_all_templates unless config.assets
33
32
  end
34
33
 
35
34
  # Returns true, if this sprocket should be
@@ -41,6 +40,11 @@ module Machined
41
40
  config.compile && config.url
42
41
  end
43
42
 
43
+ # Override to use Machined's Index
44
+ def index
45
+ Index.new(self)
46
+ end
47
+
44
48
  # Loops through the available Tilt templates
45
49
  # and registers them as processor engines for
46
50
  # Sprockets. By default, Sprockets cherry picks
@@ -23,7 +23,7 @@ module Machined
23
23
  next unless compiled_assets[url].nil? && compile?(url)
24
24
 
25
25
  if asset = sprocket.find_asset(logical_path)
26
- compiled_assets[url] = write_asset(asset)
26
+ compiled_assets[url] = write_asset(sprocket, asset)
27
27
  end
28
28
  end
29
29
  end
@@ -39,8 +39,8 @@ module Machined
39
39
 
40
40
  # Writes the asset to its destination, also
41
41
  # writing a gzipped version if necessary.
42
- def write_asset(asset)
43
- filename = path_for(asset)
42
+ def write_asset(environment, asset)
43
+ filename = path_for(environment, asset)
44
44
  FileUtils.mkdir_p File.dirname(filename)
45
45
  asset.write_to filename
46
46
  asset.write_to "#{filename}.gz" if gzip?(filename)
@@ -52,15 +52,15 @@ module Machined
52
52
  # Gets the full output path for the given asset.
53
53
  # If it's supposed to include a digest, it will return the
54
54
  # digest_path.
55
- def path_for(asset) # :nodoc:
56
- path = digest?(asset) ? asset.digest_path : asset.logical_path
57
- File.join(machined.output_path, asset.environment.config.url, path)
55
+ def path_for(environment, asset) # :nodoc:
56
+ path = digest?(environment, asset) ? asset.digest_path : asset.logical_path
57
+ File.join(machined.output_path, environment.config.url, path)
58
58
  end
59
59
 
60
60
  # Determines if we should use the digest_path for the given
61
61
  # asset.
62
- def digest?(asset) # :nodoc:
63
- machined.config.digest_assets && asset.environment.config.assets
62
+ def digest?(environment, asset) # :nodoc:
63
+ machined.config.digest_assets && environment.config.assets
64
64
  end
65
65
 
66
66
  # Determines if we should gzip the asset.
@@ -1,3 +1,3 @@
1
1
  module Machined
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -18,11 +18,11 @@ Gem::Specification.new do |s|
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
20
 
21
- s.add_dependency "sprockets", "~> 2.0.3"
21
+ s.add_dependency "sprockets", "~> 2.0.0"
22
22
  s.add_dependency "sprockets-helpers", "~> 0.2.1"
23
- s.add_dependency "sprockets-sass", "~> 0.4.1"
23
+ s.add_dependency "sprockets-sass", "~> 0.5.0"
24
24
  s.add_dependency "padrino-helpers", "~> 0.10.5"
25
- s.add_dependency "activesupport", "~> 3.1.1"
25
+ s.add_dependency "activesupport", "~> 3.1.3"
26
26
  s.add_dependency "i18n", "~> 0.6.0"
27
27
  s.add_dependency "thor", "~> 0.14.6"
28
28
  s.add_dependency "crush", "~> 0.3.3"
@@ -30,7 +30,7 @@ Gem::Specification.new do |s|
30
30
  s.add_development_dependency "rack-test", "~> 0.6.1"
31
31
  s.add_development_dependency "test-construct", "~> 1.2.0"
32
32
  s.add_development_dependency "unindent", "~> 1.0"
33
- s.add_development_dependency "railties", "~> 3.1.1"
33
+ s.add_development_dependency "railties", "~> 3.1.3"
34
34
  s.add_development_dependency "haml"
35
35
  s.add_development_dependency "sass"
36
36
  s.add_development_dependency "slim"
@@ -1,41 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Machined::Helpers::PageHelpers do
4
- describe "#context_for" do
5
- it "returns the context for the given path" do
6
- within_construct do |c|
7
- c.file "pages/index.html.erb", "<%= context_for('about').title %>"
8
- c.file "pages/about.html", "---\ntitle: Hello World\n---\n"
9
-
10
- machined.pages["index.html"].to_s.should == "Hello World"
11
- end
12
- end
13
-
14
- it "returns a self reference to avoid circular dependencies" do
15
- within_construct do |c|
16
- c.file "pages/index.html.erb", "<%= context_for('index') == self %>"
17
-
18
- machined.pages["index.html"].to_s.should == "true"
19
- end
20
- end
21
-
22
- it "adds the found context as a dependency" do
23
- within_construct do |c|
24
- c.file "pages/index.html.erb", "<%= context_for('about').title %>"
25
- dep = c.file "pages/about.html", "---\ntitle: Hello World\n---\n"
26
-
27
- asset = machined.pages["index.html"]
28
- asset.should be_fresh
29
-
30
- dep.open("w") { |f| f.write("---\ntitle: This Changed!\n---\n") }
31
- mtime = Time.now + 600
32
- dep.utime mtime, mtime
33
-
34
- asset.should be_stale
35
- end
36
- end
37
- end
38
-
39
4
  describe "#layout" do
40
5
  it "defaults to the default layout" do
41
6
  within_construct do |c|
@@ -86,13 +86,13 @@ describe Machined::Helpers::RenderHelpers do
86
86
  dep = c.file "views/partial.haml", "Hello World"
87
87
 
88
88
  asset = machined.pages["index.html"]
89
- asset.should be_fresh
89
+ asset.should be_fresh(machined.pages)
90
90
 
91
91
  dep.open("w") { |f| f.write("%h1 Hello World") }
92
92
  mtime = Time.now + 600
93
93
  dep.utime mtime, mtime
94
94
 
95
- asset.should be_stale
95
+ asset.should_not be_fresh(machined.pages)
96
96
  end
97
97
  end
98
98
 
@@ -36,13 +36,13 @@ describe Machined::Processors::LayoutProcessor do
36
36
  dep = c.file "views/layouts/main.html.haml", "= yield"
37
37
 
38
38
  asset = machined.pages["index.html"]
39
- asset.should be_fresh
40
-
39
+ asset.should be_fresh(machined.pages)
40
+
41
41
  dep.open("w") { |f| f.write("#layout= yield") }
42
42
  mtime = Time.now + 600
43
43
  dep.utime mtime, mtime
44
44
 
45
- asset.should be_stale
45
+ asset.should_not be_fresh(machined.pages)
46
46
  end
47
47
  end
48
48
  end
@@ -0,0 +1,17 @@
1
+ RSpec::Matchers.define :be_fresh do |env|
2
+ match do |actual|
3
+ if actual.method(:fresh?).arity == 1
4
+ actual.fresh?(env)
5
+ else
6
+ actual.fresh?
7
+ end
8
+ end
9
+
10
+ failure_message_for_should do |env|
11
+ "expected asset to be fresh"
12
+ end
13
+
14
+ failure_message_for_should_not do |env|
15
+ "expected asset to be stale"
16
+ end
17
+ end
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: machined
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
5
4
  prerelease:
6
- segments:
7
- - 0
8
- - 4
9
- - 0
10
- version: 0.4.0
5
+ version: 0.5.0
11
6
  platform: ruby
12
7
  authors:
13
8
  - Pete Browne
@@ -15,327 +10,239 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2011-11-14 00:00:00 Z
13
+ date: 2011-11-30 00:00:00 Z
19
14
  dependencies:
20
15
  - !ruby/object:Gem::Dependency
16
+ name: sprockets
21
17
  requirement: &id001 !ruby/object:Gem::Requirement
22
18
  none: false
23
19
  requirements:
24
20
  - - ~>
25
21
  - !ruby/object:Gem::Version
26
- hash: 9
27
- segments:
28
- - 2
29
- - 0
30
- - 3
31
- version: 2.0.3
32
- name: sprockets
22
+ version: 2.0.0
23
+ type: :runtime
33
24
  prerelease: false
34
25
  version_requirements: *id001
35
- type: :runtime
36
26
  - !ruby/object:Gem::Dependency
27
+ name: sprockets-helpers
37
28
  requirement: &id002 !ruby/object:Gem::Requirement
38
29
  none: false
39
30
  requirements:
40
31
  - - ~>
41
32
  - !ruby/object:Gem::Version
42
- hash: 21
43
- segments:
44
- - 0
45
- - 2
46
- - 1
47
33
  version: 0.2.1
48
- name: sprockets-helpers
34
+ type: :runtime
49
35
  prerelease: false
50
36
  version_requirements: *id002
51
- type: :runtime
52
37
  - !ruby/object:Gem::Dependency
38
+ name: sprockets-sass
53
39
  requirement: &id003 !ruby/object:Gem::Requirement
54
40
  none: false
55
41
  requirements:
56
42
  - - ~>
57
43
  - !ruby/object:Gem::Version
58
- hash: 13
59
- segments:
60
- - 0
61
- - 4
62
- - 1
63
- version: 0.4.1
64
- name: sprockets-sass
44
+ version: 0.5.0
45
+ type: :runtime
65
46
  prerelease: false
66
47
  version_requirements: *id003
67
- type: :runtime
68
48
  - !ruby/object:Gem::Dependency
49
+ name: padrino-helpers
69
50
  requirement: &id004 !ruby/object:Gem::Requirement
70
51
  none: false
71
52
  requirements:
72
53
  - - ~>
73
54
  - !ruby/object:Gem::Version
74
- hash: 61
75
- segments:
76
- - 0
77
- - 10
78
- - 5
79
55
  version: 0.10.5
80
- name: padrino-helpers
56
+ type: :runtime
81
57
  prerelease: false
82
58
  version_requirements: *id004
83
- type: :runtime
84
59
  - !ruby/object:Gem::Dependency
60
+ name: activesupport
85
61
  requirement: &id005 !ruby/object:Gem::Requirement
86
62
  none: false
87
63
  requirements:
88
64
  - - ~>
89
65
  - !ruby/object:Gem::Version
90
- hash: 1
91
- segments:
92
- - 3
93
- - 1
94
- - 1
95
- version: 3.1.1
96
- name: activesupport
66
+ version: 3.1.3
67
+ type: :runtime
97
68
  prerelease: false
98
69
  version_requirements: *id005
99
- type: :runtime
100
70
  - !ruby/object:Gem::Dependency
71
+ name: i18n
101
72
  requirement: &id006 !ruby/object:Gem::Requirement
102
73
  none: false
103
74
  requirements:
104
75
  - - ~>
105
76
  - !ruby/object:Gem::Version
106
- hash: 7
107
- segments:
108
- - 0
109
- - 6
110
- - 0
111
77
  version: 0.6.0
112
- name: i18n
78
+ type: :runtime
113
79
  prerelease: false
114
80
  version_requirements: *id006
115
- type: :runtime
116
81
  - !ruby/object:Gem::Dependency
82
+ name: thor
117
83
  requirement: &id007 !ruby/object:Gem::Requirement
118
84
  none: false
119
85
  requirements:
120
86
  - - ~>
121
87
  - !ruby/object:Gem::Version
122
- hash: 43
123
- segments:
124
- - 0
125
- - 14
126
- - 6
127
88
  version: 0.14.6
128
- name: thor
89
+ type: :runtime
129
90
  prerelease: false
130
91
  version_requirements: *id007
131
- type: :runtime
132
92
  - !ruby/object:Gem::Dependency
93
+ name: crush
133
94
  requirement: &id008 !ruby/object:Gem::Requirement
134
95
  none: false
135
96
  requirements:
136
97
  - - ~>
137
98
  - !ruby/object:Gem::Version
138
- hash: 21
139
- segments:
140
- - 0
141
- - 3
142
- - 3
143
99
  version: 0.3.3
144
- name: crush
100
+ type: :runtime
145
101
  prerelease: false
146
102
  version_requirements: *id008
147
- type: :runtime
148
103
  - !ruby/object:Gem::Dependency
104
+ name: rspec
149
105
  requirement: &id009 !ruby/object:Gem::Requirement
150
106
  none: false
151
107
  requirements:
152
108
  - - ~>
153
109
  - !ruby/object:Gem::Version
154
- hash: 19
155
- segments:
156
- - 2
157
- - 7
158
- - 0
159
110
  version: 2.7.0
160
- name: rspec
111
+ type: :development
161
112
  prerelease: false
162
113
  version_requirements: *id009
163
- type: :development
164
114
  - !ruby/object:Gem::Dependency
115
+ name: rack-test
165
116
  requirement: &id010 !ruby/object:Gem::Requirement
166
117
  none: false
167
118
  requirements:
168
119
  - - ~>
169
120
  - !ruby/object:Gem::Version
170
- hash: 5
171
- segments:
172
- - 0
173
- - 6
174
- - 1
175
121
  version: 0.6.1
176
- name: rack-test
122
+ type: :development
177
123
  prerelease: false
178
124
  version_requirements: *id010
179
- type: :development
180
125
  - !ruby/object:Gem::Dependency
126
+ name: test-construct
181
127
  requirement: &id011 !ruby/object:Gem::Requirement
182
128
  none: false
183
129
  requirements:
184
130
  - - ~>
185
131
  - !ruby/object:Gem::Version
186
- hash: 31
187
- segments:
188
- - 1
189
- - 2
190
- - 0
191
132
  version: 1.2.0
192
- name: test-construct
133
+ type: :development
193
134
  prerelease: false
194
135
  version_requirements: *id011
195
- type: :development
196
136
  - !ruby/object:Gem::Dependency
137
+ name: unindent
197
138
  requirement: &id012 !ruby/object:Gem::Requirement
198
139
  none: false
199
140
  requirements:
200
141
  - - ~>
201
142
  - !ruby/object:Gem::Version
202
- hash: 15
203
- segments:
204
- - 1
205
- - 0
206
143
  version: "1.0"
207
- name: unindent
144
+ type: :development
208
145
  prerelease: false
209
146
  version_requirements: *id012
210
- type: :development
211
147
  - !ruby/object:Gem::Dependency
148
+ name: railties
212
149
  requirement: &id013 !ruby/object:Gem::Requirement
213
150
  none: false
214
151
  requirements:
215
152
  - - ~>
216
153
  - !ruby/object:Gem::Version
217
- hash: 1
218
- segments:
219
- - 3
220
- - 1
221
- - 1
222
- version: 3.1.1
223
- name: railties
154
+ version: 3.1.3
155
+ type: :development
224
156
  prerelease: false
225
157
  version_requirements: *id013
226
- type: :development
227
158
  - !ruby/object:Gem::Dependency
159
+ name: haml
228
160
  requirement: &id014 !ruby/object:Gem::Requirement
229
161
  none: false
230
162
  requirements:
231
163
  - - ">="
232
164
  - !ruby/object:Gem::Version
233
- hash: 3
234
- segments:
235
- - 0
236
165
  version: "0"
237
- name: haml
166
+ type: :development
238
167
  prerelease: false
239
168
  version_requirements: *id014
240
- type: :development
241
169
  - !ruby/object:Gem::Dependency
170
+ name: sass
242
171
  requirement: &id015 !ruby/object:Gem::Requirement
243
172
  none: false
244
173
  requirements:
245
174
  - - ">="
246
175
  - !ruby/object:Gem::Version
247
- hash: 3
248
- segments:
249
- - 0
250
176
  version: "0"
251
- name: sass
177
+ type: :development
252
178
  prerelease: false
253
179
  version_requirements: *id015
254
- type: :development
255
180
  - !ruby/object:Gem::Dependency
181
+ name: slim
256
182
  requirement: &id016 !ruby/object:Gem::Requirement
257
183
  none: false
258
184
  requirements:
259
185
  - - ">="
260
186
  - !ruby/object:Gem::Version
261
- hash: 3
262
- segments:
263
- - 0
264
187
  version: "0"
265
- name: slim
188
+ type: :development
266
189
  prerelease: false
267
190
  version_requirements: *id016
268
- type: :development
269
191
  - !ruby/object:Gem::Dependency
192
+ name: erubis
270
193
  requirement: &id017 !ruby/object:Gem::Requirement
271
194
  none: false
272
195
  requirements:
273
196
  - - ">="
274
197
  - !ruby/object:Gem::Version
275
- hash: 3
276
- segments:
277
- - 0
278
198
  version: "0"
279
- name: erubis
199
+ type: :development
280
200
  prerelease: false
281
201
  version_requirements: *id017
282
- type: :development
283
202
  - !ruby/object:Gem::Dependency
203
+ name: rdiscount
284
204
  requirement: &id018 !ruby/object:Gem::Requirement
285
205
  none: false
286
206
  requirements:
287
207
  - - ">="
288
208
  - !ruby/object:Gem::Version
289
- hash: 3
290
- segments:
291
- - 0
292
209
  version: "0"
293
- name: rdiscount
210
+ type: :development
294
211
  prerelease: false
295
212
  version_requirements: *id018
296
- type: :development
297
213
  - !ruby/object:Gem::Dependency
214
+ name: uglifier
298
215
  requirement: &id019 !ruby/object:Gem::Requirement
299
216
  none: false
300
217
  requirements:
301
218
  - - ">="
302
219
  - !ruby/object:Gem::Version
303
- hash: 3
304
- segments:
305
- - 0
306
220
  version: "0"
307
- name: uglifier
221
+ type: :development
308
222
  prerelease: false
309
223
  version_requirements: *id019
310
- type: :development
311
224
  - !ruby/object:Gem::Dependency
225
+ name: jquery-rails
312
226
  requirement: &id020 !ruby/object:Gem::Requirement
313
227
  none: false
314
228
  requirements:
315
229
  - - ">="
316
230
  - !ruby/object:Gem::Version
317
- hash: 3
318
- segments:
319
- - 0
320
231
  version: "0"
321
- name: jquery-rails
232
+ type: :development
322
233
  prerelease: false
323
234
  version_requirements: *id020
324
- type: :development
325
235
  - !ruby/object:Gem::Dependency
236
+ name: rake
326
237
  requirement: &id021 !ruby/object:Gem::Requirement
327
238
  none: false
328
239
  requirements:
329
240
  - - ">="
330
241
  - !ruby/object:Gem::Version
331
- hash: 3
332
- segments:
333
- - 0
334
242
  version: "0"
335
- name: rake
243
+ type: :development
336
244
  prerelease: false
337
245
  version_requirements: *id021
338
- type: :development
339
246
  description: Why another static site generator? Machined is for the developers who know and love the asset pipeline of Rails 3.1 and want to develop blazingly fast static websites. It's built from the ground up using Sprockets 2.0.
340
247
  email:
341
248
  - me@petebrowne.com
@@ -361,6 +268,7 @@ files:
361
268
  - lib/machined/helpers/output_helpers.rb
362
269
  - lib/machined/helpers/page_helpers.rb
363
270
  - lib/machined/helpers/render_helpers.rb
271
+ - lib/machined/index.rb
364
272
  - lib/machined/initializable.rb
365
273
  - lib/machined/processors/front_matter_processor.rb
366
274
  - lib/machined/processors/layout_processor.rb
@@ -395,6 +303,7 @@ files:
395
303
  - spec/machined/static_compiler_spec.rb
396
304
  - spec/machined/utils_spec.rb
397
305
  - spec/spec_helper.rb
306
+ - spec/support/be_fresh_matcher.rb
398
307
  - spec/support/helpers.rb
399
308
  - spec/support/match_paths_matcher.rb
400
309
  homepage: https://github.com/petebrowne/machined
@@ -410,7 +319,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
410
319
  requirements:
411
320
  - - ">="
412
321
  - !ruby/object:Gem::Version
413
- hash: 3
322
+ hash: -2894475183900037284
414
323
  segments:
415
324
  - 0
416
325
  version: "0"
@@ -419,14 +328,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
419
328
  requirements:
420
329
  - - ">="
421
330
  - !ruby/object:Gem::Version
422
- hash: 3
331
+ hash: -2894475183900037284
423
332
  segments:
424
333
  - 0
425
334
  version: "0"
426
335
  requirements: []
427
336
 
428
337
  rubyforge_project: machined
429
- rubygems_version: 1.8.5
338
+ rubygems_version: 1.8.8
430
339
  signing_key:
431
340
  specification_version: 3
432
341
  summary: A static site generator and Rack server built using Sprockets 2.0
@@ -447,5 +356,6 @@ test_files:
447
356
  - spec/machined/static_compiler_spec.rb
448
357
  - spec/machined/utils_spec.rb
449
358
  - spec/spec_helper.rb
359
+ - spec/support/be_fresh_matcher.rb
450
360
  - spec/support/helpers.rb
451
361
  - spec/support/match_paths_matcher.rb