xrb 0.3.0 → 0.5.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
2
  SHA256:
3
- metadata.gz: 474ad7c9ebec6fba7e79782a390ca3adc53846778c44114653f8dfec1d9343d6
4
- data.tar.gz: 5be0e794884ef893ccdb2a5f6fc8117d797381401ff11b9d494feb9f063524f2
3
+ metadata.gz: ad30d066b439b8ec2f61fa0e6ce50ac25dcc95ee7f4efe266382b15b486e1cd0
4
+ data.tar.gz: 34d047c9ec0d9848f235e9e5becb7a9b33b25d3e5afdc6cfa097befc677f2b77
5
5
  SHA512:
6
- metadata.gz: 132854e0a26f998ed20640e764dacae455f5e4f210fe69e5d2c9e9dc517a4fb4bd79a8e38997754ca475c60433bb4c0074f5215e5a36082e1eb9dd65b2823fe6
7
- data.tar.gz: d8229a75ce4b215d413495f807cb27eedcc9f434bf401ae590aa37945a4e59b94d7477d0d038b5b860f20fe91fb28496ca5abb7e0577b2b6298d185c12366619
6
+ metadata.gz: b56901d68f70088b2fe021c772af7b62bd4a6153f35780142ca9ea1203395faa3bce87ab6d678866fbdf2c0a0201db17f01c0a556ef45c6e3a1d3c118be62838
7
+ data.tar.gz: efdfdaa9d81a87ee5d62e72a13169653fc13dade9ba555afbf2103c282c6f98792880599feda8de6aff0fc4cbe073ad3ceedc87bbf5cb5bbc2fb4966e7af6d0f
checksums.yaml.gz.sig CHANGED
Binary file
Binary file
data/ext/escape.o CHANGED
Binary file
data/ext/extconf.rb CHANGED
@@ -11,7 +11,6 @@ $CFLAGS << " -O3 -Wall -Wno-unknown-pragmas -std=c99"
11
11
 
12
12
  have_func("rb_sym2str")
13
13
  have_func("rb_str_cat_cstr")
14
- have_func("rb_str_reserve")
15
14
 
16
15
  $srcs = Dir.glob("xrb/*.c")
17
16
  $VPATH << "$(srcdir)/xrb"
data/ext/markup.o CHANGED
Binary file
data/ext/mkmf.log CHANGED
@@ -58,59 +58,6 @@ checked program was:
58
58
 
59
59
  --------------------
60
60
 
