sprockets 0.9.0 → 0.9.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.

data/lib/sprockets.rb CHANGED
@@ -3,6 +3,33 @@ $:.unshift File.dirname(__FILE__)
3
3
  require "yaml"
4
4
  require "fileutils"
5
5
 
6
+ module Sprockets
7
+ class << self
8
+ def running_on_windows?
9
+ RUBY_PLATFORM =~ /(win|w)32$/
10
+ end
11
+
12
+ def absolute?(location)
13
+ same_when_expanded?(location) || platform_absolute_path?(location)
14
+ end
15
+
16
+ protected
17
+ def same_when_expanded?(location)
18
+ location[0, 1] == File.expand_path(location)[0, 1]
19
+ end
20
+
21
+ def platform_absolute_path?(location)
22
+ false
23
+ end
24
+
25
+ if Sprockets.running_on_windows?
26
+ def platform_absolute_path?(location)
27
+ location[0, 1] == File::SEPARATOR && File.expand_path(location) =~ /[A-Za-z]:[\/\\]/
28
+ end
29
+ end
30
+ end
31
+ end
32
+
6
33
  require "sprockets/version"
7
34
  require "sprockets/error"
8
35
  require "sprockets/environment"
@@ -12,3 +39,4 @@ require "sprockets/source_file"
12
39
  require "sprockets/concatenation"
13
40
  require "sprockets/preprocessor"
14
41
  require "sprockets/secretary"
42
+
@@ -22,7 +22,7 @@ module Sprockets
22
22
  end
23
23
 
24
24
  def find(location)
25
- if absolute?(location) && File.exists?(location)
25
+ if Sprockets.absolute?(location) && File.exists?(location)
26
26
  pathname_from(location)
27
27
  else
28
28
  find_all(location).first
@@ -39,13 +39,9 @@ module Sprockets
39
39
  end
40
40
 
41
41
  protected
42
- def absolute?(location)
43
- location[0, 1] == File::SEPARATOR
44
- end
45
-
46
42
  def absolute_location_from(location)
47
43
  location = location.to_s
48
- location = File.join(root.absolute_location, location) unless absolute?(location)
44
+ location = File.join(root.absolute_location, location) unless Sprockets.absolute?(location)
49
45
  File.expand_path(location)
50
46
  end
51
47
 
@@ -42,26 +42,8 @@ module Sprockets
42
42
  end
43
43
 
44
44
  def record_source_line(source_line)
45
- skip_pdoc_comments(source_line) do
46
- unless source_line.comment? && strip_comments?
47
- concatenation.record(source_line)
48
- end
49
- end
50
- end
51
-
52
- def skip_pdoc_comments(source_line)
53
- yield unless strip_comments?
54
-
55
- @commented ||= false
56
-
57
- if source_line.begins_multiline_comment?
58
- @commented = true
59
- end
60
-
61
- yield unless @commented
62
-
63
- if source_line.closes_multiline_comment?
64
- @commented = false
45
+ unless source_line.comment? && strip_comments?
46
+ concatenation.record(source_line)
65
47
  end
66
48
  end
67
49
 
@@ -72,7 +72,7 @@ module Sprockets
72
72
  end
73
73
 
74
74
  def from_root(path)
75
- if path[0, 1] == File::SEPARATOR
75
+ if Sprockets.absolute?(path)
76
76
  path
77
77
  else
78
78
  File.join(@options[:root], path)
@@ -6,15 +6,37 @@ module Sprockets
6
6
  @environment = environment
7
7
  @pathname = pathname
8
8
  end
9
-
10
- def each_source_line
11
- File.open(pathname.absolute_location) do |file|
12
- file.each do |line|
13
- yield SourceLine.new(self, line, file.lineno)
9
+
10
+ def source_lines
11
+ @lines ||= begin
12
+ lines = []
13
+
14
+ comments = []
15
+ File.open(pathname.absolute_location) do |file|
16
+ file.each do |line|
17
+ lines << line = SourceLine.new(self, line, file.lineno)
18
+
19
+ if line.begins_pdoc_comment? || comments.any?
20
+ comments << line
21
+ end
22
+
23
+ if line.ends_multiline_comment?
24
+ if line.ends_pdoc_comment?
25
+ comments.each { |l| l.comment! }
26
+ end
27
+ comments.clear
28
+ end
29
+ end
14
30
  end
