hexp 0.4.0.beta1 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +12 -1
- data/lib/hexp-rails.rb +31 -0
- data/lib/hexp/css_selector.rb +1 -0
- data/lib/hexp/list.rb +4 -0
- data/lib/hexp/node/children.rb +3 -0
- data/lib/hexp/unparser.rb +33 -18
- data/lib/hexp/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1f3d62af18c9ae3a5a4c28fdb30e44a082e58f4
|
4
|
+
data.tar.gz: 4379e67e153aca5cb338f3b1f002c871b8f71010
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c0244e52ce84768cb92828ecdfb0021ebd6a62ae0c72ad3beaeb801f2386f5177f61008055d528b91444896aa26a47baa705269e04cc6baa2939d4c19fabc83
|
7
|
+
data.tar.gz: db32b6b92696bd5953c666d5fcbaeb9190b9d87dac0320487eeade385d92536b98067373aeb3ffad753eb0cff9ee5c2ef25e67f77d71fe730da8b8c8a483627a
|
data/Changelog.md
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
### Development
|
2
2
|
|
3
|
-
[full diff](http://github.com/plexus/hexp/compare/v0.
|
3
|
+
[full diff](http://github.com/plexus/hexp/compare/v0.4.1...master)
|
4
|
+
|
5
|
+
### v0.4.1
|
6
|
+
|
7
|
+
* Make Hexp::List#+ return a Hexp::List
|
8
|
+
* Add Hexp::Node#append as a convenient API for adding child nodes
|
9
|
+
* Make Unparser Adamantium-immutable so instances can be included in
|
10
|
+
Adamantiumized objects
|
11
|
+
* Skip escaping inside <script> tags
|
12
|
+
* Add a "rails integration" (ugh) to play nice with
|
13
|
+
ActiveSupport::SafeBuffer. use `gem 'hexp', require: 'hexp-rails'`
|
14
|
+
in your Gemfile
|
4
15
|
|
5
16
|
### v0.4.0.beta1
|
6
17
|
|
data/lib/hexp-rails.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'hexp'
|
2
|
+
require 'hexp/core_ext/nil' # Opt-in to NilClass#to_hexp
|
3
|
+
|
4
|
+
module Hexp
|
5
|
+
# Transparently use Hexp nodes in templates
|
6
|
+
class Node
|
7
|
+
def to_s
|
8
|
+
to_html.html_safe
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class List
|
13
|
+
def to_s
|
14
|
+
to_html.html_safe
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class TextNode
|
19
|
+
def to_s
|
20
|
+
to_html.html_safe
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Honor ActiveSupport::SafeBuffer's "html_safe" flag
|
25
|
+
class Unparser
|
26
|
+
alias orig_escape_text escape_text
|
27
|
+
def escape_text(text)
|
28
|
+
text.html_safe? ? text : orig_escape_text(text)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/hexp/css_selector.rb
CHANGED
data/lib/hexp/list.rb
CHANGED
data/lib/hexp/node/children.rb
CHANGED
data/lib/hexp/unparser.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module Hexp
|
2
2
|
class Unparser
|
3
|
+
include Adamantium
|
4
|
+
|
3
5
|
APOS = ?'.freeze
|
4
6
|
QUOT = ?".freeze
|
5
7
|
LT = '<'.freeze
|
@@ -24,46 +26,59 @@ module Hexp
|
|
24
26
|
ESCAPE_TEXT_REGEX = Regexp.new("[#{ESCAPE_TEXT.keys.join}]")
|
25
27
|
|
26
28
|
DEFAULT_OPTIONS = {
|
27
|
-
encoding: Encoding.default_external
|
29
|
+
encoding: Encoding.default_external,
|
30
|
+
no_escape: [:script]
|
28
31
|
}
|
29
32
|
|
33
|
+
attr_reader :options
|
34
|
+
|
30
35
|
def initialize(options)
|
31
36
|
@options = DEFAULT_OPTIONS.merge(options)
|
32
37
|
end
|
33
38
|
|
34
39
|
def call(node)
|
35
|
-
|
36
|
-
add_node(node)
|
37
|
-
|
40
|
+
buffer = String.new.force_encoding(options[:encoding])
|
41
|
+
add_node(buffer, node)
|
42
|
+
buffer.freeze
|
38
43
|
end
|
39
44
|
|
40
45
|
private
|
41
46
|
|
42
|
-
def add_node(node)
|
47
|
+
def add_node(buffer, node)
|
43
48
|
if node.text?
|
44
|
-
|
49
|
+
buffer << escape_text(node)
|
45
50
|
else
|
46
|
-
add_tag(node.tag, node.attributes, node.children)
|
51
|
+
add_tag(buffer, node.tag, node.attributes, node.children)
|
47
52
|
end
|
48
53
|
end
|
49
54
|
|
50
|
-
def add_tag(tag, attrs, children)
|
51
|
-
|
55
|
+
def add_tag(buffer, tag, attrs, children)
|
56
|
+
buffer << LT << tag.to_s
|
52
57
|
unless attrs.empty?
|
53
|
-
attrs.each {|k,v| add_attr(k,v)}
|
58
|
+
attrs.each {|k,v| add_attr(buffer, k,v)}
|
59
|
+
end
|
60
|
+
buffer << GT
|
61
|
+
add_child_nodes(buffer, tag, children)
|
62
|
+
buffer << LT << FSLASH << tag.to_s << GT
|
63
|
+
end
|
64
|
+
|
65
|
+
def add_child_nodes(buffer, tag, children)
|
66
|
+
# TODO look into the special parsing mode that browsers use inside <script> tags,
|
67
|
+
# at the least we should throw an error if the text contains </script>
|
68
|
+
if options[:no_escape].include?(tag) && children.length == 1 && children.first.text?
|
69
|
+
buffer << children.first
|
70
|
+
else
|
71
|
+
children.each {|node| add_node(buffer, node) }
|
54
72
|
end
|
55
|
-
@buffer << GT
|
56
|
-
children.each(&method(:add_node))
|
57
|
-
@buffer << LT << FSLASH << tag.to_s << GT
|
58
73
|
end
|
59
74
|
|
60
|
-
def add_attr(key, value)
|
61
|
-
|
62
|
-
add_attr_value(value)
|
75
|
+
def add_attr(buffer, key, value)
|
76
|
+
buffer << SPACE << key << EQ
|
77
|
+
add_attr_value(buffer, value)
|
63
78
|
end
|
64
79
|
|
65
|
-
def add_attr_value(value)
|
66
|
-
|
80
|
+
def add_attr_value(buffer, value)
|
81
|
+
buffer << APOS << value.gsub(ESCAPE_ATTR_APOS_REGEX, ESCAPE_ATTR_APOS) << APOS
|
67
82
|
end
|
68
83
|
|
69
84
|
def escape_text(text)
|
data/lib/hexp/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hexp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arne Brasseur
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sass
|
@@ -167,6 +167,7 @@ files:
|
|
167
167
|
- examples/todo.rb
|
168
168
|
- examples/widget.rb
|
169
169
|
- hexp.gemspec
|
170
|
+
- lib/hexp-rails.rb
|
170
171
|
- lib/hexp.rb
|
171
172
|
- lib/hexp/builder.rb
|
172
173
|
- lib/hexp/core_ext/nil.rb
|
@@ -241,12 +242,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
241
242
|
version: '0'
|
242
243
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
243
244
|
requirements:
|
244
|
-
- - "
|
245
|
+
- - ">="
|
245
246
|
- !ruby/object:Gem::Version
|
246
|
-
version:
|
247
|
+
version: '0'
|
247
248
|
requirements: []
|
248
249
|
rubyforge_project:
|
249
|
-
rubygems_version: 2.
|
250
|
+
rubygems_version: 2.2.2
|
250
251
|
signing_key:
|
251
252
|
specification_version: 4
|
252
253
|
summary: Generate and manipulate HTML documents and nodes.
|