patch-asset_library 0.5.0.1

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.
@@ -0,0 +1,90 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe(AssetLibrary) do
4
+ include TemporaryDirectory
5
+
6
+ class ReverseCompiler < AssetLibrary::Compiler::Base
7
+ def write_all_caches(format = nil)
8
+ asset_modules.each do |asset_module|
9
+ asset_module.each_compilation do |input_paths, output_path|
10
+ open(output_path, 'w') do |file|
11
+ file.print config[:header]
12
+ input_paths.reverse_each do |input|
13
+ file << File.read(input)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ before do
22
+ AssetLibrary::Compiler.register(:reverse, ReverseCompiler)
23
+ end
24
+
25
+ describe "AssetLibrary.write_all_caches" do
26
+ it "should generate cached asset libraries for each asset module, with the configured compiler" do
27
+ write_file "#{tmp}/root/cssbase/stylesheet-1.css", "style1 { background: #000 }"
28
+ write_file "#{tmp}/root/cssbase/stylesheet-2.css.opt", "style2 { background: #fff }"
29
+ write_file "#{tmp}/root/jsbase/javascript-1.js", "function f1(){alert('1');}"
30
+ write_file "#{tmp}/root/jsbase/javascript-2.js.opt", "function f2(){alert('2');}"
31
+ config_path = "#{tmp}/config.yml"
32
+ open(config_path, 'w'){|f| f.puts <<-EOS}
33
+ compilers:
34
+ reverse:
35
+ header: HEADER
36
+
37
+ modules:
38
+ stylsheets:
39
+ cache: lib
40
+ optional_suffix: opt
41
+ base: cssbase
42
+ suffix: css
43
+ files:
44
+ - stylesheet-1
45
+ - stylesheet-2
46
+
47
+ javascripts:
48
+ cache: lib
49
+ optional_suffix: opt
50
+ base: jsbase
51
+ suffix: js
52
+ compiler: reverse
53
+ files:
54
+ - javascript-1
55
+ - javascript-2
56
+ EOS
57
+ AssetLibrary.root = "#{tmp}/root"
58
+ AssetLibrary.config_path = config_path
59
+ AssetLibrary.write_all_caches
60
+ File.read("#{tmp}/root/cssbase/lib.css").should == "style1 { background: #000 }style2 { background: #fff }"
61
+ File.read("#{tmp}/root/jsbase/lib.js").should == "HEADERfunction f2(){alert('2');}function f1(){alert('1');}"
62
+ end
63
+ end
64
+
65
+ describe "AssetLibrary.delete_all_caches" do
66
+ it "should delete all caches" do
67
+ write_file "#{tmp}/root/cssbase/lib.css"
68
+ config_path = "#{tmp}/config.yml"
69
+ open(config_path, 'w'){|f| f.puts <<-EOS}
70
+ modules:
71
+ stylesheets:
72
+ cache: lib
73
+ base: cssbase
74
+ suffix: css
75
+ files:
76
+ - stylesheet-1
77
+ - stylesheet-2
78
+ EOS
79
+ AssetLibrary.root = "#{tmp}/root"
80
+ AssetLibrary.config_path = config_path
81
+ AssetLibrary.delete_all_caches
82
+ File.should_not exist("#{tmp}/root/cssbase/lib.css")
83
+ end
84
+ end
85
+
86
+ def write_file(path, content='...')
87
+ FileUtils.mkdir_p File.dirname(path)
88
+ open(path, 'w'){|f| f.print content}
89
+ end
90
+ end
@@ -0,0 +1,70 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+
4
+ require File.dirname(__FILE__) + '/../lib/asset_library'
5
+
6
+ module TemporaryDirectory
7
+ TMP = File.expand_path(File.dirname(__FILE__) + '/tmp')
8
+
9
+ def self.included(base)
10
+ base.before do
11
+ remove_tmp
12
+ make_tmp
13
+ enter_tmp
14
+ end
15
+
16
+ base.after do
17
+ leave_tmp
18
+ remove_tmp
19
+ end
20
+ end
21
+
22
+ def make_tmp
23
+ FileUtils.mkdir_p tmp
24
+ end
25
+
26
+ def remove_tmp
27
+ FileUtils.rm_rf tmp
28
+ end
29
+
30
+ def enter_tmp
31
+ @original_pwd = Dir.pwd
32
+ Dir.chdir tmp
33
+ end
34
+
35
+ def leave_tmp
36
+ Dir.chdir @original_pwd
37
+ end
38
+
39
+ def tmp
40
+ TMP
41
+ end
42
+ end
43
+
44
+ module CompilerHelpers
45
+ def mock_asset_module(name, format, output_path, *input_paths)
46
+ config = input_paths.last.is_a?(Hash) ? input_paths.pop : {}
47
+ asset_module = mock(:name => name)
48
+ asset_module.stub!(:compiler_flags).and_return(config[:compiler_flags] || [])
49
+ asset_module.stub!(:config).and_return(config)
50
+ asset_module.stub!(:each_compilation).and_yield(input_paths, output_path)
51
+ asset_module
52
+ end
53
+ end
54
+
55
+ Spec::Runner.configure do |config|
56
+ config.before do
57
+ @old_app_root = AssetLibrary.app_root
58
+ @old_root = AssetLibrary.root
59
+ @old_config_path = AssetLibrary.config_path
60
+ @old_cache = AssetLibrary.cache
61
+ end
62
+
63
+ config.after do
64
+ AssetLibrary.app_root = @app_root
65
+ AssetLibrary.root = @old_root
66
+ AssetLibrary.config_path = @old_config_path
67
+ AssetLibrary.cache = @old_cache
68
+ AssetLibrary.reset!
69
+ end
70
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: patch-asset_library
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 5
8
+ - 0
9
+ - 1
10
+ version: 0.5.0.1
11
+ platform: ruby
12
+ authors:
13
+ - adamh
14
+ - alegscogs
15
+ - oggy
16
+ autorequire:
17
+ bindir: bin
18
+ cert_chain: []
19
+
20
+ date: 2010-03-11 00:00:00 -05:00
21
+ default_executable:
22
+ dependencies:
23
+ - !ruby/object:Gem::Dependency
24
+ name: adamh-glob_fu
25
+ prerelease: false
26
+ requirement: &id001 !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ segments:
31
+ - 0
32
+ - 0
33
+ - 4
34
+ version: 0.0.4
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ description:
38
+ email: george@patch.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files:
44
+ - README.rdoc
45
+ files:
46
+ - lib/asset_library.rb
47
+ - lib/asset_library/asset.rb
48
+ - lib/asset_library/asset_module.rb
49
+ - lib/asset_library/compiler.rb
50
+ - lib/asset_library/compiler/base.rb
51
+ - lib/asset_library/compiler/closure.rb
52
+ - lib/asset_library/compiler/default.rb
53
+ - lib/asset_library/helpers.rb
54
+ - lib/asset_library/rake_tasks.rb
55
+ - lib/asset_library/util.rb
56
+ - rails/init.rb
57
+ - README.rdoc
58
+ has_rdoc: true
59
+ homepage: http://github.com/oggy/asset_library/tree/patch
60
+ licenses: []
61
+
62
+ post_install_message:
63
+ rdoc_options:
64
+ - --charset=UTF-8
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ requirements: []
82
+
83
+ rubyforge_project:
84
+ rubygems_version: 1.3.6
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: Manage and bundle CSS and JavaScript files
88
+ test_files:
89
+ - spec/asset_library/asset_module_spec.rb
90
+ - spec/asset_library/asset_spec.rb
91
+ - spec/asset_library/compiler/base_spec.rb
92
+ - spec/asset_library/compiler/closure_spec.rb
93
+ - spec/asset_library/compiler/default_spec.rb
94
+ - spec/asset_library/compiler_spec.rb
95
+ - spec/asset_library/helpers_spec.rb
96
+ - spec/asset_library_spec.rb
97
+ - spec/integration_spec.rb
98
+ - spec/spec_helper.rb