oga 0.3.0-java → 0.3.1-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 89ef02859eae3c3117773035f01723b32a7031a7
4
- data.tar.gz: db6f29804d9ff062b5614996414461fd70dca00b
3
+ metadata.gz: ac227c01680fb6b04932a7715c113e2fc09b1c62
4
+ data.tar.gz: 412ab533e651333c671442239e7165ba3bbec2e7
5
5
  SHA512:
6
- metadata.gz: 0faba8accbbb9709bb68ed1b688a9728ad4e34125a9eb28f8a6eb50db3c19c320f1bbf89f9ce84ea66fadc5fbc4b7a8bc836b32904a5ad50e8ff49678f21a120
7
- data.tar.gz: 720d2c649056d5ffaf460725aaffd456081999a0311801cc11332795f81382836e88f77ef2d5d3ae30ca9a0e64801851cdf7af6e52858307e67beacf817def57
6
+ metadata.gz: 7daa67d63f5148e7894bd03df2f6a85562a5f9a08eee09388ce41f5a510896e65f7fe5c6a582d46b6efac8399050ed752bd5a33b6494a4fd11ffa1a4b598b523
7
+ data.tar.gz: 12a94c68692f33941c0d040ea576537e0eb3e6dcc3326c7f7f4ad6664282688fc2b454e2b3b3bc27864a8f60d36d9424032c25f6ee24e95ab6d988426aaf91d3
data/lib/liboga.jar CHANGED
Binary file
data/lib/oga.rb CHANGED
@@ -6,6 +6,7 @@ require 'thread'
6
6
  require_relative 'oga/version'
7
7
  require_relative 'oga/oga'
8
8
  require_relative 'oga/lru'
9
+ require_relative 'oga/entity_decoder'
9
10
 
10
11
  # Load these first so that the native extensions don't have to define the
11
12
  # Oga::XML namespace.
@@ -0,0 +1,21 @@
1
+ module Oga
2
+ module EntityDecoder
3
+ ##
4
+ # @see [decode]
5
+ #
6
+ def self.try_decode(input, html = false)
7
+ return input ? decode(input, html) : nil
8
+ end
9
+
10
+ ##
11
+ # @param [String] input
12
+ # @param [TrueClass|FalseClass] html
13
+ # @return [String]
14
+ #
15
+ def self.decode(input, html = false)
16
+ decoder = html ? HTML::Entities : XML::Entities
17
+
18
+ return decoder.decode(input)
19
+ end
20
+ end # EntityDecoder
21
+ end # Oga
data/lib/oga/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Oga
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end # Oga
@@ -10,16 +10,12 @@ module Oga
10
10
  # @!attribute [rw] namespace_name
11
11
  # @return [String]
12
12
  #
13
- # @!attribute [rw] value
14
- # The value of the attribute.
15
- # @return [String]
16
- #
17
13
  # @!attribute [r] element
18
14
  # The element this attribute belongs to.
19
15
  # @return [Oga::XML::Element]
20
16
  #
21
17
  class Attribute
22
- attr_accessor :name, :namespace_name, :element, :value
18
+ attr_accessor :name, :namespace_name, :element
23
19
 
24
20
  ##
25
21
  # The default namespace available to all attributes. This namespace can
@@ -67,8 +63,28 @@ module Oga
67
63
  end
68
64
 
69
65
  ##
70
- # Returns the value of the attribute.
66
+ # @param [String] value
71
67
  #
68
+ def value=(value)
69
+ @value = value
70
+ @decoded = false
71
+ end
72
+
73
+ ##
74
+ # Returns the value of the attribute or nil if no explicit value was set.
75
+ #
76
+ # @return [String|NilClass]
77
+ #
78
+ def value
79
+ if !@decoded and @value
80
+ @value = EntityDecoder.try_decode(@value, html?)
81
+ @decoded = true
82
+ end
83
+
84
+ return @value
85
+ end
86
+
87
+ ##
72
88
  # @return [String]
73
89
  #
74
90
  def text
@@ -108,6 +124,15 @@ module Oga
108
124
 
109
125
  return "Attribute(#{segments.join(' ')})"
110
126
  end
127
+
128
+ private
129
+
130
+ ##
131
+ # @return [TrueClass|FalseClass]
132
+ #
133
+ def html?
134
+ return !!@element && @element.html?
135
+ end
111
136
  end # Attribute
112
137
  end # XML
113
138
  end # Oga
data/lib/oga/xml/text.rb CHANGED
@@ -26,9 +26,8 @@ module Oga
26
26
  # @return [String]
27
27
  #
28
28
  def text
29
- unless @decoded
30
- decoder = html? ? HTML::Entities : Entities
31
- @text = decoder.decode(@text)
29
+ if decode_entities?
30
+ @text = EntityDecoder.try_decode(@text, html?)
32
31
  @decoded = true
33
32
  end
34
33
 
@@ -39,15 +38,29 @@ module Oga
39
38
  # @see [Oga::XML::CharacterNode#to_xml]
40
39
  #
41
40
  def to_xml
