front-compiler 1.0.6

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,253 @@
1
+ require File.dirname(__FILE__)+"/../../../spec_helper"
2
+
3
+ describe FrontCompiler::JavaScript::SelfBuilder do
4
+ def new_script(src)
5
+ FrontCompiler::JavaScript.new(src)
6
+ end
7
+
8
+ def compact(src)
9
+ new_script(src).instance_eval do
10
+ compact_hashes_in(self).first
11
+ end
12
+ end
13
+
14
+ def build(src)
15
+ new_script(src).instance_eval do
16
+ process_hashes_in self
17
+ end
18
+ end
19
+
20
+ it "should compact the hash names in a simple case like that" do
21
+ compact(%{
22
+ var hash = {
23
+ first: 1,
24
+ second: 2,
25
+ third: 3,
26
+ copy: {
27
+ first: 1,
28
+ second: 2,
29
+ third: 3,
30
+ copy: {
31
+ first : 1,
32
+ second: 2,
33
+ third : 3,
34
+ copy: {
35
+ first : 1,
36
+ second: 2,
37
+ third : 3,
38
+ copy: function() {
39
+ var a = hash.first.second.third.copy();
40
+ var a = hash.first.second.third.copy();
41
+ var b = hash.firstsecond.thirdcopy();
42
+ }
43
+ }
44
+ }
45
+ }
46
+ }
47
+ }).should == %{
48
+ 8 7 = {
49
+ 5: 1,
50
+ 0: 2,
51
+ 4: 3,
52
+ 6: {
53
+ 5: 1,
54
+ 0: 2,
55
+ 4: 3,
56
+ 6: {
57
+ 5 : 1,
58
+ 0: 2,
59
+ 4 : 3,
60
+ 6: {
61
+ 5 : 1,
62
+ 0: 2,
63
+ 4 : 3,
64
+ 6: function() {
65
+ 8 a = 7.5.0.4.6();
66
+ 8 a = 7.5.0.4.6();
67
+ 8 b = 7.50.46();
68
+ }
69
+ }
70
+ }
71
+ }
72
+ }
73
+ }
74
+ end
75
+
76
+ it "should watch keys intersections when rename keys" do
77
+ compact(%{
78
+ var hash = {
79
+ a: 1,
80
+ b: 2,
81
+ c: {
82
+ avrora: {},
83
+ bear: {},
84
+ communism: function() {
85
+ hash.a.b.c.avrora().bear.communism();
86
+ hash.a.b.c.avrora().bear.communism();
87
+ }
88
+ }
89
+ }
90
+ }).should == %{
91
+ var 4 = {
92
+ a: 1,
93
+ b: 2,
94
+ c: {
95
+ 3: {},
96
+ 5: {},
97
+ 0: function() {
98
+ 4.a.b.c.3().5.0();
99
+ 4.a.b.c.3().5.0();
100
+ }
101
+ }
102
+ }
103
+ }
104
+ end
105
+
106
+ it "should watch other methods intersections when rename keys" do
107
+ compact(%{
108
+ var hash = {
109
+ first : 1,
110
+ second: 2,
111
+ third : function() {
112
+ var hash = hash.f.s.t();
113
+ var hash = hash.first.second.third();
114
+ var hash = hash.first.second.third();
115
+ }
116
+ }
117
+ }).should == %{
118
+ 6 0 = {
119
+ 5 : 1,
120
+ 3: 2,
121
+ 4 : function() {
122
+ 6 0 = 0.f.s.t();
123
+ 6 0 = 0.5.3.4();
124
+ 6 0 = 0.5.3.4();
125
+ }
126
+ }
127
+ }
128
+ end
129
+
130
+ it "should be casesensitive" do
131
+ compact(%{
132
+ var hash = {
133
+ camel: 1,
134
+ cAmel: 2,
135
+ caMeL: function() {
136
+ var camel = hash.camel.cAmel().caMeL;
137
+ var camel = hash.camel.cAmel().caMeL;
138
+ }
139
+ }
140
+ }).should == %{
141
+ 6 5 = {
142
+ 0: 1,
143
+ 4: 2,
144
+ 3: function() {
145
+ 6 0 = 5.0.4().3;
146
+ 6 0 = 5.0.4().3;
147
+ }
148
+ }
149
+ }
150
+ end
151
+
152
+ it "should not touch the standard constructions if they are present less then twice" do
153
+ compact(%{
154
+ var f = function () {
155
+ while () {
156
+ switch () {
157
+ }
158
+ }
159
+ }
160
+ }).should == %{
161
+ var f = function () {
162
+ while () {
163
+ switch () {
164
+ }
165
+ }
166
+ }
167
+ }
168
+ end
169
+
170
+ it "should shortify standard constructions when they appear in the code more than once" do
171
+ compact(%{
172
+ var function = function() {
173
+ switch () {
174
+ while () {
175
+ do();
176
+ }
177
+ }
178
+ };
179
+ var function = function name() {
180
+ switch () {
181
+ while () {
182
+ do();
183
+ }
184
+ }
185
+ };
186
+ }).should == %{
187
+ 3 0 = 0() {
188
+ 1 () {
189
+ 2 () {
190
+ do();
191
+ }
192
+ }
193
+ };
194
+ 3 0 = 0 name() {
195
+ 1 () {
196
+ 2 () {
197
+ do();
198
+ }
199
+ }
200
+ };
201
+ }
202
+ end
203
+
204
+ it "should not touch javascript commands which appears less than twice" do
205
+ compact(%{
206
+ return bla;
207
+ }).should == %{
208
+ return bla;
209
+ }
210
+ end
211
+
212
+ it "should compress commands which are appears in the code more than once" do
213
+ compact(%{
214
+ return bla;
215
+ return bla;
216
+ }).should == %{
217
+ 0 1;
218
+ 0 1;
219
+ }
220
+ end
221
+
222
+ it "should not touch javascript objects which appear less than twice in the code" do
223
+ compact(%{
224
+ Object.bla;
225
+ }).should == %{
226
+ Object.bla;
227
+ }
228
+ end
229
+
230
+ it "should compress objects which apperas in the code more than once" do
231
+ compact(%{
232
+ Object.bla;
233
+ Object.bla;
234
+ }).should == %{
235
+ 0.1;
236
+ 0.1;
237
+ }
238
+ end
239
+
240
+ it "should create a correct rebuild script" do
241
+ build(%{
242
+ var hash = {
243
+ first : '1',
244
+ second: "2",
245
+ third : /3/,
246
+ common: function() {
247
+ hash.first.second().third;
248
+ hash.first.second().third;
249
+ }
250
+ }
251
+ }).should == "eval((function(s,d){for(var i=d.length-1;i>-1;i--)if(d[i])s=s.replace(new RegExp(i,'g'),d[i]);return s})(\"\\n var 6 = {\\n 5 : '1',\\n 0: \\\"2\\\",\\n 4 : /3/,\\n common: function() {\\n 6.5.0().4;\\n 6.5.0().4;\\n }\\n }\\n \",\"second,,,,third,first,hash\".split(\",\")));"
252
+ end
253
+ end
@@ -0,0 +1,60 @@
1
+ require File.dirname(__FILE__)+"/../../spec_helper"
2
+
3
+ describe FrontCompiler::JavaScript do
4
+ def js(src)
5
+ FrontCompiler::JavaScript.new(src)
6
+ end
7
+
8
+ it "should remove comments" do
9
+ js(%{
10
+ /**
11
+ * bla bla bla
12
+ */
13
+ var bla = // bla bla bla
14
+ "bla // bla /* bla */";
15
+ }).remove_comments!.should == %{
16
+
17
+ var bla =
18
+ "bla // bla /* bla */";
19
+ }
20
+ end
21
+
22
+ it "should remove empty lines" do
23
+ js(%{
24
+
25
+ var str1 = "asdfsdf \\n\\n\\n asd";
26
+ var str2 = 'asdfasdf';
27
+
28
+
29
+
30
+ }).remove_empty_lines!.should == %{
31
+ var str1 = "asdfsdf \\n\\n\\n asd";
32
+ var str2 = 'asdfasdf';
33
+ }
34
+ end
35
+
36
+ it "should remove trailing spaces" do
37
+ js(%{
38
+ for ( var bla = "asdf + asdf"; bla.match(/sdfsdf [ ]/ ); [ sdfsdf % sdf ]) {
39
+ bla(
40
+ bla(bla, bla),
41
+ bla_bla / bla_bla_bla * sdfsd - asfasdf
42
+ );
43
+ }
44
+ }).remove_trailing_spaces!.should == "" \
45
+ "for(var bla=\"asdf + asdf\";bla.match(/sdfsdf [ ]/);[sdfsdf % sdf]){" \
46
+ "bla(bla(bla,bla),bla_bla/bla_bla_bla*sdfsd-asfasdf)}"
47
+ end
48
+
49
+ it "should escape/restore strings and regexps properly" do
50
+ js(%{
51
+ var str = "asdf \\\\ \\n /* asdf */";
52
+ var str = /\\D/;
53
+ var str = '\\D';
54
+ }).remove_comments!.should == %{
55
+ var str = "asdf \\\\ \\n /* asdf */";
56
+ var str = /\\D/;
57
+ var str = '\\D';
58
+ }
59
+ end
60
+ end
@@ -0,0 +1,26 @@
1
+ require File.dirname(__FILE__)+"/../../spec_helper"
2
+
3
+ describe FrontCompiler::SourceCode do
4
+ before :all do
5
+ @src = FrontCompiler::SourceCode.new("bla")
6
+ end
7
+ it "should extend the String class" do
8
+ @src.should == "bla"
9
+ end
10
+
11
+ it do
12
+ @src.should respond_to(:compact!)
13
+ end
14
+
15
+ it do
16
+ @src.should respond_to(:remove_comments!)
17
+ end
18
+
19
+ it do
20
+ @src.should respond_to(:remove_empty_lines!)
21
+ end
22
+
23
+ it do
24
+ @src.should respond_to(:remove_trailing_spaces!)
25
+ end
26
+ end
@@ -0,0 +1,34 @@
1
+ require File.dirname(__FILE__)+"/../spec_helper"
2
+ require "lib/front_compiler_helper"
3
+
4
+ describe FrontCompilerHelper do
5
+ include FrontCompilerHelper
6
+
7
+ def front_compiler
8
+ @c
9
+ end
10
+
11
+ before :all do
12
+ @c = FrontCompiler.new
13
+ end
14
+
15
+ it "should involve the js compactor" do
16
+ @c.should_receive(:compact_js).and_return('')
17
+ compact_js('')
18
+ end
19
+
20
+ it "should involve the css compactor" do
21
+ @c.should_receive(:compact_css).and_return('')
22
+ compact_css('')
23
+ end
24
+
25
+ it "should involve the html compactor" do
26
+ @c.should_receive(:compact_html).and_return('')
27
+ compact_html('')
28
+ end
29
+
30
+ it "should involve the css compactor" do
31
+ @c.should_receive(:inline_css).and_return('')
32
+ inline_css('')
33
+ end
34
+ end
@@ -0,0 +1,36 @@
1
+ require File.dirname(__FILE__)+"/../spec_helper"
2
+
3
+ describe FrontCompiler do
4
+ before :each do
5
+ @js = FrontCompiler::JavaScript.new ''
6
+ @css = FrontCompiler::CssSource.new ''
7
+ @html = FrontCompiler::HTMLCompactor.new
8
+
9
+ FrontCompiler::HTMLCompactor.should_receive(:new).and_return(@html)
10
+
11
+ @c = FrontCompiler.new
12
+ end
13
+
14
+ it "should involve the js compactor" do
15
+ FrontCompiler::JavaScript.should_receive(:new).and_return(@js)
16
+ @js.should_receive(:compact).and_return('')
17
+ @c.compact_js('')
18
+ end
19
+
20
+ it "should involve the css compactor" do
21
+ FrontCompiler::CssSource.should_receive(:new).and_return(@css)
22
+ @css.should_receive(:compact).and_return('')
23
+ @c.compact_css('')
24
+ end
25
+
26
+ it "should involve the html compactor" do
27
+ @html.should_receive(:minimize).and_return('')
28
+ @c.compact_html('')
29
+ end
30
+
31
+ it "should involve the css compactor" do
32
+ FrontCompiler::CssSource.should_receive(:new).and_return(@css)
33
+ @css.should_receive(:to_javascript).and_return('')
34
+ @c.inline_css('')
35
+ end
36
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,5 @@
1
+ --colour
2
+ --diff
3
+ --format progress
4
+ --loadby mtime
5
+ --reverse
@@ -0,0 +1,7 @@
1
+ require "spec"
2
+
3
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
4
+
5
+ require 'front_compiler'
6
+ require 'front_compiler/source_code'
7
+ require 'front_compiler/java_script'
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: front-compiler
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.6
5
+ platform: ruby
6
+ authors:
7
+ - Nikolay Nemshilov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-14 00:00:00 +03:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: FrontCompiler is a Ruby based JavaScript/CSS/HTML compressor. It provides the basic JavaScript/CSS/HTML minifying feature. Plus it can create albeit packed JavaScript files, can inline CSS inside JavaScript, works with DRYed CSS files and also can work as a RubyOnRails plugin.
17
+ email: nemshilov@gmail.com
18
+ executables:
19
+ - frontcc
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/front-compiler.rb
26
+ - lib/front_compiler/css_source/nested_styles.rb
27
+ - lib/front_compiler/css_source.rb
28
+ - lib/front_compiler/html_compactor.rb
29
+ - lib/front_compiler/java_script/logic_compactor.rb
30
+ - lib/front_compiler/java_script/names_compactor.rb
31
+ - lib/front_compiler/java_script/self_builder.rb
32
+ - lib/front_compiler/java_script.rb
33
+ - lib/front_compiler/source_code.rb
34
+ - lib/front_compiler.rb
35
+ - lib/front_compiler_helper.rb
36
+ - spec/lib/front_compiler/css_source/nested_styles_spec.rb.rb
37
+ - spec/lib/front_compiler/css_source_spec.rb
38
+ - spec/lib/front_compiler/html_compactor_spec.rb
39
+ - spec/lib/front_compiler/java_script/logic_compactor_spec.rb
40
+ - spec/lib/front_compiler/java_script/names_compactor_spec.rb
41
+ - spec/lib/front_compiler/java_script/self_builder_spec.rb
42
+ - spec/lib/front_compiler/java_script_spec.rb
43
+ - spec/lib/front_compiler/source_code_spec.rb
44
+ - spec/lib/front_compiler_helper_spec.rb
45
+ - spec/lib/front_compiler_spec.rb
46
+ - spec/spec.opts
47
+ - spec/spec_helper.rb
48
+ - README
49
+ - LICENSE
50
+ - CHANGELOG
51
+ - Rakefile
52
+ - init.rb
53
+ has_rdoc: true
54
+ homepage: http://github.com/MadRabbit/frontcompiler
55
+ licenses: []
56
+
57
+ post_install_message:
58
+ rdoc_options: []
59
+
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ version:
74
+ requirements: []
75
+
76
+ rubyforge_project:
77
+ rubygems_version: 1.3.5
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: FrontCompiler is a Ruby based JavaScript/CSS/HTML compressor
81
+ test_files: []
82
+