sprockets 1.0.2 → 2.0.0

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 (64) hide show
  1. data/LICENSE +21 -0
  2. data/README.md +356 -0
  3. data/lib/sprockets.rb +26 -37
  4. data/lib/sprockets/asset.rb +212 -0
  5. data/lib/sprockets/asset_attributes.rb +158 -0
  6. data/lib/sprockets/base.rb +163 -0
  7. data/lib/sprockets/bundled_asset.rb +258 -0
  8. data/lib/sprockets/cache/file_store.rb +41 -0
  9. data/lib/sprockets/caching.rb +123 -0
  10. data/lib/sprockets/charset_normalizer.rb +41 -0
  11. data/lib/sprockets/context.rb +217 -0
  12. data/lib/sprockets/digest.rb +67 -0
  13. data/lib/sprockets/directive_processor.rb +380 -0
  14. data/lib/sprockets/eco_template.rb +38 -0
  15. data/lib/sprockets/ejs_template.rb +37 -0
  16. data/lib/sprockets/engines.rb +98 -0
  17. data/lib/sprockets/environment.rb +81 -40
  18. data/lib/sprockets/errors.rb +17 -0
  19. data/lib/sprockets/index.rb +79 -0
  20. data/lib/sprockets/jst_processor.rb +26 -0
  21. data/lib/sprockets/mime.rb +38 -0
  22. data/lib/sprockets/processing.rb +280 -0
  23. data/lib/sprockets/processor.rb +32 -0
  24. data/lib/sprockets/safety_colons.rb +28 -0
  25. data/lib/sprockets/server.rb +272 -0
  26. data/lib/sprockets/static_asset.rb +86 -0
  27. data/lib/sprockets/trail.rb +114 -0
  28. data/lib/sprockets/utils.rb +67 -0
  29. data/lib/sprockets/version.rb +1 -7
  30. metadata +212 -64
  31. data/Rakefile +0 -19
  32. data/bin/sprocketize +0 -54
  33. data/ext/nph-sprockets.cgi +0 -127
  34. data/lib/sprockets/concatenation.rb +0 -36
  35. data/lib/sprockets/error.rb +0 -5
  36. data/lib/sprockets/pathname.rb +0 -37
  37. data/lib/sprockets/preprocessor.rb +0 -91
  38. data/lib/sprockets/secretary.rb +0 -106
  39. data/lib/sprockets/source_file.rb +0 -54
  40. data/lib/sprockets/source_line.rb +0 -82
  41. data/test/fixtures/assets/images/script_with_assets/one.png +0 -1
  42. data/test/fixtures/assets/images/script_with_assets/two.png +0 -1
  43. data/test/fixtures/assets/stylesheets/script_with_assets.css +0 -1
  44. data/test/fixtures/constants.yml +0 -1
  45. data/test/fixtures/double_slash_comments_that_are_not_requires_should_be_ignored_when_strip_comments_is_false.js +0 -8
  46. data/test/fixtures/double_slash_comments_that_are_not_requires_should_be_removed_by_default.js +0 -2
  47. data/test/fixtures/multiline_comments_should_be_removed_by_default.js +0 -4
  48. data/test/fixtures/requiring_a_file_after_it_has_already_been_required_should_do_nothing.js +0 -5
  49. data/test/fixtures/requiring_a_file_that_does_not_exist_should_raise_an_error.js +0 -1
  50. data/test/fixtures/requiring_a_single_file_should_replace_the_require_comment_with_the_file_contents.js +0 -3
  51. data/test/fixtures/requiring_the_current_file_should_do_nothing.js +0 -1
  52. data/test/fixtures/src/constants.yml +0 -3
  53. data/test/fixtures/src/foo.js +0 -1
  54. data/test/fixtures/src/foo/bar.js +0 -4
  55. data/test/fixtures/src/foo/foo.js +0 -1
  56. data/test/fixtures/src/script_with_assets.js +0 -3
  57. data/test/test_concatenation.rb +0 -28
  58. data/test/test_environment.rb +0 -64
  59. data/test/test_helper.rb +0 -55
  60. data/test/test_pathname.rb +0 -43
  61. data/test/test_preprocessor.rb +0 -107
  62. data/test/test_secretary.rb +0 -83
  63. data/test/test_source_file.rb +0 -34
  64. data/test/test_source_line.rb +0 -89
