sprockets 2.12.5 → 3.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sprockets might be problematic. Click here for more details.

Files changed (62) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE +2 -2
  3. data/README.md +61 -34
  4. data/lib/rake/sprocketstask.rb +5 -4
  5. data/lib/sprockets.rb +123 -85
  6. data/lib/sprockets/asset.rb +161 -200
  7. data/lib/sprockets/asset_uri.rb +64 -0
  8. data/lib/sprockets/base.rb +138 -373
  9. data/lib/sprockets/bower.rb +56 -0
  10. data/lib/sprockets/bundle.rb +32 -0
  11. data/lib/sprockets/cache.rb +220 -0
  12. data/lib/sprockets/cache/file_store.rb +145 -13
  13. data/lib/sprockets/cache/memory_store.rb +66 -0
  14. data/lib/sprockets/cache/null_store.rb +46 -0
  15. data/lib/sprockets/cached_environment.rb +103 -0
  16. data/lib/sprockets/closure_compressor.rb +30 -12
  17. data/lib/sprockets/coffee_script_template.rb +23 -0
  18. data/lib/sprockets/compressing.rb +20 -25
  19. data/lib/sprockets/configuration.rb +95 -0
  20. data/lib/sprockets/context.rb +68 -131
  21. data/lib/sprockets/directive_processor.rb +138 -179
  22. data/lib/sprockets/eco_template.rb +10 -19
  23. data/lib/sprockets/ejs_template.rb +10 -19
  24. data/lib/sprockets/encoding_utils.rb +246 -0
  25. data/lib/sprockets/engines.rb +40 -29
  26. data/lib/sprockets/environment.rb +10 -66
  27. data/lib/sprockets/erb_template.rb +23 -0
  28. data/lib/sprockets/errors.rb +5 -13
  29. data/lib/sprockets/http_utils.rb +97 -0
  30. data/lib/sprockets/jst_processor.rb +28 -15
  31. data/lib/sprockets/lazy_processor.rb +15 -0
  32. data/lib/sprockets/legacy.rb +23 -0
  33. data/lib/sprockets/legacy_proc_processor.rb +35 -0
  34. data/lib/sprockets/legacy_tilt_processor.rb +29 -0
  35. data/lib/sprockets/manifest.rb +128 -99
  36. data/lib/sprockets/mime.rb +114 -33
  37. data/lib/sprockets/path_utils.rb +179 -0
  38. data/lib/sprockets/paths.rb +13 -26
  39. data/lib/sprockets/processing.rb +198 -107
  40. data/lib/sprockets/resolve.rb +289 -0
  41. data/lib/sprockets/sass_compressor.rb +36 -17
  42. data/lib/sprockets/sass_template.rb +269 -46
  43. data/lib/sprockets/server.rb +113 -83
  44. data/lib/sprockets/transformers.rb +69 -0
  45. data/lib/sprockets/uglifier_compressor.rb +36 -15
  46. data/lib/sprockets/utils.rb +161 -44
  47. data/lib/sprockets/version.rb +1 -1
  48. data/lib/sprockets/yui_compressor.rb +37 -12
  49. metadata +64 -106
  50. data/lib/sprockets/asset_attributes.rb +0 -137
  51. data/lib/sprockets/bundled_asset.rb +0 -78
  52. data/lib/sprockets/caching.rb +0 -96
  53. data/lib/sprockets/charset_normalizer.rb +0 -41
  54. data/lib/sprockets/index.rb +0 -100
  55. data/lib/sprockets/processed_asset.rb +0 -152
  56. data/lib/sprockets/processor.rb +0 -32
  57. data/lib/sprockets/safety_colons.rb +0 -28
  58. data/lib/sprockets/sass_cache_store.rb +0 -29
  59. data/lib/sprockets/sass_functions.rb +0 -70
  60. data/lib/sprockets/sass_importer.rb +0 -30
  61. data/lib/sprockets/scss_template.rb +0 -13
  62. data/lib/sprockets/static_asset.rb +0 -60
