nokogiri-xml-range 0.1.0 → 0.1.1

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
- SHA1:
3
- metadata.gz: 2b9a05b01ac98bf6a41a88fa74ee6e7c12caebdf
4
- data.tar.gz: 491dc04b1eb68735c18330a472b3645f62c01ac7
2
+ SHA256:
3
+ metadata.gz: 92f36b17f2298f254b71c2afc1e074f427a15b76f6e732c6a253d64c7e6b67d4
4
+ data.tar.gz: 648f5fe677f526e735c7d7f24e26541daaf45374d9dbd883070e22511eb7a248
5
5
  SHA512:
6
- metadata.gz: d197d502e3fc10c82510bc074ecdd04a728dffff385eb97f1e304504d7f325f92340285c66ab1abe99492f5fd222477bb16c2796970f492a6386ce1bc8374a74
7
- data.tar.gz: 1f2606fa9df9778aa7c2ef4289d24f1469a8242e5ccbbda4cb2bda073ff581320442945d74c17ee1843fa808c804af53b1ba53f974fec653095424ee22eda144
6
+ metadata.gz: 24917bcad96a0e62148748c23d9022082e7809c810581820fd6bf5dfd8fea4fc26f0422216f6511ff567223e6c9edf27ea0b041de9fc6c8275cb7c9600fb3224
7
+ data.tar.gz: 84025d816602ec7622733e7b22d4bbeb5161bf89e65282d7d83b6f9359626da9aef5fbc4970ef76800cb4f9824f7ff995dff0f9c79a1cf41be0e0a1fe428772d
data/.document CHANGED
@@ -1,3 +1,3 @@
1
1
  -
2
2
  ChangeLog.md
3
- LICENSE.txt
3
+ COPYING.txt
data/.gitignore CHANGED
@@ -1,2 +1,4 @@
1
1
  doc/
2
2
  pkg/
3
+ .yardoc/
4
+ coverage/
@@ -0,0 +1,17 @@
1
+ before_script:
2
+ - gem install --no-document nokogiri test-unit test-unit-notify rubygems-tasks yard rake pry simplecov
3
+
4
+ test:2.4:
5
+ image: ruby:2.4
6
+ script:
7
+ - rake test
8
+
9
+ test:2.5:
10
+ image: ruby:2.5
11
+ script:
12
+ - rake test
13
+
14
+ test:2.6:
15
+ image: ruby:2.6
16
+ script:
17
+ - rake test
@@ -1,3 +1,7 @@
1
+ ### 0.1.1 / 2019-05-05
2
+
3
+ * Use refinements to add method to CharacterData and ProcessingInstruction instead of module inclusion
4
+
1
5
  ### 0.1.0 / 2015-09-05
2
6
 
3
7
  * Initial release:
data/README.md CHANGED
@@ -1,11 +1,13 @@
1
1
  Nokogiri::XML::Range
2
2
  ====================
3
3
 
