berns 3.0.5 → 3.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.org +3 -6
- data/ext/berns/berns.c +2 -0
- data/ext/mkmf.log +7 -0
- data/lib/berns/berns.bundle +0 -0
- data/lib/berns/berns.so +0 -0
- data/lib/berns/version.rb +1 -1
- metadata +22 -13
- data/.editorconfig +0 -20
- data/.github/workflows/main.yml +0 -24
- data/.gitignore +0 -9
- data/.rubocop.yml +0 -58
- data/CHANGELOG.org +0 -157
- data/Gemfile +0 -5
- data/Rakefile +0 -20
- data/berns.gemspec +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0513b5d30f4b3b8cc581baa1d46a2bd64469d76224638cdcdb45fe3faab1e66
|
4
|
+
data.tar.gz: 857d58645cdad849eea710bc68bd3e5ab3695e9e0ba763b54392fa96956836dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa90410871bd7491fc665c55cb3527dfa7441c43962c2a50fab5f68fb0e87f9c5b2960e619aa97273d0f91164c9d7c6d63dda6ebd93534227e3b3f5a034fcf34
|
7
|
+
data.tar.gz: d8ed28163f684577aec0f8b1fe8010e9135e8c03ecabba2797a8e60640d55143763b9db0adf0f0258fd660faf7f6d975dc70f9c97dfa39691fc90a9b7e4945ed
|
data/README.org
CHANGED
@@ -26,10 +26,7 @@ gem install berns
|
|
26
26
|
|
27
27
|
** Usage
|
28
28
|
|
29
|
-
|
30
|
-
create e.g. a link with =Berns.a=. In addition, there are methods to sanitize
|
31
|
-
strings i.e. remove HTML from them, convert hashes into a string of HTML
|
32
|
-
attributes, and more.
|
29
|
+
Note that all return string values will be UTF-8 encoded.
|
33
30
|
|
34
31
|
*** =void(tag, attributes)=
|
35
32
|
|
@@ -94,8 +91,8 @@ Berns.sanitize('This <span>should be clean</span>') # => 'This should be clean'
|
|
94
91
|
|
95
92
|
*** Standard and void elements
|
96
93
|
|
97
|
-
|
98
|
-
|
94
|
+
All standard and void HTML elements are defined as methods on Berns, so you can
|
95
|
+
create e.g. a link with =Berns.a=. Below is the full list of standard elements.
|
99
96
|
|
100
97
|
#+begin_example
|
101
98
|
a abbr address article aside audio b bdi bdo blockquote body button
|
data/ext/berns/berns.c
CHANGED
@@ -316,6 +316,8 @@ static VALUE berns_internal_element(VALUE tag, VALUE attributes) {
|
|
316
316
|
|
317
317
|
if (TYPE(content) == T_NIL || TYPE(content) == T_FALSE) {
|
318
318
|
content = rb_utf8_str_new_cstr("");
|
319
|
+
} else if (TYPE(content) != T_STRING) {
|
320
|
+
content = rb_funcall(content, rb_intern("to_s"), 0);
|
319
321
|
}
|
320
322
|
} else {
|
321
323
|
content = rb_utf8_str_new_cstr("");
|
data/ext/mkmf.log
ADDED
Binary file
|
data/lib/berns/berns.so
ADDED
Binary file
|
data/lib/berns/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: berns
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Taylor Beck
|
8
8
|
- Evan Lecklider
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-04-
|
12
|
+
date: 2021-04-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cgi
|
@@ -109,6 +109,20 @@ dependencies:
|
|
109
109
|
- - ">="
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: '0'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: rubocop-packaging
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
112
126
|
- !ruby/object:Gem::Dependency
|
113
127
|
name: rubocop-performance
|
114
128
|
requirement: !ruby/object:Gem::Requirement
|
@@ -146,19 +160,14 @@ extensions:
|
|
146
160
|
- ext/berns/extconf.rb
|
147
161
|
extra_rdoc_files: []
|
148
162
|
files:
|
149
|
-
- ".editorconfig"
|
150
|
-
- ".github/workflows/main.yml"
|
151
|
-
- ".gitignore"
|
152
|
-
- ".rubocop.yml"
|
153
|
-
- CHANGELOG.org
|
154
|
-
- Gemfile
|
155
163
|
- LICENSE.txt
|
156
164
|
- README.org
|
157
|
-
- Rakefile
|
158
|
-
- berns.gemspec
|
159
165
|
- ext/berns/berns.c
|
160
166
|
- ext/berns/extconf.rb
|
167
|
+
- ext/mkmf.log
|
161
168
|
- lib/berns.rb
|
169
|
+
- lib/berns/berns.bundle
|
170
|
+
- lib/berns/berns.so
|
162
171
|
- lib/berns/version.rb
|
163
172
|
homepage: https://github.com/evanleck/berns
|
164
173
|
licenses:
|
@@ -166,7 +175,7 @@ licenses:
|
|
166
175
|
metadata:
|
167
176
|
bug_tracker_uri: https://github.com/evanleck/berns/issues
|
168
177
|
source_code_uri: https://github.com/evanleck/berns
|
169
|
-
post_install_message:
|
178
|
+
post_install_message:
|
170
179
|
rdoc_options: []
|
171
180
|
require_paths:
|
172
181
|
- lib
|
@@ -182,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
182
191
|
version: '0'
|
183
192
|
requirements: []
|
184
193
|
rubygems_version: 3.2.15
|
185
|
-
signing_key:
|
194
|
+
signing_key:
|
186
195
|
specification_version: 4
|
187
196
|
summary: A utility library for generating HTML strings.
|
188
197
|
test_files: []
|
data/.editorconfig
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
# http://EditorConfig.org
|
2
|
-
# This is the top most config file.
|
3
|
-
root = true
|
4
|
-
|
5
|
-
# All files
|
6
|
-
[*]
|
7
|
-
|
8
|
-
# Unix-style newlines with a newline ending every file
|
9
|
-
end_of_line = lf
|
10
|
-
insert_final_newline = true
|
11
|
-
|
12
|
-
# Character set
|
13
|
-
charset = utf-8
|
14
|
-
|
15
|
-
# Trim extra whitespace.
|
16
|
-
trim_trailing_whitespace = true
|
17
|
-
|
18
|
-
# Soft tabs and 2 spaces.
|
19
|
-
indent_style = space
|
20
|
-
indent_size = 2
|
data/.github/workflows/main.yml
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
name: Ruby
|
2
|
-
|
3
|
-
on: [push,pull_request]
|
4
|
-
|
5
|
-
jobs:
|
6
|
-
test:
|
7
|
-
strategy:
|
8
|
-
fail-fast: false
|
9
|
-
matrix:
|
10
|
-
os: [ubuntu-latest, macos-latest]
|
11
|
-
ruby-version: ['3.0', 2.7, 2.6, 2.5]
|
12
|
-
|
13
|
-
runs-on: ${{ matrix.os }}
|
14
|
-
steps:
|
15
|
-
- uses: actions/checkout@v2
|
16
|
-
|
17
|
-
- name: Set up Ruby ${{ matrix.ruby-version }}
|
18
|
-
uses: ruby/setup-ruby@v1
|
19
|
-
with:
|
20
|
-
bundler-cache: true
|
21
|
-
ruby-version: ${{ matrix.ruby-version }}
|
22
|
-
|
23
|
-
- name: Run tests & lint
|
24
|
-
run: bundle exec rake
|
data/.gitignore
DELETED
data/.rubocop.yml
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
# http://rubocop.readthedocs.io
|
2
|
-
# https://github.com/bbatsov/rubocop/blob/master/config/enabled.yml
|
3
|
-
require:
|
4
|
-
- rubocop-minitest
|
5
|
-
- rubocop-performance
|
6
|
-
- rubocop-rake
|
7
|
-
|
8
|
-
AllCops:
|
9
|
-
DisplayCopNames: true
|
10
|
-
DisplayStyleGuide: true
|
11
|
-
ExtraDetails: true
|
12
|
-
NewCops: enable
|
13
|
-
TargetRubyVersion: 2.5
|
14
|
-
|
15
|
-
Layout/ParameterAlignment:
|
16
|
-
EnforcedStyle: with_fixed_indentation
|
17
|
-
|
18
|
-
Layout/EmptyLineAfterMagicComment:
|
19
|
-
Enabled: false
|
20
|
-
|
21
|
-
Layout/FirstHashElementIndentation:
|
22
|
-
EnforcedStyle: consistent
|
23
|
-
|
24
|
-
Layout/MultilineOperationIndentation:
|
25
|
-
EnforcedStyle: indented
|
26
|
-
|
27
|
-
Layout/SpaceInsideStringInterpolation:
|
28
|
-
EnforcedStyle: space
|
29
|
-
|
30
|
-
Layout/LineLength:
|
31
|
-
Enabled: false
|
32
|
-
|
33
|
-
Metrics/AbcSize:
|
34
|
-
Enabled: false
|
35
|
-
|
36
|
-
Metrics/BlockLength:
|
37
|
-
Enabled: false
|
38
|
-
|
39
|
-
Metrics/ClassLength:
|
40
|
-
Enabled: false
|
41
|
-
|
42
|
-
Metrics/CyclomaticComplexity:
|
43
|
-
Enabled: false
|
44
|
-
|
45
|
-
Metrics/MethodLength:
|
46
|
-
Enabled: false
|
47
|
-
|
48
|
-
Metrics/ModuleLength:
|
49
|
-
Enabled: false
|
50
|
-
|
51
|
-
Metrics/PerceivedComplexity:
|
52
|
-
Enabled: false
|
53
|
-
|
54
|
-
Style/IfUnlessModifier:
|
55
|
-
Enabled: false
|
56
|
-
|
57
|
-
Style/Next:
|
58
|
-
MinBodyLength: 8
|
data/CHANGELOG.org
DELETED
@@ -1,157 +0,0 @@
|
|
1
|
-
* Berns Changelog
|
2
|
-
|
3
|
-
** 3.0.5
|
4
|
-
|
5
|
-
Fix a regression when content blocks are false. They should be treated the same
|
6
|
-
as if they are not there instead of throwing an error.
|
7
|
-
|
8
|
-
This allows the use of conditions in combination with content blocks e.g.
|
9
|
-
|
10
|
-
#+begin_src ruby
|
11
|
-
Berns.div { user_can_view? && "You can see this sometimes" }
|
12
|
-
#+end_src
|
13
|
-
|
14
|
-
** 3.0.4
|
15
|
-
|
16
|
-
Fix an =ArgumentError= when passing a nested empty hash to =to_attribute=.
|
17
|
-
|
18
|
-
** 3.0.3
|
19
|
-
|
20
|
-
Fix a buffer overflow error.
|
21
|
-
|
22
|
-
** 3.0.2
|
23
|
-
|
24
|
-
Ensure all returned strings are UTF-8 encoded.
|
25
|
-
|
26
|
-
** 3.0.1
|
27
|
-
|
28
|
-
Fix a regression when content blocks are nil. They should be treated the same as
|
29
|
-
if they are not there instead of throwing an error.
|
30
|
-
|
31
|
-
** 3.0.0
|
32
|
-
|
33
|
-
Version 3.0 is another mostly API-compatible refactor of Berns, this time in
|
34
|
-
blazing fast C! I debated simply calling this version 2.1.0 but because it's a
|
35
|
-
complete rewrite it didn't seem right to do a simple point release and there may
|
36
|
-
be corner cases that I've not accounted for in this new C-backed version.
|
37
|
-
|
38
|
-
Running the same benchmarks as from 2.0 but pitting 2.0 against 3.0 yields some
|
39
|
-
great speed improvements, particularly for the =empty= and =simple= cases.
|
40
|
-
|
41
|
-
/These benchmarks were performed on a desktop with a AMD Ryzen 5 3600X 6-Core
|
42
|
-
Processor running Linux Mint 20.1 and kernel 5.4./
|
43
|
-
|
44
|
-
Before:
|
45
|
-
|
46
|
-
#+begin_example
|
47
|
-
empty 1.668M (± 0.6%) i/s - 8.356M in 5.011099s
|
48
|
-
simple 442.102k (± 1.3%) i/s - 2.214M in 5.008068s
|
49
|
-
nested 267.716k (± 0.4%) i/s - 1.357M in 5.068747s
|
50
|
-
#+end_example
|
51
|
-
|
52
|
-
After:
|
53
|
-
|
54
|
-
#+begin_example
|
55
|
-
empty 3.573M (± 1.2%) i/s - 17.881M in 5.005001s
|
56
|
-
simple 840.631k (± 0.6%) i/s - 4.253M in 5.059771s
|
57
|
-
nested 267.281k (± 0.5%) i/s - 1.347M in 5.037887s
|
58
|
-
#+end_example
|
59
|
-
|
60
|
-
With both empty and simple attributes we see performance effectively double, and
|
61
|
-
with nested attributes performance remains more or less the same.
|
62
|
-
|
63
|
-
This is another set of fairly contrived benchmarks, testing a singleton method,
|
64
|
-
=void= call, and =element= call against each other.
|
65
|
-
|
66
|
-
Before:
|
67
|
-
|
68
|
-
#+begin_example
|
69
|
-
br 3.061M (± 0.8%) i/s - 15.613M in 5.100154s
|
70
|
-
void("br") 6.141M (± 1.4%) i/s - 30.990M in 5.047338s
|
71
|
-
element("div") 2.789M (± 0.6%) i/s - 14.171M in 5.080626s
|
72
|
-
#+end_example
|
73
|
-
|
74
|
-
After:
|
75
|
-
|
76
|
-
#+begin_example
|
77
|
-
br 8.155M (± 1.0%) i/s - 41.339M in 5.069681s
|
78
|
-
void("br") 9.782M (± 1.5%) i/s - 49.096M in 5.020114s
|
79
|
-
element("div") 6.769M (± 1.1%) i/s - 33.983M in 5.021362s
|
80
|
-
#+end_example
|
81
|
-
|
82
|
-
Lastly, benchmarking =to_attributes= with the following hash as the only
|
83
|
-
argument shows about double the performance with 3.0.
|
84
|
-
|
85
|
-
#+begin_src ruby
|
86
|
-
ATTRS = { this: 'tag', should: 'work', data: { foo: 'bar', bar: { baz: 'foo' } } }.freeze
|
87
|
-
#+end_src
|
88
|
-
|
89
|
-
Before:
|
90
|
-
|
91
|
-
#+begin_example
|
92
|
-
to_attributes 228.829k (± 1.3%) i/s - 1.159M in 5.065714s
|
93
|
-
#+end_example
|
94
|
-
|
95
|
-
After:
|
96
|
-
|
97
|
-
#+begin_example
|
98
|
-
to_attributes 457.387k (± 1.2%) i/s - 2.305M in 5.041036s
|
99
|
-
#+end_example
|
100
|
-
|
101
|
-
** 2.0.0
|
102
|
-
|
103
|
-
Version 2.0 is a mostly API-compatible refactor of all of the core
|
104
|
-
methods that make up Berns. The goal is to improve performance, mostly
|
105
|
-
using mutable strings and inlining variables that were otherwise short
|
106
|
-
lived.
|
107
|
-
|
108
|
-
In addition, the target Ruby version has been raised to 2.5 or later.
|
109
|
-
2.4 has reached its end of life.
|
110
|
-
|
111
|
-
Running this benchmarking code:
|
112
|
-
|
113
|
-
#+begin_src ruby
|
114
|
-
Benchmark.ips do |x|
|
115
|
-
x.report('empty') { Berns.element(:a) { 'Link to something' } }
|
116
|
-
x.report('simple') { Berns.element(:a, { href: 'Something', class: 'my-class' }) { 'Link to something' } }
|
117
|
-
x.report('nested') { Berns.element(:a, { href: 'Something', class: 'my-class', data: { something: 'Else' } }) { 'Link to something' } }
|
118
|
-
|
119
|
-
x.compare!
|
120
|
-
end
|
121
|
-
#+end_src
|
122
|
-
|
123
|
-
Before:
|
124
|
-
|
125
|
-
#+begin_example
|
126
|
-
empty 993.521k (± 1.7%) i/s - 5.062M in 5.096368s
|
127
|
-
simple 340.795k (± 0.4%) i/s - 1.729M in 5.074101s
|
128
|
-
nested 215.160k (± 1.0%) i/s - 1.081M in 5.025324s
|
129
|
-
#+end_example
|
130
|
-
|
131
|
-
After:
|
132
|
-
|
133
|
-
#+begin_example
|
134
|
-
empty 1.769M (± 1.9%) i/s - 9.012M in 5.094973s
|
135
|
-
simple 441.020k (± 1.0%) i/s - 2.233M in 5.063326s
|
136
|
-
nested 280.255k (± 3.0%) i/s - 1.400M in 5.001009s
|
137
|
-
#+end_example
|
138
|
-
|
139
|
-
With empty attributes we see ~ 100% increase in iterations per second,
|
140
|
-
with simple attributes we see ~ 30% increase in the same, and with
|
141
|
-
nested attributes we see ~ 30% increase as well.
|
142
|
-
|
143
|
-
** 1.3.0
|
144
|
-
|
145
|
-
With version 1.3, nested HTML attributes can be created with nil keys
|
146
|
-
and boolean values to produce e.g. "data-foo data-foo-bar='whatever'"
|
147
|
-
from =data: { foo: { nil => true, bar: 'whatever' } }=
|
148
|
-
|
149
|
-
** 1.2.0 - 1.2.2
|
150
|
-
|
151
|
-
Starting with version 1.2, Berns will now HTML-escape all attribute
|
152
|
-
values using =CGI.escapeHTML=. This should prevent attribute values from
|
153
|
-
escaping themselves and injecting HTML into the DOM.
|
154
|
-
|
155
|
-
** 1.1.0
|
156
|
-
|
157
|
-
- Add =#sanitize= method.
|
data/Gemfile
DELETED
data/Rakefile
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require 'bundler/gem_tasks'
|
3
|
-
require 'rake/extensiontask'
|
4
|
-
require 'rake/testtask'
|
5
|
-
require 'rubocop/rake_task'
|
6
|
-
|
7
|
-
Rake::ExtensionTask.new 'berns' do |ext|
|
8
|
-
ext.lib_dir = 'lib/berns'
|
9
|
-
end
|
10
|
-
|
11
|
-
Rake::TestTask.new(:test) do |t|
|
12
|
-
t.deps = :compile
|
13
|
-
t.libs << 'test'
|
14
|
-
t.libs << 'lib'
|
15
|
-
t.test_files = FileList['test/**/*_test.rb']
|
16
|
-
end
|
17
|
-
|
18
|
-
RuboCop::RakeTask.new
|
19
|
-
|
20
|
-
task default: %i[test rubocop]
|
data/berns.gemspec
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require_relative 'lib/berns/version'
|
3
|
-
|
4
|
-
Gem::Specification.new do |spec|
|
5
|
-
spec.name = 'berns'
|
6
|
-
spec.version = Berns::VERSION
|
7
|
-
spec.authors = ['Taylor Beck', 'Evan Lecklider']
|
8
|
-
spec.email = ['beck.taylorg@gmail.com', 'evan@lecklider.com']
|
9
|
-
|
10
|
-
spec.summary = 'A utility library for generating HTML strings.'
|
11
|
-
spec.description = 'A utility library for generating HTML strings.'
|
12
|
-
spec.homepage = 'https://github.com/evanleck/berns'
|
13
|
-
spec.license = 'MIT'
|
14
|
-
spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
|
15
|
-
|
16
|
-
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
17
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
18
|
-
end
|
19
|
-
|
20
|
-
spec.require_paths = ['lib']
|
21
|
-
spec.extensions = %w[ext/berns/extconf.rb]
|
22
|
-
|
23
|
-
spec.metadata = {
|
24
|
-
'bug_tracker_uri' => 'https://github.com/evanleck/berns/issues',
|
25
|
-
'source_code_uri' => 'https://github.com/evanleck/berns'
|
26
|
-
}
|
27
|
-
|
28
|
-
spec.add_dependency 'cgi'
|
29
|
-
|
30
|
-
spec.add_development_dependency 'bundler'
|
31
|
-
spec.add_development_dependency 'minitest'
|
32
|
-
spec.add_development_dependency 'rake'
|
33
|
-
spec.add_development_dependency 'rake-compiler'
|
34
|
-
spec.add_development_dependency 'rubocop'
|
35
|
-
spec.add_development_dependency 'rubocop-minitest'
|
36
|
-
spec.add_development_dependency 'rubocop-performance'
|
37
|
-
spec.add_development_dependency 'rubocop-rake'
|
38
|
-
end
|