trenni-sanitize 0.2.0 → 0.3.0

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: fd1bd015d1fe0b61494d1289eb43e200e1610e5a
4
- data.tar.gz: 4ae3952d6ef7bf38a8b16ae3aff29f0a1f38dee4
2
+ SHA256:
3
+ metadata.gz: 692099586ce2e3dfb2e1ff3911cafa0e39a22d5dac957ef4401f3fd31be32565
4
+ data.tar.gz: d0a4d9ff3f8e5937119f08638b188c6d7c386fa428fb3c98fe64334d8fd8e705
5
5
  SHA512:
6
- metadata.gz: 7e352c69337f48b62c5292970cbb849563d4e10974a0547d9abcdc79979cc80e26523db4453c5e9c26d085b628b57a883ca86b6bbbdf05cea27f861db53b888e
7
- data.tar.gz: 77aa0739c366265b9cf2fa91c256155d709f59c179fa18cac859cf26d5bcfcf5fcd61fc61c7286ce098e67c812962be39da860815f09b1ab1713b2af33377d1f
6
+ metadata.gz: 4668acf3447f634251f01a4b3ffef72592552ff6da12178b7201a221e25b6dc1f0f6115903201ad75532e73d6df93dda13cb8e4cb68a890e651569710700852c
7
+ data.tar.gz: bde8b725c3a2455b3eb762eb25036538d4a591aa77e3e6e5c30642a8680f3907fd4f429c906e893b70401b1e7b9b1616dd4153f38d7c0533dfc698351658aebe
@@ -1,17 +1,22 @@
1
1
  language: ruby
2
- sudo: false
3
- rvm:
4
- - 2.1
5
- - 2.2
6
- - 2.3
7
- - 2.4
8
- - ruby-head
9
- - jruby-head
10
- - rbx-2
11
- env:
12
- - COVERAGE=true
2
+ dist: xenial
3
+ cache: bundler
4
+
13
5
  matrix:
6
+ include:
7
+ - rvm: 2.3
8
+ - rvm: 2.4
9
+ - rvm: 2.5
10
+ - rvm: 2.6
11
+ - rvm: 2.6
12
+ os: osx
13
+ - rvm: 2.6
14
+ env: COVERAGE=BriefSummary,Coveralls
15
+ - rvm: truffleruby
16
+ - rvm: jruby-head
17
+ env: JRUBY_OPTS="--debug -X+O"
18
+ - rvm: ruby-head
14
19
  allow_failures:
15
- - rvm: "rbx-2"
16
- - rvm: "ruby-head"
17
- - rvm: "jruby-head"
20
+ - rvm: truffleruby
21
+ - rvm: ruby-head
22
+ - rvm: jruby-head
data/README.md CHANGED
@@ -1,31 +1,36 @@
1
- # trenni-sanitize::Sanitize
1
+ # Trenni::Sanitize
2
2
 
3
- Sanitize markup by adding, changing or removing tags.
3
+ Sanitize markup by adding, changing or removing tags, using the [trenni] stream processor (which has a naive C implementation).
4
4
 
