abbreviato 0.9.4 → 0.10.0
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.
- checksums.yaml +4 -4
- data/README.md +7 -0
- data/lib/abbreviato/abbreviato.rb +15 -0
- data/lib/abbreviato/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5085c8300a7d9a509c4f72e2cb9daf5a3e1d4b87
|
4
|
+
data.tar.gz: eef2da69fa0c5ce8be05f46c6ccdc62e3942ed3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a3d5bdf9ddcd1804697a8904e86189016603f6d4cb9b982989279ec8388c794097fe03baff381c4643bd5388d444fc579e012fd4d87600e298c3e9986d66d9d
|
7
|
+
data.tar.gz: 381c985b43bab367387842aca67c1125fa57d89c02ff11d4b5e537d8865e96fa444fe44176765d224e098f221db9962a972f217454ace9ed0e0a2d6cd5e03ea5
|
data/README.md
CHANGED
@@ -37,6 +37,13 @@ Abbreviato was designed with performance in mind. Its main motivation was that e
|
|
37
37
|
bundle exec rake
|
38
38
|
```
|
39
39
|
|
40
|
+
## Running a single test
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
rspec spec/abbreviato/abbreviato_spec.rb
|
44
|
+
rspec spec/abbreviato/abbreviato_spec.rb:357
|
45
|
+
```
|
46
|
+
|
40
47
|
## Running all checks
|
41
48
|
|
42
49
|
```ruby
|
@@ -12,6 +12,9 @@ module Abbreviato
|
|
12
12
|
# @param [String] source the XML source to truncate
|
13
13
|
# @param [Hash] user_options truncation options
|
14
14
|
# @option user_options [Integer] :max_length Maximum length
|
15
|
+
# @option user_options [Boolean] :truncate_incomplete_row Indicates whether or
|
16
|
+
# not to truncate the last row in a table if truncation due to max_length
|
17
|
+
# occurs in the middle of a row.
|
15
18
|
# @option user_options [String] :tail Text to append when the truncation happens
|
16
19
|
# @option user_options [Boolean] :fragment Indicates whether the document to be truncated is an HTML fragment
|
17
20
|
# or an entire document (with `HTML`, `HEAD` & `BODY` tags). Setting to true prevents automatic addition of
|
@@ -22,6 +25,18 @@ module Abbreviato
|
|
22
25
|
truncated_sax_document = TruncatedSaxDocument.new(DEFAULT_OPTIONS.merge(user_options))
|
23
26
|
parser = Nokogiri::HTML::SAX::Parser.new(truncated_sax_document)
|
24
27
|
parser.parse(source) { |context| context.replace_entities = false }
|
28
|
+
|
29
|
+
if truncated_sax_document.truncated && user_options[:truncate_incomplete_row]
|
30
|
+
html_fragment = Nokogiri::HTML.fragment(truncated_sax_document.truncated_string.strip)
|
31
|
+
last_table_in_doc = html_fragment.xpath('.//table').last
|
32
|
+
cols_in_first_row = last_table_in_doc.xpath('.//tr').first.xpath('.//td').length
|
33
|
+
last_table_in_doc.xpath('.//tr').reverse.each do |element|
|
34
|
+
element.remove if element.xpath('.//td').length != cols_in_first_row
|
35
|
+
end
|
36
|
+
|
37
|
+
return [html_fragment.to_html, truncated_sax_document.truncated]
|
38
|
+
end
|
39
|
+
|
25
40
|
[truncated_sax_document.truncated_string.strip, truncated_sax_document.truncated]
|
26
41
|
end
|
27
42
|
end
|
data/lib/abbreviato/version.rb
CHANGED