html_slicer 0.1.0 → 0.1.1
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/CHANGELOG +4 -0
- data/lib/html_slicer/config.rb +3 -3
- data/lib/html_slicer/interface.rb +1 -1
- data/lib/html_slicer/mappers/slicing.rb +19 -23
- data/lib/html_slicer/utilities.rb +6 -7
- data/lib/html_slicer/version.rb +1 -1
- metadata +2 -2
data/CHANGELOG
CHANGED
data/lib/html_slicer/config.rb
CHANGED
@@ -159,7 +159,7 @@ module HtmlSlicer
|
|
159
159
|
when HTML::Text then
|
160
160
|
if sliced?
|
161
161
|
if range = slicing.map.get(node, slice)
|
162
|
-
"#{node.content[Range.new(*range)]}#{slicing.options.text_break unless range.last == -1}"
|
162
|
+
"#{node.content[Range.new(*range)]}#{slicing.options.text_break unless range.last == -1 || !slicing.map.get(node, slice+1)}"
|
163
163
|
end
|
164
164
|
else
|
165
165
|
node.to_s
|
@@ -37,24 +37,28 @@ module HtmlSlicer
|
|
37
37
|
if sliceable?(node)
|
38
38
|
sanitize_content!(node)
|
39
39
|
content = node.to_s
|
40
|
-
index = 0
|
41
40
|
begin
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
if
|
46
|
-
units_count
|
47
|
-
index =
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
41
|
+
start_index = 0
|
42
|
+
last_index = 0
|
43
|
+
content.scan(@options.unit) do
|
44
|
+
if $~.begin(0) >= start_index
|
45
|
+
units_count += 1
|
46
|
+
index = $~.end(0)
|
47
|
+
if units_count == @options.maximum
|
48
|
+
units_count = 0
|
49
|
+
if complete_regexp = @options.complete
|
50
|
+
index = content.match(complete_regexp, index).try(:begin, 0)||index
|
51
|
+
start_index = index
|
52
|
+
end
|
53
|
+
@map.commit(node, @slice_number, [last_index, index-1])
|
54
|
+
last_index = index
|
55
|
+
limited? ? raise(Exception) : @slice_number += 1
|
56
|
+
end
|
56
57
|
end
|
57
58
|
end
|
59
|
+
if units_count > 0
|
60
|
+
@map.commit(node, @slice_number, [last_index, -1])
|
61
|
+
end
|
58
62
|
rescue Exception
|
59
63
|
break
|
60
64
|
end
|
@@ -94,14 +98,6 @@ module HtmlSlicer
|
|
94
98
|
node.instance_variable_set(:@content, content)
|
95
99
|
end
|
96
100
|
|
97
|
-
def complete!(content, index)
|
98
|
-
if regexp = @options.complete
|
99
|
-
content.match(regexp, index).try(:begin, 0)||index
|
100
|
-
else
|
101
|
-
index
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
101
|
def sliceable?(node)
|
106
102
|
able_to?(node, @options)
|
107
103
|
end
|
@@ -64,14 +64,13 @@ module HtmlSlicer
|
|
64
64
|
raise(TypeError, "Array expected!") unless array.is_a?(Array)
|
65
65
|
raise(Exception, "At least 2 elements needed!") if array.size < 2
|
66
66
|
value = array.delete_at(-1)
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
67
|
+
{}.tap do |hash|
|
68
|
+
index = 0
|
69
|
+
while index < array.size
|
70
|
+
hash = hash[array.at(index)] = (index + 1 == array.size) ? value : {}
|
71
|
+
index += 1
|
72
|
+
end
|
73
73
|
end
|
74
|
-
hash
|
75
74
|
end
|
76
75
|
end
|
77
76
|
|
data/lib/html_slicer/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: html_slicer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
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-07-
|
12
|
+
date: 2012-07-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|