htmlmin 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -23,7 +23,8 @@ Usage:
23
23
  require 'htmlmin'
24
24
  options = {
25
25
  :remove_comments => true,
26
- :minify_whitespaces => true
26
+ :minify_whitespaces => true,
27
+ :max_line_len => 32768, # 0 - disable this safety feature
27
28
  }
28
29
  minified_html = HTMLMin.minify(html, options)
29
30
 
data/lib/htmlmin.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "htmlmin/version"
2
2
  require "htmlmin/buffer"
3
+ require "htmlmin/max_line_len"
3
4
  require "htmlmin/slot_machines"
4
5
 
5
6
  module HTMLMin
@@ -12,6 +13,7 @@ module HTMLMin
12
13
  END_OF_FILE = ''
13
14
 
14
15
  extend HTMLMin::Buffer
16
+ extend HTMLMin::MaxLineLen
15
17
  extend HTMLMin::SlotMachines::Common
16
18
  extend HTMLMin::SlotMachines::Comment
17
19
  extend HTMLMin::SlotMachines::Doctype
@@ -24,6 +26,8 @@ module HTMLMin
24
26
 
25
27
  :minify_whitespaces => true,
26
28
 
29
+ :max_line_len => 32768, # 32k - safety feature
30
+
27
31
  :debug => false
28
32
  }
29
33
 
@@ -46,6 +50,7 @@ module HTMLMin
46
50
  end
47
51
 
48
52
  def init_slot_machine
53
+ init_max_line_len
49
54
  clear_buffer
50
55
  @state = :text_prespaced
51
56
  @prev_state = nil
@@ -13,7 +13,9 @@ module HTMLMin
13
13
  end
14
14
 
15
15
  def flush_buffer
16
- @result += @result_buffer.join('')
16
+ @result_buffer.each do |char|
17
+ add_to_result(char)
18
+ end
17
19
  clear_buffer
18
20
  end
19
21
 
@@ -0,0 +1,30 @@
1
+ module HTMLMin
2
+
3
+ module MaxLineLen
4
+
5
+ private
6
+
7
+ SPACE = [" ", "\s", "\n", "\r", "\t"]
8
+
9
+ def check_max_line_len(char)
10
+ if char == "\n"
11
+ init_max_line_len
12
+ else
13
+ @newline_pos = @result.length if SPACE.include?(char)
14
+ @line_length += 1
15
+ end
16
+
17
+ if @line_length >= @settings[:max_line_len] && !@newline_pos.nil?
18
+ @result[@newline_pos - 1] = "\n"
19
+ init_max_line_len
20
+ end
21
+ end
22
+
23
+ def init_max_line_len
24
+ @newline_pos = nil
25
+ @line_length = 0
26
+ end
27
+
28
+ end
29
+
30
+ end
@@ -5,11 +5,13 @@ module HTMLMin
5
5
  module Common
6
6
 
7
7
  private
8
-
8
+
9
9
  def add_to_result(char)
10
10
  @result += char
11
+
12
+ check_max_line_len(char) if @settings[:max_line_len] > 0
11
13
  end
12
-
14
+
13
15
  def change_state_to(new_state)
14
16
  @state = new_state
15
17
  end
@@ -1,3 +1,3 @@
1
1
  module Htmlmin
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1 @@
1
+ Hello there, i am just a long line text - nothing else. I should be splitted at the end of previous sentence.
@@ -0,0 +1 @@
1
+ Hello there, i am just a long line text - nothing else. I should be splitted at the end of previous sentence.
@@ -0,0 +1,11 @@
1
+
2
+
3
+
4
+ Hello there, i am just a long line text - nothing else.
5
+
6
+
7
+
8
+ I should be splitted at the end of previous sentence.
9
+
10
+
11
+
@@ -0,0 +1,2 @@
1
+ veryverylonglineveryverylonglineveryverylonglineveryverylonglineveryverylongline
2
+ Hello there, i am just a long line text - nothing else. I should be splitted at the end of previous sentence.
@@ -2,5 +2,6 @@
2
2
  :remove_comments => false,
3
3
 
4
4
  :minify_whitespaces => true,
5
- :debug => false
5
+ :debug => false,
6
+ :max_line_len => 0
6
7
  }
@@ -2,5 +2,6 @@
2
2
  :remove_comments => true,
3
3
 
4
4
  :minify_whitespaces => false,
5
- :debug => false
5
+ :debug => false,
6
+ :max_line_len => 0
6
7
  }
