alula 0.4.9 → 0.4.10

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.9
1
+ 0.4.10
@@ -1,6 +1,7 @@
1
1
  require 'sass'
2
2
  require 'uglifier'
3
3
  require 'htmlcompressor'
4
+ require 'alula/core_ext/htmlcompressor'
4
5
 
5
6
  module Alula
6
7
  class Compressors
@@ -48,7 +49,7 @@ module Alula
48
49
 
49
50
  class HTMLCompressor
50
51
  def initialize
51
- HtmlCompressor::Compressor.send(:include, HTMLCompressorExt)
52
+ # HtmlCompressor::Compressor.send(:include, HTMLCompressorExt)
52
53
  @compressor = HtmlCompressor::Compressor.new
53
54
  # remove_surrounding_spaces: HtmlCompressor::Compressor::BLOCK_TAGS_MAX + ",source,title,meta,header,footer,div,section,article,time,img,video,script",
54
55
  # remove_intertag_spaces: true,
@@ -79,42 +80,6 @@ module Alula
79
80
  ensure
80
81
  @compressor.profile = _old_profile
81
82
  end
82
-
83
- module HTMLCompressorExt
84
- def profile
85
- @profile
86
- end
87
-
88
- def profile=(profile)
89
- @profile = profile
90
- case profile
91
- when :none
92
- @options[:enabled] = false
93
- when :normal
94
- @options[:enabled] = true
95
- @options[:remove_surrounding_spaces] = HtmlCompressor::Compressor::BLOCK_TAGS_MAX + ",source,title,meta,header,footer,div,section,article,time,img,video,script"
96
- @options[:remove_intertag_spaces] = true
97
- @options[:remove_quotes] = false
98
- @options[:remove_script_attributes] = true
99
- @options[:remove_style_attributes] = true
100
- @options[:remove_link_attributes] = true
101
- @options[:simple_boolean_attributes] = true
102
- @options[:remove_http_protocol] = false
103
- @options[:remove_https_protocol] = false
104
- when :high
105
- @options[:enabled] = true
106
- @options[:remove_surrounding_spaces] = HtmlCompressor::Compressor::BLOCK_TAGS_MAX + ",source,title,meta,header,footer,div,section,article,time,img,video,script"
107
- @options[:remove_intertag_spaces] = true
108
- @options[:remove_quotes] = true
109
- @options[:remove_script_attributes] = true
110
- @options[:remove_style_attributes] = true
111
- @options[:remove_link_attributes] = true
112
- @options[:simple_boolean_attributes] = true
113
- @options[:remove_http_protocol] = "href,src,cite,action,data-original,data-hires"
114
- @options[:remove_https_protocol] = "href,src,cite,action,data-original,data-hires"
115
- end
116
- end
117
- end
118
83
  end
119
84
  end
120
85
  end
