massimo 0.8.5 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,14 @@ require 'sprockets'
2
2
 
3
3
  module Massimo
4
4
  class Javascript < Massimo::Resource
5
+ def extension
6
+ if Tilt.registered?(super[1..-1])
7
+ '.js'
8
+ else
9
+ super
10
+ end
11
+ end
12
+
5
13
  def render
6
14
  output = if source_path.extname == '.js'
7
15
  options = Massimo.config.options_for(:sprockets).merge(
@@ -17,10 +25,6 @@ module Massimo
17
25
  compress(output)
18
26
  end
19
27
 
20
- def extension
21
- @extension ||= '.js'
22
- end
23
-
24
28
  protected
25
29
 
26
30
  def compress(javascript)
@@ -7,12 +7,7 @@ require 'yaml'
7
7
  module Massimo
8
8
  class Page < Resource
9
9
  def render
10
- output = if template?
11
- meta_data = @meta_data.merge self.class.resource_name.singularize.to_sym => self
12
- template.render Massimo.site.template_scope, meta_data
13
- else
14
- content
15
- end
10
+ output = super
16
11
 
17
12
  if found_layout = Massimo::View.find("layouts/#{layout}")
18
13
  output = found_layout.render(:page => self) { output }
@@ -26,7 +21,13 @@ module Massimo
26
21
  end
27
22
 
28
23
  def extension
29
- @meta_data[:extension] ||= '.html'
24
+ if @meta_data[:extension]
25
+ @meta_data[:extension]
26
+ elsif Tilt.registered?(super[1..-1])
27
+ '.html'
28
+ else
29
+ super
30
+ end
30
31
  end
31
32
 
32
33
  def url
@@ -48,6 +49,10 @@ module Massimo
48
49
 
49
50
  protected
50
51
 
52
+ def template_locals
53
+ @meta_data.merge self.class.resource_name.singularize.to_sym => self
54
+ end
55
+
51
56
  def read_source
52
57
  case source_path.extname
53
58
  when '.yml', '.yaml'
@@ -1,11 +1,14 @@
1
1
  require 'active_support/core_ext/string/starts_ends_with'
2
2
  require 'active_support/inflector'
3
+ require 'active_support/memoizable'
3
4
  require 'fileutils'
4
5
  require 'pathname'
5
6
  require 'tilt'
6
7
 
7
8
  module Massimo
8
9
  class Resource
10
+ extend ActiveSupport::Memoizable
11
+
9
12
  class << self
10
13
  # The underscored, pluralized name of the resource.
11
14
  def resource_name
@@ -42,10 +45,10 @@ module Massimo
42
45
 
43
46
  protected
44
47
 
45
- def unprocessable
46
- def self.processable?; false; end
47
- define_method(:process) { false }
48
- end
48
+ def unprocessable
49
+ def self.processable?; false; end
50
+ define_method(:process) { false }
51
+ end
49
52
  end
50
53
 
51
54
  attr_reader :source_path, :content
@@ -53,43 +56,50 @@ module Massimo
53
56
  # Creates a new resource for the given source file.
54
57
  # The contents of the file will automatically be read.
55
58
  def initialize(source)
56
- @source_path = source.is_a?(Pathname) ? source.expand_path : Pathname.new(source).expand_path
59
+ @source_path = Pathname.new(source).expand_path
57
60
  read_source
58
61
  end
59
62
 
60
63
  # The basename of the source file.
61
64
  def filename
62
- @filename ||= source_path.basename.to_s
65
+ source_path.basename.to_s
63
66
  end
64
67
 
65
68
  # The extension to output with.
66
69
  def extension
67
- @extension ||= source_path.extname
70
+ extensions.first
71
+ end
72
+
73
+ # A list of all the extensions appended to the filename.
74
+ def extensions
75
+ filename.scan /\.[^.]+/
68
76
  end
69
77
 
70
78
  # The url to the resource. This is created by swiching the base path
71
79
  # of the source file with the base url.
72
80
  def url
73
- @url ||= begin
74
- url = source_path.to_s.sub(/^#{Regexp.escape(self.class.path)}/, '')
75
- url = url.sub(/\.[^\.]+$/, extension)
76
- url = File.join(self.class.url, url) unless url.starts_with? self.class.url
77
- url = url.dasherize
78
- url
79
- end
81
+ url = source_path.to_s.sub(/^#{Regexp.escape(self.class.path)}/, '')
82
+ url = url.sub(/\..+$/, extension)
83
+ url = File.join(self.class.url, url) unless url.starts_with? self.class.url
84
+ url = url.dasherize
85
+ url
80
86
  end
81
87
 
82
88
  # The path to the output file.
83
89
  def output_path
84
- @output_path ||= Pathname.new File.join(Massimo.config.output_path, url.sub(/^#{Regexp.escape(Massimo.config.base_url)}/, ''))
90
+ Pathname.new File.join(Massimo.config.output_path, url.sub(/^#{Regexp.escape(Massimo.config.base_url)}/, ''))
85
91
  end
86
92
 
87
93
  # Runs the content through any necessary filters, templates, etc.
88
94
  def render
89
- if template?
90
- template.render
91
- else
92
- content
95
+ extensions.reverse.inject(content) do |output, ext|
96
+ if template_type = Tilt[ext]
97
+ template_options = Massimo.config.options_for(ext[1..-1])
98
+ template = template_type.new(source_path.to_s, @line, template_options) { output }
99
+ template.render(template_scope, template_locals)
100
+ else
101
+ output
102
+ end
93
103
  end
94
104
  end
95
105
 
@@ -107,17 +117,14 @@ module Massimo
107
117
  @content = source_path.read
108
118
  end
109
119
 
110
- def template
111
- @template ||= begin
112
- if template_type = Tilt[filename]
113
- options = Massimo.config.options_for(source_path.extname[1..-1])
114
- template_type.new(source_path.to_s, @line, options) { content }
115
- end
116
- end
120
+ def template_scope
121
+ Massimo.site.template_scope
117
122
  end
118
123
 
119
- def template?
120
- !!Tilt[filename]
124
+ def template_locals
125
+ {}
121
126
  end
127
+
128
+ memoize :filename, :extension, :extensions, :url, :output_path
122
129
  end
123
130
  end
@@ -1,7 +1,11 @@
1
1
  module Massimo
2
2
  class Stylesheet < Massimo::Resource
3
3
  def extension
4
- @extension ||= '.css'
4
+ if Tilt.registered?(super[1..-1])
5
+ '.css'
6
+ else
7
+ super
8
+ end
5
9
  end
6
10
  end
7
11
  end
@@ -1,3 +1,3 @@
1
1
  module Massimo
2
- VERSION = '0.8.5'
2
+ VERSION = '0.9.0'
3
3
  end
@@ -5,9 +5,9 @@ module Massimo
5
5
  unprocessable
6
6
 
7
7
  def render(locals = {}, &block)
8
- options = Massimo.config.options_for(source_path.extname[1..-1])
9
- template = Tilt.new(source_path.to_s, 1, options) { content }
10
- template.render(Massimo.site.template_scope, locals, &block)
8
+ template_options = Massimo.config.options_for(extension[1..-1])
9
+ template = Tilt.new(source_path.to_s, 1, template_options) { content }
10
+ template.render(template_scope, locals, &block)
11
11
  end
12
12
  end
13
13
  end
@@ -1,6 +1,32 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Massimo::Javascript do
4
+ describe '#extension' do
5
+ context 'with multiple extensions' do
6
+ it 'should return the first extension' do
7
+ with_file 'file.js.coffee' do
8
+ Massimo::Javascript.new('file.js.coffee').extension.should == '.js'
9
+ end
10
+ end
11
+ end
12
+
13
+ context 'with a single Tilt registered extension' do
14
+ it 'should default to .js' do
15
+ with_file 'file.coffee' do
16
+ Massimo::Javascript.new('file.coffee').extension.should == '.js'
17
+ end
18
+ end
19
+ end
20
+
21
+ context 'with a single unregistered extension' do
22
+ it 'should be that extension' do
23
+ with_file 'file.json' do
24
+ Massimo::Javascript.new('file.json').extension.should == '.json'
25
+ end
26
+ end
27
+ end
28
+ end
29
+
4
30
  context 'with normal .js files' do
5
31
  let(:javascript) { Massimo::Javascript.new 'javascripts/main.js' }
6
32
 
@@ -84,6 +84,32 @@ describe Massimo::Page do
84
84
  end
85
85
  end
86
86
 
87
+ describe '#extension' do
88
+ context 'with multiple extensions' do
89
+ it 'should return the first extension' do
90
+ with_file 'file.rss.erb' do
91
+ Massimo::Page.new('file.rss.erb').extension.should == '.rss'
92
+ end
93
+ end
94
+ end
95
+
96
+ context 'with a single Tilt registered extension' do
97
+ it 'should default to .html' do
98
+ with_file 'file.md' do
99
+ Massimo::Page.new('file.md').extension.should == '.html'
100
+ end
101
+ end
102
+ end
103
+
104
+ context 'with a single unregistered extension' do
105
+ it 'should be that extension' do
106
+ with_file 'file.json' do
107
+ Massimo::Page.new('file.json').extension.should == '.json'
108
+ end
109
+ end
110
+ end
111
+ end
112
+
87
113
  describe '#render' do
88
114
  let(:page) { Massimo::Page.new 'page.erb' }
89
115
 
@@ -48,6 +48,26 @@ describe Massimo::Resource do
48
48
  Massimo::Resource.new('url.erb').extension.should == '.erb'
49
49
  end
50
50
  end
51
+
52
+ it 'should be the first extension of the file' do
53
+ with_file 'url.html.md.erb' do
54
+ Massimo::Resource.new('url.html.md.erb').extension.should == '.html'
55
+ end
56
+ end
57
+ end
58
+
59
+ describe '#extensions' do
60
+ it 'should be the extension of the file' do
61
+ with_file 'url.erb' do
62
+ Massimo::Resource.new('url.erb').extensions.should == %w(.erb)
63
+ end
64
+ end
65
+
66
+ it 'should be all of the extensions of the file' do
67
+ with_file 'url.html.md.erb' do
68
+ Massimo::Resource.new('url.html.md.erb').extensions.should == %w(.html .md .erb)
69
+ end
70
+ end
51
71
  end
52
72
 
53
73
  describe '#filename' do
@@ -79,6 +99,14 @@ describe Massimo::Resource do
79
99
  end
80
100
  end
81
101
  end
102
+
103
+ context 'with multiple template extensions' do
104
+ it 'should only use the first extension' do
105
+ with_file 'file.html.md.erb' do
106
+ Massimo::Resource.new('file.html.md.erb').output_path.to_s.should == File.expand_path('public/file.html')
107
+ end
108
+ end
109
+ end
82
110
  end
83
111
 
84
112
  describe '#content' do
@@ -95,6 +123,18 @@ describe Massimo::Resource do
95
123
  resource.render.should == 'content'
96
124
  end
97
125
  end
126
+
127
+ it 'should render the content using Tilt' do
128
+ with_file 'file.erb', '<%= "hello" %>' do
129
+ Massimo::Resource.new('file.erb').render.should == 'hello'
130
+ end
131
+ end
132
+
133
+ it 'should render the content using multiple Tilt templates' do
134
+ with_file 'file.css.scss.erb', '$color: <%= "#999" %>; body { color: $color; }' do
135
+ Massimo::Resource.new('file.css.scss.erb').render.gsub(/\s/, '').should == 'body{color:#999999;}'
136
+ end
137
+ end
98
138
  end
99
139
 
100
140
  describe '#process' do
@@ -1,6 +1,32 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Massimo::Stylesheet do
4
+ describe '#extension' do
5
+ context 'with multiple extensions' do
6
+ it 'should return the first extension' do
7
+ with_file 'file.css.scss' do
8
+ Massimo::Stylesheet.new('file.css.scss').extension.should == '.css'
9
+ end
10
+ end
11
+ end
12
+
13
+ context 'with a single Tilt registered extension' do
14
+ it 'should default to .css' do
15
+ with_file 'file.scss' do
16
+ Massimo::Stylesheet.new('file.scss').extension.should == '.css'
17
+ end
18
+ end
19
+ end
20
+
21
+ context 'with a single unregistered extension' do
22
+ it 'should be that extension' do
23
+ with_file 'file.jpg' do
24
+ Massimo::Stylesheet.new('file.jpg').extension.should == '.jpg'
25
+ end
26
+ end
27
+ end
28
+ end
29
+
4
30
  context 'with normal .css files' do
5
31
  let(:stylesheet) { Massimo::Stylesheet.new('stylesheets/main.css') }
6
32
 
metadata CHANGED
@@ -1,8 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: massimo
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 59
4
5
  prerelease:
5
- version: 0.8.5
6
+ segments:
7
+ - 0
8
+ - 9
9
+ - 0
10
+ version: 0.9.0
6
11
  platform: ruby
7
12
  authors:
8
13
  - Pete Browne
@@ -10,7 +15,7 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2011-05-23 00:00:00 Z
18
+ date: 2011-05-24 00:00:00 Z
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: activesupport
@@ -20,6 +25,11 @@ dependencies:
20
25
  requirements:
21
26
  - - ~>
22
27
  - !ruby/object:Gem::Version
28
+ hash: 7
29
+ segments:
30
+ - 3
31
+ - 0
32
+ - 0
23
33
  version: 3.0.0
24
34
  type: :runtime
25
35
  version_requirements: *id001
@@ -31,6 +41,11 @@ dependencies:
31
41
  requirements:
32
42
  - - ~>
33
43
  - !ruby/object:Gem::Version
44
+ hash: 15
45
+ segments:
46
+ - 0
47
+ - 4
48
+ - 0
34
49
  version: 0.4.0
35
50
  type: :runtime
36
51
  version_requirements: *id002
@@ -42,6 +57,11 @@ dependencies:
42
57
  requirements:
43
58
  - - ~>
44
59
  - !ruby/object:Gem::Version
60
+ hash: 31
61
+ segments:
62
+ - 1
63
+ - 2
64
+ - 0
45
65
  version: 1.2.0
46
66
  type: :runtime
47
67
  version_requirements: *id003
@@ -53,6 +73,11 @@ dependencies:
53
73
  requirements:
54
74
  - - ~>
55
75
  - !ruby/object:Gem::Version
76
+ hash: 59
77
+ segments:
78
+ - 0
79
+ - 9
80
+ - 0
56
81
  version: 0.9.0
57
82
  type: :runtime
58
83
  version_requirements: *id004
@@ -64,6 +89,11 @@ dependencies:
64
89
  requirements:
65
90
  - - ~>
66
91
  - !ruby/object:Gem::Version
92
+ hash: 39
93
+ segments:
94
+ - 0
95
+ - 14
96
+ - 0
67
97
  version: 0.14.0
68
98
  type: :runtime
69
99
  version_requirements: *id005
@@ -75,6 +105,11 @@ dependencies:
75
105
  requirements:
76
106
  - - ~>
77
107
  - !ruby/object:Gem::Version
108
+ hash: 25
109
+ segments:
110
+ - 1
111
+ - 3
112
+ - 1
78
113
  version: 1.3.1
79
114
  type: :runtime
80
115
  version_requirements: *id006
@@ -86,6 +121,11 @@ dependencies:
86
121
  requirements:
87
122
  - - ~>
88
123
  - !ruby/object:Gem::Version
124
+ hash: 19
125
+ segments:
126
+ - 0
127
+ - 3
128
+ - 0
89
129
  version: 0.3.0
90
130
  type: :runtime
91
131
  version_requirements: *id007
@@ -97,6 +137,11 @@ dependencies:
97
137
  requirements:
98
138
  - - ~>
99
139
  - !ruby/object:Gem::Version
140
+ hash: 23
141
+ segments:
142
+ - 1
143
+ - 0
144
+ - 0
100
145
  version: 1.0.0
101
146
  type: :runtime
102
147
  version_requirements: *id008
@@ -108,6 +153,11 @@ dependencies:
108
153
  requirements:
109
154
  - - ~>
110
155
  - !ruby/object:Gem::Version
156
+ hash: 27
157
+ segments:
158
+ - 2
159
+ - 5
160
+ - 0
111
161
  version: 2.5.0
112
162
  type: :development
113
163
  version_requirements: *id009
@@ -119,6 +169,11 @@ dependencies:
119
169
  requirements:
120
170
  - - ~>
121
171
  - !ruby/object:Gem::Version
172
+ hash: 23
173
+ segments:
174
+ - 1
175
+ - 0
176
+ - 0
122
177
  version: 1.0.0
123
178
  type: :development
124
179
  version_requirements: *id010
@@ -130,6 +185,11 @@ dependencies:
130
185
  requirements:
131
186
  - - ~>
132
187
  - !ruby/object:Gem::Version
188
+ hash: 31
189
+ segments:
190
+ - 1
191
+ - 2
192
+ - 0
133
193
  version: 1.2.0
134
194
  type: :development
135
195
  version_requirements: *id011
@@ -141,6 +201,11 @@ dependencies:
141
201
  requirements:
142
202
  - - ~>
143
203
  - !ruby/object:Gem::Version
204
+ hash: 11
205
+ segments:
206
+ - 0
207
+ - 5
208
+ - 0
144
209
  version: 0.5.0
145
210
  type: :development
146
211
  version_requirements: *id012
@@ -152,6 +217,11 @@ dependencies:
152
217
  requirements:
153
218
  - - ~>
154
219
  - !ruby/object:Gem::Version
220
+ hash: 59
221
+ segments:
222
+ - 0
223
+ - 9
224
+ - 0
155
225
  version: 0.9.0
156
226
  type: :development
157
227
  version_requirements: *id013
@@ -163,6 +233,11 @@ dependencies:
163
233
  requirements:
164
234
  - - ~>
165
235
  - !ruby/object:Gem::Version
236
+ hash: 3
237
+ segments:
238
+ - 3
239
+ - 1
240
+ - 0
166
241
  version: 3.1.0
167
242
  type: :development
168
243
  version_requirements: *id014
@@ -174,6 +249,11 @@ dependencies:
174
249
  requirements:
175
250
  - - ~>
176
251
  - !ruby/object:Gem::Version
252
+ hash: 3
253
+ segments:
254
+ - 3
255
+ - 1
256
+ - 0
177
257
  version: 3.1.0
178
258
  type: :development
179
259
  version_requirements: *id015
@@ -185,6 +265,11 @@ dependencies:
185
265
  requirements:
186
266
  - - ~>
187
267
  - !ruby/object:Gem::Version
268
+ hash: 31
269
+ segments:
270
+ - 1
271
+ - 2
272
+ - 0
188
273
  version: 1.2.0
189
274
  type: :development
190
275
  version_requirements: *id016
@@ -196,6 +281,11 @@ dependencies:
196
281
  requirements:
197
282
  - - ~>
198
283
  - !ruby/object:Gem::Version
284
+ hash: 7
285
+ segments:
286
+ - 2
287
+ - 2
288
+ - 0
199
289
  version: 2.2.0
200
290
  type: :development
201
291
  version_requirements: *id017
@@ -207,6 +297,11 @@ dependencies:
207
297
  requirements:
208
298
  - - ~>
209
299
  - !ruby/object:Gem::Version
300
+ hash: 23
301
+ segments:
302
+ - 1
303
+ - 0
304
+ - 0
210
305
  version: 1.0.0
211
306
  type: :development
212
307
  version_requirements: *id018
@@ -218,6 +313,11 @@ dependencies:
218
313
  requirements:
219
314
  - - ~>
220
315
  - !ruby/object:Gem::Version
316
+ hash: 3
317
+ segments:
318
+ - 3
319
+ - 1
320
+ - 0
221
321
  version: 3.1.0
222
322
  type: :development
223
323
  version_requirements: *id019
@@ -229,6 +329,11 @@ dependencies:
229
329
  requirements:
230
330
  - - ~>
231
331
  - !ruby/object:Gem::Version
332
+ hash: 59
333
+ segments:
334
+ - 0
335
+ - 9
336
+ - 0
232
337
  version: 0.9.0
233
338
  type: :development
234
339
  version_requirements: *id020
@@ -240,6 +345,11 @@ dependencies:
240
345
  requirements:
241
346
  - - ~>
242
347
  - !ruby/object:Gem::Version
348
+ hash: 19
349
+ segments:
350
+ - 0
351
+ - 3
352
+ - 0
243
353
  version: 0.3.0
244
354
  type: :development
245
355
  version_requirements: *id021
@@ -251,6 +361,11 @@ dependencies:
251
361
  requirements:
252
362
  - - ~>
253
363
  - !ruby/object:Gem::Version
364
+ hash: 23
365
+ segments:
366
+ - 1
367
+ - 0
368
+ - 0
254
369
  version: 1.0.0
255
370
  type: :development
256
371
  version_requirements: *id022
@@ -323,12 +438,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
323
438
  requirements:
324
439
  - - ">="
325
440
  - !ruby/object:Gem::Version
441
+ hash: 3
442
+ segments:
443
+ - 0
326
444
  version: "0"
327
445
  required_rubygems_version: !ruby/object:Gem::Requirement
328
446
  none: false
329
447
  requirements:
330
448
  - - ">="
331
449
  - !ruby/object:Gem::Version
450
+ hash: 3
451
+ segments:
452
+ - 0
332
453
  version: "0"
333
454
  requirements: []
334
455