@@ -0,0 +1,67 @@
1
+ module Sprockets
2
+ # `Utils`, we didn't know where else to put it!
3
+ module Utils
4
+ # If theres encoding support (aka Ruby 1.9)
5
+ if "".respond_to?(:valid_encoding?)
6
+ # Define UTF-8 BOM pattern matcher.
7
+ # Avoid using a Regexp literal because it inheirts the files
8
+ # encoding and we want to avoid syntax errors in other interpreters.
9
+ UTF8_BOM_PATTERN = Regexp.new("\\A\uFEFF".encode('utf-8'))
10
+
11
+ def self.read_unicode(pathname)
12
+ pathname.read.tap do |data|
13
+ # Eager validate the file's encoding. In most cases we
14
+ # expect it to be UTF-8 unless `default_external` is set to
15
+ # something else. An error is usually raised if the file is
16
+ # saved as UTF-16 when we expected UTF-8.
17
+ if !data.valid_encoding?
18
+ raise EncodingError, "#{pathname} has a invalid " +
19
+ "#{data.encoding} byte sequence"
20
+
21
+ # If the file is UTF-8 and theres a BOM, strip it for safe concatenation.
22
+ elsif data.encoding.name == "UTF-8" && data =~ UTF8_BOM_PATTERN
23
+ data.sub!(UTF8_BOM_PATTERN, "")
24
+ end
25
+ end
26
+ end
27
+
28
+ else
29
+ # Define UTF-8 and UTF-16 BOM pattern matchers.
30
+ # Avoid using a Regexp literal to prevent syntax errors in other interpreters.
31
+ UTF8_BOM_PATTERN = Regexp.new("\\A\\xEF\\xBB\\xBF")
32
+ UTF16_BOM_PATTERN = Regexp.new("\\A(\\xFE\\xFF|\\xFF\\xFE)")
33
+
34
+ def self.read_unicode(pathname)
35
+ pathname.read.tap do |data|
36
+ # If the file is UTF-8 and theres a BOM, strip it for safe concatenation.
37
+ if data =~ UTF8_BOM_PATTERN
38
+ data.sub!(UTF8_BOM_PATTERN, "")
39
+
40
+ # If we find a UTF-16 BOM, theres nothing we can do on
41
+ # 1.8. Only UTF-8 is supported.
42
+ elsif data =~ UTF16_BOM_PATTERN
43
+ raise EncodingError, "#{pathname} has a UTF-16 BOM. " +
44
+ "Resave the file as UTF-8 or upgrade to Ruby 1.9."
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ # Prepends a leading "." to an extension if its missing.
51
+ #
52
+ # normalize_extension("js")
53
+ # # => ".js"
54
+ #
55
+ # normalize_extension(".css")
56
+ # # => ".css"
57
+ #
58
+ def self.normalize_extension(extension)
59
+ extension = extension.to_s
60
+ if extension[/^\./]
61
+ extension
62
+ else
63
+ ".#{extension}"
64
+ end
65
+ end
66
+ end
67
+ end
@@ -1,9 +1,3 @@
1
1
  module Sprockets
2
- module Version
3
- MAJOR = 1
4
- MINOR = 0
5
- TINY = 2
6
-
7
- STRING = [MAJOR, MINOR, TINY].join(".")
8
- end
2
+ VERSION = "2.0.0"
9
3
  end
metadata CHANGED
@@ -1,104 +1,252 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sprockets
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ hash: 15
5
+ prerelease:
6
+ segments:
7
+ - 2
8
+ - 0
9
+ - 0
10
+ version: 2.0.0
5
11
  platform: ruby
6
12
  authors:
7
13
  - Sam Stephenson
