berns 3.4.0 → 3.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.org +6 -5
- data/ext/berns/berns.c +20 -25
- data/ext/berns/extconf.rb +1 -0
- data/lib/berns/berns.bundle +0 -0
- data/lib/berns/builder.rb +15 -0
- data/lib/berns/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bcded7fea247763fc7b27807c2c945943e0f08895b117ae086e4041bf1b08371
|
4
|
+
data.tar.gz: 965518819feb3eef689f19b7cc5470a973198b891e00f9d7f8ac7fd5b4620119
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f023bfcde5d5b272477d2dd7e7c2d6de430c4ec544d6a10da75f7ff72b5980349d282710796a2ac5c4bede5e72df5456dd733828c7869f3f1231b26314f450e4
|
7
|
+
data.tar.gz: d606bdeed6b199fa467c4f80236d9dab40ef0db13e3105397bbe411caffa71c00274ea5902e1ce3f4764ab915cada0a9574d133905f07e28a348e2e28f9b7cfa
|
data/README.org
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
* Berns
|
2
2
|
|
3
3
|
[[https://badge.fury.io/rb/berns][https://badge.fury.io/rb/berns.svg]]
|
4
|
+
[[https://github.com/evanleck/berns/actions/workflows/main.yml][https://github.com/evanleck/berns/actions/workflows/main.yml/badge.svg]]
|
4
5
|
|
5
6
|
A utility library for generating HTML strings.
|
6
7
|
|
@@ -121,11 +122,11 @@ template = Berns::Builder.new do
|
|
121
122
|
end
|
122
123
|
#+end_src
|
123
124
|
|
124
|
-
Within the block provided to =Berns::Builder.new= every standard
|
125
|
-
element
|
126
|
-
result is appended to an internal buffer.
|
127
|
-
used to append a plain text string to the
|
128
|
-
escaped, so it's good for untrusted content.
|
125
|
+
Within the block provided to =Berns::Builder.new= every standard element method,
|
126
|
+
void element method, =#element=, and =#void= are available as methods and each
|
127
|
+
time you use one of those methods the result is appended to an internal buffer.
|
128
|
+
In addition, the =#text= method can be used to append a plain text string to the
|
129
|
+
buffer and that text will be HTML escaped, so it's good for untrusted content.
|
129
130
|
|
130
131
|
Once initialized, rendering the template to a string can be done with the
|
131
132
|
=#call= method and any arguments, positional or keyword, will be passed through
|
data/ext/berns/berns.c
CHANGED
@@ -228,7 +228,7 @@ static char * hash_value_to_attribute(const char *attr, const size_t attrlen, VA
|
|
228
228
|
|
229
229
|
Check_Type(value, T_HASH);
|
230
230
|
|
231
|
-
if (
|
231
|
+
if (RHASH_SIZE(value) == 0) {
|
232
232
|
return strdup("");
|
233
233
|
}
|
234
234
|
|
@@ -439,7 +439,7 @@ static VALUE external_to_attribute(RB_UNUSED_VAR(VALUE self), VALUE attr, VALUE
|
|
439
439
|
static VALUE external_to_attributes(RB_UNUSED_VAR(VALUE self), VALUE attributes) {
|
440
440
|
Check_Type(attributes, T_HASH);
|
441
441
|
|
442
|
-
if (
|
442
|
+
if (RHASH_SIZE(attributes) == 0) {
|
443
443
|
return rb_utf8_str_new_cstr("");
|
444
444
|
}
|
445
445
|
|
@@ -453,37 +453,32 @@ static VALUE external_to_attributes(RB_UNUSED_VAR(VALUE self), VALUE attributes)
|
|
453
453
|
}
|
454
454
|
|
455
455
|
static char * void_element(const char *tag, size_t tlen, VALUE attributes) {
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
char *string = malloc(total);
|
460
|
-
char *ptr;
|
461
|
-
char *end = string + total;
|
456
|
+
const char *empty = "";
|
457
|
+
char *attrs = hash_value_to_attribute(empty, 0, attributes);
|
458
|
+
size_t alen = strlen(attrs);
|
462
459
|
|
463
|
-
|
464
|
-
ptr = stecpy(ptr, tag, end);
|
465
|
-
ptr = stecpy(ptr, tag_close, end);
|
460
|
+
size_t total = tag_olen + tlen + tag_clen + 1;
|
466
461
|
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
462
|
+
/* If we have some attributes, add a space and the attributes' length. */
|
463
|
+
if (alen > 0) {
|
464
|
+
total += splen + alen;
|
465
|
+
}
|
471
466
|
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
char *end = string + total;
|
467
|
+
char *dest = malloc(total);
|
468
|
+
char *ptr = NULL;
|
469
|
+
char *end = dest + total;
|
476
470
|
|
477
|
-
|
478
|
-
|
471
|
+
ptr = stecpy(dest, tag_open, end);
|
472
|
+
ptr = stecpy(ptr, tag, end);
|
473
|
+
|
474
|
+
if (alen > 0) {
|
479
475
|
ptr = stecpy(ptr, space, end);
|
480
476
|
ptr = stecpy(ptr, attrs, end);
|
481
|
-
|
477
|
+
}
|
482
478
|
|
483
|
-
|
479
|
+
ptr = stecpy(ptr, tag_close, end);
|
484
480
|
|
485
|
-
|
486
|
-
}
|
481
|
+
return dest;
|
487
482
|
}
|
488
483
|
|
489
484
|
/*
|
data/ext/berns/extconf.rb
CHANGED
data/lib/berns/berns.bundle
CHANGED
Binary file
|
data/lib/berns/builder.rb
CHANGED
@@ -28,6 +28,21 @@ module Berns
|
|
28
28
|
@buffer << Berns.escape_html(string.to_s)
|
29
29
|
end
|
30
30
|
|
31
|
+
# Append an arbitrary standard element to the buffer.
|
32
|
+
#
|
33
|
+
# @return [String]
|
34
|
+
def element(*args, **opts, &block)
|
35
|
+
content = Builder.new.instance_exec(*args, **opts, &block) if block
|
36
|
+
@buffer << Berns.element(*args, **opts) { content }
|
37
|
+
end
|
38
|
+
|
39
|
+
# Append an arbitrary void element to the buffer.
|
40
|
+
#
|
41
|
+
# @return [String]
|
42
|
+
def void(*args, **opts)
|
43
|
+
@buffer << Berns.void(*args, **opts)
|
44
|
+
end
|
45
|
+
|
31
46
|
Berns::STANDARD.each do |meth|
|
32
47
|
define_method(meth) do |*args, **opts, &block|
|
33
48
|
content = Builder.new.instance_exec(*args, **opts, &block) if block
|
data/lib/berns/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: berns
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Taylor Beck
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-02-
|
12
|
+
date: 2022-02-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: benchmark-ips
|