sundawg-sinatra-assetpack-fork 0.0.12.pre1 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/.gitignore +1 -1
  2. data/.travis.yml +17 -0
  3. data/CONTRIBUTING.md +27 -0
  4. data/Gemfile +2 -1
  5. data/Gemfile.lock +72 -0
  6. data/HISTORY.md +60 -1
  7. data/README.md +54 -11
  8. data/examples/basic/app.rb +12 -1
  9. data/lib/sinatra/assetpack.rb +1 -1
  10. data/lib/sinatra/assetpack/class_methods.rb +8 -6
  11. data/lib/sinatra/assetpack/compressor.rb +1 -0
  12. data/lib/sinatra/assetpack/css.rb +1 -1
  13. data/lib/sinatra/assetpack/engines/less.rb +11 -0
  14. data/lib/sinatra/assetpack/helpers.rb +13 -3
  15. data/lib/sinatra/assetpack/html_helpers.rb +12 -0
  16. data/lib/sinatra/assetpack/image.rb +2 -2
  17. data/lib/sinatra/assetpack/options.rb +24 -9
  18. data/lib/sinatra/assetpack/package.rb +15 -8
  19. data/lib/sinatra/assetpack/version.rb +1 -1
  20. data/sinatra-assetpack.gemspec +5 -0
  21. data/test/app/app.rb +8 -1
  22. data/test/app/app/fonts/cantarell-regular-webfont.eot +0 -0
  23. data/test/app/app/fonts/cantarell-regular-webfont.svg +18 -0
  24. data/test/app/app/fonts/cantarell-regular-webfont.ttf +0 -0
  25. data/test/app/app/fonts/cantarell-regular-webfont.woff +0 -0
  26. data/test/app/app/js/jquery-1.8.0.min.js +1 -0
  27. data/test/app/app/packages/a_package/package.css +1 -0
  28. data/test/app/app/packages/a_package/package.js +1 -0
  29. data/test/app/app/packages/a_package/package.png +0 -0
  30. data/test/app/config.ru +2 -0
  31. data/test/arity_test.rb +8 -2
  32. data/test/cache_test.rb +17 -1
  33. data/test/glob_test.rb +3 -0
  34. data/test/ignore_test.rb +2 -2
  35. data/test/img_test.rb +2 -2
  36. data/test/local_file_test.rb +6 -0
  37. data/test/mime_type_test.rb +20 -0
  38. data/test/redundant_test.rb +1 -0
  39. data/test/sqwish_test.rb +4 -3
  40. data/test/test_helper.rb +6 -1
  41. data/test/tilt_test.rb +1 -0
  42. data/test/unit_test.rb +42 -5
  43. metadata +207 -189
  44. data/lib/sinatra/assetpack/hasharray.rb +0 -66
data/.gitignore CHANGED
@@ -1,4 +1,4 @@
1
- /Gemfile.lock
2
1
  /.rvmrc
3
2
  /.sass-cache
4
3
  /doc/