31
+
32
+ lines
15
33
  end
16
34
  end
17
-
35
+
36
+ def each_source_line(&block)
37
+ source_lines.each(&block)
38
+ end
39
+
18
40
  def find(location, kind = :file)
19
41
  pathname.parent_pathname.find(location, kind)
20
42
  end
@@ -7,7 +7,7 @@ module Sprockets
7
7
  @line = line
8
8
  @number = number
9
9
  end
10
-
10
+
11
11
  def comment
12
12
  @comment ||= line[/^\s*\/\/(.*)/, 1]
13
13
  end
@@ -16,11 +16,23 @@ module Sprockets
16
16
  !!comment
17
17
  end
18
18
 
19
+ def comment!
20
+ @comment = line
21
+ end
22
+
19
23
  def begins_multiline_comment?
24
+ line =~ /^\s*\/\*(.*)/
25
+ end
26
+
27
+ def begins_pdoc_comment?
20
28
  line =~ /^\s*\/\*\*(.*)/
21
29
  end
22
30
 
23
- def closes_multiline_comment?
31
+ def ends_multiline_comment?
32
+ line =~ /^(.*)*\*\/\s*/
33
+ end
34
+
35
+ def ends_pdoc_comment?
24
36
  line =~ /^(.*)*\*\*\/\s*/
25
37
  end
26
38
 
@@ -2,7 +2,7 @@ module Sprockets
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 9
5
- TINY = 0
5
+ TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join(".")
8
8
  end
@@ -1,2 +1,8 @@
1
1
  // This is a double-slash comment that should appear in the resulting output file.
2
2
  /* This is a slash-star comment that should appear in the resulting output file. */
3
+ /* This is multiline slash-star comment
4
+ * that should appear in the resulting
5
+ * output file */
6
+ /**
7
+ This is not a PDoc comment that should appear in the resulting output file.
8
+ */
@@ -1,4 +1,4 @@
1
1
  /**
2
- * This is a slash-star comment
2
+ * This is a PDoc comment
3
3
  * that should appear in the resulting output file.
4
4
  **/
@@ -59,6 +59,6 @@ class EnvironmentTest < Test::Unit::TestCase
59
59
 
60
60
  protected
61
61
  def assert_load_path_equals(load_path_absolute_locations, environment)
62
- assert load_path_absolute_locations.zip(environment.load_path).map { |location, pathname| location == pathname.absolute_location }.all?
62
+ assert load_path_absolute_locations.zip(environment.load_path).map { |location, pathname| File.expand_path(location) == pathname.absolute_location }.all?
63
63
  end
64
64
  end
data/test/test_helper.rb CHANGED
@@ -24,7 +24,7 @@ class Test::Unit::TestCase
24
24
  end
25
25
 
26
26
  def assert_absolute_location(location, pathname)
27
- assert_equal location, pathname.absolute_location
27
+ assert_equal File.expand_path(location), pathname.absolute_location
28
28
  end
29
29
 
30
30
  def assert_absolute_location_ends_with(location_ending, pathname)
@@ -17,12 +17,18 @@ class PreprocessorTest < Test::Unit::TestCase
17
17
  require_file_for_this_test
18
18
  assert_concatenation_contains_line "// This is a double-slash comment that should appear in the resulting output file."
19
19
  assert_concatenation_contains_line "/* This is a slash-star comment that should appear in the resulting output file. */"
20
+
21
+ assert_concatenation_contains_line "/* This is multiline slash-star comment"
22
+ assert_concatenation_contains_line "* that should appear in the resulting"
23
+ assert_concatenation_contains_line "* output file */"
24
+
25
+ assert_concatenation_contains_line "This is not a PDoc comment that should appear in the resulting output file."
20
26
  end
21
27
 
22
28
  def test_multiline_comments_should_be_removed_by_default
23
29
  require_file_for_this_test
24
30
  assert_concatenation_does_not_contain_line "/**"
