asset_bundler 0.1.0 → 0.2.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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -2,7 +2,8 @@ require 'asset_timestamps_cache'
2
2
  require 'fileutils'
3
3
 
4
4
  module AssetBundler
5
-
5
+ class FileNotFound < StandardError; end
6
+
6
7
  # Mix this in to view context for convenient access
7
8
  module ViewHelper
8
9
  def javascript_include_tag(*args)
@@ -53,16 +54,19 @@ module AssetBundler
53
54
  end
54
55
 
55
56
  def self.join_asset_file_contents(paths)
56
- paths.collect { |path| File.read(asset_file_path(path)) }.join("\n\n")
57
+ paths.collect { |path| File.read(path) }.join("\n\n")
57
58
  end
58
59
 
59
60
  def self.write_asset_file_contents(joined_asset_path, asset_paths)
61
+ file_paths = asset_paths.map {|p| asset_file_path(p)}
62
+ file_paths.each {|p| raise(FileNotFound, "#{p.inspect} does not exist") unless File.exist?(p)}
63
+
60
64
  FileUtils.mkdir_p(File.dirname(joined_asset_path))
61
- File.open(joined_asset_path, "w+") { |cache| cache.write(join_asset_file_contents(asset_paths)) }
65
+ File.open(joined_asset_path, "w+") { |cache| cache.write(join_asset_file_contents(file_paths)) }
62
66
 
63
67
  # Set mtime to the latest of the combined files to allow for
64
68
  # consistent ETag without a shared filesystem.
65
- mt = asset_paths.map { |p| File.mtime(asset_file_path(p)) }.max
69
+ mt = file_paths.map { |p| File.mtime(p) }.max
66
70
  File.utime(mt, mt, joined_asset_path)
67
71
  end
68
72
 
@@ -28,6 +28,7 @@ class TestAssetBundler < Test::Unit::TestCase
28
28
  %(<script type="text/javascript" src="/scripts/#{name}.js?#{mtime}"></script>)
29
29
  end.join("\n")
30
30
  assert_equal expected, html
31
+ assert !File.exist?("public/scripts/all.js")
31
32
  end
32
33
 
33
34
  def test_stylesheet_link_tag_html_output_without_cache
@@ -37,6 +38,7 @@ class TestAssetBundler < Test::Unit::TestCase
37
38
  %{<link rel="stylesheet" href="/styles/#{name}.css?#{mtime}" type="text/css">}
38
39
  end.join("\n")
39
40
  assert_equal expected, html
41
+ assert !File.exist?("public/styles/all.js")
40
42
  end
41
43
 
42
44
  def test_javascript_include_tag_html_output_with_cache
@@ -44,19 +46,37 @@ class TestAssetBundler < Test::Unit::TestCase
44
46
  mtime = File.mtime("public/scripts/all.js").to_i
45
47
  expected = %(<script type="text/javascript" src="/scripts/all.js?#{mtime}"></script>)
46
48
  assert_equal expected, html
49
+ assert File.exist?("public/scripts/all.js")
50
+ assert_equal joined_script_contents, File.read("public/scripts/all.js")
47
51
  ensure
48
52
  File.delete("public/scripts/all.js")
49
53
  end
54
+
55
+ def test_javascript_include_tag_html_output_with_cache_when_nonexistent_file_is_specified
56
+ assert_raises AssetBundler::FileNotFound do
57
+ @scope.javascript_include_tag('/scripts/one.js', '/scripts/two.js', '/scripts/three.js', '/scripts/doesnotexist.js', :cache => '/scripts/all.js')
58
+ end
59
+ assert !File.exist?("public/scripts/all.js")
60
+ end
50
61
 
51
62
  def test_stylesheet_link_tag_html_output_with_cache
52
63
  html = @scope.stylesheet_link_tag('/styles/one.css', '/styles/two.css', '/styles/three.css', :cache => '/styles/all.css')
53
64
  mtime = File.mtime("public/styles/all.css").to_i
54
65
  expected = %{<link rel="stylesheet" href="/styles/all.css?#{mtime}" type="text/css">}
55
66
  assert_equal expected, html
67
+ assert File.exist?("public/styles/all.css")
68
+ assert_equal joined_style_contents, File.read("public/styles/all.css")
56
69
  ensure
