ox 2.8.4 → 2.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2692a3ee9c693345cc57103c76621a299bfeab9cab5900f88c5b5f132b04fb1e
4
- data.tar.gz: 17152570c95b478910eb791d85a68c70919a877a2ec84fc0c3a4d27ef02ada43
3
+ metadata.gz: 693a38e51ce73f6ba1d09252209e4591cad455a42cf60a1f883fd7bd20bf06bc
4
+ data.tar.gz: 97f767135d353480b0c56273c6f1b5829dd9960c8d0930739643a2a0b8182dc2
5
5
  SHA512:
6
- metadata.gz: a52d48cf7884d97343ed5fb1a2be404b430b530dca159237acd410b58bd13bf55d5d7fe57032103d2dcd573a15d523874d57235002f6a26ebad0f68393c05e57
7
- data.tar.gz: ae87c98eff8381aecd6dcf5d98a8c548b16495df184e38fef2d6683cd1f2d09fe09babce7f2806fea490670984c4c362796b7bd07dfeb311c2af791418b0416d
6
+ metadata.gz: a5cefe49cf18bc5bd7eaf3a921417f916b2cd5b900189a844e2a31788b97c625f5e2f704096225445622042b1bc157856fd3a2b51db6f868d3de49e16537cb4b
7
+ data.tar.gz: 9ca097653ef960651953d3b6c8926f30a3769ee9615ecc6fcbf1721b0097604524ed2ed3cce6656eb40eda9518a64247fdadb455b0d5388fd349a49cab812718
@@ -1,4 +1,10 @@
1
1
 
2
+ ## 2.9.0 - March 13, 2018
3
+
4
+ - New builder methods for building HTML.
5
+
6
+ - Examples added.
7
+
2
8
  ## 2.8.4 - March 4, 2018
3
9
 
4
10
  - Commented out debuf statement.