14
+ - Joshua Peek
8
15
  autorequire:
9
16
  bindir: bin
10
17
  cert_chain: []
11
18
 
12
- date: 2009-02-24 00:00:00 -06:00
19
+ date: 2011-08-29 00:00:00 -05:00
13
20
  default_executable:
14
- dependencies: []
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: hike
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ hash: 11
31
+ segments:
32
+ - 1
33
+ - 2
34
+ version: "1.2"
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rack
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 15
46
+ segments:
47
+ - 1
48
+ - 0
49
+ version: "1.0"
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: tilt
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ hash: 13
61
+ segments:
62
+ - 1
63
+ - 1
64
+ version: "1.1"
65
+ - - "!="
66
+ - !ruby/object:Gem::Version
67
+ hash: 27
68
+ segments:
69
+ - 1
70
+ - 3
71
+ - 0
72
+ version: 1.3.0
73
+ type: :runtime
74
+ version_requirements: *id003
75
+ - !ruby/object:Gem::Dependency
76
+ name: coffee-script
77
+ prerelease: false
78
+ requirement: &id004 !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ~>
82
+ - !ruby/object:Gem::Version
83
+ hash: 3
84
+ segments:
85
+ - 2
86
+ - 0
87
+ version: "2.0"
88
+ type: :development
89
+ version_requirements: *id004
90
+ - !ruby/object:Gem::Dependency
91
+ name: eco
92
+ prerelease: false
93
+ requirement: &id005 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ~>
97
+ - !ruby/object:Gem::Version
98
+ hash: 15
99
+ segments:
100
+ - 1
101
+ - 0
102
+ version: "1.0"
103
+ type: :development
104
+ version_requirements: *id005
105
+ - !ruby/object:Gem::Dependency
106
+ name: ejs
107
+ prerelease: false
108
+ requirement: &id006 !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ~>
112
+ - !ruby/object:Gem::Version
113
+ hash: 15
114
+ segments:
115
+ - 1
116
+ - 0
117
+ version: "1.0"
118
+ type: :development
119
+ version_requirements: *id006
120
+ - !ruby/object:Gem::Dependency
121
+ name: execjs
122
+ prerelease: false
123
+ requirement: &id007 !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ~>
127
+ - !ruby/object:Gem::Version
128
+ hash: 15
129
+ segments:
130
+ - 1
131
+ - 0
132
+ version: "1.0"
133
+ type: :development
134
+ version_requirements: *id007
135
+ - !ruby/object:Gem::Dependency
136
+ name: json
137
+ prerelease: false
138
+ requirement: &id008 !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ hash: 3
144
+ segments:
145
+ - 0
146
+ version: "0"
147
+ type: :development
148
+ version_requirements: *id008
149
+ - !ruby/object:Gem::Dependency
150
+ name: rack-test
151
+ prerelease: false
152
+ requirement: &id009 !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ hash: 3
158
+ segments:
159
+ - 0
160
+ version: "0"
161
+ type: :development
162
+ version_requirements: *id009
163
+ - !ruby/object:Gem::Dependency
164
+ name: rake
165
+ prerelease: false
166
+ requirement: &id010 !ruby/object:Gem::Requirement
167
+ none: false
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ hash: 3
172
+ segments:
173
+ - 0
174
+ version: "0"
175
+ type: :development
176
+ version_requirements: *id010
177
+ description: Sprockets is a Rack-based asset packaging system that concatenates and serves JavaScript, CoffeeScript, CSS, LESS, Sass, and SCSS.
178
+ email:
179
+ - sstephenson@gmail.com
180
+ - josh@joshpeek.com
181
+ executables: []
15
182
 
16
- description: Sprockets is a Ruby library that preprocesses and concatenates JavaScript source files.
17
- email: sstephenson@gmail.com
18
- executables:
19
- - sprocketize
20
183
  extensions: []
21
184
 
22
185
  extra_rdoc_files: []
23
186
 
24
187
  files:
