minify 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +14 -0
- data/examples/simple.rb +4 -0
- data/lib/core_ext/string.rb +9 -0
- data/lib/minify.rb +1 -1
- data/lib/minify/parser.rb +5 -0
- data/lib/minify/parser/class_methods.rb +45 -0
- data/lib/minify/parser/instance_methods.rb +4 -0
- data/lib/minify/parser/registered_mime_types.rb +43 -0
- data/minify-0.1.1.gem +0 -0
- data/minify.gemspec +1 -7
- data/pkg/minify-0.1.0.gem +0 -0
- metadata +14 -5
data/Gemfile.lock
ADDED
data/examples/simple.rb
ADDED
data/lib/minify.rb
CHANGED
@@ -0,0 +1,45 @@
|
|
1
|
+
class Minify
|
2
|
+
class Parser
|
3
|
+
class << self
|
4
|
+
include MetaTools
|
5
|
+
|
6
|
+
attr_reader :index
|
7
|
+
|
8
|
+
def register(mime_type, &blk)
|
9
|
+
mime_type = MIME::Types[mime_type].first unless mime_type.is_a?(MIME::Type)
|
10
|
+
meth = mime_type.sub_type.gsub(/-/, "_").to_sym
|
11
|
+
(@index ||= {})[mime_type.to_s] = meth
|
12
|
+
meta_def(meth, &blk)
|
13
|
+
end # Parser.register
|
14
|
+
|
15
|
+
def call(mime_type, input)
|
16
|
+
send(@index[mime_type], input)
|
17
|
+
end # Parser.call
|
18
|
+
|
19
|
+
#---
|
20
|
+
# HELPER METHODS
|
21
|
+
#+++
|
22
|
+
|
23
|
+
# Try to require multiple libraries and return the first library that exists
|
24
|
+
# and require it
|
25
|
+
def use(*libs)
|
26
|
+
lib = libs.find do |lib|
|
27
|
+
result = begin
|
28
|
+
r = require(lib)
|
29
|
+
puts "r: #{r}"
|
30
|
+
true
|
31
|
+
rescue LoadError
|
32
|
+
false
|
33
|
+
end
|
34
|
+
puts "result: #{result}"
|
35
|
+
result
|
36
|
+
end
|
37
|
+
puts "lib: #{lib}"
|
38
|
+
raise(LoadError, "no such files to load -- #{libs.join(", ")}") if lib.nil?
|
39
|
+
|
40
|
+
lib
|
41
|
+
end # Parser.use
|
42
|
+
|
43
|
+
end # << self
|
44
|
+
end # Parser
|
45
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
class Minify
|
2
|
+
class Parser
|
3
|
+
|
4
|
+
register 'text/plain' do |input|
|
5
|
+
input.trim.strip
|
6
|
+
end
|
7
|
+
|
8
|
+
register 'text/html' do |input|
|
9
|
+
p "YAY"
|
10
|
+
p input
|
11
|
+
|
12
|
+
case use('tidy-ext', 'tidy-fork', 'tidy_ffi', 'tidy')
|
13
|
+
when 'tidy' || 'tidy-fork' || 'tidy-ext'
|
14
|
+
Tidy.path = '/usr/lib/tidylib.so'
|
15
|
+
Tidy.open(:show_warnings=>true) do |tidy|
|
16
|
+
puts tidy.options.show_warnings
|
17
|
+
tidy.clean(input)
|
18
|
+
end
|
19
|
+
when 'tidy_ffi'
|
20
|
+
TidyFFI::Tidy.new(input).clean
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
register 'text/css' do |input|
|
25
|
+
case use('cssmin')
|
26
|
+
when 'cssmin'
|
27
|
+
CSSMin.minify(input)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
register 'application/javascript' do |input|
|
32
|
+
case use('jsmin_c', 'Jsmin', 'jsmin_ffi', 'jsmin')
|
33
|
+
when 'jsmin_c'
|
34
|
+
JS.new.minimize(input)
|
35
|
+
when 'jsmin' || 'Jsmin'
|
36
|
+
JS.minify(input)
|
37
|
+
when 'jsmin_ffi'
|
38
|
+
JS.minify!(input)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
data/minify-0.1.1.gem
ADDED
Binary file
|
data/minify.gemspec
CHANGED
@@ -13,12 +13,6 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.summary = "Minify JS, CSS, HTML, ..."
|
14
14
|
s.extra_rdoc_files = ["README.md"]
|
15
15
|
s.require_paths = ["lib"]
|
16
|
-
s.files = [
|
17
|
-
"LICENSE",
|
18
|
-
"README.md",
|
19
|
-
"Gemfile",
|
20
|
-
"minify.gemspec",
|
21
|
-
"lib/minify.rb"
|
22
|
-
]
|
16
|
+
s.files = Dir['**/*']
|
23
17
|
end
|
24
18
|
|
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -19,11 +19,20 @@ extensions: []
|
|
19
19
|
extra_rdoc_files:
|
20
20
|
- README.md
|
21
21
|
files:
|
22
|
-
-
|
23
|
-
- README.md
|
22
|
+
- examples/simple.rb
|
24
23
|
- Gemfile
|
25
|
-
-
|
24
|
+
- Gemfile.lock
|
25
|
+
- lib/core_ext/string.rb
|
26
|
+
- lib/minify/parser/class_methods.rb
|
27
|
+
- lib/minify/parser/instance_methods.rb
|
28
|
+
- lib/minify/parser/registered_mime_types.rb
|
29
|
+
- lib/minify/parser.rb
|
26
30
|
- lib/minify.rb
|
31
|
+
- LICENSE
|
32
|
+
- minify-0.1.1.gem
|
33
|
+
- minify.gemspec
|
34
|
+
- pkg/minify-0.1.0.gem
|
35
|
+
- README.md
|
27
36
|
has_rdoc: true
|
28
37
|
homepage: http://github.com/c00lryguy/minify
|
29
38
|
licenses: []
|
@@ -39,7 +48,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
39
48
|
version: '0'
|
40
49
|
segments:
|
41
50
|
- 0
|
42
|
-
hash:
|
51
|
+
hash: 4575470771353003559
|
43
52
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
53
|
none: false
|
45
54
|
requirements:
|