evax 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ tmp
6
+ .rvmrc
@@ -0,0 +1 @@
1
+ rvm use 1.9.2@evax
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
@@ -0,0 +1 @@
1
+ # Evax
@@ -0,0 +1,17 @@
1
+ # require 'bundler/gem_tasks'
2
+
3
+ require 'rake'
4
+ require 'rake/testtask'
5
+ require 'bundler'
6
+
7
+ include Rake::DSL
8
+
9
+ Bundler::GemHelper.install_tasks
10
+
11
+ task :default => :test
12
+
13
+ Rake::TestTask.new do |t|
14
+ t.libs << '.'
15
+ t.test_files = FileList['test/*_test.rb']
16
+ t.verbose = true
17
+ end
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Use:
4
+ # evax /path/to/assets.yml /relative/path
5
+
6
+ begin
7
+ require 'evax'
8
+ rescue LoadError
9
+ require 'rubygems'
10
+ require 'evax'
11
+ end
12
+
13
+ if( ARGV.size < 2 )
14
+ puts "use: $ evax <config_file_path> <relative_path>"
15
+ exit 1
16
+ end
17
+
18
+ Evax.new( ARGV[0], ARGV[1] ).build
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "evax/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "evax"
7
+ s.version = Evax::VERSION
8
+ s.authors = ["Fernando Guillen", "Juan Vidal"]
9
+ s.email = ["fguillen.mail@gmail.com", "juanjicho@gmail.com "]
10
+ s.homepage = ""
11
+ s.summary = "Very simple assets compressor"
12
+ s.description = "Very simple assets compressor"
13
+
14
+ s.rubyforge_project = "evax"
15
+
16
+ s.add_development_dependency "bundler", ">= 1.0.0.rc.6"
17
+ s.add_development_dependency "rake"
18
+ s.add_development_dependency "uglifier"
19
+
20
+ s.add_development_dependency "mocha"
21
+
22
+ s.files = `git ls-files`.split("\n")
23
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
24
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
25
+ s.require_paths = ["lib"]
26
+ end
@@ -0,0 +1,74 @@
1
+ require "yaml"
2
+ require "uglifier"
3
+
4
+ require_relative "evax/version"
5
+ require_relative "evax/css_minifier"
6
+
7
+ class Evax
8
+ attr_reader :config_file, :relative_path
9
+
10
+ def initialize( config_file, relative_path )
11
+ @config_file = config_file
12
+ @relative_path = relative_path
13
+
14
+ puts "[Evax] Config File: #{config_file}"
15
+ puts "[Evax] Relative Path: #{relative_path}"
16
+ end
17
+
18
+ def config
19
+ YAML::load_file( @config_file )
20
+ end
21
+
22
+ def join( type, group_name )
23
+ config[type.to_s][group_name].map do |file_path|
24
+ File.read file_path
25
+ end.join( "\n" )
26
+ end
27
+
28
+ def build
29
+ build_js
30
+ build_css
31
+ end
32
+
33
+ def build_js
34
+ config["javascripts"].each_key do |group_name|
35
+ join_string = join( :javascripts, group_name )
36
+ compress_string = Evax.compress_js( join_string )
37
+
38
+ write_output( "#{group_name}.js", compress_string )
39
+ end
40
+ end
41
+
42
+ def build_css
43
+ config["stylesheets"].each_key do |group_name|
44
+ join_string = join( :stylesheets, group_name )
45
+ compress_string = Evax.compress_css( join_string )
46
+
47
+ write_output( "#{group_name}.css", compress_string )
48
+ end
49
+ end
50
+
51
+ def write_output( file_name, string )
52
+ path = File.expand_path( File.join( relative_path, config['output_path'] ) )
53
+ file_path = File.join( path, file_name )
54
+
55
+ puts "[Evax] Writting file: #{file_path}"
56
+
57
+ FileUtils.mkdir_p path
58
+ File.open( file_path, 'w') { |f| f.write string }
59
+ end
60
+
61
+ def self.compress_js( js_string )
62
+ opts = {
63
+ :max_line_length => 1024,
64
+ :toplevel => true,
65
+ :copyright => false
66
+ }
67
+ Uglifier.compile( js_string, opts )
68
+ end
69
+
70
+ def self.compress_css( css_string )
71
+ Evax::CssMinifier.build( css_string )
72
+ end
73
+
74
+ end
@@ -0,0 +1,17 @@
1
+ module Evax::CssMinifier
2
+
3
+ def self.build(css_string)
4
+ css_string.split('}').map do |block|
5
+ block.gsub!(/\n/,' ')
6
+ block.gsub!(/\/\*.*?\*\//m,'')
7
+ block.gsub!(/\s*:\s*/, ':')
8
+ block.gsub!(/\s*;\s*/, ';')
9
+ block.gsub!(/\s*,\s*/, ',')
10
+ block.gsub!(/\s*\{\s*/, '{')
11
+ block.gsub!(/\s\s+/, ' ')
12
+
13
+ block.strip + '}' if block.include?('{')
14
+ end.join(' ')
15
+ end
16
+
17
+ end
@@ -0,0 +1,3 @@
1
+ class Evax
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,76 @@
1
+ require 'test/unit'
2
+ require "mocha"
3
+ require_relative "../lib/evax.rb"
4
+
5
+ FIXTURES = "#{File.dirname(__FILE__)}/fixtures"
6
+
7
+ class EvaxTest < Test::Unit::TestCase
8
+ def test_initialize
9
+ evax = Evax.new( "wadus", "tradus" )
10
+ assert_equal( "wadus", evax.config_file )
11
+ assert_equal( "tradus", evax.relative_path )
12
+ end
13
+
14
+ def test_read_config_file
15
+ evax = Evax.new( "#{FIXTURES}/assets.yml", nil )
16
+ assert_equal( "tmp/", evax.config["output_path"] )
17
+ assert_equal( 2, evax.config["javascripts"].size )
18
+ end
19
+
20
+ def test_join_js_files
21
+ evax = Evax.new( "#{FIXTURES}/assets.yml", nil )
22
+ assert_equal File.read("#{FIXTURES}/js_one.js"), evax.join( :javascripts, "js_one" )
23
+ end
24
+
25
+ def test_join_css_files
26
+ evax = Evax.new( "#{FIXTURES}/assets.yml", nil )
27
+
28
+ assert_equal File.read("#{FIXTURES}/css_one.css"), evax.join( :stylesheets, "css_one" )
29
+ end
30
+
31
+ def test_compress_js
32
+ result = Evax.compress_js( File.read( "#{FIXTURES}/js_one.js" ) )
33
+
34
+ assert_equal( File.read( "#{FIXTURES}/js_one.compress.js" ), result)
35
+ end
36
+
37
+ def test_compress_css
38
+ result = Evax.compress_css( File.read( "#{FIXTURES}/css_one.css" ) )
39
+
40
+ assert_equal( File.read( "#{FIXTURES}/css_one.compress.css" ), result)
41
+ end
42
+
43
+ def test_write_output
44
+ Dir.mktmpdir do |dir|
45
+ evax = Evax.new( "#{FIXTURES}/assets.yml", dir )
46
+ evax.write_output( "wadus.txt", "write this!" )
47
+
48
+ assert_equal( "write this!", File.read( "#{dir}/tmp/wadus.txt" ) )
49
+ end
50
+ end
51
+
52
+ def test_build_js
53
+ evax = Evax.new( "#{FIXTURES}/assets.yml", "#{File.dirname(__FILE__)}/.." )
54
+ evax.expects( :write_output ).with( "js_one.js", File.read( "#{FIXTURES}/js_one.compress.js" ) )
55
+ evax.expects( :write_output ).with( "js_two.js", File.read( "#{FIXTURES}/js_two.compress.js" ) )
56
+
57
+ evax.build_js
58
+ end
59
+
60
+ def test_build_css
61
+ evax = Evax.new( "#{FIXTURES}/assets.yml", "#{File.dirname(__FILE__)}/.." )
62
+ evax.expects( :write_output ).with( "css_one.css", File.read( "#{FIXTURES}/css_one.compress.css" ) )
63
+ evax.expects( :write_output ).with( "css_two.css", File.read( "#{FIXTURES}/css_two.compress.css" ) )
64
+
65
+ evax.build_css
66
+ end
67
+
68
+ def test_build
69
+ evax = Evax.new( nil, nil )
70
+ evax.expects( :build_js )
71
+ evax.expects( :build_css )
72
+
73
+ evax.build
74
+ end
75
+
76
+ end
@@ -0,0 +1,17 @@
1
+ output_path: tmp/
2
+
3
+ javascripts:
4
+ js_one:
5
+ - test/fixtures/javascripts/one.js
6
+ - test/fixtures/javascripts/two.js
7
+ - test/fixtures/javascripts/three.js
8
+ js_two:
9
+ - test/fixtures/javascripts/four.js
10
+
11
+ stylesheets:
12
+ css_one:
13
+ - test/fixtures/stylesheets/one.css
14
+ - test/fixtures/stylesheets/two.css
15
+ css_two:
16
+ - test/fixtures/stylesheets/three.css
17
+ - test/fixtures/stylesheets/four.css
@@ -0,0 +1 @@
1
+ #my-id-one{background-color:pink;} #my-id-two{background-color:pink;}
@@ -0,0 +1,9 @@
1
+ /* CSS ONE */
2
+ #my-id-one{
3
+ background-color: pink;
4
+ }
5
+
6
+ /* CSS TWO */
7
+ #my-id-two{
8
+ background-color: pink;
9
+ }
@@ -0,0 +1 @@
1
+ #my-id-three{background-color:pink;} #my-id-four{background-color:pink;}
@@ -0,0 +1,3 @@
1
+ /* This is the JS FOUR */
2
+ function js_four(){
3
+ }
@@ -0,0 +1,3 @@
1
+ /* This is the JS ONE */
2
+ function js_one(){
3
+ }
@@ -0,0 +1,3 @@
1
+ /* This is the JS THREE */
2
+ function js_three(){
3
+ }
@@ -0,0 +1,3 @@
1
+ /* This is the JS TWO */
2
+ function js_two(){
3
+ }
@@ -0,0 +1 @@
1
+ function a(){}function b(){}function c(){}
@@ -0,0 +1,9 @@
1
+ /* This is the JS ONE */
2
+ function js_one(){
3
+ }
4
+ /* This is the JS TWO */
5
+ function js_two(){
6
+ }
7
+ /* This is the JS THREE */
8
+ function js_three(){
9
+ }
@@ -0,0 +1 @@
1
+ function a(){}
@@ -0,0 +1,4 @@
1
+ /* CSS FOUR */
2
+ #my-id-four{
3
+ background-color: pink;
4
+ }
@@ -0,0 +1,4 @@
1
+ /* CSS ONE */
2
+ #my-id-one{
3
+ background-color: pink;
4
+ }
@@ -0,0 +1,4 @@
1
+ /* CSS THREE */
2
+ #my-id-three{
3
+ background-color: pink;
4
+ }
@@ -0,0 +1,4 @@
1
+ /* CSS TWO */
2
+ #my-id-two{
3
+ background-color: pink;
4
+ }
metadata ADDED
@@ -0,0 +1,162 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: evax
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 2
9
+ version: 0.0.2
10
+ platform: ruby
11
+ authors:
12
+ - Fernando Guillen
13
+ - Juan Vidal
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-12-12 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: bundler
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ segments:
30
+ - 1
31
+ - 0
32
+ - 0
33
+ - rc
34
+ - 6
35
+ version: 1.0.0.rc.6
36
+ type: :development
37
+ version_requirements: *id001
38
+ - !ruby/object:Gem::Dependency
39
+ name: rake
40
+ prerelease: false
41
+ requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ type: :development
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: uglifier
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ type: :development
63
+ version_requirements: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ name: mocha
66
+ prerelease: false
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ type: :development
76
+ version_requirements: *id004
77
+ description: Very simple assets compressor
78
+ email:
79
+ - fguillen.mail@gmail.com
80
+ - "juanjicho@gmail.com "
81
+ executables:
82
+ - evax
83
+ extensions: []
84
+
85
+ extra_rdoc_files: []
86
+
87
+ files:
88
+ - .gitignore
89
+ - .rvmrc.example
90
+ - Gemfile
91
+ - README.md
92
+ - Rakefile
93
+ - bin/evax
94
+ - evax.gemspec
95
+ - lib/evax.rb
96
+ - lib/evax/css_minifier.rb
97
+ - lib/evax/version.rb
98
+ - test/evax_test.rb
99
+ - test/fixtures/assets.yml
100
+ - test/fixtures/css_one.compress.css
101
+ - test/fixtures/css_one.css
102
+ - test/fixtures/css_two.compress.css
103
+ - test/fixtures/javascripts/four.js
104
+ - test/fixtures/javascripts/one.js
105
+ - test/fixtures/javascripts/three.js
106
+ - test/fixtures/javascripts/two.js
107
+ - test/fixtures/js_one.compress.js
108
+ - test/fixtures/js_one.js
109
+ - test/fixtures/js_two.compress.js
110
+ - test/fixtures/stylesheets/four.css
111
+ - test/fixtures/stylesheets/one.css
112
+ - test/fixtures/stylesheets/three.css
113
+ - test/fixtures/stylesheets/two.css
114
+ has_rdoc: true
115
+ homepage: ""
116
+ licenses: []
117
+
118
+ post_install_message:
119
+ rdoc_options: []
120
+
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ segments:
129
+ - 0
130
+ version: "0"
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ none: false
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ segments:
137
+ - 0
138
+ version: "0"
139
+ requirements: []
140
+
141
+ rubyforge_project: evax
142
+ rubygems_version: 1.3.7
143
+ signing_key:
144
+ specification_version: 3
145
+ summary: Very simple assets compressor
146
+ test_files:
147
+ - test/evax_test.rb
148
+ - test/fixtures/assets.yml
149
+ - test/fixtures/css_one.compress.css
150
+ - test/fixtures/css_one.css
151
+ - test/fixtures/css_two.compress.css
152
+ - test/fixtures/javascripts/four.js
153
+ - test/fixtures/javascripts/one.js
154
+ - test/fixtures/javascripts/three.js
155
+ - test/fixtures/javascripts/two.js
156
+ - test/fixtures/js_one.compress.js
157
+ - test/fixtures/js_one.js
158
+ - test/fixtures/js_two.compress.js
159
+ - test/fixtures/stylesheets/four.css
160
+ - test/fixtures/stylesheets/one.css
161
+ - test/fixtures/stylesheets/three.css
162
+ - test/fixtures/stylesheets/two.css