25
- - Rakefile
26
- - bin/sprocketize
27
- - lib/sprockets
28
- - lib/sprockets/concatenation.rb
188
+ - README.md
189
+ - LICENSE
190
+ - lib/sprockets/asset.rb
191
+ - lib/sprockets/asset_attributes.rb
192
+ - lib/sprockets/base.rb
193
+ - lib/sprockets/bundled_asset.rb
194
+ - lib/sprockets/cache/file_store.rb
195
+ - lib/sprockets/caching.rb
196
+ - lib/sprockets/charset_normalizer.rb
197
+ - lib/sprockets/context.rb
198
+ - lib/sprockets/digest.rb
199
+ - lib/sprockets/directive_processor.rb
200
+ - lib/sprockets/eco_template.rb
201
+ - lib/sprockets/ejs_template.rb
202
+ - lib/sprockets/engines.rb
29
203
  - lib/sprockets/environment.rb
30
- - lib/sprockets/error.rb
31
- - lib/sprockets/pathname.rb
32
- - lib/sprockets/preprocessor.rb
33
- - lib/sprockets/secretary.rb
34
- - lib/sprockets/source_file.rb
35
- - lib/sprockets/source_line.rb
204
+ - lib/sprockets/errors.rb
205
+ - lib/sprockets/index.rb
206
+ - lib/sprockets/jst_processor.rb
207
+ - lib/sprockets/mime.rb
208
+ - lib/sprockets/processing.rb
209
+ - lib/sprockets/processor.rb
210
+ - lib/sprockets/safety_colons.rb
211
+ - lib/sprockets/server.rb
212
+ - lib/sprockets/static_asset.rb
213
+ - lib/sprockets/trail.rb
214
+ - lib/sprockets/utils.rb
36
215
  - lib/sprockets/version.rb
37
216
  - lib/sprockets.rb
38
- - test/fixtures
39
- - test/fixtures/assets
40
- - test/fixtures/assets/images
41
- - test/fixtures/assets/images/script_with_assets
42
- - test/fixtures/assets/images/script_with_assets/one.png
43
- - test/fixtures/assets/images/script_with_assets/two.png
44
- - test/fixtures/assets/stylesheets
45
- - test/fixtures/assets/stylesheets/script_with_assets.css
46
- - test/fixtures/constants.yml
47
- - test/fixtures/double_slash_comments_that_are_not_requires_should_be_ignored_when_strip_comments_is_false.js
48
- - test/fixtures/double_slash_comments_that_are_not_requires_should_be_removed_by_default.js
49
- - test/fixtures/multiline_comments_should_be_removed_by_default.js
50
- - test/fixtures/requiring_a_file_after_it_has_already_been_required_should_do_nothing.js
51
- - test/fixtures/requiring_a_file_that_does_not_exist_should_raise_an_error.js
52
- - test/fixtures/requiring_a_single_file_should_replace_the_require_comment_with_the_file_contents.js
53
- - test/fixtures/requiring_the_current_file_should_do_nothing.js
54
- - test/fixtures/src
55
- - test/fixtures/src/constants.yml
56
- - test/fixtures/src/foo
57
- - test/fixtures/src/foo/bar.js
58
- - test/fixtures/src/foo/foo.js
59
- - test/fixtures/src/foo.js
60
- - test/fixtures/src/script_with_assets.js
61
- - test/test_concatenation.rb
62
- - test/test_environment.rb
63
- - test/test_helper.rb
64
- - test/test_pathname.rb
65
- - test/test_preprocessor.rb
66
- - test/test_secretary.rb
67
- - test/test_source_file.rb
68
- - test/test_source_line.rb
69
- - ext/nph-sprockets.cgi
70
- has_rdoc: false
217
+ has_rdoc: true
71
218
  homepage: http://getsprockets.org/
219
+ licenses: []
220
+
72
221
  post_install_message:
73
222
  rdoc_options: []
74
223
 
75
224
  require_paths:
76
225
  - lib
77
226
  required_ruby_version: !ruby/object:Gem::Requirement