61
- have_func: checking for rb_str_reserve()... -------------------- no
62
-
63
- DYLD_LIBRARY_PATH=.:/Users/samuel/.rubies/ruby-3.3.0/lib "clang -o conftest -I/Users/samuel/.rubies/ruby-3.3.0/include/ruby-3.3.0/arm64-darwin23 -I/Users/samuel/.rubies/ruby-3.3.0/include/ruby-3.3.0/ruby/backward -I/Users/samuel/.rubies/ruby-3.3.0/include/ruby-3.3.0 -I. -I/opt/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wextra-tokens -Wdeprecated-declarations -Wdivision-by-zero -Wdiv-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wmisleading-indentation -Wundef -pipe -O3 -Wall -Wno-unknown-pragmas -std=c99 conftest.c -L. -L/Users/samuel/.rubies/ruby-3.3.0/lib -L/opt/local/lib -L. -fstack-protector-strong -L/opt/local/lib -arch arm64 -lruby.3.3-static -framework CoreFoundation -ldl -lobjc -lpthread -lpthread "
64
- conftest.c:14:57: error: use of undeclared identifier 'rb_str_reserve'
65
- int t(void) { void ((*volatile p)()); p = (void ((*)()))rb_str_reserve; return !p; }
66
- ^
67
- 1 error generated.
68
- checked program was:
69
- /* begin */
70
- 1: #include "ruby.h"
71
- 2:
72
- 3: /*top*/
73
- 4: extern int t(void);
74
- 5: int main(int argc, char **argv)
75
- 6: {
76
- 7: if (argc > 1000000) {
77
- 8: int (* volatile tp)(void)=(int (*)(void))&t;
78
- 9: printf("%d", (*tp)());
79
- 10: }
80
- 11:
81
- 12: return !!argv[argc];
82
- 13: }
83
- 14: int t(void) { void ((*volatile p)()); p = (void ((*)()))rb_str_reserve; return !p; }
84
- /* end */
85
-
86
- DYLD_LIBRARY_PATH=.:/Users/samuel/.rubies/ruby-3.3.0/lib "clang -o conftest -I/Users/samuel/.rubies/ruby-3.3.0/include/ruby-3.3.0/arm64-darwin23 -I/Users/samuel/.rubies/ruby-3.3.0/include/ruby-3.3.0/ruby/backward -I/Users/samuel/.rubies/ruby-3.3.0/include/ruby-3.3.0 -I. -I/opt/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wextra-tokens -Wdeprecated-declarations -Wdivision-by-zero -Wdiv-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wmisleading-indentation -Wundef -pipe -O3 -Wall -Wno-unknown-pragmas -std=c99 conftest.c -L. -L/Users/samuel/.rubies/ruby-3.3.0/lib -L/opt/local/lib -L. -fstack-protector-strong -L/opt/local/lib -arch arm64 -lruby.3.3-static -framework CoreFoundation -ldl -lobjc -lpthread -lpthread "
87
- ld: warning: ignoring duplicate libraries: '-lpthread'
88
- Undefined symbols for architecture arm64:
89
- "_rb_str_reserve", referenced from:
90
- _t in conftest-abc093.o
91
- ld: symbol(s) not found for architecture arm64
92
- clang: error: linker command failed with exit code 1 (use -v to see invocation)
93
- checked program was:
94
- /* begin */
95
- 1: #include "ruby.h"
96
- 2:
97
- 3: /*top*/
98
- 4: extern int t(void);
99
- 5: int main(int argc, char **argv)
100
- 6: {
101
- 7: if (argc > 1000000) {
102
- 8: int (* volatile tp)(void)=(int (*)(void))&t;
103
- 9: printf("%d", (*tp)());
104
- 10: }
105
- 11:
106
- 12: return !!argv[argc];
107
- 13: }
108
- 14: extern void rb_str_reserve();
109
- 15: int t(void) { rb_str_reserve(); return 0; }
110
- /* end */
111
-
112
- --------------------
113
-
114
61
  extconf.h is:
115
62
  /* begin */
116
63
  1: #ifndef EXTCONF_H
data/ext/query.o CHANGED
Binary file
data/ext/tag.o CHANGED
Binary file
data/ext/template.o CHANGED
Binary file
data/ext/xrb/escape.c CHANGED
@@ -103,9 +103,27 @@ VALUE XRB_Markup_append_string(VALUE buffer, VALUE string) {
103
103
  return XRB_Markup_append_buffer(buffer, s, p, end);
104
104
  }
105
105
 
