sinatra-assetpack 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.md CHANGED
@@ -1,3 +1,11 @@
1
+ v0.1.1 - Jan 15, 2013
2
+ ----------------------
3
+
4
+ ### Fixed
5
+ * Added less engine support and test (#69)
6
+ * Support for fonts & other AssetPack.supported_formats file format. (#50)
7
+ * Deal with multiple static files with same name but different extensions (ex. fonts).
8
+
1
9
  v0.1.0 - Jan 14, 2013
2
10
  ----------------------
3
11
 
data/README.md CHANGED
@@ -639,6 +639,11 @@ class Main
639
639
  end
640
640
  ```
641
641
 
642
+ Running the tests
643
+ ---------------
644
+
645
+ rake
646
+
642
647
  Acknowledgements
643
648
  ----------------
644
649
 
@@ -43,9 +43,9 @@ module Sinatra
43
43
 
44
44
  # Sanity checks
45
45
  pass unless AssetPack.supported_formats.include?(fmt)
46
- fn = asset_path_for(file, from) or pass
46
+ fn = asset_path_for(file, from) or pass
47
47
 
48
- pass if settings.assets.ignored?("#{path}/#{file}")
48
+ pass if settings.assets.ignored?("#{path}/#{file}")
49
49
 
50
50
  # Send headers
51
51
  content_type fmt.to_sym
@@ -55,12 +55,13 @@ module Sinatra
55
55
  format = File.extname(fn)[1..-1]
56
56
 
57
57
  if AssetPack.supported_formats.include?(format)
58
- # It's a raw file, just send it
59
- not_found unless format == fmt
60
-
58
+ # Static file
61
59
  if fmt == 'css'
60
+ # Matching static file format
61
+ pass unless fmt == File.extname(fn)[1..-1]
62
62
  @template_cache.fetch(fn) { asset_filter_css File.read(fn) }
63
63
  else
64
+ # It's a raw file, just send it
64
65
  send_file fn
65
66
  end
66
67
  else
@@ -47,6 +47,7 @@ module Sinatra
47
47
  require "#{AssetPack::PREFIX}/assetpack/engines/jsmin"
48
48
  require "#{AssetPack::PREFIX}/assetpack/engines/yui"
49
49
  require "#{AssetPack::PREFIX}/assetpack/engines/sass"
50
+ require "#{AssetPack::PREFIX}/assetpack/engines/less"
50
51
  require "#{AssetPack::PREFIX}/assetpack/engines/sqwish"
51
52
  require "#{AssetPack::PREFIX}/assetpack/engines/closure"
52
53
  require "#{AssetPack::PREFIX}/assetpack/engines/uglify"
@@ -0,0 +1,11 @@
1
+ module Sinatra::AssetPack
2
+ class LessEngine < Engine
3
+ def css(str, options={})
4
+ Tilt.new("less", {:style => :compressed}) { str }.render
5
+ rescue LoadError
6
+ nil
7
+ end
8
+ end
9
+
10
+ Compressor.register :css, :less, LessEngine
11
+ end
@@ -245,11 +245,16 @@ module Sinatra
245
245
  file.sub(/^(.*)(\.[^\.]+)$/) { file, extension = $1, $2 }
246
246
 
247
247
  # Remove cache-buster (/js/app.28389.js => /js/app)
248
- file = $1 if file =~ /^(.*)\.[0-9]+$/
248
+ file = $1 if file =~ /^(.*)\.[0-9]+$/
249
249
 
250
250
  matches = Dir[File.join(app.root, from, "#{file}.*")]
251
+
251
252
  # Fix for filenames with dots (can't do this with glob)
252
- matches.select { |f| f =~ /#{file}\.[^.]+$/ }.first
253
+ matches.select! { |f| f =~ /#{file}\.[^.]+$/ }
254
+
255
+ # Sort static file match first
256
+ matches.sort! { |f| File.basename(f) == "#{file}#{extension}" ? -1 : 1 }
257
+ matches.first
253
258
  end
254
259
 
255
260
  # Writes `public/#{path}` based on contents of `output`.
@@ -1,7 +1,7 @@
1
1
  module Sinatra
2
2
  module AssetPack
3
3
  def self.version
4
- "0.1.0"
4
+ "0.1.1"
5
5
  end
6
6
  end
7
7
  end
@@ -24,4 +24,5 @@ Gem::Specification.new do |s|
24
24
  s.add_development_dependency "stylus"
25
25
  s.add_development_dependency "uglifier"
26
26
  s.add_development_dependency "rake"
27
+ s.add_development_dependency "less"
27
28
  end
@@ -17,6 +17,7 @@ class Main < Sinatra::Base
17
17
  #serve '/js', :from => 'app/js'
18
18
  serve '/css', :from => 'app/css'
19
19
  serve '/images', :from => 'app/images'
20
+ serve '/fonts', :from => 'app/fonts'
20
21
 
21
22
  js :skitch, '/skitch.js', [
22
23
  '/js/hi.js',
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" standalone="no"?>
2
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" >
3
+ <svg xmlns="http://www.w3.org/2000/svg">
4
+ <metadata></metadata>
5
+ <defs>
6
+ <font id="cantarellregular" horiz-adv-x="748" >
7
+ <font-face units-per-em="2048" ascent="1513" descent="-535" />
8
+ <missing-glyph horiz-adv-x="559" />
9
+ <glyph horiz-adv-x="2048" />
10
+ <glyph horiz-adv-x="2048" />
11
+ <glyph unicode="&#xd;" horiz-adv-x="682" />
12
+ <glyph unicode=" " horiz-adv-x="559" />
13
+ <glyph unicode="&#x09;" horiz-adv-x="559" />
14
+ <glyph unicode="&#xa0;" horiz-adv-x="559" />
15
+ <glyph unicode="A" horiz-adv-x="1382" d="M129 0l506 1421h192l506 -1421h-172l-143 414h-588l-143 -414h-158zM481 561h484l-240 694z" />
16
+ <glyph unicode="&#xe000;" horiz-adv-x="985" d="M0 0v985h985v-985h-985z" />
17
+ </font>
18
+ </defs></svg>
@@ -0,0 +1,2 @@
1
+ require './app'
2
+ run Main
@@ -6,6 +6,7 @@ class LocalFileTest < UnitTest
6
6
 
7
7
  assets {
8
8
  css :application, [ '/css/*.css' ]
9
+ serve '/fonts', :from => 'app/fonts'
9
10
  }
10
11
  end
11
12
 
@@ -14,6 +15,11 @@ class LocalFileTest < UnitTest
14
15
  assert_equal r('app/images/background.jpg'), fn
15
16
  end
16
17
 
18
+ test "local file for (in existing files, custom serve path)" do
19
+ fn = App.assets.local_file_for '/fonts/cantarell-regular-webfont.ttf'
20
+ assert_equal r('app/fonts/cantarell-regular-webfont.ttf'), fn
21
+ end
22
+
17
23
  test "local file for (in nonexisting files)" do
18
24
  fn = App.assets.local_file_for '/images/404.jpg'
19
25
  assert fn.nil?
@@ -30,4 +30,29 @@ class AppTest < UnitTest
30
30
  get '/skitch.js'
31
31
  assert last_response.content_type =~ %r[^.*?/javascript]
32
32
  end
33
+
34
+ test 'eot' do
35
+ get '/fonts/cantarell-regular-webfont.eot'
36
+ assert last_response.content_type =~ %r[^application/vnd.ms-fontobject]
37
+ end
38
+
39
+ test 'svg' do
40
+ get '/fonts/cantarell-regular-webfont.svg'
41
+ assert last_response.content_type =~ %r[^image/svg\+xml]
42
+ end
43
+
44
+ test 'ttf' do
45
+ get '/fonts/cantarell-regular-webfont.ttf'
46
+ assert last_response.content_type =~ %r[^application/octet-stream]
47
+ end
48
+
49
+ test 'woff' do
50
+ get '/fonts/cantarell-regular-webfont.woff'
51
+ assert last_response.content_type =~ %r[^application/font-woff]
52
+ end
53
+
54
+ test 'woff' do
55
+ get '/fonts/cantarell-regular-webfont.woff'
56
+ assert last_response.content_type =~ %r[^application/font-woff]
57
+ end
33
58
  end
@@ -5,6 +5,7 @@ class OptionsTest < UnitTest
5
5
  @formats = Sinatra::AssetPack.tilt_formats
6
6
  assert @formats['sass'] == 'css'
7
7
  assert @formats['scss'] == 'css'
8
+ assert @formats['less'] == 'css'
8
9
  assert @formats['coffee'] == 'js'
9
10
  end
10
11
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-assetpack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-14 00:00:00.000000000 Z
12
+ date: 2013-01-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: tilt
@@ -219,6 +219,22 @@ dependencies:
219
219
  - !ruby/object:Gem::Version
220
220
  version: '0'
221
221
  none: false
222
+ - !ruby/object:Gem::Dependency
223
+ name: less
224
+ prerelease: false
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ! '>='
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ none: false
231
+ type: :development
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ! '>='
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
237
+ none: false
222
238
  description: Package your assets for Sinatra.
223
239
  email:
224
240
  - rico@sinefunc.com
@@ -269,6 +285,7 @@ files:
269
285
  - lib/sinatra/assetpack/engine.rb
270
286
  - lib/sinatra/assetpack/engines/closure.rb
271
287
  - lib/sinatra/assetpack/engines/jsmin.rb
288
+ - lib/sinatra/assetpack/engines/less.rb
272
289
  - lib/sinatra/assetpack/engines/sass.rb
273
290
  - lib/sinatra/assetpack/engines/simple.rb
274
291
  - lib/sinatra/assetpack/engines/sqwish.rb
@@ -293,6 +310,10 @@ files:
293
310
  - test/app/app/css/style.css
294
311
  - test/app/app/css/stylus.styl
295
312
  - test/app/app/css_stylus/stylus.styl
313
+ - test/app/app/fonts/cantarell-regular-webfont.eot
314
+ - test/app/app/fonts/cantarell-regular-webfont.svg
315
+ - test/app/app/fonts/cantarell-regular-webfont.ttf
316
+ - test/app/app/fonts/cantarell-regular-webfont.woff
296
317
  - test/app/app/images/background.jpg
297
318
  - test/app/app/images/email.png
298
319
  - test/app/app/js/_ignoreme.js
@@ -306,6 +327,7 @@ files:
306
327
  - test/app/app/js_glob/a/b/c2/hi.js
307
328
  - test/app/app/js_glob/a/b/c2/hola.js
308
329
  - test/app/app/views/index.haml
330
+ - test/app/config.ru
309
331
  - test/arity_test.rb
310
332
  - test/build_test.rb
311
333
  - test/cache_test.rb