4
+ *.gem
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - 2.0.0
7
+ - rbx-18mode
8
+ - rbx-19mode
9
+ - jruby-18mode
10
+ - jruby-19mode
11
+ - jruby-head
12
+ - ruby-head
13
+ matrix:
14
+ allow_failures:
15
+ - rvm: jruby-head
16
+ - rvm: ruby-head
17
+ - rvm: 2.0.0
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,27 @@
1
+ # Contributing
2
+
3
+ > If I have seen further it is by standing on the shoulders of giants. - Isaac Newton
4
+
5
+ Please follow theses simples steps to contribute to this project :
6
+
7
+ 1. Fork the repo.
8
+
9
+ 2. Run the tests before doing anything.
10
+
11
+ 3. Add test(s) for your code modification.
12
+
13
+ 4. Rebase your code onto upstream master (this repository) if not up to date.
14
+
15
+ 5. Squash or fixup your commits to achieve a clean commit log.
16
+
17
+ 6. Submit a pull request and ensure tests passes on travis-ci for all supported ruby versions.
18
+
19
+ ## Running the tests
20
+
21
+ As simple as running the `rake` command.
22
+
23
+ The default `rake` task is `rake test`.
24
+
25
+ ## Syntax
26
+
27
+ Follow [Ruby Styleguide](https://github.com/styleguide/ruby) by Github and existing code.
data/Gemfile CHANGED
@@ -1,2 +1,3 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
+
2
3
  gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,72 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sinatra-assetpack (0.1.6)
5
+ jsmin
6
+ rack-test
7
+ sinatra
8
+ tilt (>= 1.3.0)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ POpen4 (0.1.4)
14
+ Platform (>= 0.4.0)
15
+ open4
16
+ Platform (0.4.0)
17
+ coffee-script (2.2.0)
18
+ coffee-script-source
19
+ execjs
20
+ coffee-script-source (1.5.0)
21
+ commonjs (0.2.6)
22
+ contest (0.1.3)
23
+ execjs (1.4.0)
24
+ multi_json (~> 1.0)
25
+ haml (4.0.0)
26
+ tilt
27
+ jsmin (1.0.1)
28
+ less (2.2.2)
29
+ commonjs (~> 0.2.6)
30
+ metaclass (0.0.1)
31
+ mocha (0.13.2)
32
+ metaclass (~> 0.0.1)
33
+ multi_json (1.6.1)
34
+ open4 (1.3.0)
35
+ rack (1.5.2)
36
+ rack-protection (1.4.0)
37
+ rack
38
+ rack-test (0.6.2)
39
+ rack (>= 1.0)
40
+ rake (10.0.3)
41
+ sass (3.2.6)
42
+ sinatra (1.3.5)
43
+ rack (~> 1.4)
44
+ rack-protection (~> 1.3)
45
+ tilt (~> 1.3, >= 1.3.3)
46
+ stylus (0.7.1)
47
+ execjs
48
+ stylus-source
49
+ stylus-source (0.31.0)
50
+ tilt (1.3.4)
51
+ uglifier (1.3.0)
52
+ execjs (>= 0.3.0)
53
+ multi_json (~> 1.0, >= 1.0.2)
54
+ yui-compressor (0.9.6)
55
+ POpen4 (>= 0.1.4)
56
+
57
+ PLATFORMS
58
+ java
59
+ ruby
60
+
61
+ DEPENDENCIES
62
+ coffee-script
63
+ contest
64
+ haml
65
+ less
66
+ mocha
67
+ rake
68
+ sass
69
+ sinatra-assetpack!
70
+ stylus
71
+ uglifier
72
+ yui-compressor
data/HISTORY.md CHANGED
@@ -1,3 +1,62 @@
1
+ v0.1.6 - March 1, 2013
2
+ ----------------------
3
+
4
+ ### Fixed
5
+
6
+ * Do not use instance helpers for environment check. (#79)
7
+
8
+ v0.1.5 - Feb 12, 2013
9
+ ----------------------
10
+
11
+ ### Fixed
12
+ * Stylus 0.7.1 support.
13
+
14
+ v0.1.4 - Feb 12, 2013
15
+ ----------------------
16
+
17
+ ### Added
18
+ * Multiple asset hosts support. (#27)
19
+
20
+ ### Fixed
21
+ * Lock stylus to 0.7.0 until 0.7.1 is supported.
22
+
23
+ v0.1.3 - Feb 3, 2013
24
+ ----------------------
25
+
26
+ ### Added
27
+ * JRuby 1.9 and 1.8 now supported.
28
+
29
+ ### Fixed:
30
+ * Deal with assets with exact same name but extensions. (#75)
31
+ * Ruby 1.8 support (broken in previous v0.1 releases).
32
+
33
+ v0.1.2 - Jan 20, 2013
34
+ ----------------------
35
+
36
+ ### Added:
37
+ * Support for custom cache control headers for packed assets. (#43)
38
+
39
+ v0.1.1 - Jan 15, 2013
40
+ ----------------------
41
+
42
+ ### Fixed
43
+ * Added less engine support and test (#69)
44
+ * Support for fonts & other AssetPack.supported_formats file format. (#50)
45
+ * Deal with multiple static files with same name but different extensions (ex. fonts).
46
+
47
+ v0.1.0 - Jan 14, 2013
48
+ ----------------------
49
+
50
+ ### Changed
51
+ * Using `file` utility instead `identify` utility. (#26)
52
+
53
+ ### Fixed
54
+ * Deal with different encodings in combined assets. (#47)
55
+ * Serve files with dots in name. (#32, #66)
56
+ * Deal with character encoding issues in ruby 1.8. (#51)
57
+ * Add missing depedency for development unit test. (#63)
58
+ * Deal with binary files copy (ex. images), fix errors like `"\x89" from ASCII-8BIT to UTF-8"`. (#38, #67)
59
+
1
60
  v0.0.11 - Feb 21, 2012
2
61
  ----------------------
3
62
 
@@ -12,7 +71,7 @@ v0.0.11 - Feb 21, 2012
12
71
  * Built files from 'rake assetpack:build' now match the mtimes of their sources. (#12)
13
72
  * Update the readme with a note on SASS compression.
14
73
  * Use regular expression route matcher instead of splat pattern for Padrino compatibility. (#19)
15
- * Made <link> and <script> tags (generated by helpers) be more HTML5-like.
74
+ * Made `link` and `script` tags (generated by helpers) be more HTML5-like.
16
75
 
17
76
  ### Fixed:
18
77
  * Sinatra >= 1.3.0 compatibility. Use 'public_folder' in Sinatra >=1.3.0. (#25)
data/README.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # [Sinatra AssetPack](http://ricostacruz.com/sinatra-assetpack)
2
- #### Asset packer for Sinatra
2
+
3
+ > Package your assets transparently in Sinatra.
4
+
5
+ [![Build Status](https://travis-ci.org/rstacruz/sinatra-assetpack.png?branch=master)](https://travis-ci.org/rstacruz/sinatra-assetpack)
6
+ [![Gem Version](https://badge.fury.io/rb/sinatra-assetpack.png)](http://badge.fury.io/rb/sinatra-assetpack)
7
+ [![Dependency Status](https://gemnasium.com/rstacruz/sinatra-assetpack.png)](https://gemnasium.com/rstacruz/sinatra-assetpack)
8
+ [![Code Climate](https://codeclimate.com/github/rstacruz/sinatra-assetpack.png)](https://codeclimate.com/github/rstacruz/sinatra-assetpack)
9
+
10
+ How it works
11
+ ------------
3
12
 
4
13
  This is *the* most convenient way to set up your CSS/JS (and images) in a
5
14
  [Sinatra](http://sinatrarb.com) app. Seriously. No need for crappy routes to
@@ -9,9 +18,9 @@ render Sass or whatever. No-siree!
9
18
  * JavaScript/CoffeeScript files in `/app/js`
10
19
  * CSS/Sass/Less/CSS files in `/app/css`
11
20
  * Images into `/app/images`
12
- 3. Add `register Sinatra::AssetPack` and set up options to your app (see below)
13
- 4. Use `<%= css :application %>` to your layouts. Use this instead of
14
- messy *script* and *link* tags
21
+ 3. Add `register Sinatra::AssetPack` and set up options to your app (see below).
22
+ 4. Use `<%= js :app %>` and `<%= css :application %>` to your layouts. Use these instead of
23
+ messy *script* and *link* tags.
15
24
  5. BOOM! You're in business baby!
16
25
 
17
26
  Installation
@@ -527,6 +536,32 @@ end
527
536
  # >> Listening on 0.0.0.0:4567, CTRL+C to stop
528
537
  ```
529
538
 
539
+ ### assets.expires
540
+ Sets cache control headers for all assets handled by AssetPack. Defaults to `expires 86400*30, :public`. Passes the arguments to [Sinatras #expires](http://rubydoc.info/gems/sinatra/Sinatra/Helpers#expires-instance_method).
541
+
542
+ ``` ruby
543
+ # Usage:
544
+ expires amount, *values
545
+ ```
546
+
547
+ #### Example
548
+ In this example all assets get cached for a year.
549
+
550
+ ``` ruby
551
+ class App < Sinatra::Base
552
+ assets {
553
+ js_compression :closure
554
+
555
+ js :application, [
556
+ '/js/vendor/jquery.*.js',
557
+ '/js/vendor/jquery.js'
558
+ ]
559
+ expires 86400*365, :public
560
+ }
561
+ end
562
+ ```
563
+
564
+
530
565
  API reference: helpers
531
566
  ----------------------
532
567
 
@@ -637,20 +672,28 @@ class Main
637
672
  end
638
673
  ```
639
674
 
675
+ Contributing
676
+ ------------
677
+
678
+ See [CONTRIBUTING.md](https://github.com/rstacruz/sinatra-assetpack/blob/master/CONTRIBUTING.md) for details on contributing and running test.
679
+
640
680
  Acknowledgements
641
681
  ----------------
642
682
 
643
- © 2011, Rico Sta. Cruz. Released under the [MIT
683
+ © 2011-2013, Rico Sta. Cruz. Released under the [MIT
644
684
  License](http://www.opensource.org/licenses/mit-license.php).
645
685
 
646
- Sinatra-AssetPack is authored and maintained by [Rico Sta. Cruz][rsc] with help
647
- from it's [contributors][c]. It is sponsored by my startup, [Sinefunc, Inc][sf].
686
+ Sinatra-AssetPack is authored by [Rico Sta. Cruz][rsc] with help
687
+ from it's [contributors][c]. It is sponsored by [Sinefunc, Inc][sf].
688
+
689
+ Sinatra-AssetPack is maintained by [Jean-Philipe Doyle][j15e] at [Hookt Studios][hookt].
690
+
691
+ Github : [@rstacruz](http://github.com/rstacruz), [@j15e](http://github.com/j15e)
648
692
 
649
- * [My website](http://ricostacruz.com) (ricostacruz.com)
650
- * [Sinefunc, Inc.](http://sinefunc.com) (sinefunc.com)
651
- * [Github](http://github.com/rstacruz) (@rstacruz)
652
- * [Twitter](http://twitter.com/rstacruz) (@rstacruz)
693
+ Twitter : [@rstacruz](http://twitter.com/rstacruz), [@j15e](http://twitter.com/j15e)
653
694
 
654
695
  [rsc]: http://ricostacruz.com
655
696
  [c]: http://github.com/rstacruz/sinatra-assetpack/contributors
656
697
  [sf]: http://sinefunc.com
698
+ [j15e]: http://github.com/j15e
699
+ [hookt]: http://github.com/hooktstudios
@@ -26,7 +26,18 @@ class App < Sinatra::Base
26
26
  '/css/more/*.css'
27
27
  ]
28
28
 
29
- prebuild true
29
+ prebuild false
30
+
31
+ # Can set this as an environment variable like "HOST" or "CDN_HOST"
32
+ # This will add the domain name to the beginning of compiled assets
33
+ # Useful if you need to serve production assets from a CDN
34
+ asset_hosts [
35
+ '//cdn-0.example.org',
36
+ '//cdn-1.example.org',
37
+ '//cdn-2.example.org',
38
+ '//cdn-3.example.org'
39
+ ]
40
+
30
41
  end
31
42
 
32
43
  get '/' do
@@ -1,4 +1,5 @@
1
1
  require 'rack/test'
2
+ require 'backports' if RUBY_VERSION < "1.9"
2
3
 
3
4
  module Sinatra
4
5
  module AssetPack
@@ -47,7 +48,6 @@ module Sinatra
47
48
  autoload :Image, "#{PREFIX}/assetpack/image"
48
49
  autoload :Css, "#{PREFIX}/assetpack/css"
49
50
  autoload :Configurator, "#{PREFIX}/assetpack/configurator"
50
- autoload :HashArray, "#{PREFIX}/assetpack/hasharray"
51
51
 
52
52
  include ClassMethods
53
53
 
@@ -30,6 +30,7 @@ module Sinatra
30
30
 
31
31
  content_type package.type
32
32
  last_modified mtime
33
+ assets_expires
33
34
  contents
34
35
  end
35
36
  end
@@ -43,24 +44,25 @@ module Sinatra
43
44
 
44
45
  # Sanity checks
45
46
  pass unless AssetPack.supported_formats.include?(fmt)
46
- fn = asset_path_for(file, from) or pass
47
+ fn = asset_path_for(file, from) or pass
47
48
 
48
- pass if settings.assets.ignored?("#{path}/#{file}")
49
+ pass if settings.assets.ignored?("#{path}/#{file}")
49
50
 
50
51
  # Send headers
51
52
  content_type fmt.to_sym
52
53
  last_modified File.mtime(fn).to_i
53
- expires 86400*30, :public
54
+ assets_expires
54
55
 
55
56
  format = File.extname(fn)[1..-1]
56
57
 
57
58
  if AssetPack.supported_formats.include?(format)
58
- # It's a raw file, just send it
59
- not_found unless format == fmt
60
-
59
+ # Static file
61
60
  if fmt == 'css'
61
+ # Matching static file format
62
+ pass unless fmt == File.extname(fn)[1..-1]
62
63
  @template_cache.fetch(fn) { asset_filter_css File.read(fn) }
63
64
  else
65
+ # It's a raw file, just send it
64
66
  send_file fn
65
67
  end
66
68
  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"
@@ -11,7 +11,7 @@ module Sinatra
11
11
  if options.to_s.include?('embed')
12
12
  to_data_uri(local)
13
13
  else
14
- BusterHelpers.add_cache_buster(file, local)
14
+ HtmlHelpers.get_file_uri(file, assets)
15
15
  end
16
16
  else
17
17
  path
@@ -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
@@ -15,7 +15,9 @@ module Sinatra
15
15
  local = settings.assets.local_file_for src
16
16
  if local
17
17
  i = Image[local]
18
- attrs[:src] = BusterHelpers.add_cache_buster(src, local)
18
+
19
+ attrs[:src] = HtmlHelpers.get_file_uri(src, settings.assets)
20
+
19
21
  if i.dimensions?
20
22
  attrs[:width] ||= i.width
21
23
  attrs[:height] ||= i.height
@@ -42,8 +44,7 @@ module Sinatra
42
44
  pack = settings.assets.packages["#{name}.#{type}"]
43
45
  return "" unless pack
44
46
 
45
- # force production packageing for override, stage, or production
46
- if ENV['ASSETPACK_FORCE_PRODUCTION'] || settings.stage? || settings.production?
47
+ if settings.environment == :production || settings.environment == :stage
47
48
  pack.to_production_html options
48
49
  else
49
50
  pack.to_development_html options
@@ -57,6 +58,15 @@ module Sinatra
57
58
  def asset_path_for(file, from)
58
59
  settings.assets.dyn_local_file_for file, from
59
60
  end
61
+
62
+ def assets_expires
63
+ if settings.assets.expires.nil?
64
+ expires 86400*30, :public
65
+ else
66
+ expires *settings.assets.expires
67
+ end
68
+ end
69
+
60
70
  end
61
71
  end
62
72
  end