ruby-xml-smart 0.1.11-i486-linux

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/AUTHORS +4 -0
  2. data/COPYING +504 -0
  3. data/Changelog +192 -0
  4. data/README +52 -0
  5. data/Rakefile +112 -0
  6. data/TODO +6 -0
  7. data/examples/EXAMPLE.xml +17 -0
  8. data/examples/EXAMPLE.xml.sic +17 -0
  9. data/examples/Visualise/EXAMPLE.xml +18 -0
  10. data/examples/Visualise/term-ansicolor-0.0.4/CHANGES +11 -0
  11. data/examples/Visualise/term-ansicolor-0.0.4/GPL +340 -0
  12. data/examples/Visualise/term-ansicolor-0.0.4/README.en +23 -0
  13. data/examples/Visualise/term-ansicolor-0.0.4/Rakefile +72 -0
  14. data/examples/Visualise/term-ansicolor-0.0.4/VERSION +1 -0
  15. data/examples/Visualise/term-ansicolor-0.0.4/examples/cdiff.rb +20 -0
  16. data/examples/Visualise/term-ansicolor-0.0.4/examples/example.rb +82 -0
  17. data/examples/Visualise/term-ansicolor-0.0.4/install.rb +12 -0
  18. data/examples/Visualise/term-ansicolor-0.0.4/lib/term/ansicolor.rb +78 -0
  19. data/examples/Visualise/xpath_visual.rb +45 -0
  20. data/examples/add_children.rb +14 -0
  21. data/examples/add_elements.rb +13 -0
  22. data/examples/attrs.rb +15 -0
  23. data/examples/children.rb +14 -0
  24. data/examples/concurrent.rb +30 -0
  25. data/examples/copy.rb +23 -0
  26. data/examples/create.rb +18 -0
  27. data/examples/delete.rb +30 -0
  28. data/examples/move_elements.rb +12 -0
  29. data/examples/namespace.rb +14 -0
  30. data/examples/namespace_detailed.rb +36 -0
  31. data/examples/namespace_find.rb +20 -0
  32. data/examples/pull.rb +18 -0
  33. data/examples/qname.rb +16 -0
  34. data/examples/replace.rb +14 -0
  35. data/examples/set_OR_replace.rb +32 -0
  36. data/examples/signals.rb +28 -0
  37. data/examples/string.rb +27 -0
  38. data/examples/write.rb +11 -0
  39. data/examples/xpath_attrs.rb +19 -0
  40. data/examples/xpath_functions.rb +7 -0
  41. data/examples/xpath_root.rb +6 -0
  42. data/extconf.rb +29 -0
  43. data/rbxs.c +136 -0
  44. data/rbxs.h +53 -0
  45. data/rbxs_dom.c +483 -0
  46. data/rbxs_dom.h +32 -0
  47. data/rbxs_domattribute.c +189 -0
  48. data/rbxs_domattribute.h +18 -0
  49. data/rbxs_domattributeset.c +182 -0
  50. data/rbxs_domattributeset.h +17 -0
  51. data/rbxs_domelement.c +656 -0
  52. data/rbxs_domelement.h +18 -0
  53. data/rbxs_domnamespace.c +127 -0
  54. data/rbxs_domnamespace.h +18 -0
  55. data/rbxs_domnamespaceset.c +276 -0
  56. data/rbxs_domnamespaceset.h +17 -0
  57. data/rbxs_domnodeset.c +284 -0
  58. data/rbxs_domnodeset.h +19 -0
  59. data/rbxs_domother.c +121 -0
  60. data/rbxs_domother.h +18 -0
  61. data/rbxs_domtext.c +165 -0
  62. data/rbxs_domtext.h +18 -0
  63. data/rbxs_pull.c +244 -0
  64. data/rbxs_pull.h +17 -0
  65. data/rbxs_pullattribute.c +124 -0
  66. data/rbxs_pullattribute.h +18 -0
  67. data/rbxs_pullattributeset.c +156 -0
  68. data/rbxs_pullattributeset.h +17 -0
  69. data/rbxs_qname.c +267 -0
  70. data/rbxs_qname.h +18 -0
  71. data/rbxs_utils.h +39 -0
  72. data/test/namespace_test.rb +83 -0
  73. metadata +125 -0
