h5-min 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -11
- data/VERSION +1 -1
- data/lib/h5-min.rb +16 -1
- metadata +3 -3
data/Rakefile
CHANGED
@@ -21,17 +21,8 @@ rescue LoadError
|
|
21
21
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
22
22
|
end
|
23
23
|
|
24
|
-
require '
|
25
|
-
|
26
|
-
spec.libs << 'lib' << 'spec'
|
27
|
-
spec.spec_files = FileList['spec/**/*_spec.rb']
|
28
|
-
end
|
29
|
-
|
30
|
-
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
31
|
-
spec.libs << 'lib' << 'spec'
|
32
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
33
|
-
spec.rcov = true
|
34
|
-
end
|
24
|
+
require 'rspec/core/rake_task'
|
25
|
+
RSpec::Core::RakeTask.new(:spec)
|
35
26
|
|
36
27
|
task :spec => :check_dependencies
|
37
28
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/h5-min.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'nokogiri'
|
2
2
|
require 'htmlentities'
|
3
|
+
require 'tempfile'
|
3
4
|
require_relative 'h5-min/optional'
|
4
5
|
|
5
6
|
module HTML5
|
@@ -54,7 +55,7 @@ module HTML5
|
|
54
55
|
end
|
55
56
|
|
56
57
|
def cdata_block string
|
57
|
-
|
58
|
+
text_node << string
|
58
59
|
end
|
59
60
|
|
60
61
|
def characters chars
|
@@ -97,6 +98,7 @@ module HTML5
|
|
97
98
|
end
|
98
99
|
|
99
100
|
def format_text_node
|
101
|
+
return HTML5.minify_css(text_node) if @stack.last == :style
|
100
102
|
text = format_entities text_node, {quot: ?", apos: ?'}
|
101
103
|
return text if in_pre_element?
|
102
104
|
text.gsub!(/[\n\t]/,'')
|
@@ -121,6 +123,19 @@ module HTML5
|
|
121
123
|
end
|
122
124
|
end
|
123
125
|
|
126
|
+
def self.minify_css text
|
127
|
+
Tempfile.open('css') do |input|
|
128
|
+
input << text
|
129
|
+
input.close
|
130
|
+
return begin
|
131
|
+
`yuicompressor --type css --charset utf-8 #{input.to_path}`
|
132
|
+
rescue Errno::ENOENT
|
133
|
+
warn "yuicompressor not found; won't minify CSS"
|
134
|
+
text
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
124
139
|
def self.minify html
|
125
140
|
minifier = @minifier.new
|
126
141
|
Nokogiri::HTML::SAX::Parser.new(minifier).parse(html)
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
- 1
|
8
7
|
- 2
|
9
|
-
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Run Paint Run Run
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-09-26 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|