42
- node = parent
43
-
44
- if node.is_a?(Element) and html? \
45
- and Lexer::LITERAL_HTML_ELEMENTS.include?(node.name)
46
- return super
47
- end
41
+ return super if inside_literal_html?
48
42
 
49
43
  return Entities.encode(super)
50
44
  end
45
+
46
+ private
47
+
48
+ ##
49
+ # @return [TrueClass|FalseClass]
50
+ #
51
+ def decode_entities?
52
+ return !@decoded && !inside_literal_html?
53
+ end
54
+
55
+ ##
56
+ # @return [TrueClass|FalseClass]
57
+ #
58
+ def inside_literal_html?
59
+ node = parent
60
+
61
+ return node.is_a?(Element) && html? &&
62
+ Lexer::LITERAL_HTML_ELEMENTS.include?(node.name)
63
+ end
51
64
  end # Text
52
65
  end # XML
53
66
  end # Oga
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oga
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: java
6
6
  authors:
7
7
  - Yorick Peterse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-03 00:00:00.000000000 Z
11
+ date: 2015-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ast
@@ -142,56 +142,57 @@ executables: []
142
142
  extensions: []
143
143
  extra_rdoc_files: []
144
144
  files:
145
- - doc/xml_namespaces.md
146
145
  - doc/manually_creating_documents.md
146
+ - doc/DCO.md
147
+ - doc/xml_namespaces.md
147
148
  - doc/css_selectors.md
148
149
  - doc/migrating_from_nokogiri.md
149
- - doc/DCO.md
150
150
  - doc/css/common.css
151
151
  - lib/oga.rb
152
+ - lib/oga/oga.rb
152
153
  - lib/oga/version.rb
153
154
  - lib/oga/lru.rb
154
- - lib/oga/oga.rb
155
+ - lib/oga/entity_decoder.rb
155
156
  - lib/oga/css/lexer.rb
156
157
  - lib/oga/css/parser.rb
157
- - lib/oga/xml/namespace.rb
158
+ - lib/oga/html/sax_parser.rb
159
+ - lib/oga/html/parser.rb
160
+ - lib/oga/html/entities.rb
158
161
  - lib/oga/xml/lexer.rb
162
+ - lib/oga/xml/namespace.rb
163
+ - lib/oga/xml/processing_instruction.rb
164
+ - lib/oga/xml/character_node.rb
165
+ - lib/oga/xml/sax_parser.rb
166
+ - lib/oga/xml/doctype.rb
167
+ - lib/oga/xml/document.rb
168
+ - lib/oga/xml/comment.rb
169
+ - lib/oga/xml/default_namespace.rb
170
+ - lib/oga/xml/text.rb
159
171
  - lib/oga/xml/querying.rb
172
+ - lib/oga/xml/attribute.rb
173
+ - lib/oga/xml/pull_parser.rb
160
174
  - lib/oga/xml/parser.rb
161
- - lib/oga/xml/traversal.rb
162
- - lib/oga/xml/text.rb
175
+ - lib/oga/xml/entities.rb
176
+ - lib/oga/xml/html_void_elements.rb
163
177
  - lib/oga/xml/node.rb
164
- - lib/oga/xml/document.rb
165
- - lib/oga/xml/pull_parser.rb
166
178
  - lib/oga/xml/node_set.rb
167
- - lib/oga/xml/sax_parser.rb
168
- - lib/oga/xml/cdata.rb
169
179
  - lib/oga/xml/element.rb
170
- - lib/oga/xml/character_node.rb
171
- - lib/oga/xml/doctype.rb
172
- - lib/oga/xml/html_void_elements.rb
173
- - lib/oga/xml/entities.rb
174
- - lib/oga/xml/default_namespace.rb
175
- - lib/oga/xml/attribute.rb
176
180
  - lib/oga/xml/xml_declaration.rb
177
- - lib/oga/xml/processing_instruction.rb
178
- - lib/oga/xml/comment.rb
179
- - lib/oga/html/parser.rb
180
- - lib/oga/html/sax_parser.rb
181
- - lib/oga/html/entities.rb
181
+ - lib/oga/xml/cdata.rb
182
+ - lib/oga/xml/traversal.rb
182
183
  - lib/oga/xpath/lexer.rb
183
- - lib/oga/xpath/parser.rb
184
184
  - lib/oga/xpath/evaluator.rb
185
- - ext/ragel/base_lexer.rl
186
- - ext/java/Liboga.java
187
- - ext/java/org/liboga/xml/Lexer.java
188
- - ext/java/org/liboga/xml/Lexer.rl
189
- - ext/c/extconf.rb
185
+ - lib/oga/xpath/parser.rb
186
+ - ext/c/lexer.c
190
187
  - ext/c/lexer.rl
191
188
  - ext/c/lexer.h
192
189
  - ext/c/liboga.c
193
- - ext/c/lexer.c
190
+ - ext/c/extconf.rb
194
191
  - ext/c/liboga.h
192
+ - ext/ragel/base_lexer.rl
193
+ - ext/java/Liboga.java
194
+ - ext/java/org/liboga/xml/Lexer.java
195
+ - ext/java/org/liboga/xml/Lexer.rl
195
196
  - README.md
196
197
  - LICENSE
197
198
  - oga.gemspec