sstephenson-sprockets 0.5.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/sprocketize +1 -1
- data/lib/sprockets/{output_file.rb → concatenation.rb} +1 -1
- data/lib/sprockets/preprocessor.rb +3 -3
- data/lib/sprockets/secretary.rb +10 -2
- data/lib/sprockets/version.rb +1 -1
- data/lib/sprockets.rb +1 -1
- data/test/test_concatenation.rb +28 -0
- data/test/test_preprocessor.rb +17 -17
- metadata +4 -4
- data/test/test_output_file.rb +0 -28
data/bin/sprocketize
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
module Sprockets
|
|
2
2
|
class Preprocessor
|
|
3
|
-
attr_reader :environment, :
|
|
3
|
+
attr_reader :environment, :concatenation, :source_files, :asset_paths
|
|
4
4
|
|
|
5
5
|
def initialize(environment, options = {})
|
|
6
6
|
@environment = environment
|
|
7
|
-
@
|
|
7
|
+
@concatenation = Concatenation.new
|
|
8
8
|
@source_files = []
|
|
9
9
|
@asset_paths = []
|
|
10
10
|
@options = options
|
|
@@ -44,7 +44,7 @@ module Sprockets
|
|
|
44
44
|
def record_source_line(source_line)
|
|
45
45
|
skip_pdoc_comments(source_line) do
|
|
46
46
|
unless source_line.comment? && strip_comments?
|
|
47
|
-
|
|
47
|
+
concatenation.record(source_line)
|
|
48
48
|
end
|
|
49
49
|
end
|
|
50
50
|
end
|
data/lib/sprockets/secretary.rb
CHANGED
|
@@ -10,6 +10,10 @@ module Sprockets
|
|
|
10
10
|
attr_reader :environment, :preprocessor
|
|
11
11
|
|
|
12
12
|
def initialize(options = {})
|
|
13
|
+
reset!(options)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def reset!(options = @options)
|
|
13
17
|
@options = DEFAULT_OPTIONS.merge(options)
|
|
14
18
|
@environment = Sprockets::Environment.new(@options[:root])
|
|
15
19
|
@preprocessor = Sprockets::Preprocessor.new(@environment)
|
|
@@ -42,8 +46,8 @@ module Sprockets
|
|
|
42
46
|
end
|
|
43
47
|
end
|
|
44
48
|
|
|
45
|
-
def
|
|
46
|
-
preprocessor.
|
|
49
|
+
def concatenation
|
|
50
|
+
preprocessor.concatenation
|
|
47
51
|
end
|
|
48
52
|
|
|
49
53
|
def install_assets
|
|
@@ -54,6 +58,10 @@ module Sprockets
|
|
|
54
58
|
end
|
|
55
59
|
end
|
|
56
60
|
|
|
61
|
+
def source_last_modified
|
|
62
|
+
preprocessor.source_files.map { |s| s.mtime }.max
|
|
63
|
+
end
|
|
64
|
+
|
|
57
65
|
protected
|
|
58
66
|
def expand_paths(paths, options = {})
|
|
59
67
|
if options.has_key?(:expand_paths) ? options[:expand_paths] : @options[:expand_paths]
|
data/lib/sprockets/version.rb
CHANGED
data/lib/sprockets.rb
CHANGED
|
@@ -9,6 +9,6 @@ require "sprockets/environment"
|
|
|
9
9
|
require "sprockets/pathname"
|
|
10
10
|
require "sprockets/source_line"
|
|
11
11
|
require "sprockets/source_file"
|
|
12
|
-
require "sprockets/
|
|
12
|
+
require "sprockets/concatenation"
|
|
13
13
|
require "sprockets/preprocessor"
|
|
14
14
|
require "sprockets/secretary"
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class ConcatenationTest < Test::Unit::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
@concatenation = Sprockets::Concatenation.new
|
|
6
|
+
@environment = environment_for_fixtures
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def test_record
|
|
10
|
+
assert_equal [], @concatenation.source_lines
|
|
11
|
+
assert_equal "hello\n", @concatenation.record(source_line("hello\n")).to_s
|
|
12
|
+
assert_equal "world\n", @concatenation.record(source_line("world\n")).to_s
|
|
13
|
+
assert_equal ["hello\n", "world\n"], @concatenation.source_lines.map { |source_line| source_line.to_s }
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_to_s
|
|
17
|
+
@concatenation.record(source_line("hello\n"))
|
|
18
|
+
@concatenation.record(source_line("world\n"))
|
|
19
|
+
assert_equal "hello\nworld\n", @concatenation.to_s
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_save_to
|
|
23
|
+
filename = File.join(FIXTURES_PATH, "output.js")
|
|
24
|
+
@concatenation.save_to(filename)
|
|
25
|
+
assert_equal @concatenation.to_s, IO.read(filename)
|
|
26
|
+
File.unlink(filename)
|
|
27
|
+
end
|
|
28
|
+
end
|
data/test/test_preprocessor.rb
CHANGED
|
@@ -8,28 +8,28 @@ class PreprocessorTest < Test::Unit::TestCase
|
|
|
8
8
|
|
|
9
9
|
def test_double_slash_comments_that_are_not_requires_should_be_removed_by_default
|
|
10
10
|
require_file_for_this_test
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
assert_concatenation_does_not_contain_line "// This is a double-slash comment that should not appear in the resulting output file."
|
|
12
|
+
assert_concatenation_contains_line "/* This is a slash-star comment that should not appear in the resulting output file. */"
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def test_double_slash_comments_that_are_not_requires_should_be_ignored_when_strip_comments_is_false
|
|
16
16
|
@preprocessor = Sprockets::Preprocessor.new(@environment, :strip_comments => false)
|
|
17
17
|
require_file_for_this_test
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
assert_concatenation_contains_line "// This is a double-slash comment that should appear in the resulting output file."
|
|
19
|
+
assert_concatenation_contains_line "/* This is a slash-star comment that should appear in the resulting output file. */"
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def test_multiline_comments_should_be_removed_by_default
|
|
23
23
|
require_file_for_this_test
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
assert_concatenation_does_not_contain_line "/**"
|
|
25
|
+
assert_concatenation_does_not_contain_line " * This is a slash-star comment"
|
|
26
|
+
assert_concatenation_does_not_contain_line " * that should appear in the resulting output file."
|
|
27
|
+
assert_concatenation_does_not_contain_line "**/"
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def test_requiring_a_single_file_should_replace_the_require_comment_with_the_file_contents
|
|
31
31
|
require_file_for_this_test
|
|
32
|
-
|
|
32
|
+
assert_concatenation_contains <<-LINES
|
|
33
33
|
var before_require;
|
|
34
34
|
var Foo = { };
|
|
35
35
|
var after_require;
|
|
@@ -49,7 +49,7 @@ class PreprocessorTest < Test::Unit::TestCase
|
|
|
49
49
|
|
|
50
50
|
def test_requiring_a_file_after_it_has_already_been_required_should_do_nothing
|
|
51
51
|
require_file_for_this_test
|
|
52
|
-
|
|
52
|
+
assert_concatenation_contains <<-LINES
|
|
53
53
|
var before_first_require;
|
|
54
54
|
var Foo = { };
|
|
55
55
|
var after_first_require_and_before_second_require;
|
|
@@ -60,16 +60,16 @@ class PreprocessorTest < Test::Unit::TestCase
|
|
|
60
60
|
protected
|
|
61
61
|
attr_reader :environment, :preprocessor
|
|
62
62
|
|
|
63
|
-
def
|
|
64
|
-
preprocessor.
|
|
63
|
+
def concatenation
|
|
64
|
+
preprocessor.concatenation
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
def output_text
|
|
68
|
-
preprocessor.
|
|
68
|
+
preprocessor.concatenation.to_s
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
def source_lines_matching(line)
|
|
72
|
-
|
|
72
|
+
concatenation.source_lines.select { |source_line| source_line.line.strip == line }
|
|
73
73
|
end
|
|
74
74
|
|
|
75
75
|
def require_file(location)
|
|
@@ -84,15 +84,15 @@ class PreprocessorTest < Test::Unit::TestCase
|
|
|
84
84
|
caller.map { |c| c[/`(.*?)'$/, 1] }.grep(/^test_/).first[5..-1] + ".js"
|
|
85
85
|
end
|
|
86
86
|
|
|
87
|
-
def
|
|
87
|
+
def assert_concatenation_does_not_contain_line(line)
|
|
88
88
|
assert source_lines_matching(line).empty?, "Expected #{line.inspect} to not exist"
|
|
89
89
|
end
|
|
90
90
|
|
|
91
|
-
def
|
|
91
|
+
def assert_concatenation_contains_line(line)
|
|
92
92
|
assert source_lines_matching(line).any?, "Expected #{line.inspect} to exist"
|
|
93
93
|
end
|
|
94
94
|
|
|
95
|
-
def
|
|
95
|
+
def assert_concatenation_contains(indented_text)
|
|
96
96
|
lines = indented_text.split($/)
|
|
97
97
|
initial_indent = lines.first[/^\s*/].length
|
|
98
98
|
unindented_text = lines.map { |line| line[initial_indent..-1] }.join($/)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sstephenson-sprockets
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.9.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sam Stephenson
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2009-
|
|
12
|
+
date: 2009-02-09 00:00:00 -08:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies: []
|
|
15
15
|
|
|
@@ -29,7 +29,7 @@ files:
|
|
|
29
29
|
- lib/sprockets/preprocessor.rb
|
|
30
30
|
- lib/sprockets/source_file.rb
|
|
31
31
|
- lib/sprockets/error.rb
|
|
32
|
-
- lib/sprockets/
|
|
32
|
+
- lib/sprockets/concatenation.rb
|
|
33
33
|
- lib/sprockets/secretary.rb
|
|
34
34
|
- lib/sprockets/environment.rb
|
|
35
35
|
- lib/sprockets/version.rb
|
|
@@ -39,7 +39,7 @@ files:
|
|
|
39
39
|
- test/test_secretary.rb
|
|
40
40
|
- test/test_source_line.rb
|
|
41
41
|
- test/test_source_file.rb
|
|
42
|
-
- test/
|
|
42
|
+
- test/test_concatenation.rb
|
|
43
43
|
- test/fixtures
|
|
44
44
|
- test/fixtures/src
|
|
45
45
|
- test/fixtures/src/foo
|
data/test/test_output_file.rb
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
require "test_helper"
|
|
2
|
-
|
|
3
|
-
class OutputFileTest < Test::Unit::TestCase
|
|
4
|
-
def setup
|
|
5
|
-
@output_file = Sprockets::OutputFile.new
|
|
6
|
-
@environment = environment_for_fixtures
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def test_record
|
|
10
|
-
assert_equal [], @output_file.source_lines
|
|
11
|
-
assert_equal "hello\n", @output_file.record(source_line("hello\n")).to_s
|
|
12
|
-
assert_equal "world\n", @output_file.record(source_line("world\n")).to_s
|
|
13
|
-
assert_equal ["hello\n", "world\n"], @output_file.source_lines.map { |source_line| source_line.to_s }
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def test_to_s
|
|
17
|
-
@output_file.record(source_line("hello\n"))
|
|
18
|
-
@output_file.record(source_line("world\n"))
|
|
19
|
-
assert_equal "hello\nworld\n", @output_file.to_s
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def test_save_to
|
|
23
|
-
filename = File.join(FIXTURES_PATH, "output.js")
|
|
24
|
-
@output_file.save_to(filename)
|
|
25
|
-
assert_equal @output_file.to_s, IO.read(filename)
|
|
26
|
-
File.unlink(filename)
|
|
27
|
-
end
|
|
28
|
-
end
|