faster_asset_compiler 0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8cbb9b4cd427f05d2a59f1e65526f1379f3a438e
4
+ data.tar.gz: 86078f1e6a00c2164f43391734c9cc1096f0b392
5
+ SHA512:
6
+ metadata.gz: e16166a6ceee4d234db2de1310a5080b2e5fe996085dc51f3fbd794ba09cde4775225b68d48a813b401fb6d7d10b4f8589f12901bb157ed79e0361d9de44c45b
7
+ data.tar.gz: 58ad97cfe03837b76609544554db54c75b087b5ec0d00f5827e7b2905be74f11cb5092f9c75ae3abccca1219d7cd09ba1d000162ff7585409ebcd42e9bb1be46
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ jruby-1.7.5
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jorge Falcão
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # FasterAssetCompiler
2
+
3
+ A pure java yui and closure compressor, loading directly .jar files.
4
+
5
+ Current versions:
6
+ * yuicompressor: 2.4.8
7
+ * closure: v20130823
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'faster_asset_compiler'
14
+
15
+ And add to production.rb
16
+
17
+ config.assets.compress = true
18
+ config.assets.js_compressor = :yui # or closure - is a little bit slower than yui
19
+ config.assets.css_compressor = :yui
20
+
21
+ Restrictions:
22
+ * Don't use js_compressor = :yui and therubyrhino; don't work.
23
+
24
+ ## TODO
25
+
26
+ * Add more customization to compressors
27
+
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs.push "lib"
7
+ t.test_files = FileList['test/*_test.rb']
8
+ t.verbose = true
9
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'faster_asset_compiler/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "faster_asset_compiler"
8
+ spec.version = FasterAssetCompiler::VERSION
9
+ spec.authors = ["Jorge Falcão"]
10
+ spec.email = ["falcao@intelie.com.br"]
11
+ spec.description = %q{}
12
+ spec.summary = %q{A simple and faster rails asset compiler - JRuby only!}
13
+ spec.homepage = "https://github.com/jlbfalcao/faster_asset_compiler"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,38 @@
1
+
2
+ module Closure
3
+ class Compiler
4
+ def initialize
5
+ require File.expand_path "compiler.jar", File.dirname(__FILE__)
6
+
7
+ require 'java'
8
+ import com.google.javascript.jscomp.JSSourceFile
9
+ import com.google.javascript.jscomp.Compiler
10
+ import com.google.javascript.jscomp.VariableRenamingPolicy
11
+ import com.google.javascript.jscomp.CompilerOptions
12
+ import com.google.javascript.jscomp.CompilationLevel
13
+ import com.google.javascript.jscomp.WarningLevel
14
+ import java.util.logging.Level
15
+
16
+ @opts = CompilerOptions.new
17
+ # @opts.skipAllCompilerPasses()
18
+
19
+ # TODO: configure Compilation Level
20
+ CompilationLevel::SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(@opts)
21
+
22
+ # TODO: configure Warning Level
23
+ # WarningLevel.const_get(warning_level).setOptionsForWarningLevel(opts)
24
+ com.google.javascript.jscomp.Compiler.setLoggingLevel(Level::SEVERE)
25
+ end
26
+
27
+ def compress(js)
28
+ source = JSSourceFile.fromCode("unknown", js)
29
+ compiler ||= Java::ComGoogleJavascriptJscomp::Compiler.new
30
+
31
+ res = compiler.compile([], [source], @opts)
32
+ result = compiler.toSource() + "\n"
33
+
34
+ raise Error, result unless res.success
35
+ return result
36
+ end
37
+ end
38
+ end
data/lib/compiler.jar ADDED
Binary file
@@ -0,0 +1,3 @@
1
+ module FasterAssetCompiler
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "faster_asset_compiler/version"
2
+
3
+ module FasterAssetCompiler
4
+ # nothing todo
5
+ end
@@ -0,0 +1,67 @@
1
+
2
+ module YUI
3
+ class Compressor
4
+ def initialize
5
+ require File.expand_path('../yuicompressor-2.4.8.jar', __FILE__)
6
+ java_import java.io.InputStreamReader
7
+ java_import java.io.OutputStreamWriter
8
+ java_import com.yahoo.platform.yui.compressor.JavaScriptCompressor
9
+ java_import com.yahoo.platform.yui.compressor.CssCompressor
10
+ end
11
+
12
+ def stream(content, &block)
13
+ output = StringIO.new
14
+ reader = InputStreamReader.new(StringIO.new(content.to_s).to_inputstream)
15
+ writer = OutputStreamWriter.new(output.to_outputstream)
16
+ compressor = yield(reader, writer)
17
+
18
+ writer.flush
19
+ output.rewind
20
+ output.read
21
+ end
22
+ end
23
+
24
+ class ErrorReporter #:nodoc:
25
+ def error(message, source_name, line, line_source, line_offset)
26
+ if line < 0
27
+ "\n[ERROR] %s" % message
28
+ else
29
+ "\n[ERROR] %s:%s:%s" % [line, line_offset, message]
30
+ end
31
+ end
32
+
33
+ alias :warning :error
34
+
35
+ def runtimeError(*args)
36
+ raise 'Compression failed: %s' % error(*args)
37
+ end
38
+ end
39
+
40
+ class CssCompressor < Compressor
41
+ def compress(css)
42
+ stream(css) do |reader, writer|
43
+ compressor = Java::ComYahooPlatformYuiCompressor::CssCompressor.new(reader)
44
+ compressor.compress(writer, 0)
45
+ compressor
46
+ end
47
+ end
48
+ end
49
+
50
+ class JavaScriptCompressor < Compressor
51
+ def compress(js)
52
+ stream(js) do |reader, writer|
53
+ compressor = Java::ComYahooPlatformYuiCompressor::JavaScriptCompressor.new(reader, ErrorReporter.new)
54
+
55
+ linebreak = 0
56
+ munge = true
57
+ verbose = false
58
+ preserveAllSemiColons = false
59
+ disableOptimizations = false
60
+
61
+ compressor.compress(writer, linebreak, munge, verbose, preserveAllSemiColons, disableOptimizations)
62
+ compressor
63
+ end
64
+ end
65
+ end
66
+ end
67
+
Binary file
@@ -0,0 +1,18 @@
1
+ require 'test/unit'
2
+ require 'closure-compiler'
3
+
4
+ class Closure::CompilerTest < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @c = Closure::Compiler.new
8
+ end
9
+
10
+ def test_compressing_one_file
11
+ assert_equal @c.compress("function f(name) { return name;\n};\nalert('foo');\n"), "function f(a){return a}alert(\"foo\");\n"
12
+ end
13
+
14
+ def test_compressing_many_files
15
+ assert_equal @c.compress("var n = 10;\nalert('foo');\n"), "var n=10;alert(\"foo\");\n"
16
+ assert_equal @c.compress("var n = 10;\nalert('foo')\n var b = 's';;"), "var n=10;alert(\"foo\");var b=\"s\";\n"
17
+ end
18
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/setup'
2
+ Bundler.require :default, :test
3
+
4
+ # require 'active_support/test_case'
5
+ require 'minitest/autorun'
6
+ require 'mocha/setup'
@@ -0,0 +1,16 @@
1
+
2
+ require 'test/unit'
3
+ require 'yui/compressor'
4
+
5
+ class YUI::CssCompressorTest < Test::Unit::TestCase
6
+ def test_compressing_one_file
7
+ assert_equal YUI::CssCompressor.new.compress("#id {\n font-size: 10px; \n}\n"), "#id{font-size:10px}"
8
+ end
9
+
10
+ def test_compressing_many_files
11
+ c = YUI::CssCompressor.new
12
+ # assert_equal c.compress("#id {\n font-size: 10px; \n}\n"), "#id{font-size:10px}"
13
+ # assert_equal c.compress("#id {\n font-size: 10px; \n}\nbody {}\ndiv {background: #f0f;}\n"), "#id{font-size:10px}\ndiv{background:#f0f}"
14
+ end
15
+ end
16
+
@@ -0,0 +1,18 @@
1
+
2
+ require 'test/unit'
3
+ require 'yui/compressor'
4
+
5
+ class YUI::JavascriptCompressorTest < Test::Unit::TestCase
6
+ def setup
7
+ @c = YUI::JavaScriptCompressor.new
8
+ end
9
+ def test_compressing_one_file
10
+ assert_equal @c.compress("function f(name) { return name;\n};\nalert('foo');\n"), "function f(a){return a\n}alert(\"foo\");"
11
+ end
12
+
13
+ def test_compressing_many_files
14
+ assert_equal @c.compress("var n = 10;\nalert('foo');\n"), "var n=10;\nalert(\"foo\");"
15
+ assert_equal @c.compress("var n = 10;\nalert('foo')\n var b = 's';;"), "var n=10;\nalert(\"foo\");\nvar b=\"s\";"
16
+ end
17
+ end
18
+
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: faster_asset_compiler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jorge Falcão
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: '1.3'
25
+ prerelease: false
26
+ type: :development
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ prerelease: false
40
+ type: :development
41
+ description: ''
42
+ email:
43
+ - falcao@intelie.com.br
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - .ruby-version
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - faster_asset_compiler.gemspec
55
+ - lib/closure-compiler.rb
56
+ - lib/compiler.jar
57
+ - lib/faster_asset_compiler.rb
58
+ - lib/faster_asset_compiler/version.rb
59
+ - lib/yui/compressor.rb
60
+ - lib/yui/yuicompressor-2.4.8.jar
61
+ - test/closure_test.rb
62
+ - test/helper.rb
63
+ - test/yui_css_compressor_test.rb
64
+ - test/yui_js_compressor_test.rb
65
+ homepage: https://github.com/jlbfalcao/faster_asset_compiler
66
+ licenses:
67
+ - MIT
68
+ metadata: {}
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 2.1.5
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: A simple and faster rails asset compiler - JRuby only!
89
+ test_files:
90
+ - test/closure_test.rb
91
+ - test/helper.rb
92
+ - test/yui_css_compressor_test.rb
93
+ - test/yui_js_compressor_test.rb