106
+ VALUE XRB_Markup_append_slow(VALUE self, VALUE buffer, VALUE value) {
107
+ if (value == Qnil) return Qnil;
108
+
109
+ if (!XRB_Markup_is_markup(value)) {
110
+ value = XRB_Markup_escape_string(Qnil, value);
111
+ }
112
+
113
+ rb_funcall(buffer, id_concat, 1, value);
114
+
115
+ return buffer;
116
+ }
117
+
106
118
  VALUE XRB_Markup_append(VALUE self, VALUE buffer, VALUE value) {
107
119
  if (value == Qnil) return Qnil;
108
120
 
121
+ if (RB_TYPE_P(buffer, T_STRING)) {
122
+ rb_str_modify(buffer);
123
+ } else {
124
+ return XRB_Markup_append_slow(self, buffer, value);
125
+ }
126
+
109
127
  if (XRB_Markup_is_markup(value)) {
110
128
  rb_str_append(buffer, value);
111
129
  } else {
@@ -121,6 +139,10 @@ VALUE XRB_Markup_append(VALUE self, VALUE buffer, VALUE value) {
121
139
 
122
140
  // Convert markup special characters to entities. May return the original string if no changes were made.
123
141
  VALUE XRB_Markup_escape_string(VALUE self, VALUE string) {
142
+ if (rb_type(string) != T_STRING) {
143
+ rb_raise(rb_eTypeError, "expected a string");
144
+ }
145
+
124
146
  const char * begin = RSTRING_PTR(string);
125
147
  const char * end = begin + RSTRING_LEN(string);
126
148
 
@@ -135,7 +157,7 @@ VALUE XRB_Markup_escape_string(VALUE self, VALUE string) {
135
157
  return XRB_Markup_append_buffer(XRB_buffer_for(string), s, p, end);
136
158
  }
137
159
 
138
- void Init_xrb_escape() {
160
+ void Init_XRB_escape(void) {
139
161
  rb_XRB_MarkupString = rb_define_class_under(rb_XRB, "MarkupString", rb_cString);
140
162
  rb_gc_register_mark_object(rb_XRB_MarkupString);
141
163
 
data/ext/xrb/escape.h CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  #include "xrb.h"
5
5
 
6
- void Init_xrb_escape();
6
+ void Init_XRB_escape(void);
7
7
 
8
8
  // Given a string, replace it's class with XRB::MarkupString so that it would be output as is.
9
9
  VALUE XRB_MarkupString_raw(VALUE self, VALUE string);
data/ext/xrb/tag.c CHANGED
@@ -138,7 +138,7 @@ VALUE XRB_Tag_format_tag(VALUE self, VALUE name, VALUE attributes, VALUE content
138
138
  rb_encoding *encoding = rb_enc_get(name);
139
139
 
140
140
  VALUE buffer = rb_enc_str_new(0, 0, encoding);
141
- rb_str_reserve(buffer, 256);
141
+ rb_str_modify_expand(buffer, 256);
142
142
 
143
143
  XRB_Tag_append_tag(self, buffer, name, attributes, content);
144
144
 
@@ -152,7 +152,7 @@ VALUE XRB_Tag_write_opening_tag(VALUE self, VALUE buffer) {
152
152
 
153
153
  StringValue(name);
154
154
 
155
- rb_str_reserve(buffer, RSTRING_LEN(name) + 256);
155
+ rb_str_modify_expand(buffer, RSTRING_LEN(name) + 256);
156
156
 
157
157
  rb_str_cat_cstr(buffer, "<");
158
158
  rb_str_buf_append(buffer, name);
@@ -173,7 +173,7 @@ VALUE XRB_Tag_write_closing_tag(VALUE self, VALUE buffer) {
173
173
 
174
174
  StringValue(name);
175
175
 
176
- rb_str_reserve(buffer, RSTRING_LEN(name) + 3);
176
+ rb_str_modify_expand(buffer, RSTRING_LEN(name) + 3);
177
177
 
178
178
  rb_str_cat_cstr(buffer, "</");
179
179
  rb_str_buf_append(buffer, name);
@@ -182,7 +182,7 @@ VALUE XRB_Tag_write_closing_tag(VALUE self, VALUE buffer) {
182
182
  return Qnil;
183
183
  }
184
184
 
185
- void Init_xrb_tag() {
185
+ void Init_XRB_Tag(void) {
186
186
  rb_undef_method(rb_class_of(rb_XRB_Tag), "append_attributes");
187
187
  rb_define_singleton_method(rb_XRB_Tag, "append_attributes", XRB_Tag_append_attributes, 3);
188
188
 
data/ext/xrb/tag.h CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  #include "xrb.h"
5
5
 
6
- void Init_xrb_tag();
6
+ void Init_XRB_Tag(void);
7
7
 
8
8
  // Split a qualified name `namespace:name` into it's components. Return `[nil, name]` if no namespace is present.
9
9
  // Usage: namespace, name = XRB::Tag.split(qualified_name)
data/ext/xrb/xrb.c CHANGED
@@ -8,7 +8,7 @@
8
8
  #include "escape.h"
9
9
 
10
10
  VALUE rb_XRB = Qnil, rb_XRB_Native = Qnil, rb_XRB_Tag = Qnil, rb_XRB_Markup = Qnil, rb_XRB_MarkupString = Qnil, rb_XRB_ParseError = Qnil;
11
- ID id_cdata, id_open_tag_begin, id_open_tag_end, id_attribute, id_close_tag, id_text, id_doctype, id_comment, id_instruction, id_read, id_expression, id_key_get, id_string, id_integer, id_append, id_assign, id_pair, id_new, id_name, id_attributes, id_closed, id_to_s, id_is_a;
11
+ ID id_cdata, id_open_tag_begin, id_open_tag_end, id_attribute, id_close_tag, id_text, id_doctype, id_comment, id_instruction, id_read, id_expression, id_key_get, id_string, id_integer, id_append, id_assign, id_pair, id_new, id_name, id_attributes, id_closed, id_to_s, id_is_a, id_concat;
12
12
 
13
13
  void XRB_raise_error(const char * message, VALUE buffer, size_t offset) {
14
14
  VALUE exception = rb_funcall(rb_XRB_ParseError, id_new, 3, rb_str_new_cstr(message), buffer, ULONG2NUM(offset));
@@ -16,7 +16,7 @@ void XRB_raise_error(const char * message, VALUE buffer, size_t offset) {
16
16
  rb_exc_raise(exception);
17
17
  }
18
18
 
19
- void Init_XRB_Extension() {
19
+ void Init_XRB_Extension(void) {
20
20
  id_open_tag_begin = rb_intern("open_tag_begin");
21
21
  id_open_tag_end = rb_intern("open_tag_end");
22
22
  id_close_tag = rb_intern("close_tag");
@@ -47,6 +47,8 @@ void Init_XRB_Extension() {
47
47
  id_to_s = rb_intern("to_s");
48
48
  id_is_a = rb_intern("is_a?");
49
49
 
50
+ id_concat = rb_intern("<<");
51
+
50
52
  rb_XRB = rb_define_module("XRB");
51
53
  rb_gc_register_mark_object(rb_XRB);
52
54
 
@@ -56,7 +58,7 @@ void Init_XRB_Extension() {
56
58
  rb_XRB_Native = rb_define_module_under(rb_XRB, "Native");
57
59
  rb_gc_register_mark_object(rb_XRB_Native);
58
60
 
59
- Init_xrb_escape();
61
+ Init_XRB_escape();
60
62
 
61
63
  rb_XRB_ParseError = rb_const_get_at(rb_XRB, rb_intern("ParseError"));
62
64
  rb_gc_register_mark_object(rb_XRB_ParseError);
@@ -68,5 +70,5 @@ void Init_XRB_Extension() {
68
70
  rb_XRB_Tag = rb_const_get_at(rb_XRB, rb_intern("Tag"));
69
71
  rb_gc_register_mark_object(rb_XRB_Tag);
70
72
 
71
- Init_xrb_tag();
73
+ Init_XRB_Tag();
72
74
  }
data/ext/xrb/xrb.h CHANGED
@@ -19,16 +19,6 @@
19
19
  #define RB_IMMEDIATE_P IMMEDIATE_P
20
20
  #endif
21
21
 
22
- // A helper to reserve a specific capacity of data for a buffer.
23
- #ifndef HAVE_RB_STR_RESERVE
24
- inline VALUE rb_str_reserve(VALUE string, long extra) {
25
- long actual = RSTRING_LEN(string);
26
- rb_str_resize(string, actual + extra);
27
- rb_str_set_len(string, actual);
28
- return string;
29
- }
30
- #endif
31
-
32
22
  // Modules and classes exposed by XRB.
33
23
  extern VALUE
34
24
  rb_XRB,
@@ -62,7 +52,8 @@ extern ID
62
52
  id_attributes,
63
53
  id_closed,
64
54
  id_to_s,
65
- id_is_a;
55
+ id_is_a,
56
+ id_concat;
66
57
 
67
58
  // A convenient C string token class.
68
59
  typedef struct {
@@ -84,7 +75,7 @@ static inline VALUE XRB_string(const char * begin, const char * end, rb_encoding
84
75
  static inline VALUE XRB_buffer_for(VALUE string) {
85
76
  VALUE buffer = rb_enc_str_new(0, 0, rb_enc_get(string));
86
77
 
87
- rb_str_reserve(buffer, RSTRING_LEN(string) + 128);
78
+ rb_str_modify_expand(buffer, RSTRING_LEN(string) + 128);
88
79
 
89
80
  return buffer;
90
81
  }
data/ext/xrb.o CHANGED
Binary file
data/lib/xrb/template.rb CHANGED
@@ -20,7 +20,7 @@ module XRB
20
20
  end
21
21
 
22
22
  class Template
23
- # Returns the output produced by calling the given block.
23
+ # @returns [String] the output produced by calling the given block.
24
24
  def self.capture(*arguments, output: nil, &block)
25
25
  scope = block.binding
26
26
  previous_output = scope.local_variable_get(OUT)
@@ -34,7 +34,7 @@ module XRB
34
34
  scope.local_variable_set(OUT, previous_output)
35
35
  end
36
36
 
37
- return output
37
+ return output.to_str
38
38
  end
39
39
 
40
40
  # Returns the buffer used for capturing output.
data/lib/xrb/version.rb CHANGED
@@ -4,5 +4,5 @@
4
4
  # Copyright, 2012-2024, by Samuel Williams.
5
5
 
6
6
  module XRB
7
- VERSION = "0.3.0"
7
+ VERSION = "0.5.0"
8
8
  end
data/readme.md CHANGED
@@ -4,14 +4,52 @@ XRB is a templating system built loosely on top of XHTML markup. It uses efficie
4
4
 
5
5
  [![Development Status](https://github.com/socketry/xrb/workflows/Test/badge.svg)](https://github.com/socketry/xrb/actions?workflow=Test)
6
6
 
7
+ ``` xrb
8
+ <h1>XRB Examples</h1>
9
+
10
+ <ul>
11
+ <li>XRB uses normal string interpolation syntax: #{"Hello World"}</li>
12
+
13
+ <?r if true ?>
14
+ <li>XRB also adopts standard #{"<?r ... ?>"} script tags</li>
15
+ <?r end ?>
16
+
17
+ <!-- That's all of the syntax! -->
18
+ <ul>
19
+ ```
20
+
21
+ Generates the following output using `XRB::Template.load_file(path).to_string`:
22
+
23
+ ``` xml
24
+ <h1>XRB Examples</h1>
25
+
26
+ <ul>
27
+ <li>XRB uses normal string interpolation syntax: Hello World</li>
28
+
29
+ <li>XRB also adopts standard &lt;?r ... ?&gt; script tags</li>
30
+
31
+ <!-- That's all of the syntax! -->
32
+ <ul>
33
+ ```
34
+
35
+ ## Is it fast?
36
+
37
+ Yes. XRB is designed to be fast. It uses a combination of efficient native parsers and Ruby code generation to ensure that templates are compiled into efficient Ruby code. This means that XRB is suitable for use in high performance applications. In comparison to `ERB`, it is generally about 10x faster.
38
+
7
39
  ## Usage
8
40
 
9
41
  Please see the [project documentation](https://socketry.github.io/xrb/) for more details.
10
42
 
11
- - [Usage](https://socketry.github.io/xrb/guides/getting-started/index) - This guide gives a brief overview of the XRB templating system and how to use it.
43
+ - [Getting Started](https://socketry.github.io/xrb/guides/getting-started/index) - This guide gives a brief overview of the XRB templating system and how to use it.
44
+
45
+ - [Capturing Output](https://socketry.github.io/xrb/guides/capturing-output/index) - This guide explains how to capture intermediate output during template rendering.
46
+
47
+ - [Markup Parser](https://socketry.github.io/xrb/guides/markup-parser/index) - This guide explains how to parse and manipulate Markup using the XRB templating system.
12
48
 
13
49
  ## See Also
14
50
 
51
+ - [xrb-rails](https://github.com/socketry/xrb-rails) - A Rails ActionView integration for rendering XRB templates.
52
+ - [xrb-sanitize](https://github.com/socketry/xrb-sanitize) - A stream-based HTML sanitizer for XRB, based on the XRB Markup parser.
15
53
  - [xrb-vscode](https://github.com/socketry/xrb-vscode) - A syntax highlighting package for Visual Studio Code.
16
54
  - [trenni](https://github.com/ioquatix/trenni) - The original templating system which XRB is based on.
17
55
 
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -39,7 +39,7 @@ cert_chain:
39
39
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
40
40
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
41
41
  -----END CERTIFICATE-----
42
- date: 2024-04-27 00:00:00.000000000 Z
42
+ date: 2024-04-28 00:00:00.000000000 Z
43
43
  dependencies: []
44
44
  description:
45
45
  email:
metadata.gz.sig CHANGED
Binary file