@@ -1,32 +0,0 @@
1
- require 'tilt'
2
-
3
- module Sprockets
4
- # `Processor` creates an anonymous processor class from a block.
5
- #
6
- # register_preprocessor 'text/css', :my_processor do |context, data|
7
- # # ...
8
- # end
9
- #
10
- class Processor < Tilt::Template
11
- # `processor` is a lambda or block
12
- def self.processor
13
- @processor
14
- end
15
-
16
- def self.name
17
- "Sprockets::Processor (#{@name})"
18
- end
19
-
20
- def self.to_s
21
- name
22
- end
23
-
24
- def prepare
25
- end
26
-
27
- # Call processor block with `context` and `data`.
28
- def evaluate(context, locals)
29
- self.class.processor.call(context, data)
30
- end
31
- end
32
- end
@@ -1,28 +0,0 @@
1
- require 'tilt'
2
-
3
- module Sprockets
4
- # For JS developers who are colonfobic, concatenating JS files using
5
- # the module pattern usually leads to syntax errors.
6
- #
7
- # The `SafetyColons` processor will insert missing semicolons to the
8
- # end of the file.
9
- #
10
- # This behavior can be disabled with:
11
- #
12
- # environment.unregister_postprocessor 'application/javascript', Sprockets::SafetyColons
13
- #
14
- class SafetyColons < Tilt::Template
15
- def prepare
16
- end
17
-
18
- def evaluate(context, locals, &block)
19
- # If the file is blank or ends in a semicolon, leave it as is
20
- if data =~ /\A\s*\Z/m || data =~ /;\s*\Z/m
21
- data
22
- else
23
- # Otherwise, append a semicolon and newline
24
- "#{data};\n"
25
- end
26
- end
27
- end
28
- end
@@ -1,29 +0,0 @@
1
- require 'sass'
2
-
3
- module Sprockets
4
- class SassCacheStore < ::Sass::CacheStores::Base
5
- attr_reader :environment
6
-
7
- def initialize(environment)
8
- @environment = environment
9
- end
10
-
11
- def _store(key, version, sha, contents)
12
- environment.cache_set("sass/#{key}", {:version => version, :sha => sha, :contents => contents})
13
- end
14
-
15
- def _retrieve(key, version, sha)
16
- if obj = environment.cache_get("sass/#{key}")
17
- return unless obj[:version] == version
18
- return unless obj[:sha] == sha
19
- obj[:contents]
20
- else
21
- nil
22
- end
23
- end
24
-
25
- def path_to(key)
26
- key
27
- end
28
- end
29
- end
@@ -1,70 +0,0 @@
1
- require 'sass'
2
-
3
- module Sprockets
4
- module SassFunctions
5
- def asset_path(path)
6
- ::Sass::Script::String.new(sprockets_context.asset_path(path.value), :string)
7
- end
8
-
9
- def asset_url(path)
10
- ::Sass::Script::String.new("url(" + sprockets_context.asset_path(path.value) + ")")
11
- end
12
-
13
- def image_path(path)
14
- ::Sass::Script::String.new(sprockets_context.image_path(path.value), :string)
15
- end
16
-
17
- def image_url(path)
18
- ::Sass::Script::String.new("url(" + sprockets_context.image_path(path.value) + ")")
19
- end
20
-
21
- def video_path(path)
22
- ::Sass::Script::String.new(sprockets_context.video_path(path.value), :string)
23
- end
24
-
25
- def video_url(path)
26
- ::Sass::Script::String.new("url(" + sprockets_context.video_path(path.value) + ")")
27
- end
28
-
29
- def audio_path(path)
30
- ::Sass::Script::String.new(sprockets_context.audio_path(path.value), :string)
31
- end
32
-
33
- def audio_url(path)
34
- ::Sass::Script::String.new("url(" + sprockets_context.audio_path(path.value) + ")")
35
- end
36
-
37
- def font_path(path)
38
- ::Sass::Script::String.new(sprockets_context.font_path(path.value), :string)
39
- end
40
-
41
- def font_url(path)
42
- ::Sass::Script::String.new("url(" + sprockets_context.font_path(path.value) + ")")
43
- end
44
-
45
- def javascript_path(path)
46
- ::Sass::Script::String.new(sprockets_context.javascript_path(path.value), :string)
47
- end
48
-
49
- def javascript_url(path)
50
- ::Sass::Script::String.new("url(" + sprockets_context.javascript_path(path.value) + ")")
51
- end
52
-
53
- def stylesheet_path(path)
54
- ::Sass::Script::String.new(sprockets_context.stylesheet_path(path.value), :string)
55
- end
56
-
57
- def stylesheet_url(path)
58
- ::Sass::Script::String.new("url(" + sprockets_context.stylesheet_path(path.value) + ")")
59
- end
60
-
61
- protected
62
- def sprockets_context
63
- options[:sprockets][:context]
64
- end
65
-
66
- def sprockets_environment
67
- options[:sprockets][:environment]
68
- end
69
- end
70
- end
@@ -1,30 +0,0 @@
1
- require 'sass'
2
-
3
- module Sprockets
4
- # This custom importer that tracks all imported filenames during
5
- # compile.
6
- class SassImporter < ::Sass::Importers::Filesystem
7
- attr_reader :imported_filenames
8
-
9
- def initialize(*args)
10
- @imported_filenames = []
11
- super
12
- end
13
-
14
- def find_relative(*args)
15
- engine = super
16
- if engine && (filename = engine.options[:filename])
17
- @imported_filenames << filename
18
- end
19
- engine
20
- end
21
-
22
- def find(*args)
23
- engine = super
24
- if engine && (filename = engine.options[:filename])
25
- @imported_filenames << filename
26
- end
27
- engine
28
- end
29
- end
30
- end
@@ -1,13 +0,0 @@
1
- require 'sprockets/sass_template'
2
-
3
- module Sprockets
4
- # Scss handler to replace Tilt's builtin one. See `SassTemplate` and
5
- # `SassImporter` for more infomation.
6
- class ScssTemplate < SassTemplate
7
- self.default_mime_type = 'text/css'
8
-
9
- def syntax
10
- :scss
11
- end
12
- end
13
- end
@@ -1,60 +0,0 @@
1
- require 'sprockets/asset'
2
- require 'fileutils'
3
- require 'zlib'
4
-
5
- module Sprockets
6
- # `StaticAsset`s are used for files that are served verbatim without
7
- # any processing or concatenation. These are typical images and
8
- # other binary files.
9
- class StaticAsset < Asset
10
- # Returns file contents as its `source`.
11
- def source
12
- # File is read everytime to avoid memory bloat of large binary files
13
- pathname.open('rb') { |f| f.read }
14
- end
15
-
16
- # Implemented for Rack SendFile support.
17
- def to_path
18
- pathname.to_s
19
- end
20
-
21
- # Save asset to disk.
22
- def write_to(filename, options = {})
23
- # Gzip contents if filename has '.gz'
24
- unless options.key?(:compress)
25
- options[:compress] = File.extname(filename) == '.gz' && File.extname(logical_path) != '.gz'
26
- end
27
-
28
- FileUtils.mkdir_p File.dirname(filename)
29
-
30
- if options[:compress]
31
- # Open file and run it through `Zlib`
32
- pathname.open('rb') do |rd|
33
- File.open("#{filename}+", 'wb') do |wr|
34
- gz = Zlib::GzipWriter.new(wr, Zlib::BEST_COMPRESSION)
35
- gz.mtime = mtime.to_i
36
- buf = ""
37
- while rd.read(16384, buf)
38
- gz.write(buf)
39
- end
40
- gz.close
41
- end
42
- end
43
- else
44
- # If no compression needs to be done, we can just copy it into place.
45
- FileUtils.cp(pathname, "#{filename}+")
46
- end
47
-
48
- # Atomic write
49
- FileUtils.mv("#{filename}+", filename)
50
-
51
- # Set mtime correctly
52
- File.utime(mtime, mtime, filename)
53
-
54
- nil
55
- ensure
56
- # Ensure tmp file gets cleaned up
57
- FileUtils.rm("#{filename}+") if File.exist?("#{filename}+")
58
- end
59
- end
60
- end