wbdv_packer 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.
Files changed (4) hide show
  1. data/LICENSE +18 -0
  2. data/README.md +0 -0
  3. data/bin/wbdv_packer +156 -0
  4. metadata +66 -0
data/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2012 Seraf Dos Santos
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
File without changes
data/bin/wbdv_packer ADDED
@@ -0,0 +1,156 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ #
4
+ # wbdv_packer – Compresses Javascript & CSS Files.
5
+ # @author Seraf Dos Santos <webmaster@cyb3r.ca>
6
+ # @license MIT License
7
+ # @copyright (c) 2012 Seraf Dos Santos
8
+
9
+ require "yui/compressor"
10
+ require "optparse"
11
+
12
+ module WbdVpacker
13
+ extend self
14
+
15
+ VERSION = Version = 0.1
16
+
17
+ def execute(*args)
18
+ charset = 'utf-8';
19
+ chars_num = 1337
20
+ optimize = false
21
+ preserve = false
22
+ short = false
23
+ #merge = false
24
+ #out_filename = nil
25
+
26
+ opts = OptionParser.new do |opts|
27
+
28
+ opts.banner = "Usage: wbdv_packer [options] [filename or stdin]"
29
+ #+" [filename] ..."
30
+
31
+ opts.on('-c', '--charset [CHARSET]', 'Sets the output charset (CSS & JS). Default: '+charset) do |c|
32
+ charset = c
33
+ end
34
+
35
+ opts.on('-l', '--line-break [NUMBER]', 'Sets the max output line width (CSS & JS). Default: '+chars_num.to_s()) do |l|
36
+ chars_num = l
37
+ end
38
+
39
+ opts.on('-o', '--optimize', 'Sets code optimization on compress (JS Only). Default: '+optimize.to_s()) do |o|
40
+ optimize = o
41
+ end
42
+
43
+ opts.on('-p', '--preserve', 'Sets preserved semi-colons (JS Only). Default: '+preserve.to_s()) do |p|
44
+ preserve = p
45
+ end
46
+
47
+ opts.on('-s', '--short', 'Sets shortened local variables (JS Only). Default: '+short.to_s()) do |s|
48
+ short = s
49
+ end
50
+
51
+ #opts.on('-e', '--merge', 'Flag for files merge.') do |e|
52
+ # merge = e
53
+ #end
54
+
55
+ #opts.on('-f', '--out-filename [FILENAME]', 'Identifies the output filename.') do |f|
56
+ # out_filename = f
57
+ #end
58
+
59
+ opts.on('-v', '--version', 'Print version') do
60
+ puts WbdVpacker::Version
61
+ exit
62
+ end
63
+
64
+ opts.on('-h', '--help', 'Display this screen') do
65
+ puts opts
66
+ exit
67
+ end
68
+ end
69
+
70
+ opts.parse!(args)
71
+
72
+ begin
73
+
74
+ if args.empty?
75
+ puts opts
76
+ exit
77
+ end
78
+
79
+ files = args.inject([]) do |files, file|
80
+ abort "Can't find #{file}" unless File.exists?(file)
81
+ files.push({
82
+ :input => File.read(file),
83
+ :filename => file,
84
+ :extension => (File.extname(file) if file.include?('.'))
85
+ })
86
+ end
87
+
88
+ for file in files
89
+ if file[:extension].downcase() == ".css"
90
+ compress_css_file(file[:filename],file[:input],charset,chars_num)
91
+ elsif file[:extension].downcase() == ".js"
92
+ compress_js_file(file[:filename],file[:input],charset,chars_num,short,optimize,preserve)
93
+ end
94
+ end
95
+
96
+ #if merge == true
97
+ # is_css = 0
98
+ # is_js = 0
99
+ # file_content = ""
100
+ # for file in files
101
+ # if file[:extension].downcase() == ".css"
102
+ # is_css+=1
103
+ # elsif file[:extension].downcase() == ".js"
104
+ # is_js+=1
105
+ # end
106
+ # file_content += "\n" + file[:input]
107
+ # end
108
+ # if is_css == files.length && is_js == 0
109
+ # compress_css(out_filename,file_content,charset,chars_num)
110
+ # elsif is_js == files.length && is_css == 0
111
+ # compress_js(out_filename,file_content,charset,chars_num,short,optimize,preserve)
112
+ # end
113
+ #else
114
+ # for file in files
115
+ # if file[:extension].downcase() == ".css"
116
+ # compress_css(file[:filename],file[:input],charset,chars_num)
117
+ # elsif file[:extension].downcase() == ".js"
118
+ # compress_js(file[:filename],file[:input],charset,chars_num,short,optimize,preserve)
119
+ # end
120
+ # end
121
+ #end
122
+
123
+ rescue => e
124
+ warn e
125
+ puts opts
126
+ end
127
+ end
128
+
129
+ def compress_css_file(filename,content,charset,line_break)
130
+ newname = filename.sub(/\.css$/,'.min.css')
131
+ f = File.new(newname, "w")
132
+ compressor = YUI::CssCompressor.new(:charset=>charset,:line_break=>line_break)
133
+ f.puts compressor.compress(content)
134
+ f.close
135
+ end
136
+
137
+ def compress_js_file(filename,content,charset,line_break,munge,optimize,preserve)
138
+ newname = filename.sub(/\.js$/,'.min.js')
139
+ f = File.new(newname, "w")
140
+ compressor = YUI::JavaScriptCompressor.new(:charset=>charset,:line_break=>line_break,:munge=>munge,:optimize=>optimize,:preserve_semicolons=>preserve)
141
+ f.puts compressor.compress(content)
142
+ f.close
143
+ end
144
+
145
+ def compress_css_code(content,charset,line_break)
146
+ compressor = YUI::CssCompressor.new(:charset=>charset,:line_break=>line_break)
147
+ puts compressor.compress(content)
148
+ end
149
+
150
+ def compress_js_code(content,charset,line_break,munge,optimize,preserve)
151
+ compressor = YUI::JavaScriptCompressor.new(:charset=>charset,:line_break=>line_break,:munge=>munge,:optimize=>optimize,:preserve_semicolons=>preserve)
152
+ puts compressor.compress(content)
153
+ end
154
+ end
155
+
156
+ WbdVpacker.execute(*ARGV)
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wbdv_packer
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: "0.1"
6
+ platform: ruby
7
+ authors:
8
+ - Seraf Dos Santos
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-01-23 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: yui-compressor
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - "="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.9.4
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ description: " Compresses Javascript & CSS files on the terminal.\n \n Usage: wbdv_packer [options] [filename or stdin]\n -c, --charset [CHARSET] Sets the output charset (CSS & JS). Default: utf-8\n -l, --line-break [NUMBER] Sets the max output line width (CSS & JS). Default: 1337\n -o, --optimize Sets code optimization on compress (JS Only). Default: true\n -p, --preserve Sets preserved semi-colons (JS Only). Default: true\n -s, --short Sets shortened local variables (JS Only). Default: true\n -v, --version Print version\n -h, --help Display this screen\n"
27
+ email: webmaster@cyb3r.ca
28
+ executables:
29
+ - wbdv_packer
30
+ extensions: []
31
+
32
+ extra_rdoc_files: []
33
+
34
+ files:
35
+ - README.md
36
+ - LICENSE
37
+ - bin/wbdv_packer
38
+ homepage: http://syr3f.github.com/wbdv_packer
39
+ licenses: []
40
+
41
+ post_install_message:
42
+ rdoc_options: []
43
+
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ requirements:
59
+ - yui-compressor 0.9.4 or greater
60
+ rubyforge_project:
61
+ rubygems_version: 1.8.15
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: Compresses Javascript & CSS Files On The Terminal
65
+ test_files: []
66
+