jbundle 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.md +24 -1
- data/lib/jbundle/builder.rb +20 -10
- data/lib/jbundle/config.rb +3 -3
- data/lib/jbundle/version.rb +1 -1
- data/spec/JFile +12 -1
- data/spec/jbundle_spec.rb +4 -4
- data/spec/test_src/file4.js +2 -1
- data/spec/test_src/license.txt +1 -1
- metadata +4 -4
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -23,7 +23,7 @@ Define a set of javascript files to bundle and minify
|
|
23
23
|
|
24
24
|
# Filters can be use for string substitution
|
25
25
|
filter do |src, config|
|
26
|
-
src.gsub
|
26
|
+
src.gsub(/<VERSION>/, config.version)
|
27
27
|
end
|
28
28
|
|
29
29
|
target_dir 'dist'
|
@@ -74,6 +74,29 @@ You can bundle licenses in bundles. Licenses will not be minified even though th
|
|
74
74
|
|
75
75
|
All defined filters will run on the src for all these cases.
|
76
76
|
|
77
|
+
## Filters
|
78
|
+
|
79
|
+
You can filter both minified and un-minified source and license content with the filter method
|
80
|
+
|
81
|
+
# Filters can be use for string substitution
|
82
|
+
filter do |src, config|
|
83
|
+
src.gsub(/<VERSION>/, config.version)
|
84
|
+
end
|
85
|
+
|
86
|
+
You can declare filters that run on un-minified output only
|
87
|
+
|
88
|
+
filter :src do |src, config|
|
89
|
+
src.gsub(/<SRC_MODE>/, 'full source')
|
90
|
+
end
|
91
|
+
|
92
|
+
... And minified output only
|
93
|
+
|
94
|
+
filter :min do |src, config|
|
95
|
+
src.gsub(/<SRC_MODE>/, 'minified source')
|
96
|
+
end
|
97
|
+
|
98
|
+
All filters must return a copy of the source, so use src.gsub instead of src.gsub!
|
99
|
+
|
77
100
|
## Jfile
|
78
101
|
|
79
102
|
You can add configuration in a Jfile in the root of your project.
|
data/lib/jbundle/builder.rb
CHANGED
@@ -8,8 +8,8 @@ module JBundle
|
|
8
8
|
|
9
9
|
attr_reader :name, :src_dir, :dir
|
10
10
|
|
11
|
-
def initialize(name, file_list,
|
12
|
-
@file_list, @src_dir = file_list, src_dir
|
11
|
+
def initialize(name, file_list, config)
|
12
|
+
@config, @file_list, @src_dir = config, file_list, config.src_dir
|
13
13
|
@name, @dir = parse_name(name)
|
14
14
|
end
|
15
15
|
|
@@ -23,11 +23,19 @@ module JBundle
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def src
|
26
|
-
@src ||=
|
26
|
+
@src ||= filter(filtered_licenses + filtered_src, :src)
|
27
27
|
end
|
28
28
|
|
29
29
|
def min
|
30
|
-
@min ||=
|
30
|
+
@min ||= filter(filtered_licenses, :min) + Closure::Compiler.new.compile(filter(filtered_src, :min))
|
31
|
+
end
|
32
|
+
|
33
|
+
def filtered_licenses
|
34
|
+
@filtered_licenses ||= filter(licenses, :all)
|
35
|
+
end
|
36
|
+
|
37
|
+
def filtered_src
|
38
|
+
@filtered_src ||= filter(raw_src, :all)
|
31
39
|
end
|
32
40
|
|
33
41
|
def min_name
|
@@ -65,6 +73,13 @@ module JBundle
|
|
65
73
|
[n,d]
|
66
74
|
end
|
67
75
|
|
76
|
+
def filter(content, mode)
|
77
|
+
@config.filters[mode].each do |filter|
|
78
|
+
content = filter.call(content, @config)
|
79
|
+
end
|
80
|
+
content
|
81
|
+
end
|
82
|
+
|
68
83
|
end
|
69
84
|
|
70
85
|
|
@@ -82,12 +97,7 @@ module JBundle
|
|
82
97
|
end
|
83
98
|
|
84
99
|
def build_one(f)
|
85
|
-
|
86
|
-
@config.filters.each do |filter|
|
87
|
-
filter.call(compiler.licenses, @config)
|
88
|
-
filter.call(compiler.raw_src, @config)
|
89
|
-
end
|
90
|
-
compiler
|
100
|
+
Compiler.new(f.name, f, @config)
|
91
101
|
end
|
92
102
|
|
93
103
|
end
|
data/lib/jbundle/config.rb
CHANGED
@@ -7,7 +7,7 @@ module JBundle
|
|
7
7
|
def initialize
|
8
8
|
@bundles = []
|
9
9
|
@files = []
|
10
|
-
@filters = []
|
10
|
+
@filters = {:all => [], :min => [], :src => []}
|
11
11
|
@after_write_blocks = []
|
12
12
|
end
|
13
13
|
|
@@ -40,8 +40,8 @@ module JBundle
|
|
40
40
|
@files << JBundle::File.new(f)
|
41
41
|
end
|
42
42
|
|
43
|
-
def filter(&block)
|
44
|
-
filters << block
|
43
|
+
def filter(mode = :all, &block)
|
44
|
+
filters[mode.to_sym] << block
|
45
45
|
end
|
46
46
|
|
47
47
|
def after_write(&block)
|
data/lib/jbundle/version.rb
CHANGED
data/spec/JFile
CHANGED
@@ -22,8 +22,19 @@ file 'nested/foo.txt'
|
|
22
22
|
|
23
23
|
file 'nested/foo.txt' => 'flat_foo.txt'
|
24
24
|
|
25
|
+
# Filter all
|
25
26
|
filter do |src, config|
|
26
|
-
src.gsub
|
27
|
+
src.gsub(/<VERSION>/, config.version.full)
|
28
|
+
end
|
29
|
+
|
30
|
+
# filter full src only
|
31
|
+
filter :src do |src, config|
|
32
|
+
src.gsub(/<SRC_MODE>/, 'src')
|
33
|
+
end
|
34
|
+
|
35
|
+
# filter minified src only
|
36
|
+
filter :min do |src, config|
|
37
|
+
src.gsub(/<SRC_MODE>/, 'min')
|
27
38
|
end
|
28
39
|
|
29
40
|
after_write do |config|
|
data/spec/jbundle_spec.rb
CHANGED
@@ -22,7 +22,7 @@ describe "JBundle" do
|
|
22
22
|
|
23
23
|
it 'should build single bundles' do
|
24
24
|
JBundle.build('foo.js').src.should == "var VERSION = '1.6.1';\nvar a1 = 1;\nvar a2 = 2;\n"
|
25
|
-
JBundle.build('file4.js').min.should == "var a4=4;\n"
|
25
|
+
JBundle.build('file4.js').min.should == "var a4=4,src_mode=\"min\";\n"
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'should bundle bundles' do
|
@@ -32,9 +32,9 @@ describe "JBundle" do
|
|
32
32
|
JBundle.output[0].min.should == "var VERSION=\"1.6.1\",a1=1,a2=2;\n"
|
33
33
|
end
|
34
34
|
|
35
|
-
it 'should not minify licenses' do
|
36
|
-
JBundle.build('foo2.js').src.should == "/* Version: 1.6.1
|
37
|
-
JBundle.build('foo2.js').min.should == "/* Version: 1.6.1
|
35
|
+
it 'should not minify licenses and run min and src filters' do
|
36
|
+
JBundle.build('foo2.js').src.should == "/* Version: 1.6.1. This is the src version.\nThis is a license\n-----------------------*/\nvar a3 = 3;\nvar a4 = 4;\nvar src_mode = 'src';\n"
|
37
|
+
JBundle.build('foo2.js').min.should == "/* Version: 1.6.1. This is the min version.\nThis is a license\n-----------------------*/\nvar a3=3,a4=4,src_mode=\"min\";\n"
|
38
38
|
end
|
39
39
|
|
40
40
|
end
|
data/spec/test_src/file4.js
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
var a4 = 4;
|
1
|
+
var a4 = 4;
|
2
|
+
var src_mode = '<SRC_MODE>';
|
data/spec/test_src/license.txt
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jbundle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 8
|
10
|
+
version: 0.0.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ismael Celis
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-01-
|
18
|
+
date: 2011-01-21 00:00:00 -03:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|