cli-yui-compressor 0.3

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 (5) hide show
  1. data/LICENSE +18 -0
  2. data/README.md +17 -0
  3. data/bin/cli-yui-compressor +160 -0
  4. data/bin/cyc +9 -0
  5. metadata +68 -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.
@@ -0,0 +1,17 @@
1
+ # wbdv_packer – A RubyGem To Compress Javascript & CSS Files On The Command Prompt
2
+
3
+ ```
4
+ Usage: wbdv_packer [options] [filename]
5
+ -c, --charset [CHARSET] Sets the output charset (CSS & JS). Default: utf-8
6
+ -l, --line-break [NUMBER] Sets the max output line width (CSS & JS). Default: 1337
7
+ -o, --optimize Sets code optimization on compress (JS Only). Default: true
8
+ -p, --preserve Sets preserved semi-colons (JS Only). Default: true
9
+ -s, --short Sets shortened local variables (JS Only). Default: true
10
+ -v, --version Print version
11
+ -h, --help Display this screen
12
+ ```
13
+
14
+ ---
15
+ > Seraf Dos Santos
16
+ > MIT License
17
+ > Copyright (c) 2012 Seraf Dos Santos – All rights reserved.
@@ -0,0 +1,160 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ #
4
+ # cli-yui-compressor – 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 CliYuiCompressor
13
+ extend self
14
+
15
+ VERSION = Version = 0.3
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: cli-yui-compressor | cyc [options] [filename]"
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 CliYuiCompressor::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
+ newfile = compress_css_file(file[:filename],file[:input],charset,chars_num)
91
+ elsif file[:extension].downcase() == ".js"
92
+ newfile = compress_js_file(file[:filename],file[:input],charset,chars_num,short,optimize,preserve)
93
+ end
94
+ end
95
+
96
+ puts "\ncli-yui-compressor generated "+newfile
97
+
98
+ #if merge == true
99
+ # is_css = 0
100
+ # is_js = 0
101
+ # file_content = ""
102
+ # for file in files
103
+ # if file[:extension].downcase() == ".css"
104
+ # is_css+=1
105
+ # elsif file[:extension].downcase() == ".js"
106
+ # is_js+=1
107
+ # end
108
+ # file_content += "\n" + file[:input]
109
+ # end
110
+ # if is_css == files.length && is_js == 0
111
+ # compress_css(out_filename,file_content,charset,chars_num)
112
+ # elsif is_js == files.length && is_css == 0
113
+ # compress_js(out_filename,file_content,charset,chars_num,short,optimize,preserve)
114
+ # end
115
+ #else
116
+ # for file in files
117
+ # if file[:extension].downcase() == ".css"
118
+ # compress_css(file[:filename],file[:input],charset,chars_num)
119
+ # elsif file[:extension].downcase() == ".js"
120
+ # compress_js(file[:filename],file[:input],charset,chars_num,short,optimize,preserve)
121
+ # end
122
+ # end
123
+ #end
124
+
125
+ rescue => e
126
+ warn e
127
+ puts opts
128
+ end
129
+ end
130
+
131
+ def compress_css_file(filename,content,charset,line_break)
132
+ newname = filename.sub(/\.css$/,'.min.css')
133
+ f = File.new(newname, "w")
134
+ compressor = YUI::CssCompressor.new(:charset=>charset,:line_break=>line_break)
135
+ f.puts compressor.compress(content)
136
+ f.close
137
+ return newname
138
+ end
139
+
140
+ def compress_js_file(filename,content,charset,line_break,munge,optimize,preserve)
141
+ newname = filename.sub(/\.js$/,'.min.js')
142
+ f = File.new(newname, "w")
143
+ compressor = YUI::JavaScriptCompressor.new(:charset=>charset,:line_break=>line_break,:munge=>munge,:optimize=>optimize,:preserve_semicolons=>preserve)
144
+ f.puts compressor.compress(content)
145
+ f.close
146
+ return newname
147
+ end
148
+
149
+ def compress_css_code(content,charset,line_break)
150
+ compressor = YUI::CssCompressor.new(:charset=>charset,:line_break=>line_break)
151
+ puts compressor.compress(content)
152
+ end
153
+
154
+ def compress_js_code(content,charset,line_break,munge,optimize,preserve)
155
+ compressor = YUI::JavaScriptCompressor.new(:charset=>charset,:line_break=>line_break,:munge=>munge,:optimize=>optimize,:preserve_semicolons=>preserve)
156
+ puts compressor.compress(content)
157
+ end
158
+ end
159
+
160
+ CliYuiCompressor.execute(*ARGV)
data/bin/cyc ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ #
4
+ # cyc – Shorthand for cli-yui-compressor – Compresses Javascript & CSS Files with yui-compressor
5
+ # @author Seraf Dos Santos <webmaster@cyb3r.ca>
6
+ # @license MIT License
7
+ # @copyright (c) 2012 Seraf Dos Santos
8
+
9
+ system("cli-yui-compressor "+ARGV.join(" "))
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cli-yui-compressor
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: "0.3"
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 command line \n interface with yui-compressor. Run `cli-yui-compressor` \n or its shorthand `cyc`.\n \n Usage: cli-yui-compressor | cyc [options] [filename]\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 \n A \n \n"
27
+ email: webmaster@cyb3r.ca
28
+ executables:
29
+ - cli-yui-compressor
30
+ - cyc
31
+ extensions: []
32
+
33
+ extra_rdoc_files: []
34
+
35
+ files:
36
+ - README.md
37
+ - LICENSE
38
+ - bin/cli-yui-compressor
39
+ - bin/cyc
40
+ homepage: http://github.com/Syr3f/cli-yui-compressor
41
+ licenses: []
42
+
43
+ post_install_message:
44
+ rdoc_options: []
45
+
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ requirements:
61
+ - yui-compressor 0.9.4 or greater
62
+ rubyforge_project:
63
+ rubygems_version: 1.8.15
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Compresses Javascript & CSS Files On The Terminal
67
+ test_files: []
68
+