57
70
  File.delete("public/styles/all.css")
58
71
  end
59
72
 
73
+ def test_stylesheet_link_tag_html_output_with_cache_when_nonexistent_file_is_specified
74
+ assert_raises AssetBundler::FileNotFound do
75
+ @scope.stylesheet_link_tag('/styles/one.css', '/styles/two.css', '/styles/three.css', '/styles/doesnotexist.css', :cache => '/styles/all.css')
76
+ end
77
+ assert !File.exist?("public/styles/all.css")
78
+ end
79
+
60
80
  def test_javascript_include_tag_html_output_with_cache_does_not_bundle_in_development
61
81
  with_rack_env 'development' do
62
82
  html = @scope.javascript_include_tag('/scripts/one.js', '/scripts/two.js', '/scripts/three.js', :cache => '/scripts/all.js')
@@ -65,6 +85,7 @@ class TestAssetBundler < Test::Unit::TestCase
65
85
  %(<script type="text/javascript" src="/scripts/#{name}.js?#{mtime}"></script>)
66
86
  end.join("\n")
67
87
  assert_equal expected, html
88
+ assert !File.exist?("public/scripts/all.js")
68
89
  end
69
90
  end
70
91
 
@@ -76,6 +97,7 @@ class TestAssetBundler < Test::Unit::TestCase
76
97
  %{<link rel="stylesheet" href="/styles/#{name}.css?#{mtime}" type="text/css">}
77
98
  end.join("\n")
78
99
  assert_equal expected, html
100
+ assert !File.exist?("public/styles/all.css")
79
101
  end
80
102
  end
81
103
 
@@ -90,18 +112,19 @@ class TestAssetBundler < Test::Unit::TestCase
90
112
  File.delete("public/scripts/all.js")
91
113
  end
92
114
 
93
- def test_cached_javascript
94
- @scope.javascript_include_tag('/scripts/one.js', '/scripts/two.js', '/scripts/three.js', :cache => '/scripts/all.js')
95
- actual = File.read("public/scripts/all.js")
96
- expected = ['one', 'two', 'three'].map do |name|
97
- "// script #{name}\nfunction #{name}() {};"
98
- end.join("\n\n")
99
- assert_equal expected, actual
100
- ensure
101
- File.delete("public/scripts/all.js")
102
- end
103
-
104
115
  private
116
+ def joined_script_contents
117
+ ['one', 'two', 'three'].map do |name|
118
+ "// script #{name}\nfunction #{name}() {};"
119
+ end.join("\n\n")
120
+ end
121
+
122
+ def joined_style_contents
123
+ ['one', 'two', 'three'].map do |name|
124
+ "/* style #{name} */\n##{name} {}"
125
+ end.join("\n\n")
126
+ end
127
+
105
128
  def with_rack_env(val)
106
129
  old_env, ENV['RACK_ENV'] = ENV['RACK_ENV'], val
107
130
  yield
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asset_bundler
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 23
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
- - 1
8
+ - 2
8
9
  - 0
9
- version: 0.1.0
10
+ version: 0.2.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Geoff Buesing
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-03-05 00:00:00 -06:00
18
+ date: 2010-06-24 00:00:00 -05:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: asset_timestamps_cache
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 25
27
30
  segments:
28
31
  - 0
29
32
  - 1
@@ -63,23 +66,27 @@ rdoc_options:
63
66
  require_paths:
64
67
  - lib
65
68
  required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
66
70
  requirements:
67
71
  - - ">="
68
72
  - !ruby/object:Gem::Version
73
+ hash: 3
69
74
  segments:
70
75
  - 0
71
76
  version: "0"
72
77
  required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
73
79
  requirements:
74
80
  - - ">="
75
81
  - !ruby/object:Gem::Version
82
+ hash: 3
76
83
  segments:
77
84
  - 0
78
85
  version: "0"
79
86
  requirements: []
80
87
 
81
88
  rubyforge_project:
82
- rubygems_version: 1.3.6
89
+ rubygems_version: 1.3.7
83
90
  signing_key:
84
91
  specification_version: 3
85
92
  summary: A simple asset bundling solution.