shine 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.
- data/LICENSE +20 -0
- data/README +2 -0
- data/Rakefile +27 -0
- data/bin/shine +8 -0
- data/lib/shine.rb +186 -0
- metadata +86 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Garry Hill <garry@magnetised.info>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all 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,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
20
|
+
|
data/README
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
# Gem::manage_gems
|
3
|
+
require 'rake/gempackagetask'
|
4
|
+
|
5
|
+
spec = Gem::Specification.new do |s|
|
6
|
+
s.name = "Shine"
|
7
|
+
s.version = "0.0.1"
|
8
|
+
s.author = "Garry Hill"
|
9
|
+
s.email = "garry@magnetised.info"
|
10
|
+
s.homepage = "http://shine.magnetised.info/" s.platform = Gem::Platform::RUBY
|
11
|
+
s.summary = "Shine provides a Java-free way to use the excellent YUI compressor"
|
12
|
+
s.files = FileList["{bin,lib}/**/*"].to_a
|
13
|
+
s.require_path = "lib"
|
14
|
+
s.autorequire = "name"
|
15
|
+
s.test_files = FileList["{test}/**/*test.rb"].to_a
|
16
|
+
s.has_rdoc = true
|
17
|
+
s.extra_rdoc_files = ["README"]
|
18
|
+
s.add_dependency("multipart-post", ">= 1.0")
|
19
|
+
end
|
20
|
+
|
21
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
22
|
+
pkg.need_tar = true
|
23
|
+
end
|
24
|
+
task :default => "pkg/#{spec.name}-#{spec.version}.gem" do
|
25
|
+
puts "generated latest version"
|
26
|
+
end
|
27
|
+
|
data/bin/shine
ADDED
data/lib/shine.rb
ADDED
@@ -0,0 +1,186 @@
|
|
1
|
+
# Copyright (c) 2009 Garry Hill <garry@magnetised.info>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all 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,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require 'rubygems'
|
22
|
+
require 'net/http/post/multipart'
|
23
|
+
|
24
|
+
module Shine
|
25
|
+
class CompressionError < Exception; end
|
26
|
+
|
27
|
+
MIME = {
|
28
|
+
:js => "text/javascript",
|
29
|
+
:css => "text/css"
|
30
|
+
}
|
31
|
+
@_server = nil
|
32
|
+
|
33
|
+
def self.default_server
|
34
|
+
"http://shine.magnetised.info"
|
35
|
+
end
|
36
|
+
def self.server
|
37
|
+
@_server || default_server
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.server=(url)
|
41
|
+
@_server = url
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.compress_url(format=:js)
|
45
|
+
# URI.parse("http://shine.magnetised.info/#{format}")
|
46
|
+
URI.parse("#{server}/#{format}")
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.compress_js(filepaths, options={})
|
50
|
+
compress_files(filepaths, :js, options)
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.compress_css(filepaths, options={})
|
54
|
+
compress_files(filepaths, :css, options)
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.compress_files(filepaths, format=nil, options={})
|
58
|
+
filepaths = [filepaths] unless filepaths.is_a?(Array)
|
59
|
+
url = compress_url(format)
|
60
|
+
options = options.reject { |k, v| !v }
|
61
|
+
params = {}
|
62
|
+
begin
|
63
|
+
files = filepaths.map {|f| File.open(f) }
|
64
|
+
filepaths.each_with_index do |f, i|
|
65
|
+
params["file#{i.to_s.rjust(4, "0")}"] = UploadIO.new(f, MIME[format], filepaths[i])
|
66
|
+
end
|
67
|
+
req = Net::HTTP::Post::Multipart.new(url.path, params.merge(options))
|
68
|
+
result = Net::HTTP.start(url.host, url.port) do |http|
|
69
|
+
http.request(req)
|
70
|
+
end
|
71
|
+
case result
|
72
|
+
when Net::HTTPSuccess
|
73
|
+
result.body
|
74
|
+
else
|
75
|
+
concatenate_files(files)
|
76
|
+
end
|
77
|
+
ensure
|
78
|
+
files.each { |f| f.close rescue nil }
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.concatenate_files(files)
|
83
|
+
files.map {|f| f.read }.join("\n")
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.compress_string(source, format=nil, options={})
|
87
|
+
url = compress_url(format)
|
88
|
+
req = Net::HTTP::Post.new(url.path)
|
89
|
+
options = options.reject { |k, v| !v }
|
90
|
+
req.set_form_data({'source' => source}.merge(options))
|
91
|
+
result = Net::HTTP.start(url.host, url.port) do |http|
|
92
|
+
http.request(req)
|
93
|
+
end
|
94
|
+
case result
|
95
|
+
when Net::HTTPSuccess
|
96
|
+
result.body
|
97
|
+
else
|
98
|
+
source
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
module JS
|
103
|
+
def self.in_place(input_file_path)
|
104
|
+
compressor = Shine::JS::Compressor.new(input_file_path)
|
105
|
+
compressor.compress_in_place
|
106
|
+
end
|
107
|
+
|
108
|
+
def self.string(js, options={})
|
109
|
+
begin
|
110
|
+
Shine.compress_string(js, :js, options)
|
111
|
+
rescue CompressionError
|
112
|
+
js
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def self.file(f, options={})
|
117
|
+
self.files(f, options)
|
118
|
+
end
|
119
|
+
|
120
|
+
def self.files(input_files, options={})
|
121
|
+
input_files = [input_files] unless input_files.is_a?(Array)
|
122
|
+
input_files.flatten!
|
123
|
+
compressor = Shine::JS::Compressor.new(input_files)
|
124
|
+
compressor.compress(options)
|
125
|
+
end
|
126
|
+
|
127
|
+
class Compressor
|
128
|
+
def initialize(filepaths)
|
129
|
+
@filepaths = filepaths
|
130
|
+
end
|
131
|
+
|
132
|
+
def compress(options={})
|
133
|
+
Shine.compress_js(@filepaths, options)
|
134
|
+
end
|
135
|
+
|
136
|
+
def compress_in_place(options={})
|
137
|
+
@filepaths.each do |p|
|
138
|
+
c = Shine.compress_js(p, options)
|
139
|
+
File.open(p, 'w') { |f| f.write(c) }
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
module CSS
|
145
|
+
def self.in_place(input_file_path)
|
146
|
+
compressor = Shine::CSS::Compressor.new(input_file_path)
|
147
|
+
compressor.compress_in_place
|
148
|
+
end
|
149
|
+
|
150
|
+
def self.string(css, options={})
|
151
|
+
begin
|
152
|
+
Shine.compress_string(css, :css, options)
|
153
|
+
rescue CompressionError
|
154
|
+
js
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def self.file(f, options={})
|
159
|
+
self.files(f, options)
|
160
|
+
end
|
161
|
+
|
162
|
+
def self.files(input_files, options={})
|
163
|
+
input_files = [input_files] unless input_files.is_a?(Array)
|
164
|
+
input_files.flatten!
|
165
|
+
compressor = Shine::CSS::Compressor.new(input_files)
|
166
|
+
compressor.compress(options)
|
167
|
+
end
|
168
|
+
|
169
|
+
class Compressor
|
170
|
+
def initialize(filepaths)
|
171
|
+
@filepaths = filepaths
|
172
|
+
end
|
173
|
+
|
174
|
+
def compress(options={})
|
175
|
+
Shine.compress_css(@filepaths, options)
|
176
|
+
end
|
177
|
+
|
178
|
+
def compress_in_place(options={})
|
179
|
+
@filepaths.each do |p|
|
180
|
+
c = Shine.compress_css(p, options)
|
181
|
+
File.open(p, 'w') { |f| f.write(c) }
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shine
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 7
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 6
|
9
|
+
version: "0.6"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Garry Hill
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2009-07-27 00:00:00 +01:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: multipart-post
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 15
|
29
|
+
segments:
|
30
|
+
- 1
|
31
|
+
- 0
|
32
|
+
version: "1.0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
description: shine provides YUI compression without the need for java to be installed
|
36
|
+
email: garry@magnetised.info
|
37
|
+
executables:
|
38
|
+
- shine
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- README
|
43
|
+
- LICENSE
|
44
|
+
files:
|
45
|
+
- README
|
46
|
+
- LICENSE
|
47
|
+
- Rakefile
|
48
|
+
- bin/shine
|
49
|
+
- lib/shine.rb
|
50
|
+
has_rdoc: false
|
51
|
+
homepage: http://shine.magnetised.info
|
52
|
+
licenses: []
|
53
|
+
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options:
|
56
|
+
- --inline-source
|
57
|
+
- --charset=UTF-8
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
hash: 3
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
version: "0"
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project: shine
|
81
|
+
rubygems_version: 1.6.2
|
82
|
+
signing_key:
|
83
|
+
specification_version: 2
|
84
|
+
summary: shine provides YUI compression without the need for java to be installed.
|
85
|
+
test_files: []
|
86
|
+
|