227
+ none: false
78
228
  requirements:
79
229
  - - ">="
80
230
  - !ruby/object:Gem::Version
231
+ hash: 3
232
+ segments:
233
+ - 0
81
234
  version: "0"
82
- version:
83
235
  required_rubygems_version: !ruby/object:Gem::Requirement
236
+ none: false
84
237
  requirements:
85
238
  - - ">="
86
239
  - !ruby/object:Gem::Version
240
+ hash: 3
241
+ segments:
242
+ - 0
87
243
  version: "0"
88
- version:
89
244
  requirements: []
90
245
 
91
246
  rubyforge_project: sprockets
92
- rubygems_version: 1.3.1
247
+ rubygems_version: 1.5.2
93
248
  signing_key:
94
- specification_version: 2
95
- summary: JavaScript dependency management and concatenation
96
- test_files:
97
- - test/test_concatenation.rb
98
- - test/test_environment.rb
99
- - test/test_helper.rb
100
- - test/test_pathname.rb
101
- - test/test_preprocessor.rb
102
- - test/test_secretary.rb
103
- - test/test_source_file.rb
104
- - test/test_source_line.rb
249
+ specification_version: 3
250
+ summary: Rack-based asset packaging system
251
+ test_files: []
252
+
data/Rakefile DELETED
@@ -1,19 +0,0 @@
1
- require "rubygems"
2
- require "rake/testtask"
3
- require "rake/gempackagetask"
4
-
5
- task :default => :test
6
-
7
- Rake::TestTask.new do |t|
8
- t.libs << "test"
9
- t.test_files = FileList["test/test_*.rb"]
10
- t.verbose = true
11
- end
12
-
13
- Rake::GemPackageTask.new(eval(IO.read(File.join(File.dirname(__FILE__), "sprockets.gemspec")))) do |pkg|
14
- require File.join(File.dirname(__FILE__), "lib", "sprockets", "version")
15
- raise "Error: Sprockets::Version doesn't match gemspec" if Sprockets::Version::STRING != pkg.version.to_s
16
-
17
- pkg.need_zip = true
18
- pkg.need_tar = true
19
- end
@@ -1,54 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require File.join(File.dirname(__FILE__), *%w".. lib sprockets")
4
- require "optparse"
5
-
6
- load_path = (ENV["SPROCKETS_PATH"] || "").split(":")
7
- filenames = []
8
- options = { :load_path => load_path, :source_files => filenames, :expand_paths => false }
9
-
10
- OptionParser.new do |opts|
11
- opts.summary_width = 28
12
- opts.banner = "Usage: sprocketize [options] filename [filename ...]"
13
-
14
- def opts.show_usage
15
- puts self
16
- exit
17
- end
18
-
19
- opts.on("-C DIRECTORY", "--directory=DIRECTORY", "Change to DIRECTORY before doing anything") do |directory|
20
- Dir.chdir(directory)
21
- end
22
-
23
- opts.on("-I DIRECTORY", "--include-dir=DIRECTORY", "Adds the directory to the Sprockets load path") do |directory|
24
- load_path << directory
25
- end
26
-
27
- opts.on("-a DIRECTORY", "--asset-root=DIRECTORY", "Copy provided assets into DIRECTORY") do |directory|
28
- options[:asset_root] = directory
29
- end
30
-
31
- opts.on_tail("-h", "--help", "Shows this help message") do
32
- opts.show_usage
33
- end
34
-
35
- opts.on_tail("-v", "--version", "Shows version") do
36
- puts Sprockets::Version::STRING
37
- exit
38
- end
39
-
40
- opts.show_usage if ARGV.empty?
41
-
42
- begin
43
- opts.order(ARGV) do |filename|
44
- filenames << filename
45
- end
46
- rescue OptionParser::ParseError => e
47
- opts.warn e.message
48
- opts.show_usage
49
- end
50
- end
51
-
52
- secretary = Sprockets::Secretary.new(options)
53
- secretary.install_assets if options[:asset_root]
54
- print secretary.concatenation