25
- assert_concatenation_does_not_contain_line " * This is a slash-star comment"
31
+ assert_concatenation_does_not_contain_line " * This is a PDoc comment"
26
32
  assert_concatenation_does_not_contain_line " * that should appear in the resulting output file."
27
33
  assert_concatenation_does_not_contain_line "**/"
28
34
  end
@@ -42,7 +42,7 @@ class SecretaryTest < Test::Unit::TestCase
42
42
  assert_equal paths_relative_to(temp,
43
43
  "images", "images/script_with_assets", "images/script_with_assets/one.png",
44
44
  "images/script_with_assets/two.png", "stylesheets", "stylesheets/script_with_assets.css"),
45
- Dir[File.join(temp, "**", "*")]
45
+ Dir[File.join(temp, "**", "*")].sort
46
46
  end
47
47
  end
48
48
 
@@ -57,7 +57,7 @@ class SecretaryTest < Test::Unit::TestCase
57
57
  assert_equal paths_relative_to(temp,
58
58
  "images", "images/script_with_assets", "images/script_with_assets/one.png",
59
59
  "images/script_with_assets/two.png", "stylesheets", "stylesheets/script_with_assets.css"),
60
- Dir[File.join(temp, "**", "*")]
60
+ Dir[File.join(temp, "**", "*")].sort
61
61
  end
62
62
  end
63
63
 
@@ -72,7 +72,7 @@ class SecretaryTest < Test::Unit::TestCase
72
72
  assert_equal paths_relative_to(temp,
73
73
  "images", "images/script_with_assets", "images/script_with_assets/one.png",
74
74
  "images/script_with_assets/two.png", "stylesheets", "stylesheets/script_with_assets.css"),
75
- Dir[File.join(temp, "**", "*")]
75
+ Dir[File.join(temp, "**", "*")].sort
76
76
  end
77
77
  end
78
78
 
@@ -11,13 +11,23 @@ class SourceLineTest < Test::Unit::TestCase
11
11
  end
12
12
 
13
13
  def test_line_that_begins_a_multiline_comment
14
- assert !source_line(" /*").begins_multiline_comment?
14
+ assert source_line(" /*").begins_multiline_comment?
15
15
  assert source_line(" /**").begins_multiline_comment?
16
16
  end
17
17
 
18
- def test_line_that_closes_a_multiline_comment
19
- assert !source_line(" */").closes_multiline_comment?
20
- assert source_line(" **/").closes_multiline_comment?
18
+ def test_line_that_begins_a_pdoc_comment
19
+ assert !source_line(" /*").begins_pdoc_comment?
20
+ assert source_line(" /**").begins_pdoc_comment?
21
+ end
22
+
23
+ def test_line_that_ends_a_multiline_comment
24
+ assert source_line(" */").ends_multiline_comment?
25
+ assert source_line(" **/").ends_multiline_comment?
26
+ end
27
+
28
+ def test_line_that_ends_a_pdoc_comment
29
+ assert !source_line(" */").ends_pdoc_comment?
30
+ assert source_line(" **/").ends_pdoc_comment?
21
31
  end
22
32
 
23
33
  def test_line_that_contains_but_does_not_begin_with_double_slash_should_not_be_a_comment
@@ -60,7 +70,7 @@ class SourceLineTest < Test::Unit::TestCase
60
70
  environment = environment_for_fixtures
61
71
  pathname = Sprockets::Pathname.new(environment, "/a/b/c.js")
62
72
  source_file = Sprockets::SourceFile.new(environment, pathname)
63
- assert_equal "line 25 of /a/b/c.js", source_line("hello", source_file, 25).inspect
73
+ assert_equal "line 25 of #{File.expand_path("/a/b/c.js")}", source_line("hello", source_file, 25).inspect
64
74
  end
65
75
 
66
76
  def test_interpolation_of_constants
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sprockets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
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-02-09 00:00:00 -06:00
12
+ date: 2009-02-16 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -87,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  version:
88
88
  requirements: []
89
89
 
90
- rubyforge_project:
90
+ rubyforge_project: sprockets
91
91
  rubygems_version: 1.3.1
92
92
  signing_key:
93
93
  specification_version: 2