5
5
  [![Build Status](https://secure.travis-ci.org/ioquatix/trenni-sanitize.svg)](http://travis-ci.org/ioquatix/trenni-sanitize)
6
6
  [![Code Climate](https://codeclimate.com/github/ioquatix/trenni-sanitize.svg)](https://codeclimate.com/github/ioquatix/trenni-sanitize)
7
7
  [![Coverage Status](https://coveralls.io/repos/ioquatix/trenni-sanitize/badge.svg)](https://coveralls.io/r/ioquatix/trenni-sanitize)
8
8
 
9
+ [trenni]: https://github.com/ioquatix/trenni
10
+
9
11
  ## Motivation
10
12
 
11
- I use the [sanitize] gem and generally it's great. However, it's performance can be an issue and additionally, it doesn't preserve tag namespaces when parsing fragments due to how Nokogiri works internally.
13
+ I use the [sanitize] gem and generally it's great. However, it's performance can be an issue and additionally, it doesn't preserve tag namespaces when parsing fragments due to how Nokogiri works internally. This is a problem when processing content destined for [utopia] since it heavily depends on tag namespaces.
12
14
 
13
15
  [sanitize]: https://github.com/rgrove/sanitize/
16
+ [utopia]: https://github.com/ioquatix/utopia
14
17
 
15
18
  ## Is it fast?
16
19
 
17
20
  In my informal testing, this gem is about ~50x faster than the [sanitize] gem when generating plain text.
18
21
 
22
+ ```
19
23
  Warming up --------------------------------------
20
- Sanitize 96.000 i/100ms
24
+ Sanitize 96.000 i/100ms
21
25
  Trenni::Sanitize 4.447k i/100ms
22
26
  Calculating -------------------------------------
23
- Sanitize 958.020 (± 4.5%) i/s - 4.800k in 5.020564s
27
+ Sanitize 958.020 (± 4.5%) i/s - 4.800k in 5.020564s
24
28
  Trenni::Sanitize 44.718k (± 4.2%) i/s - 226.797k in 5.080756s
25
29
 
26
30
  Comparison:
27
31
  Trenni::Sanitize: 44718.1 i/s
28
- Sanitize: 958.0 i/s - 46.68x slower
32
+ Sanitize: 958.0 i/s - 46.68x slower
33
+ ```
29
34
 
30
35
  ## Installation
31
36
 
@@ -52,7 +57,7 @@ You can extract text using something similar to the following parser delegate:
52
57
  ```ruby
53
58
  class Text < Trenni::Sanitize::Filter
54
59
  def filter(node)
55
- skip!(TAG)
60
+ node.skip!(TAG)
56
61
  end
57
62
 
58
63
  def doctype(string)
@@ -78,16 +83,16 @@ class Fragment < Trenni::Sanitize::Filter
78
83
  'em' => [],
79
84
  'strong' => [],
80
85
  'p' => [],
81
- 'img' => [] + ['src', 'alt', 'width', 'height'],
82
- 'a' => ['href', 'target']
86
+ 'img' => ['src', 'alt', 'width', 'height'],
87
+ 'a' => ['href']
83
88
  }.freeze
84
89
 
85
90
  def filter(node)
86
91
  if attributes = ALLOWED_TAGS[node.name]
87
- node.tag.attributes.slice!(attributes)
92
+ node.tag.attributes.slice!(*attributes)
88
93
  else
89
94
  # Skip the tag, and all contents
90
- skip!(ALL)
95
+ node.skip!(ALL)
91
96
  end
92
97
  end
93
98
 
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Trenni
22
22
  module Sanitize
23
- VERSION = "0.2.0"
23
+ VERSION = "0.3.0"
24
24
  end
25
25
  end
@@ -1,23 +1,6 @@
1
1
 
2
- if ENV['COVERAGE']
3
- begin
4
- require 'simplecov'
5
-
6
- SimpleCov.start do
7
- add_filter "/spec/"
8
- end
9
-
10
- if ENV['TRAVIS']
11
- require 'coveralls'
12
- Coveralls.wear!
13
- end
14
- rescue LoadError
15
- warn "Could not load simplecov: #{$!}"
16
- end
17
- end
18
-
19
- require "bundler/setup"
20
- require "trenni/sanitize"
2
+ require 'covered/rspec'
3
+ require 'bundler/setup'
21
4
 
22
5
  begin
23
6
  require 'ruby-prof'
@@ -18,8 +18,8 @@ RSpec.describe Trenni::Sanitize do
18
18
 
19
19
  text = buffer.read
20
20
 
21
- puts Sanitize.fragment(text).inspect
22
- puts Trenni::Sanitize::Text.parse(buffer).output.inspect
21
+ # puts Sanitize.fragment(text).inspect
22
+ # puts Trenni::Sanitize::Text.parse(buffer).output.inspect
23
23
 
24
24
  Benchmark.ips do |x|
25
25
  x.report("Sanitize") do
@@ -17,8 +17,9 @@ Gem::Specification.new do |spec|
17
17
 
18
18
  spec.required_ruby_version = '~> 2.1'
19
19
 
20
- spec.add_dependency "trenni", '~> 3.5.0'
20
+ spec.add_dependency "trenni", '~> 3.5'
21
21
 
22
+ spec.add_development_dependency "covered"
22
23
  spec.add_development_dependency "bundler", "~> 1.3"
23
24
  spec.add_development_dependency "rspec", "~> 3.4"
24
25
  spec.add_development_dependency "rake"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trenni-sanitize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-15 00:00:00.000000000 Z
11
+ date: 2019-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trenni
@@ -16,14 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 3.5.0
19
+ version: '3.5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 3.5.0
26
+ version: '3.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: covered
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -111,8 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
125
  - !ruby/object:Gem::Version
112
126
  version: '0'
113
127
  requirements: []
114
- rubyforge_project:
115
- rubygems_version: 2.6.12
128
+ rubygems_version: 3.0.3
116
129
  signing_key:
117
130
  specification_version: 4
118
131
  summary: Sanitize markdown according to a set of rules.