@@ -590,7 +590,7 @@ builder_instruct(int argc, VALUE *argv, VALUE self) {
590
590
  /* call-seq: element(name,attributes)
591
591
  *
592
592
  * Adds an element with the name and attributes provided. If a block is given
593
- * then on closing of the block a pop() done at the close of the block.
593
+ * then on closing of the block a pop() is called.
594
594
  *
595
595
  * - +name+ - (String) name of the element
596
596
  * - +attributes+ - (Hash) of the element
@@ -640,7 +640,7 @@ builder_element(int argc, VALUE *argv, VALUE self) {
640
640
  b->col++;
641
641
  b->pos++;
642
642
  append_string(b, e->name, len, xml_element_chars, false);
643
- if (1 < argc) {
643
+ if (1 < argc && T_HASH == rb_type(argv[1])) {
644
644
  rb_hash_foreach(argv[1], append_attr, (VALUE)b);
645
645
  }
646
646
  // Do not close with > or /> yet. That is done with i_am_a_child() or pop().
@@ -651,6 +651,51 @@ builder_element(int argc, VALUE *argv, VALUE self) {
651
651
  return Qnil;
652
652
  }
653
653
 
654
+ /* call-seq: void_element(name,attributes)
655
+ *
656
+ * Adds an void element with the name and attributes provided.
657
+ *
658
+ * - +name+ - (String) name of the element
659
+ * - +attributes+ - (Hash) of the element
660
+ */
661
+ static VALUE
662
+ builder_void_element(int argc, VALUE *argv, VALUE self) {
663
+ Builder b = (Builder)DATA_PTR(self);
664
+ const char *name;
665
+ int len;
666
+
667
+ if (1 > argc) {
668
+ rb_raise(ox_arg_error_class, "missing element name");
669
+ }
670
+ i_am_a_child(b, false);
671
+ append_indent(b);
672
+ switch (rb_type(*argv)) {
673
+ case T_STRING:
674
+ name = StringValuePtr(*argv);
675
+ len = RSTRING_LEN(*argv);
676
+ break;
677
+ case T_SYMBOL:
678
+ name = rb_id2name(SYM2ID(*argv));
679
+ len = strlen(name);
680
+ break;
681
+ default:
682
+ rb_raise(ox_arg_error_class, "expected a Symbol or String for an element name");
683
+ break;
684
+ }
685
+ buf_append(&b->buf, '<');
686
+ b->col++;
687
+ b->pos++;
688
+ append_string(b, name, len, xml_element_chars, false);
689
+ if (1 < argc && T_HASH == rb_type(argv[1])) {
690
+ rb_hash_foreach(argv[1], append_attr, (VALUE)b);
691
+ }
692
+ buf_append_string(&b->buf, ">", 1);
693
+ b->col++;;
694
+ b->pos++;
695
+
696
+ return Qnil;
697
+ }
698
+
654
699
  /* call-seq: comment(text)
655
700
  *
656
701
  * Adds a comment element to the XML string being formed.
@@ -663,11 +708,11 @@ builder_comment(VALUE self, VALUE text) {
663
708
  rb_check_type(text, T_STRING);
664
709
  i_am_a_child(b, false);
665
710
  append_indent(b);
666
- buf_append_string(&b->buf, "<!-- ", 5);
711
+ buf_append_string(&b->buf, "<!--", 4);
667
712
  b->col += 5;
668
713
  b->pos += 5;
669
714
  append_string(b, StringValuePtr(text), RSTRING_LEN(text), xml_element_chars, false);
670
- buf_append_string(&b->buf, " --/> ", 5);
715
+ buf_append_string(&b->buf, "-->", 3);
671
716
  b->col += 5;
672
717
  b->pos += 5;
673
718
 
@@ -879,6 +924,7 @@ void ox_init_builder(VALUE ox) {
879
924
  rb_define_method(builder_class, "comment", builder_comment, 1);
880
925
  rb_define_method(builder_class, "doctype", builder_doctype, 1);
881
926
  rb_define_method(builder_class, "element", builder_element, -1);
927
+ rb_define_method(builder_class, "void_element", builder_void_element, -1);
882
928
  rb_define_method(builder_class, "text", builder_text, -1);
883
929
  rb_define_method(builder_class, "cdata", builder_cdata, 1);
884
930
  rb_define_method(builder_class, "raw", builder_raw, 1);
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Ox
3
3
  # Current version of the module.
4
- VERSION = '2.8.4'
4
+ VERSION = '2.9.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ox
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.4
4
+ version: 2.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-04 00:00:00.000000000 Z
11
+ date: 2018-03-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: "A fast XML parser and object serializer that uses only standard C lib.\n
14
14
  \ \nOptimized XML (Ox), as the name implies was written to provide speed
@@ -35,7 +35,6 @@ files:
35
35
  - ext/ox/cache8.c
36
36
  - ext/ox/cache8.h
37
37
  - ext/ox/dump.c
38
- - ext/ox/encode.h
39
38
  - ext/ox/err.c
40
39
  - ext/ox/err.h
41
40
  - ext/ox/extconf.rb
@@ -1,26 +0,0 @@
1
- /* encode.h
2
- * Copyright (c) 2011, Peter Ohler
3
- * All rights reserved.
4
- */
5
-
6
- #ifndef __OX_ENCODE_H__
7
- #define __OX_ENCODE_H__
8
-
9
- #include "ruby.h"
10
- #if HAS_ENCODING_SUPPORT
11
- #include "ruby/encoding.h"
12
- #endif
13
-
14
- static inline VALUE
15
- ox_encode(VALUE rstr) {
16
- #if HAS_ENCODING_SUPPORT
17
- rb_enc_associate(rstr, ox_utf8_encoding);
18
- #else
19
- if (Qnil != ox_utf8_encoding) {
20
- rstr = rb_funcall(ox_utf8_encoding, ox_iconv_id, 1, rstr);
21
- }
22
- #endif
23
- return rstr;
24
- }
25
-
26
- #endif /* __OX_ENCODE_H__ */