htmlmin 0.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.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +64 -0
- data/Rakefile +9 -0
- data/htmlmin.gemspec +22 -0
- data/lib/htmlmin/buffer.rb +30 -0
- data/lib/htmlmin/slot_machines/comment.rb +53 -0
- data/lib/htmlmin/slot_machines/common.rb +102 -0
- data/lib/htmlmin/slot_machines/doctype.rb +135 -0
- data/lib/htmlmin/slot_machines/tag.rb +83 -0
- data/lib/htmlmin/slot_machines.rb +4 -0
- data/lib/htmlmin/version.rb +3 -0
- data/lib/htmlmin.rb +85 -0
- data/test/input/cc_1.txt +8 -0
- data/test/input/comment_1.txt +1 -0
- data/test/input/comment_2.txt +1 -0
- data/test/input/comment_3.txt +1 -0
- data/test/input/comment_4.txt +1 -0
- data/test/input/comment_5.txt +11 -0
- data/test/input/comment_6.txt +7 -0
- data/test/input/doctype_1.txt +1 -0
- data/test/input/doctype_2.txt +6 -0
- data/test/input/tag_1.txt +7 -0
- data/test/input/tag_2.txt +6 -0
- data/test/input/text_1.txt +5 -0
- data/test/input/text_2.txt +1 -0
- data/test/input/text_3.txt +4 -0
- data/test/output/cc_1.txt +1 -0
- data/test/output/comment_1.txt +0 -0
- data/test/output/comment_2.txt +0 -0
- data/test/output/comment_3.txt +0 -0
- data/test/output/comment_4.txt +0 -0
- data/test/output/comment_5.txt +0 -0
- data/test/output/comment_6.txt +1 -0
- data/test/output/doctype_1.txt +1 -0
- data/test/output/doctype_2.txt +2 -0
- data/test/output/tag_1.txt +1 -0
- data/test/output/tag_2.txt +1 -0
- data/test/output/text_1.txt +1 -0
- data/test/output/text_2.txt +1 -0
- data/test/output/text_3.txt +1 -0
- data/test/test_htmlmin.rb +51 -0
- metadata +118 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# Introduction
|
2
|
+
|
3
|
+
HTMLMIN (HTML minimizer) is a HTML minimizer written in Ruby wich acts like a slot machine.
|
4
|
+
|
5
|
+
This document describes installation, usage, available minifications and development roadmap of HTMLMIN.
|
6
|
+
|
7
|
+
Please report issues on [Github] (https://github.com/aishek/htmlmin/issues).
|
8
|
+
|
9
|
+
For feedback, suggestions, etc. write to <aishek@gmail.com>.
|
10
|
+
|
11
|
+
**Important**: this project is in beta and may contain bugs. Current version: 0.0.1
|
12
|
+
|
13
|
+
# Installation
|
14
|
+
|
15
|
+
To install:
|
16
|
+
|
17
|
+
* run `gem install htmlmin`
|
18
|
+
|
19
|
+
# Usage
|
20
|
+
|
21
|
+
Usage:
|
22
|
+
|
23
|
+
require 'htmlmin'
|
24
|
+
options = {
|
25
|
+
:remove_comments => true,
|
26
|
+
:minify_whitespaces => true
|
27
|
+
}
|
28
|
+
minified_html = HTMLMin.minify(html, options)
|
29
|
+
|
30
|
+
# Minification
|
31
|
+
|
32
|
+
* Insert newline after DOCTYPE declaration
|
33
|
+
* Removal of whitespace
|
34
|
+
* Removal of comments
|
35
|
+
|
36
|
+
# Development roadmap
|
37
|
+
|
38
|
+
* ~~Minify whitespaces between tags~~
|
39
|
+
* ~~Insert newline after DOCTYPE declaration~~
|
40
|
+
* ~~Minify whitespaces after tag start and tag stop~~
|
41
|
+
* ~~Minify whitespaces in text~~
|
42
|
+
* ~~Remove comments~~
|
43
|
+
* Do not remove conditional comments
|
44
|
+
* Keep lines not longer that 30k (config option)
|
45
|
+
* Do not perform minify in script and style tag's content
|
46
|
+
* Do not perform minify in code, samp, pre tags's content
|
47
|
+
* Replace entities with numeric entities for shorter strings
|
48
|
+
* Replace entities with characters for shorter strings
|
49
|
+
* Minify shorttag close symbol
|
50
|
+
* Minify shorttag close whitespace
|
51
|
+
* Replace http:// with // in href and src attributes
|
52
|
+
* Minify whitespaces between tag attributes
|
53
|
+
* Minify quotes in one-word attributes
|
54
|
+
* Remove empty attributes
|
55
|
+
* Minify whitespaces in class attribute's content
|
56
|
+
* Replace css-classes in class attribute's content
|
57
|
+
|
58
|
+
# Author
|
59
|
+
|
60
|
+
Idea & implementation — Alexandr Borisov (<aishek@gmail.com>)
|
61
|
+
|
62
|
+
# Licence
|
63
|
+
|
64
|
+
HTMLMIN is licensed under [MIT](https://github.com/afelix/csso/blob/master/MIT-LICENSE.txt)
|
data/Rakefile
ADDED
data/htmlmin.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "htmlmin/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "htmlmin"
|
7
|
+
s.version = Htmlmin::VERSION
|
8
|
+
s.authors = ["Alexandr Borisov"]
|
9
|
+
s.email = ["aishek@gmail.com"]
|
10
|
+
s.platform = Gem::Platform::RUBY
|
11
|
+
s.homepage = "http://github.com/aishek/htmlmin"
|
12
|
+
s.summary = %q{HTMLMin is a HTML-code minification tool}
|
13
|
+
s.description = %q{HTMLMin is a HTML-code minification tool implemented in Ruby. It works like a slot machine.}
|
14
|
+
s.license = 'MIT'
|
15
|
+
|
16
|
+
s.rubyforge_project = "htmlmin"
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module HTMLMin
|
2
|
+
|
3
|
+
module Buffer
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
def add_to_buffer(char)
|
8
|
+
@result_buffer.push(char)
|
9
|
+
end
|
10
|
+
|
11
|
+
def space_in_buffer?
|
12
|
+
@result_buffer.length > 0 && @result_buffer[@result_buffer.length - 1] == ' '
|
13
|
+
end
|
14
|
+
|
15
|
+
def flush_buffer
|
16
|
+
@result += @result_buffer.join('')
|
17
|
+
clear_buffer
|
18
|
+
end
|
19
|
+
|
20
|
+
def unshift_spaces_from_buffer
|
21
|
+
@result_buffer = @result_buffer.drop_while {|char| char == ' '} if @settings[:minify_whitespaces]
|
22
|
+
end
|
23
|
+
|
24
|
+
def clear_buffer
|
25
|
+
@result_buffer = []
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module HTMLMin
|
2
|
+
|
3
|
+
module SlotMachines
|
4
|
+
|
5
|
+
module Comment
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def comment_begin_1(char)
|
10
|
+
case char
|
11
|
+
when "\s", "\n", "\r", "\t", " "
|
12
|
+
flush_buffer
|
13
|
+
change_state_to_text_prespaced char
|
14
|
+
when '-'
|
15
|
+
add_to_buffer char
|
16
|
+
change_state_to :comment_start_end
|
17
|
+
else
|
18
|
+
flush_buffer
|
19
|
+
add_to_result char
|
20
|
+
change_state_to :start
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def comment_start_end(char)
|
25
|
+
add_to_buffer char
|
26
|
+
change_state_to :comment
|
27
|
+
end
|
28
|
+
|
29
|
+
def comment(char)
|
30
|
+
add_to_buffer char
|
31
|
+
change_state_to :comment_end_1 if char == '-'
|
32
|
+
end
|
33
|
+
|
34
|
+
def comment_end_1(char)
|
35
|
+
add_to_buffer char
|
36
|
+
change_state_to (char == '-' ? :comment_end_2 : :comment)
|
37
|
+
end
|
38
|
+
|
39
|
+
def comment_end_2(char)
|
40
|
+
if char == '>'
|
41
|
+
clear_buffer
|
42
|
+
change_state_to :start unless restore_state
|
43
|
+
else
|
44
|
+
add_to_buffer char
|
45
|
+
change_state_to :comment
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
module HTMLMin
|
2
|
+
|
3
|
+
module SlotMachines
|
4
|
+
|
5
|
+
module Common
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def add_to_result(char)
|
10
|
+
@result += char
|
11
|
+
end
|
12
|
+
|
13
|
+
def change_state_to(new_state)
|
14
|
+
@state = new_state
|
15
|
+
end
|
16
|
+
|
17
|
+
def tag_or_tagend_or_comment_or_doctype_begin(char)
|
18
|
+
case char
|
19
|
+
when "\s", "\n", "\r", "\t", " "
|
20
|
+
flush_buffer
|
21
|
+
change_state_to_text_prespaced char
|
22
|
+
when "/"
|
23
|
+
add_to_buffer char
|
24
|
+
change_state_to :tag_end
|
25
|
+
when "!"
|
26
|
+
add_to_buffer char
|
27
|
+
change_state_to :comment_or_doctype_begin
|
28
|
+
when "a".."z", "A".."Z"
|
29
|
+
add_to_buffer char
|
30
|
+
change_state_to :tag_begin
|
31
|
+
else
|
32
|
+
flush_buffer
|
33
|
+
add_to_result char
|
34
|
+
change_state_to :start
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def comment_or_doctype_begin(char)
|
39
|
+
case char
|
40
|
+
when "\s", "\n", "\r", "\t", " "
|
41
|
+
flush_buffer
|
42
|
+
change_state_to_text_prespaced char
|
43
|
+
when "-"
|
44
|
+
if @settings[:remove_comments]
|
45
|
+
add_to_buffer char
|
46
|
+
change_state_to :comment_begin_1
|
47
|
+
else
|
48
|
+
flush_buffer
|
49
|
+
add_to_result char
|
50
|
+
change_state_to :start
|
51
|
+
end
|
52
|
+
when 'D'
|
53
|
+
add_to_buffer char
|
54
|
+
change_state_to :doctype_begin_1
|
55
|
+
else
|
56
|
+
flush_buffer
|
57
|
+
add_to_result char
|
58
|
+
change_state_to :start
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def text_prespaced(char)
|
63
|
+
case char
|
64
|
+
when "\s", "\n", "\r", "\t", " "
|
65
|
+
if @settings[:minify_whitespaces]
|
66
|
+
add_to_buffer " " unless space_in_buffer?
|
67
|
+
else
|
68
|
+
add_to_buffer char
|
69
|
+
end
|
70
|
+
when "<"
|
71
|
+
add_to_buffer char
|
72
|
+
change_state_to :tag_or_tagend_or_comment_or_doctype_begin
|
73
|
+
else
|
74
|
+
flush_buffer
|
75
|
+
add_to_result char
|
76
|
+
change_state_to :start
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def start(char)
|
81
|
+
case char
|
82
|
+
when "\s", "\n", "\r", "\t"
|
83
|
+
change_state_to_text_prespaced char
|
84
|
+
when "<"
|
85
|
+
add_to_buffer char
|
86
|
+
change_state_to :tag_or_tagend_or_comment_or_doctype_begin
|
87
|
+
else
|
88
|
+
add_to_result char
|
89
|
+
change_state_to :start
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def change_state_to_text_prespaced(char)
|
94
|
+
add_to_buffer (@settings[:minify_whitespaces] ? ' ' : char)
|
95
|
+
change_state_to :text_prespaced
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
module HTMLMin
|
2
|
+
|
3
|
+
module SlotMachines
|
4
|
+
|
5
|
+
module Doctype
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def doctype_begin_1(char)
|
10
|
+
case char
|
11
|
+
when "O"
|
12
|
+
add_to_buffer char
|
13
|
+
change_state_to :doctype_begin_2
|
14
|
+
when "\s", "\n", "\r", "\t", " "
|
15
|
+
change_state_to_text_prespaced char
|
16
|
+
else
|
17
|
+
flush_buffer
|
18
|
+
|
19
|
+
add_to_result char
|
20
|
+
change_state_to :start
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def doctype_begin_2(char)
|
25
|
+
case char
|
26
|
+
when "C"
|
27
|
+
add_to_buffer char
|
28
|
+
change_state_to :doctype_begin_3
|
29
|
+
when "\s", "\n", "\r", "\t", " "
|
30
|
+
flush_buffer
|
31
|
+
change_state_to_text_prespaced char
|
32
|
+
else
|
33
|
+
flush_buffer
|
34
|
+
|
35
|
+
add_to_result char
|
36
|
+
change_state_to :start
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def doctype_begin_3(char)
|
41
|
+
case char
|
42
|
+
when "T"
|
43
|
+
add_to_buffer char
|
44
|
+
change_state_to :doctype_begin_4
|
45
|
+
when "\s", "\n", "\r", "\t", " "
|
46
|
+
flush_buffer
|
47
|
+
change_state_to_text_prespaced char
|
48
|
+
else
|
49
|
+
flush_buffer
|
50
|
+
|
51
|
+
add_to_result char
|
52
|
+
change_state_to :start
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def doctype_begin_4(char)
|
57
|
+
case char
|
58
|
+
when "Y"
|
59
|
+
add_to_buffer char
|
60
|
+
change_state_to :doctype_begin_5
|
61
|
+
when "\s", "\n", "\r", "\t", " "
|
62
|
+
flush_buffer
|
63
|
+
change_state_to_text_prespaced char
|
64
|
+
else
|
65
|
+
flush_buffer
|
66
|
+
|
67
|
+
add_to_result char
|
68
|
+
change_state_to :start
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def doctype_begin_5(char)
|
73
|
+
case char
|
74
|
+
when "P"
|
75
|
+
add_to_buffer char
|
76
|
+
change_state_to :doctype_begin_6
|
77
|
+
when "\s", "\n", "\r", "\t", " "
|
78
|
+
flush_buffer
|
79
|
+
change_state_to_text_prespaced char
|
80
|
+
else
|
81
|
+
flush_buffer
|
82
|
+
|
83
|
+
add_to_result char
|
84
|
+
change_state_to :start
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def doctype_begin_6(char)
|
89
|
+
case char
|
90
|
+
when "E"
|
91
|
+
add_to_buffer char
|
92
|
+
change_state_to :doctype_begin_7
|
93
|
+
when "\s", "\n", "\r", "\t", " "
|
94
|
+
flush_buffer
|
95
|
+
change_state_to_text_prespaced char
|
96
|
+
else
|
97
|
+
flush_buffer
|
98
|
+
|
99
|
+
add_to_result char
|
100
|
+
change_state_to :start
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def doctype_begin_7(char)
|
105
|
+
case char
|
106
|
+
when " "
|
107
|
+
add_to_buffer char
|
108
|
+
change_state_to :doctype
|
109
|
+
when "\s", "\n", "\r", "\t"
|
110
|
+
flush_buffer
|
111
|
+
change_state_to_text_prespaced char
|
112
|
+
else
|
113
|
+
flush_buffer
|
114
|
+
|
115
|
+
add_to_result char
|
116
|
+
change_state_to :start
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def doctype(char)
|
121
|
+
add_to_buffer char
|
122
|
+
if char == '>'
|
123
|
+
unshift_spaces_from_buffer
|
124
|
+
flush_buffer
|
125
|
+
|
126
|
+
add_to_result "\n"
|
127
|
+
change_state_to :start
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module HTMLMin
|
2
|
+
|
3
|
+
module SlotMachines
|
4
|
+
|
5
|
+
module Tag
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def tag_end(char)
|
10
|
+
case char
|
11
|
+
when "a".."z", "A".."Z"
|
12
|
+
add_to_buffer char
|
13
|
+
change_state_to :tag_end_body
|
14
|
+
else
|
15
|
+
flush_buffer
|
16
|
+
change_state_to :start
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def tag_end_body(char)
|
21
|
+
case char
|
22
|
+
when "a".."z", "A".."Z"
|
23
|
+
add_to_buffer char
|
24
|
+
when '>'
|
25
|
+
add_to_buffer char
|
26
|
+
|
27
|
+
unshift_spaces_from_buffer
|
28
|
+
flush_buffer
|
29
|
+
|
30
|
+
change_state_to :tag_ended
|
31
|
+
else
|
32
|
+
flush_buffer
|
33
|
+
change_state_to :start
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def tag_begin(char)
|
38
|
+
add_to_buffer char
|
39
|
+
case char
|
40
|
+
when "/"
|
41
|
+
change_state_to :tag_end_expected
|
42
|
+
when ">"
|
43
|
+
change_state_to :tag_ended
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def tag_end_expected(char)
|
48
|
+
case char
|
49
|
+
when '>'
|
50
|
+
add_to_buffer char
|
51
|
+
change_state_to :tag_ended
|
52
|
+
else
|
53
|
+
flush_buffer
|
54
|
+
change_state_to :start
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def tag_ended(char)
|
59
|
+
case char
|
60
|
+
when "\s", "\n", "\r", "\t", " "
|
61
|
+
add_to_result char unless @settings[:minify_whitespaces]
|
62
|
+
when '<'
|
63
|
+
save_state
|
64
|
+
|
65
|
+
unshift_spaces_from_buffer
|
66
|
+
flush_buffer
|
67
|
+
|
68
|
+
add_to_buffer char
|
69
|
+
change_state_to :tag_or_tagend_or_comment_or_doctype_begin
|
70
|
+
else
|
71
|
+
unshift_spaces_from_buffer
|
72
|
+
flush_buffer
|
73
|
+
|
74
|
+
add_to_result char
|
75
|
+
change_state_to :start
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
data/lib/htmlmin.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
require "htmlmin/version"
|
2
|
+
require "htmlmin/buffer"
|
3
|
+
require "htmlmin/slot_machines"
|
4
|
+
|
5
|
+
module HTMLMin
|
6
|
+
|
7
|
+
def self.minify(html, options = {})
|
8
|
+
HTMLMin::Minifier.minify(html, options)
|
9
|
+
end
|
10
|
+
|
11
|
+
class Minifier
|
12
|
+
extend HTMLMin::Buffer
|
13
|
+
extend HTMLMin::SlotMachines::Common
|
14
|
+
extend HTMLMin::SlotMachines::Comment
|
15
|
+
extend HTMLMin::SlotMachines::Doctype
|
16
|
+
extend HTMLMin::SlotMachines::Tag
|
17
|
+
|
18
|
+
class << self
|
19
|
+
|
20
|
+
DEFAULT_OPTIONS = {
|
21
|
+
:remove_comments => true,
|
22
|
+
|
23
|
+
:minify_whitespaces => true,
|
24
|
+
|
25
|
+
:debug => false
|
26
|
+
}
|
27
|
+
|
28
|
+
def minify(html, options = {})
|
29
|
+
init_settings options
|
30
|
+
|
31
|
+
@result = ''
|
32
|
+
init_slot_machine
|
33
|
+
run_slot_machine html
|
34
|
+
|
35
|
+
@result
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def init_settings(options)
|
42
|
+
@settings = DEFAULT_OPTIONS.merge options
|
43
|
+
end
|
44
|
+
|
45
|
+
def init_slot_machine
|
46
|
+
clear_buffer
|
47
|
+
@state = :text_prespaced
|
48
|
+
@prev_state = nil
|
49
|
+
end
|
50
|
+
|
51
|
+
def run_slot_machine(html)
|
52
|
+
pos = 0
|
53
|
+
input = html.strip
|
54
|
+
while (pos < input.length) do
|
55
|
+
char = input[pos]
|
56
|
+
|
57
|
+
self.send @state, char
|
58
|
+
debug_log if @settings[:debug]
|
59
|
+
|
60
|
+
pos += 1
|
61
|
+
end
|
62
|
+
self.send @state, ''
|
63
|
+
end
|
64
|
+
|
65
|
+
def debug_log
|
66
|
+
p "char: #{char}, state: #{@state.to_s}, buffer: #{@result_buffer.join('')}"
|
67
|
+
end
|
68
|
+
|
69
|
+
def save_state
|
70
|
+
@prev_state = @state
|
71
|
+
end
|
72
|
+
|
73
|
+
def restore_state
|
74
|
+
return false if @prev_state.nil?
|
75
|
+
|
76
|
+
@state = @prev_state
|
77
|
+
return true
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
data/test/input/cc_1.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
<!---->
|
@@ -0,0 +1 @@
|
|
1
|
+
<!--<!--<!---->
|
@@ -0,0 +1 @@
|
|
1
|
+
<!--<!---->-->
|
@@ -0,0 +1 @@
|
|
1
|
+
<!-- just a comment -->
|
@@ -0,0 +1 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
@@ -0,0 +1 @@
|
|
1
|
+
hello there. how are you?
|
@@ -0,0 +1 @@
|
|
1
|
+
<html></html>
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
<p>Fix me</p>
|
@@ -0,0 +1 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
@@ -0,0 +1 @@
|
|
1
|
+
<p><em>nothing at all</em></p>
|
@@ -0,0 +1 @@
|
|
1
|
+
<div><span><i></i></span></div>
|
@@ -0,0 +1 @@
|
|
1
|
+
text
|
@@ -0,0 +1 @@
|
|
1
|
+
hello there. how are you?
|
@@ -0,0 +1 @@
|
|
1
|
+
<p>please, stay with me</p>
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'htmlmin'
|
3
|
+
|
4
|
+
class HTMLMinTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
INPUT_DIR = "test/input"
|
9
|
+
OUTPUT_DIR = "test/output"
|
10
|
+
EXTENSION = "txt"
|
11
|
+
|
12
|
+
def create_test_methods_from_data
|
13
|
+
files = input_files
|
14
|
+
files.each do |filename|
|
15
|
+
basename = File.basename(filename, File.extname(filename))
|
16
|
+
unless output_exists?(basename)
|
17
|
+
p "Output for '#{basename}' test not exists. Please, create '#{OUTPUT_DIR}/#{basename}.#{EXTENSION}' file!"
|
18
|
+
next
|
19
|
+
end
|
20
|
+
|
21
|
+
method_name = create_method_name basename
|
22
|
+
self.send :define_method, method_name do
|
23
|
+
input = File.read "#{INPUT_DIR}/#{basename}.#{EXTENSION}"
|
24
|
+
output = File.read "#{OUTPUT_DIR}/#{basename}.#{EXTENSION}"
|
25
|
+
minified = HTMLMin.minify(input)
|
26
|
+
|
27
|
+
assert_equal output, minified, "Minified '#{basename}' not equals to output!"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def output_exists?(basename)
|
36
|
+
File.exists? "#{OUTPUT_DIR}/#{basename}.txt"
|
37
|
+
end
|
38
|
+
|
39
|
+
def input_files
|
40
|
+
Dir.glob("#{INPUT_DIR}/#{ENV['input'] || '*'}.#{EXTENSION}")
|
41
|
+
end
|
42
|
+
|
43
|
+
def create_method_name(basename)
|
44
|
+
"test_#{basename}"
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
create_test_methods_from_data
|
50
|
+
|
51
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: htmlmin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Alexandr Borisov
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-08-21 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: HTMLMin is a HTML-code minification tool implemented in Ruby. It works
|
15
|
+
like a slot machine.
|
16
|
+
email:
|
17
|
+
- aishek@gmail.com
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- .gitignore
|
23
|
+
- Gemfile
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- htmlmin.gemspec
|
27
|
+
- lib/htmlmin.rb
|
28
|
+
- lib/htmlmin/buffer.rb
|
29
|
+
- lib/htmlmin/slot_machines.rb
|
30
|
+
- lib/htmlmin/slot_machines/comment.rb
|
31
|
+
- lib/htmlmin/slot_machines/common.rb
|
32
|
+
- lib/htmlmin/slot_machines/doctype.rb
|
33
|
+
- lib/htmlmin/slot_machines/tag.rb
|
34
|
+
- lib/htmlmin/version.rb
|
35
|
+
- test/input/cc_1.txt
|
36
|
+
- test/input/comment_1.txt
|
37
|
+
- test/input/comment_2.txt
|
38
|
+
- test/input/comment_3.txt
|
39
|
+
- test/input/comment_4.txt
|
40
|
+
- test/input/comment_5.txt
|
41
|
+
- test/input/comment_6.txt
|
42
|
+
- test/input/doctype_1.txt
|
43
|
+
- test/input/doctype_2.txt
|
44
|
+
- test/input/tag_1.txt
|
45
|
+
- test/input/tag_2.txt
|
46
|
+
- test/input/text_1.txt
|
47
|
+
- test/input/text_2.txt
|
48
|
+
- test/input/text_3.txt
|
49
|
+
- test/output/cc_1.txt
|
50
|
+
- test/output/comment_1.txt
|
51
|
+
- test/output/comment_2.txt
|
52
|
+
- test/output/comment_3.txt
|
53
|
+
- test/output/comment_4.txt
|
54
|
+
- test/output/comment_5.txt
|
55
|
+
- test/output/comment_6.txt
|
56
|
+
- test/output/doctype_1.txt
|
57
|
+
- test/output/doctype_2.txt
|
58
|
+
- test/output/tag_1.txt
|
59
|
+
- test/output/tag_2.txt
|
60
|
+
- test/output/text_1.txt
|
61
|
+
- test/output/text_2.txt
|
62
|
+
- test/output/text_3.txt
|
63
|
+
- test/test_htmlmin.rb
|
64
|
+
homepage: http://github.com/aishek/htmlmin
|
65
|
+
licenses:
|
66
|
+
- MIT
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project: htmlmin
|
85
|
+
rubygems_version: 1.8.8
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: HTMLMin is a HTML-code minification tool
|
89
|
+
test_files:
|
90
|
+
- test/input/cc_1.txt
|
91
|
+
- test/input/comment_1.txt
|
92
|
+
- test/input/comment_2.txt
|
93
|
+
- test/input/comment_3.txt
|
94
|
+
- test/input/comment_4.txt
|
95
|
+
- test/input/comment_5.txt
|
96
|
+
- test/input/comment_6.txt
|
97
|
+
- test/input/doctype_1.txt
|
98
|
+
- test/input/doctype_2.txt
|
99
|
+
- test/input/tag_1.txt
|
100
|
+
- test/input/tag_2.txt
|
101
|
+
- test/input/text_1.txt
|
102
|
+
- test/input/text_2.txt
|
103
|
+
- test/input/text_3.txt
|
104
|
+
- test/output/cc_1.txt
|
105
|
+
- test/output/comment_1.txt
|
106
|
+
- test/output/comment_2.txt
|
107
|
+
- test/output/comment_3.txt
|
108
|
+
- test/output/comment_4.txt
|
109
|
+
- test/output/comment_5.txt
|
110
|
+
- test/output/comment_6.txt
|
111
|
+
- test/output/doctype_1.txt
|
112
|
+
- test/output/doctype_2.txt
|
113
|
+
- test/output/tag_1.txt
|
114
|
+
- test/output/tag_2.txt
|
115
|
+
- test/output/text_1.txt
|
116
|
+
- test/output/text_2.txt
|
117
|
+
- test/output/text_3.txt
|
118
|
+
- test/test_htmlmin.rb
|