@@ -0,0 +1,87 @@
1
+ module HtmlCompressor
2
+ class Compressor
3
+ def profile
4
+ @profile
5
+ end
6
+
7
+ def profile=(profile)
8
+ @profile = profile
9
+ case profile
10
+ when :none
11
+ @options[:enabled] = false
12
+ when :normal
13
+ @options[:enabled] = true
14
+ @options[:remove_surrounding_spaces] = HtmlCompressor::Compressor::BLOCK_TAGS_MAX + ",source,title,meta,header,footer,div,section,article,time,img,video,script"
15
+ @options[:remove_intertag_spaces] = true
16
+ @options[:remove_quotes] = false
17
+ @options[:remove_script_attributes] = true
18
+ @options[:remove_style_attributes] = true
19
+ @options[:remove_link_attributes] = true
20
+ @options[:simple_boolean_attributes] = true
21
+ @options[:remove_http_protocol] = false
22
+ @options[:remove_https_protocol] = false
23
+ when :high
24
+ @options[:enabled] = true
25
+ @options[:remove_surrounding_spaces] = HtmlCompressor::Compressor::BLOCK_TAGS_MAX + ",source,title,meta,header,footer,div,section,article,time,img,video,script"
26
+ @options[:remove_intertag_spaces] = true
27
+ @options[:remove_quotes] = true
28
+ @options[:remove_script_attributes] = true
29
+ @options[:remove_style_attributes] = true
30
+ @options[:remove_link_attributes] = true
31
+ @options[:simple_boolean_attributes] = true
32
+ @options[:remove_http_protocol] = "href,src,cite,action,data-original,data-hires"
33
+ @options[:remove_https_protocol] = "href,src,cite,action,data-original,data-hires"
34
+ end
35
+ end
36
+
37
+ def remove_http_protocol(html)
38
+ # remove http protocol from tag attributes
39
+ if @options[:remove_http_protocol]
40
+ pattern = case @options[:remove_http_protocol]
41
+ when true
42
+ HTTP_PROTOCOL_PATTERN
43
+ else
44
+ Regexp.new("(<[^>]+?(?:#{@options[:remove_http_protocol].gsub(",", "|")})\\s*=\\s*['\"])http:(//[^>]+?>)", Regexp::MULTILINE | Regexp::IGNORECASE)
45
+ end
46
+ html = html.gsub(pattern) do |match|
47
+ group_1 = $1
48
+ group_2 = $2
49
+
50
+ if match =~ REL_EXTERNAL_PATTERN
51
+ match
52
+ else
53
+ "#{group_1}#{group_2}"
54
+ end
55
+ end
56
+ end
57
+
58
+ html
59
+ end
60
+
61
+ def remove_https_protocol(html)
62
+ # remove https protocol from tag attributes
63
+ if @options[:remove_https_protocol]
64
+ pattern = case @options[:remove_https_protocol]
65
+ when true
66
+ HTTPS_PROTOCOL_PATTERN
67
+ else
68
+ Regexp.new("(<[^>]+?(?:#{@options[:remove_https_protocol].gsub(",", "|")})\\s*=\\s*['\"])http:(//[^>]+?>)", Regexp::MULTILINE | Regexp::IGNORECASE)
69
+ end
70
+
71
+ html = html.gsub(pattern) do |match|
72
+ group_1 = $1
73
+ group_2 = $2
74
+
75
+ if match =~ REL_EXTERNAL_PATTERN
76
+ match
77
+ else
78
+ "#{group_1}#{group_2}"
79
+ end
80
+ end
81
+ end
82
+
83
+ html
84
+ end
85
+
86
+ end
87
+ end
@@ -1,4 +1,4 @@
1
1
  require 'alula/core_ext/tag'
2
2
  require 'alula/core_ext/filter'
3
3
 
4
- require 'alula/core_ext/environment'
4
+ require 'alula/core_ext/environment'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alula
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.9
4
+ version: 0.4.10
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: 2012-08-04 00:00:00.000000000 Z
12
+ date: 2012-08-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: parallel
@@ -478,6 +478,7 @@ files:
478
478
  - lib/alula/core_ext/environment.rb
479
479
  - lib/alula/core_ext/filter.rb
480
480
  - lib/alula/core_ext/filters/smilies.rb
481
+ - lib/alula/core_ext/htmlcompressor.rb
481
482
  - lib/alula/core_ext/tag.rb
482
483
  - lib/alula/core_ext/tags/attachment.rb
483
484
  - lib/alula/core_ext/tags/blockquote.rb
@@ -644,7 +645,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
644
645
  version: '0'
645
646
  segments:
646
647
  - 0
647
- hash: 2079066484659239768
648
+ hash: 1426660746450185901
648
649
  required_rubygems_version: !ruby/object:Gem::Requirement
649
650
  none: false
650
651
  requirements:
@@ -653,7 +654,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
653
654
  version: '0'
654
655
  segments:
655
656
  - 0
656
- hash: 2079066484659239768
657
+ hash: 1426660746450185901
657
658
  requirements: []
658
659
  rubyforge_project:
659
660
  rubygems_version: 1.8.23