4
- [![Build Status](https://travis-ci.org/KitaitiMakoto/nokogiri-xml-range.svg?branch=master)](https://travis-ci.org/KitaitiMakoto/nokogiri-xml-range)
5
- [![Coverage Status](https://coveralls.io/repos/KitaitiMakoto/nokogiri-xml-range/badge.svg?branch=master&service=github)](https://coveralls.io/github/KitaitiMakoto/nokogiri-xml-range?branch=master)
4
+ [![pipeline status](https://gitlab.com/KitaitiMakoto/nokogiri-xml-range/badges/master/pipeline.svg)](https://gitlab.com/KitaitiMakoto/nokogiri-xml-range/commits/master)
5
+ [![coverage report](https://gitlab.com/KitaitiMakoto/nokogiri-xml-range/badges/master/coverage.svg)](https://gitlab.com/KitaitiMakoto/nokogiri-xml-range/commits/master)
6
+ [![Gem Version](https://badge.fury.io/rb/nokogiri-xml-range.svg)](http://badge.fury.io/rb/nokogiri-xml-range)
6
7
 
7
- * [Homepage](https://rubygems.org/gems/nokogiri-xml-range)
8
+ * [Homepage](https://gitlab.com/KitaitiMakoto/nokogiri-xml-range)
8
9
  * [Documentation](http://rubydoc.info/gems/nokogiri-xml-range)
10
+ * [Source code](https://gitlab.com/KitaitiMakoto/nokogiri-xml-range)
9
11
  * [Email](mailto:KitaitiMakoto at gmail.com)
10
12
 
11
13
  DOM Range implementation on Nokogiri
@@ -50,9 +52,18 @@ Examples
50
52
  child2 = doc.search('child')[1]
51
53
  child1_text = child1.child
52
54
  child2_text = child2.child
55
+
53
56
  # Initialize range with nodes and offsets of start and end point
54
57
  range = Nokogiri::XML::Range.new(child1_text, 0, child2_text, 5)
58
+
55
59
  # This range expresses `child 1</child>\n <child>child`
60
+ # Pseudoly expressed as:
61
+ # <root>
62
+ # <parent>
63
+ # <child>[**START POINT**]child 1</child>
64
+ # <child>child[**END POINT**] 2</child>
65
+ # </parent>
66
+ # </root>
56
67
 
57
68
  ### Deleting contents ###
58
69
 
@@ -147,6 +158,14 @@ Install
147
158
 
148
159
  $ gem install nokogiri-xml-range
149
160
 
161
+ Todos
162
+ -----
163
+
164
+ * Helpful error messages
165
+ * C0 coverage 100%
166
+ * More test cases from use cases in the wild
167
+ * Performance optimization, especially caching
168
+
150
169
  Copyright
151
170
  ---------
152
171
 
@@ -2,20 +2,19 @@
2
2
  require 'nokogiri/xml/range/version'
3
3
  require 'nokogiri'
4
4
  require 'nokogiri/xml/range/refinement'
5
- require 'nokogiri/xml/replacable'
6
5
 
7
6
  using Nokogiri::XML::Range::Refinement
8
7
 
9
8
  module Nokogiri::XML
10
- class InvalidNodeTypeError < StandardError; end
11
- class IndexSizeError < StandardError; end
12
- class NotSupportedError < StandardError; end
13
- class WrongDocumentError < StandardError; end
14
- class HierarchyRequestError < StandardError; end
15
- class NotFoundError < StandardError; end
16
- class InvalidStateError < StandardError; end
17
-
18
9
  class Range
10
+ class InvalidNodeTypeError < StandardError; end
11
+ class IndexSizeError < StandardError; end
12
+ class NotSupportedError < StandardError; end
13
+ class WrongDocumentError < StandardError; end
14
+ class HierarchyRequestError < StandardError; end
15
+ class NotFoundError < StandardError; end
16
+ class InvalidStateError < StandardError; end
17
+
19
18
  START_TO_START = 0
20
19
  START_TO_END = 1
21
20
  END_TO_END = 2
@@ -58,7 +58,7 @@ module Nokogiri::XML
58
58
  end
59
59
 
60
60
  def replacable?
61
- kind_of? Nokogiri::XML::Replacable
61
+ kind_of?(CharacterData) || kind_of?(ProcessingInstruction)
62
62
  end
63
63
 
64
64
  def validate_pre_insertion(parent, child)
@@ -119,6 +119,36 @@ module Nokogiri::XML
119
119
  refine DocumentFragment do
120
120
  attr_accessor :host
121
121
  end
122
+
123
+ [CharacterData, ProcessingInstruction].each do |klass|
124
+ refine klass do
125
+ def replace_data(offset, count, data)
126
+ len = length
127
+ raise IndexSizeError, 'offset is greater than node length' if offset > len
128
+
129
+ count = len - offset if offset + count > len
130
+ encoding = content.encoding
131
+ utf16_content = content.encode('UTF-16LE')
132
+ utf16_data = data.encode('UTF-16LE')
133
+ result = utf16_content.byteslice(0, offset * 2) + utf16_data + utf16_content.byteslice(offset * 2, utf16_content.bytesize)
134
+ delete_offset = offset + utf16_data.bytesize / 2
135
+ result = result.byteslice(0, delete_offset * 2) + result.byteslice((delete_offset + count) * 2, result.bytesize)
136
+
137
+ self.content = result.encode(encoding)
138
+ end
139
+
140
+ def substring_data(offset, count)
141
+ len = length
142
+ raise IndexSizeError, 'offset is greater than node length' if offset > len
143
+
144
+ encoding = content.encoding
145
+ utf16_content = content.encode('UTF-16LE')
146
+
147
+ byte_length = [utf16_content.bytesize - offset * 2, count * 2].min
148
+ utf16_content.byteslice(offset * 2, byte_length).encode(encoding)
149
+ end
150
+ end
151
+ end
122
152
  end
123
153
  end
124
154
  end
@@ -2,7 +2,7 @@ module Nokogiri
2
2
  module XML
3
3
  class Range
4
4
  # nokogiri-xml-range version
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.1"
6
6
  end
7
7
  end
8
8
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
10
10
  gem.license = "LGPL"
11
11
  gem.authors = ["KITAITI Makoto"]
12
12
  gem.email = "KitaitiMakoto@gmail.com"
13
- gem.homepage = "https://rubygems.org/gems/nokogiri-xml-range"
13
+ gem.homepage = "https://gitlab.com/KitaitiMakoto/nokogiri-xml-range"
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -21,11 +21,9 @@ Gem::Specification.new do |gem|
21
21
 
22
22
  gem.add_development_dependency 'test-unit', '~> 3'
23
23
  gem.add_development_dependency 'test-unit-notify'
24
- gem.add_development_dependency 'rubygems-tasks', '~> 0.2'
25
- gem.add_development_dependency 'yard', '~> 0.8'
24
+ gem.add_development_dependency 'rubygems-tasks'
25
+ gem.add_development_dependency 'yard'
26
26
  gem.add_development_dependency 'rake'
27
- gem.add_development_dependency 'bundler'
28
27
  gem.add_development_dependency 'pry'
29
28
  gem.add_development_dependency 'simplecov'
30
- gem.add_development_dependency 'coveralls'
31
29
  end
@@ -1,10 +1,4 @@
1
1
  require 'simplecov'
2
- require 'coveralls'
3
- Coveralls.wear!
4
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5
- SimpleCov::Formatter::HTMLFormatter,
6
- Coveralls::SimpleCov::Formatter
7
- ]
8
2
  SimpleCov.start do
9
3
  add_filter '/test/'
10
4
  end
@@ -1,7 +1,6 @@
1
1
  require 'helper'
2
2
  require 'nokogiri'
3
3
  require 'nokogiri/xml/range/refinement'
4
- require 'nokogiri/xml/replacable'
5
4
 
6
5
  class TestNokogiriXMLRangeRefinement < Test::Unit::TestCase
7
6
  using Nokogiri::XML::Range::Refinement
@@ -1,9 +1,10 @@
1
1
  require 'helper'
2
2
  require 'nokogiri'
3
3
  require 'nokogiri/xml/range/refinement'
4
- require 'nokogiri/xml/replacable'
5
4
 
6
5
  class TestNokogiriXMLReplacable < Test::Unit::TestCase
6
+ using Nokogiri::XML::Range::Refinement
7
+
7
8
  def setup
8
9
  @doc = Nokogiri::XML::Document.new
9
10
  @text = Nokogiri::XML::Text.new('Hello, world.', @doc)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nokogiri-xml-range
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - KITAITI Makoto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-05 00:00:00.000000000 Z
11
+ date: 2019-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -54,34 +54,6 @@ dependencies:
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rubygems-tasks
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '0.2'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '0.2'
69
- - !ruby/object:Gem::Dependency
70
- name: yard
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '0.8'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '0.8'
83
- - !ruby/object:Gem::Dependency
84
- name: rake
85
57
  requirement: !ruby/object:Gem::Requirement
86
58
  requirements:
87
59
  - - ">="
@@ -95,7 +67,7 @@ dependencies:
95
67
  - !ruby/object:Gem::Version
96
68
  version: '0'
97
69
  - !ruby/object:Gem::Dependency
98
- name: bundler
70
+ name: yard
99
71
  requirement: !ruby/object:Gem::Requirement
100
72
  requirements:
101
73
  - - ">="
@@ -109,7 +81,7 @@ dependencies:
109
81
  - !ruby/object:Gem::Version
110
82
  version: '0'
111
83
  - !ruby/object:Gem::Dependency
112
- name: pry
84
+ name: rake
113
85
  requirement: !ruby/object:Gem::Requirement
114
86
  requirements:
115
87
  - - ">="
@@ -123,7 +95,7 @@ dependencies:
123
95
  - !ruby/object:Gem::Version
124
96
  version: '0'
125
97
  - !ruby/object:Gem::Dependency
126
- name: simplecov
98
+ name: pry
127
99
  requirement: !ruby/object:Gem::Requirement
128
100
  requirements:
129
101
  - - ">="
@@ -137,7 +109,7 @@ dependencies:
137
109
  - !ruby/object:Gem::Version
138
110
  version: '0'
139
111
  - !ruby/object:Gem::Dependency
140
- name: coveralls
112
+ name: simplecov
141
113
  requirement: !ruby/object:Gem::Requirement
142
114
  requirements:
143
115
  - - ">="
@@ -156,26 +128,23 @@ executables: []
156
128
  extensions: []
157
129
  extra_rdoc_files: []
158
130
  files:
159
- - ".coveralls.yml"
160
131
  - ".document"
161
132
  - ".gitignore"
162
- - ".travis.yml"
133
+ - ".gitlab-ci.yml"
163
134
  - ".yardopts"
164
135
  - COPYING.txt
165
136
  - ChangeLog.md
166
- - Gemfile
167
137
  - README.md
168
138
  - Rakefile
169
139
  - lib/nokogiri/xml/range.rb
170
140
  - lib/nokogiri/xml/range/refinement.rb
171
141
  - lib/nokogiri/xml/range/version.rb
172
- - lib/nokogiri/xml/replacable.rb
173
142
  - nokogiri-xml-range.gemspec
174
143
  - test/helper.rb
175
144
  - test/test_nokogiri-xml-range-refinement.rb
176
145
  - test/test_nokogiri-xml-range.rb
177
146
  - test/test_nokogiri-xml-replacable.rb
178
- homepage: https://rubygems.org/gems/nokogiri-xml-range
147
+ homepage: https://gitlab.com/KitaitiMakoto/nokogiri-xml-range
179
148
  licenses:
180
149
  - LGPL
181
150
  metadata: {}
@@ -194,8 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
163
  - !ruby/object:Gem::Version
195
164
  version: '0'
196
165
  requirements: []
197
- rubyforge_project:
198
- rubygems_version: 2.4.6
166
+ rubygems_version: 3.0.3
199
167
  signing_key:
200
168
  specification_version: 4
201
169
  summary: DOM Range implementation on Nokogiri
@@ -1 +0,0 @@
1
- service_name: travis-ci
@@ -1,5 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - ruby-head
4
- - 2.2.3
5
- - 2.1.7
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
@@ -1,39 +0,0 @@
1
- using Nokogiri::XML::Range::Refinement
2
-
3
- module Nokogiri::XML
4
- module Replacable
5
- def replace_data(offset, count, data)
6
- len = length
7
- raise IndexSizeError, 'offset is greater than node length' if offset > len
8
-
9
- count = len - offset if offset + count > len
10
- encoding = content.encoding
11
- utf16_content = content.encode('UTF-16LE')
12
- utf16_data = data.encode('UTF-16LE')
13
- result = utf16_content.byteslice(0, offset * 2) + utf16_data + utf16_content.byteslice(offset * 2, utf16_content.bytesize)
14
- delete_offset = offset + utf16_data.bytesize / 2
15
- result = result.byteslice(0, delete_offset * 2) + result.byteslice((delete_offset + count) * 2, result.bytesize)
16
-
17
- self.content = result.encode(encoding)
18
- end
19
-
20
- def substring_data(offset, count)
21
- len = length
22
- raise IndexSizeError, 'offset is greater than node length' if offset > len
23
-
24
- encoding = content.encoding
25
- utf16_content = content.encode('UTF-16LE')
26
-
27
- byte_length = [utf16_content.bytesize - offset * 2, count * 2].min
28
- utf16_content.byteslice(offset * 2, byte_length).encode(encoding)
29
- end
30
- end
31
-
32
- class CharacterData
33
- include Replacable
34
- end
35
-
36
- class ProcessingInstruction
37
- include Replacable
38
- end
39
- end