@@ -0,0 +1,18 @@
1
+ /* Please see the COPYING file for copyright and distribution information */
2
+
3
+ #ifndef __RBXS_DOMATTRIBUTE_H__
4
+ #define __RBXS_DOMATTRIBUTE_H__
5
+
6
+ #include "rbxs.h"
7
+
8
+ RUBY_EXTERN VALUE cSmartDomAttribute;
9
+
10
+ typedef struct rbxs_domattribute {
11
+ VALUE doc;
12
+ xmlAttrPtr attribute;
13
+ } rbxs_domattribute;
14
+
15
+ RUBY_EXTERN VALUE rbxs_domattribute_new(VALUE class, VALUE doc, xmlAttrPtr attribute);
16
+ RUBY_EXTERN void init_rbxs_domattribute(void);
17
+
18
+ #endif
@@ -0,0 +1,182 @@
1
+ #include "rbxs_dom.h"
2
+ #include "rbxs_domelement.h"
3
+ #include "rbxs_domattribute.h"
4
+ #include "rbxs_domattributeset.h"
5
+
6
+ /* -- */
7
+ //***********************************************************************************
8
+ // GC
9
+ //***********************************************************************************
10
+ void rbxs_domattributeset_free(rbxs_domattributeset *prbxs_domattributeset) {
11
+ if (prbxs_domattributeset != NULL) {
12
+ free(prbxs_domattributeset);
13
+ }
14
+ }
15
+
16
+ void rbxs_domattributeset_mark(rbxs_domattributeset *prbxs_domattributeset) {
17
+ if (prbxs_domattributeset == NULL) return;
18
+ if (!NIL_P(prbxs_domattributeset->node)) rb_gc_mark(prbxs_domattributeset->node);
19
+ }
20
+
21
+ //***********************************************************************************
22
+ // Methods
23
+ //***********************************************************************************
24
+ /* ++ */
25
+
26
+ /*
27
+ * Documentation
28
+ */
29
+ VALUE rbxs_domattributeset_include(VALUE self, VALUE key)
30
+ {
31
+ rbxs_domattributeset *prbxs_domattributeset;
32
+ rbxs_domelement *prbxs_domelement;
33
+ Check_Type(key, T_STRING);
34
+ Data_Get_Struct(self, rbxs_domattributeset, prbxs_domattributeset);
35
+ Data_Get_Struct(prbxs_domattributeset->node, rbxs_domelement, prbxs_domelement);
36
+ if (xmlHasProp(prbxs_domelement->node,(unsigned char *)StringValuePtr(key)))
37
+ return(Qtrue);
38
+ else
39
+ return(Qfalse);
40
+ }
41
+
42
+ /*
43
+ * Documentation
44
+ */
45
+ VALUE rbxs_domattributeset_get(VALUE self, VALUE key)
46
+ {
47
+ rbxs_domattributeset *prbxs_domattributeset;
48
+ rbxs_domelement *prbxs_domelement;
49
+ xmlChar *ret;
50
+ VALUE val;
51
+
52
+ Check_Type(key, T_STRING);
53
+ Data_Get_Struct(self, rbxs_domattributeset, prbxs_domattributeset);
54
+ Data_Get_Struct(prbxs_domattributeset->node, rbxs_domelement, prbxs_domelement);
55
+
56
+ ret = xmlGetProp(prbxs_domelement->node,(unsigned char *)StringValuePtr(key));
57
+ if (ret) {
58
+ val = rb_str_new2((char *)ret);
59
+ xmlFree(ret);
60
+ return(val);
61
+ } else
62
+ return(Qnil);
63
+ }
64
+
65
+ /*
66
+ * Documentation
67
+ */
68
+ VALUE rbxs_domattributeset_set(VALUE self, VALUE key, VALUE value)
69
+ {
70
+ rbxs_domattributeset *prbxs_domattributeset;
71
+ rbxs_domelement *prbxs_domelement;
72
+ rbxs_dom *prbxs_dom;
73
+ xmlAttrPtr attr;
74
+ unsigned char *tc;
75
+ unsigned short int type;
76
+ VALUE ret,str;
77
+
78
+ Check_Type(key, T_STRING);
79
+ Data_Get_Struct(self, rbxs_domattributeset, prbxs_domattributeset);
80
+ Data_Get_Struct(prbxs_domattributeset->node, rbxs_domelement, prbxs_domelement);
81
+ Data_Get_Struct(prbxs_domelement->doc, rbxs_dom, prbxs_dom);
82
+
83
+ str = rb_obj_as_string(value);
84
+ if (NIL_P(str) || TYPE(str) != T_STRING)
85
+ rb_raise(rb_eTypeError, "cannot convert obj to string");
86
+ tc = (unsigned char *)StringValuePtr(str);
87
+ if (!xmlCheckUTF8((unsigned char *)tc))
88
+ rb_raise(rb_eArgError, "text must be utf8 encoded");
89
+ type = xmlHasProp(prbxs_domelement->node,(unsigned char *)StringValuePtr(key)) ? RBXS_DOM_SIGNAL_CHANGE : RBXS_DOM_SIGNAL_ADD;
90
+
91
+ attr = xmlSetProp(prbxs_domelement->node,(unsigned char *)StringValuePtr(key),tc);
92
+ if (attr == NULL)
93
+ rb_raise(rb_eRuntimeError, "Couldn't set attribute");
94
+
95
+ ret = rbxs_domattribute_new(cSmartDomAttribute, prbxs_domelement->doc, (xmlAttrPtr)attr);
96
+ rbxs_dom_change_handlers_execute(prbxs_dom,type,ret);
97
+ return(ret);
98
+ }
99
+
100
+ /*
101
+ * Documentation
102
+ */
103
+ VALUE rbxs_domattributeset_get_attr(VALUE self, VALUE key)
104
+ {
105
+ rbxs_domattributeset *prbxs_domattributeset;
106
+ rbxs_domelement *prbxs_domelement;
107
+ xmlAttrPtr attr;
108
+
109
+ Check_Type(key, T_STRING);
110
+ Data_Get_Struct(self, rbxs_domattributeset, prbxs_domattributeset);
111
+ Data_Get_Struct(prbxs_domattributeset->node, rbxs_domelement, prbxs_domelement);
112
+
113
+ attr = prbxs_domelement->node->properties;
114
+ while (attr != NULL) {
115
+ if (xmlStrEqual(attr->name,BAD_CAST(StringValuePtr(key)))) {
116
+ return rbxs_domattribute_new(cSmartDomAttribute, prbxs_domelement->doc, (xmlAttrPtr)attr);
117
+ }
118
+ attr = attr->next;
119
+ }
120
+ rb_raise(rb_eRuntimeError, "Couldn't get attribute");
121
+ return(Qnil);
122
+ }
123
+
124
+ /*
125
+ * Documentation
126
+ */
127
+ VALUE rbxs_domattributeset_each(VALUE self)
128
+ {
129
+ rbxs_domattributeset *prbxs_domattributeset;
130
+ rbxs_domelement *prbxs_domelement;
131
+ VALUE obj;
132
+ xmlAttrPtr attr;
133
+
134
+ Data_Get_Struct(self, rbxs_domattributeset, prbxs_domattributeset);
135
+ Data_Get_Struct(prbxs_domattributeset->node, rbxs_domelement, prbxs_domelement);
136
+
137
+ attr = prbxs_domelement->node->properties;
138
+ while (attr != NULL) {
139
+ obj = rbxs_domattribute_new(cSmartDomAttribute, prbxs_domelement->doc, (xmlAttrPtr)attr);
140
+ rb_yield(obj);
141
+ attr = attr->next;
142
+ }
143
+ return(self);
144
+ }
145
+
146
+ //***********************************************************************************
147
+ // Constructors
148
+ //***********************************************************************************
149
+ VALUE rbxs_domattributeset_new(VALUE class, VALUE node) {
150
+ rbxs_domattributeset *prbxs_domattributeset;
151
+
152
+ prbxs_domattributeset = (rbxs_domattributeset *)malloc(sizeof(rbxs_domattributeset));
153
+ if (prbxs_domattributeset == NULL )
154
+ rb_raise(rb_eNoMemError, "No memory left for XML::Smart::Dom::AttributeSet struct");
155
+
156
+ prbxs_domattributeset->node = node;
157
+
158
+ return(Data_Wrap_Struct(class, rbxs_domattributeset_mark, rbxs_domattributeset_free, prbxs_domattributeset));
159
+ }
160
+
161
+ //***********************************************************************************
162
+ // Initialize class Node
163
+ //***********************************************************************************
164
+ #ifdef RDOC__
165
+ mXML = rb_define_module( "XML" );
166
+ cSmart = rb_define_class_under( mXML, "Smart", rb_cObject );
167
+ cSmartDom = rb_define_class_under( cSmart, "Dom", rb_cObject );
168
+ #endif
169
+ VALUE cSmartDomAttributeSet;
170
+
171
+ void init_rbxs_domattributeset(void) {
172
+ cSmartDomAttributeSet = rb_define_class_under( cSmartDom, "AttributeSet", rb_cObject );
173
+ rb_include_module(cSmartDomAttributeSet, rb_mEnumerable);
174
+
175
+ rb_define_method(cSmartDomAttributeSet, "has_attr?", rbxs_domattributeset_include, 1);
176
+ rb_define_method(cSmartDomAttributeSet, "get_attr", rbxs_domattributeset_get_attr, 1);
177
+ rb_define_method(cSmartDomAttributeSet, "include?", rbxs_domattributeset_include, 1);
178
+ rb_define_method(cSmartDomAttributeSet, "[]", rbxs_domattributeset_get, 1);
179
+ rb_define_method(cSmartDomAttributeSet, "[]=", rbxs_domattributeset_set, 2);
180
+ rb_define_method(cSmartDomAttributeSet, "add", rbxs_domattributeset_set, 2);
181
+ rb_define_method(cSmartDomAttributeSet, "each", rbxs_domattributeset_each, 0);
182
+ }
@@ -0,0 +1,17 @@
1
+ /* Please see the COPYING file for copyright and distribution information */
2
+
3
+ #ifndef __RBXS_DOMATTRIBUTESET_H__
4
+ #define __RBXS_DOMATTRIBUTESET_H__
5
+
6
+ #include "rbxs.h"
7
+
8
+ RUBY_EXTERN VALUE cSmartDomAttributeSet;
9
+
10
+ typedef struct rbxs_domattributeset {
11
+ VALUE node;
12
+ } rbxs_domattributeset;
13
+
14
+ RUBY_EXTERN VALUE rbxs_domattributeset_new(VALUE class, VALUE node);
15
+ RUBY_EXTERN void init_rbxs_domattributeset(void);
16
+
17
+ #endif