@@ -0,0 +1,7 @@
1
+ {
2
+ :max_line_len => 56,
3
+
4
+ :remove_comments => true,
5
+ :minify_whitespaces => false,
6
+ :debug => false
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ :max_line_len => 57,
3
+
4
+ :remove_comments => true,
5
+ :minify_whitespaces => false,
6
+ :debug => false
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ :max_line_len => 56,
3
+
4
+ :remove_comments => true,
5
+ :minify_whitespaces => true,
6
+ :debug => false
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ :max_line_len => 56,
3
+
4
+ :remove_comments => true,
5
+ :minify_whitespaces => true,
6
+ :debug => false
7
+ }
@@ -0,0 +1,2 @@
1
+ Hello there, i am just a long line text - nothing else.
2
+ I should be splitted at the end of previous sentence.
@@ -0,0 +1,2 @@
1
+ Hello there, i am just a long line text - nothing else.
2
+ I should be splitted at the end of previous sentence.
@@ -0,0 +1,2 @@
1
+ Hello there, i am just a long line text - nothing else.
2
+ I should be splitted at the end of previous sentence.
@@ -0,0 +1,3 @@
1
+ veryverylonglineveryverylonglineveryverylonglineveryverylonglineveryverylongline
2
+ Hello there, i am just a long line text - nothing else.
3
+ I should be splitted at the end of previous sentence.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: htmlmin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-22 00:00:00.000000000Z
12
+ date: 2011-08-24 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: HTMLMin is a HTML-code minification tool implemented in Ruby. It works
15
15
  like a slot machine.
@@ -26,6 +26,7 @@ files:
26
26
  - htmlmin.gemspec
27
27
  - lib/htmlmin.rb
28
28
  - lib/htmlmin/buffer.rb
29
+ - lib/htmlmin/max_line_len.rb
29
30
  - lib/htmlmin/slot_machines.rb
30
31
  - lib/htmlmin/slot_machines/comment.rb
31
32
  - lib/htmlmin/slot_machines/common.rb
@@ -43,6 +44,10 @@ files:
43
44
  - test/input/comment_8.txt
44
45
  - test/input/doctype_1.txt
45
46
  - test/input/doctype_2.txt
47
+ - test/input/line_length_1.txt
48
+ - test/input/line_length_2.txt
49
+ - test/input/line_length_3.txt
50
+ - test/input/line_length_4.txt
46
51
  - test/input/tag_1.txt
47
52
  - test/input/tag_2.txt
48
53
  - test/input/text_1.txt
@@ -50,6 +55,10 @@ files:
50
55
  - test/input/text_3.txt
51
56
  - test/options/comment_7.rb
52
57
  - test/options/comment_8.rb
58
+ - test/options/line_length_1.rb
59
+ - test/options/line_length_2.rb
60
+ - test/options/line_length_3.rb
61
+ - test/options/line_length_4.rb
53
62
  - test/output/cc_1.txt
54
63
  - test/output/comment_1.txt
55
64
  - test/output/comment_2.txt
@@ -61,6 +70,10 @@ files:
61
70
  - test/output/comment_8.txt
62
71
  - test/output/doctype_1.txt
63
72
  - test/output/doctype_2.txt
73
+ - test/output/line_length_1.txt
74
+ - test/output/line_length_2.txt
75
+ - test/output/line_length_3.txt
76
+ - test/output/line_length_4.txt
64
77
  - test/output/tag_1.txt
65
78
  - test/output/tag_2.txt
66
79
  - test/output/text_1.txt
@@ -104,6 +117,10 @@ test_files:
104
117
  - test/input/comment_8.txt
105
118
  - test/input/doctype_1.txt
106
119
  - test/input/doctype_2.txt
120
+ - test/input/line_length_1.txt
121
+ - test/input/line_length_2.txt
122
+ - test/input/line_length_3.txt
123
+ - test/input/line_length_4.txt
107
124
  - test/input/tag_1.txt
108
125
  - test/input/tag_2.txt
109
126
  - test/input/text_1.txt
@@ -111,6 +128,10 @@ test_files:
111
128
  - test/input/text_3.txt
112
129
  - test/options/comment_7.rb
113
130
  - test/options/comment_8.rb
131
+ - test/options/line_length_1.rb
132
+ - test/options/line_length_2.rb
133
+ - test/options/line_length_3.rb
134
+ - test/options/line_length_4.rb
114
135
  - test/output/cc_1.txt
115
136
  - test/output/comment_1.txt
116
137
  - test/output/comment_2.txt
@@ -122,6 +143,10 @@ test_files:
122
143
  - test/output/comment_8.txt
123
144
  - test/output/doctype_1.txt
124
145
  - test/output/doctype_2.txt
146
+ - test/output/line_length_1.txt
147
+ - test/output/line_length_2.txt
148
+ - test/output/line_length_3.txt
149
+ - test/output/line_length_4.txt
125
150
  - test/output/tag_1.txt
126
151
  - test/output/tag_2.txt
127
152
  - test/output/text_1.txt