teius 0.5-mswin32 → 0.12-mswin32

Sign up to get free protection for your applications and to get access to all the features.
data/ext/Makefile CHANGED
@@ -35,8 +35,8 @@ LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
35
35
  LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
36
36
  LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
37
37
 
38
- CFLAGS = -g -O2
39
- CPPFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir) -Id:/msys/local/include -Id:/msys/local/include/libxml2
38
+ CFLAGS = -g -O2 -I.
39
+ CPPFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir) -DHAVE_LIBXML_XMLVERSION_H -DHAVE_LIBXSLT_XSLT_H -Id:/msys/local/include -Id:/msys/local/include/libxml2
40
40
  CXXFLAGS = $(CFLAGS)
41
41
  DLDFLAGS = -Wl,--enable-auto-import,--export-all
42
42
  LDSHARED = gcc -shared -s
@@ -72,7 +72,7 @@ extout =
72
72
  extout_prefix =
73
73
  target_prefix =
74
74
  LOCAL_LIBS =
75
- LIBS = $(LIBRUBYARG_SHARED) -lxslt -lxml2 -lwsock32
75
+ LIBS = $(LIBRUBYARG_SHARED) -lxslt -lxml2 -lxslt -lxml2 -lwsock32
76
76
  SRCS = teius.c
77
77
  OBJS = teius.o
78
78
  TARGET = teius
data/ext/extconf.rb CHANGED
@@ -1,7 +1,51 @@
1
1
  require 'mkmf'
2
2
 
3
- dir_config('libxml', '/usr/include/libxml', '/usr/lib');
4
- dir_config('libxslt', '/usr/include', '/usr/lib');
3
+ def crash(str)
4
+ printf(" extconf failure: %s\n", str)
5
+ exit 1
6
+ end
7
+
8
+ dir_config('xml2');
9
+ unless (have_library('xml2', 'xmlParseDoc') or
10
+ find_library('xml2', '/opt/lib', '/usr/local/lib', '/usr/lib')) and
11
+ (have_header('libxml/xmlversion.h') or
12
+ find_header('libxml/xmlversion.h',
13
+ '/opt/include/libxml2',
14
+ '/usr/local/include/libxml2',
15
+ '/usr/include/libxml',
16
+ '/usr/include/libxml2'))
17
+ crash(<<EOL)
18
+ need libxml2.
19
+
20
+ Install the library or try one of the following options to extconf.rb:
21
+
22
+ --with-xml2-dir=/path/to/libxml2
23
+ --with-xml2-lib=/path/to/libxml2/lib
24
+ --with-xml2-include=/path/to/libxml2/include
25
+ EOL
26
+ end
27
+
28
+ dir_config('libxslt');
29
+ unless (have_library('xslt', 'xsltApplyStylesheet') or
30
+ find_library('xslt', '/opt/lib', '/usr/local/lib', '/usr/lib')) and
31
+ (have_header('libxslt/xslt.h') or
32
+ find_header('libxslt/xslt.h',
33
+ '/opt/include/libxslt',
34
+ '/usr/local/include/libxslt',
35
+ '/usr/include/libxslt'))
36
+ crash(<<EOL)
37
+ need libxslt.
38
+
39
+ Install the library or try one of the following options to extconf.rb:
40
+
41
+ --with-xslt-dir=/path/to/libxslt
42
+ --with-xslt-lib=/path/to/libxslt/lib
43
+ --with-xslt-include=/path/to/libxslt/include
44
+ EOL
45
+ end
46
+
5
47
  have_library('xml2', 'xmlReadFile')
6
48
  have_library('xslt', 'xsltParseStylesheetFile')
7
- create_makefile("teius")
49
+
50
+ $CFLAGS << ' ' << $INCFLAGS
51
+ create_makefile('teius')
data/ext/mkmf.log CHANGED
@@ -1,6 +1,52 @@
1
+ have_library: checking for xmlParseDoc() in -lxml2... -------------------- yes
2
+
3
+ "gcc -o conftest -I. -Id:/msys/local/lib/ruby/1.8/i386-mingw32 -Id:/msys/local/include/libxml2 -g -O2 conftest.c -L"d:/msys/local/lib" -L"d:/msys/local/lib" -lmsvcrt-ruby18-static -lxml2 -lwsock32 "
4
+ checked program was:
5
+ /* begin */
6
+
7
+ /*top*/
8
+ int main() { return 0; }
9
+ int t() { xmlParseDoc(); return 0; }
10
+ /* end */
11
+
12
+ --------------------
13
+
14
+ have_header: checking for libxml/xmlversion.h... -------------------- yes
15
+
16
+ "gcc -E -I. -Id:/msys/local/lib/ruby/1.8/i386-mingw32 -Id:/msys/local/include/libxml2 -g -O2 conftest.c -o conftest.i"
17
+ checked program was:
18
+ /* begin */
19
+ #include <libxml/xmlversion.h>
20
+ /* end */
21
+
22
+ --------------------
23
+
24
+ have_library: checking for xsltApplyStylesheet() in -lxslt... -------------------- yes
25
+
26
+ "gcc -o conftest -I. -Id:/msys/local/lib/ruby/1.8/i386-mingw32 -Id:/msys/local/include -Id:/msys/local/include/libxml2 -g -O2 conftest.c -L"d:/msys/local/lib" -L"d:/msys/local/lib" -lxml2 -lmsvcrt-ruby18-static -lxslt -lxml2 -lwsock32 "
27
+ checked program was:
28
+ /* begin */
29
+
30
+ /*top*/
31
+ int main() { return 0; }
32
+ int t() { xsltApplyStylesheet(); return 0; }
33
+ /* end */
34
+
35
+ --------------------
36
+
37
+ have_header: checking for libxslt/xslt.h... -------------------- yes
38
+
39
+ "gcc -E -I. -Id:/msys/local/lib/ruby/1.8/i386-mingw32 -Id:/msys/local/include -Id:/msys/local/include/libxml2 -g -O2 conftest.c -o conftest.i"
40
+ checked program was:
41
+ /* begin */
42
+ #include <libxslt/xslt.h>
43
+ /* end */
44
+
45
+ --------------------
46
+
1
47
  have_library: checking for xmlReadFile() in -lxml2... -------------------- yes
2
48
 
3
- "gcc -o conftest -I. -Id:/msys/local/lib/ruby/1.8/i386-mingw32 -Id:/msys/local/include -Id:/msys/local/include/libxml2 -g -O2 conftest.c -L"d:/msys/local/lib" -L"d:/msys/local/lib" -lmsvcrt-ruby18-static -lxml2 -lwsock32 "
49
+ "gcc -o conftest -I. -Id:/msys/local/lib/ruby/1.8/i386-mingw32 -Id:/msys/local/include -Id:/msys/local/include/libxml2 -g -O2 conftest.c -L"d:/msys/local/lib" -L"d:/msys/local/lib" -lxslt -lxml2 -lmsvcrt-ruby18-static -lxml2 -lxslt -lxml2 -lwsock32 "
4
50
  checked program was:
5
51
  /* begin */
6
52
 
@@ -13,7 +59,7 @@ int t() { xmlReadFile(); return 0; }
13
59
 
14
60
  have_library: checking for xsltParseStylesheetFile() in -lxslt... -------------------- yes
15
61
 
16
- "gcc -o conftest -I. -Id:/msys/local/lib/ruby/1.8/i386-mingw32 -Id:/msys/local/include -Id:/msys/local/include/libxml2 -g -O2 conftest.c -L"d:/msys/local/lib" -L"d:/msys/local/lib" -lxml2 -lmsvcrt-ruby18-static -lxslt -lxml2 -lwsock32 "
62
+ "gcc -o conftest -I. -Id:/msys/local/lib/ruby/1.8/i386-mingw32 -Id:/msys/local/include -Id:/msys/local/include/libxml2 -g -O2 conftest.c -L"d:/msys/local/lib" -L"d:/msys/local/lib" -lxml2 -lxslt -lxml2 -lmsvcrt-ruby18-static -lxslt -lxml2 -lxslt -lxml2 -lwsock32 "
17
63
  checked program was:
18
64
  /* begin */
19
65
 
data/ext/notes.txt CHANGED
@@ -1,2 +1 @@
1
- ruby extconf.rb --with-libxml-include=/usr/local/include/libxml2 --with-libxml-lib=/usr/local/lib --with-libxslt-include=
2
- /usr/local/include --with-libxslt-lib=/usr/local/lib
1
+ ruby extconf.rb --with-xml2-include=/usr/local/include/libxml2 --with-xml2-lib=/usr/local/lib --with-libxslt-include=/usr/local/include --with-libxslt-lib=/usr/local/lib
data/ext/teius.c CHANGED
@@ -35,7 +35,7 @@ static VALUE node_value(VALUE self) {
35
35
  Data_Get_Struct(self, xmlNode, node);
36
36
 
37
37
  xmlChar *val = xmlNodeGetContent(node);
38
- VALUE rVal = rb_str_new2(val);
38
+ VALUE rVal = rb_str_new2((char *)val);
39
39
  xmlFree(val);
40
40
 
41
41
  return rVal;
@@ -59,9 +59,9 @@ static VALUE node_attributes(VALUE self) {
59
59
  xmlAttrPtr attrs = node->properties;
60
60
  VALUE rHash = rb_hash_new();
61
61
  while (attrs != NULL) {
62
- VALUE rName = rb_str_new2(attrs->name);
62
+ VALUE rName = rb_str_new2((char *)attrs->name);
63
63
  xmlChar *val = xmlNodeGetContent(attrs->children);
64
- VALUE rVal = rb_str_new2(val);
64
+ VALUE rVal = rb_str_new2((char *)val);
65
65
  rb_hash_aset(rHash, rName, rVal);
66
66
  xmlFree(val);
67
67
  attrs = attrs->next;
@@ -90,7 +90,7 @@ static VALUE node_find(int argc, VALUE *argv, VALUE self) {
90
90
  context->node = node;
91
91
 
92
92
  char *xpath = StringValuePtr(rXpath);
93
- result = xmlXPathEvalExpression(xpath, context);
93
+ result = xmlXPathEvalExpression((xmlChar *)xpath, context);
94
94
  if (result == NULL) {
95
95
  xmlErrorPtr err = xmlGetLastError();
96
96
  xmlXPathFreeContext(context);
@@ -147,13 +147,42 @@ static VALUE node_find(int argc, VALUE *argv, VALUE self) {
147
147
  static VALUE node_name(VALUE self) {
148
148
  xmlNodePtr node = NULL;
149
149
  Data_Get_Struct(self, xmlNode, node);
150
- return rb_str_new2(node->name);
150
+ return rb_str_new2((char *)node->name);
151
151
  }
152
152
 
153
153
  static VALUE node_xpath(VALUE self) {
154
154
  xmlNodePtr node = NULL;
155
155
  Data_Get_Struct(self, xmlNode, node);
156
- return rb_str_new2(xmlGetNodePath(node));
156
+ return rb_str_new2((char *)xmlGetNodePath(node));
157
+ }
158
+
159
+ static VALUE node_type(VALUE self) {
160
+ xmlNodePtr node = NULL;
161
+ Data_Get_Struct(self, xmlNode, node);
162
+
163
+ switch (node->type) {
164
+ case 1: return ID2SYM(rb_intern("element"));
165
+ case 2: return ID2SYM(rb_intern("attribute"));
166
+ case 3: return ID2SYM(rb_intern("text"));
167
+ case 4: return ID2SYM(rb_intern("cdata_section"));
168
+ case 5: return ID2SYM(rb_intern("entity_ref"));
169
+ case 6: return ID2SYM(rb_intern("entity"));
170
+ case 7: return ID2SYM(rb_intern("pi"));
171
+ case 8: return ID2SYM(rb_intern("comment"));
172
+ case 9: return ID2SYM(rb_intern("document"));
173
+ case 10: return ID2SYM(rb_intern("document_type"));
174
+ case 11: return ID2SYM(rb_intern("document_fragment"));
175
+ case 12: return ID2SYM(rb_intern("notation"));
176
+ case 13: return ID2SYM(rb_intern("html_document"));
177
+ case 14: return ID2SYM(rb_intern("dtd"));
178
+ case 15: return ID2SYM(rb_intern("element_declaration"));
179
+ case 16: return ID2SYM(rb_intern("attribute_declaration"));
180
+ case 17: return ID2SYM(rb_intern("entity_declaration"));
181
+ case 18: return ID2SYM(rb_intern("namespace_declaration"));
182
+ case 19: return ID2SYM(rb_intern("xinclude_start"));
183
+ case 20: return ID2SYM(rb_intern("xinclude_end"));
184
+ case 21: return ID2SYM(rb_intern("docb_document"));
185
+ }
157
186
  }
158
187
 
159
188
  static VALUE node_pointer(VALUE self) {
@@ -180,12 +209,27 @@ static VALUE node_content(VALUE self) {
180
209
  buf = xmlBufferCreate();
181
210
  size = xmlNodeDump(buf, node->doc, node, 0, 1);
182
211
  mem = xmlBufferContent(buf);
183
- VALUE rStr = rb_str_new2(mem);
212
+ VALUE rStr = rb_str_new2((char *)mem);
184
213
  xmlBufferFree(buf);
185
214
 
186
215
  return rStr;
187
216
  }
188
217
 
218
+ static VALUE node_children(VALUE self) {
219
+ xmlNodePtr node = NULL;
220
+ xmlNodePtr cur_child = NULL;
221
+
222
+ Data_Get_Struct(self, xmlNode, node);
223
+
224
+ VALUE rArr = rb_ary_new();
225
+ for (cur_child = node->children; cur_child != NULL; cur_child = cur_child->next) {
226
+ VALUE rNode = Data_Wrap_Struct(cNode, 0, 0, cur_child);
227
+ rb_ary_push(rArr, rNode);
228
+ }
229
+
230
+ return rArr;
231
+ }
232
+
189
233
  static VALUE document_parse_file(VALUE self, VALUE rFilename) {
190
234
  xmlDocPtr doc = xmlReadFile(StringValuePtr(rFilename), NULL, 0);
191
235
  if (doc == NULL) {
@@ -195,20 +239,20 @@ static VALUE document_parse_file(VALUE self, VALUE rFilename) {
195
239
  }
196
240
 
197
241
  /* Load new document */
198
- VALUE rDoc = Data_Wrap_Struct(cDocument, 0, doc_free, doc);
242
+ VALUE rDoc = Data_Wrap_Struct(self, 0, doc_free, doc);
199
243
 
200
244
  return rDoc;
201
245
  }
202
246
 
203
247
  static VALUE document_parse_string(VALUE self, VALUE rDocString) {
204
- xmlDocPtr doc = xmlReadDoc(StringValuePtr(rDocString), NULL, NULL, 0);
248
+ xmlDocPtr doc = xmlReadDoc((xmlChar *)StringValuePtr(rDocString), NULL, NULL, 0);
205
249
  if (doc == NULL) {
206
250
  xmlErrorPtr err = xmlGetLastError();
207
251
  rb_raise(cParseError, "could not parse string: %s", err->message);
208
252
  }
209
253
 
210
254
  /* Load new document */
211
- VALUE rDoc = Data_Wrap_Struct(cDocument, 0, doc_free, doc);
255
+ VALUE rDoc = Data_Wrap_Struct(self, 0, doc_free, doc);
212
256
 
213
257
  return rDoc;
214
258
  }
@@ -220,7 +264,7 @@ static VALUE document_to_s(VALUE self) {
220
264
 
221
265
  Data_Get_Struct(self, xmlDoc, doc);
222
266
  xmlDocDumpMemory(doc, &mem, &size);
223
- VALUE rStr = rb_str_new2(mem);
267
+ VALUE rStr = rb_str_new2((char *)mem);
224
268
  xmlFree(mem);
225
269
 
226
270
  return rStr;
@@ -244,7 +288,7 @@ static void stylesheet_free(void *p) {
244
288
  }
245
289
 
246
290
  static VALUE stylesheet_parse_file(VALUE self, VALUE rFilename) {
247
- xsltStylesheetPtr xsl = xsltParseStylesheetFile(StringValuePtr(rFilename));
291
+ xsltStylesheetPtr xsl = xsltParseStylesheetFile((xmlChar *)StringValuePtr(rFilename));
248
292
  if (xsl == NULL) {
249
293
  xmlErrorPtr err = xmlGetLastError();
250
294
  rb_raise(cParseError, "could not parse file %s: %s",
@@ -252,11 +296,23 @@ static VALUE stylesheet_parse_file(VALUE self, VALUE rFilename) {
252
296
  }
253
297
 
254
298
  /* Load new document */
255
- VALUE rStylesheet = Data_Wrap_Struct(cStylesheet, 0, stylesheet_free, xsl);
299
+ VALUE rStylesheet = Data_Wrap_Struct(self, 0, stylesheet_free, xsl);
256
300
 
257
301
  return rStylesheet;
258
302
  }
259
303
 
304
+ static VALUE stylesheet_output_method(VALUE self) {
305
+ xsltStylesheetPtr stylesheet = NULL;
306
+
307
+ Data_Get_Struct(self, xsltStylesheet, stylesheet);
308
+ if (stylesheet->method == NULL) {
309
+ return Qnil;
310
+ } else {
311
+ VALUE rStr = rb_str_new2((char *)stylesheet->method);
312
+ return rStr;
313
+ }
314
+ }
315
+
260
316
  static VALUE stylesheet_apply(VALUE self, VALUE rDocument) {
261
317
  xsltStylesheetPtr stylesheet = NULL;
262
318
  xmlDocPtr doc = NULL, res = NULL;
@@ -304,7 +360,7 @@ static VALUE stylesheet_save_to_string(VALUE self, VALUE rResult) {
304
360
  rb_raise(rb_eStandardError, "could not save stylesheet result to string: %s",
305
361
  err->message);
306
362
  }
307
- VALUE rStr = rb_str_new2(mem);
363
+ VALUE rStr = rb_str_new2((char *)mem);
308
364
  xmlFree(mem);
309
365
 
310
366
  return rStr;
@@ -341,9 +397,11 @@ void Init_teius() {
341
397
  rb_define_method(cNode, "find", node_find, -1);
342
398
  rb_define_method(cNode, "name", node_name, 0);
343
399
  rb_define_method(cNode, "xpath", node_xpath, 0);
400
+ rb_define_method(cNode, "type", node_type, 0);
344
401
  rb_define_method(cNode, "pointer", node_pointer, 0);
345
402
  rb_define_method(cNode, "line", node_line, 0);
346
403
  rb_define_method(cNode, "content", node_content, 0);
404
+ rb_define_method(cNode, "children", node_children, 0);
347
405
 
348
406
  /* Document */
349
407
  cDocument = rb_define_class_under(mTeius, "Document", cNode);
@@ -353,8 +411,9 @@ void Init_teius() {
353
411
  rb_define_method(cDocument, "root", document_root, 0);
354
412
 
355
413
  /* XSL Stylesheet */
356
- cStylesheet = rb_define_class_under(mTeius, "Stylesheet", cNode);
414
+ cStylesheet = rb_define_class_under(mTeius, "Stylesheet", rb_cObject);
357
415
  rb_define_singleton_method(cStylesheet, "parse_file", stylesheet_parse_file, 1);
416
+ rb_define_method(cStylesheet, "output_method", stylesheet_output_method, 0);
358
417
  rb_define_method(cStylesheet, "apply", stylesheet_apply, 1);
359
418
  rb_define_method(cStylesheet, "save_to_string", stylesheet_save_to_string, 1);
360
419
  rb_define_method(cStylesheet, "save_to_file", stylesheet_save_to_file, 2);
data/ext/teius.o CHANGED
Binary file
data/ext/teius.so CHANGED
Binary file
data/lib/teius.rb CHANGED
@@ -1,6 +1,9 @@
1
- require File.join(File.dirname(__FILE__), '..', 'ext', 'teius.so')
1
+ $:.unshift File.dirname(__FILE__)
2
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'ext')
3
+ require 'teius.so'
2
4
 
3
5
  module Teius
6
+
4
7
  class Document
5
8
 
6
9
  def self.content(xml)
@@ -43,11 +46,7 @@ module Teius
43
46
  def siblings
44
47
  self.find :all, 'preceding-sibling::*|following-sibling::*'
45
48
  end
46
-
47
- def children
48
- self.find :all, 'child::*'
49
- end
50
-
49
+
51
50
  def to_s
52
51
  "#{name}:#{line}"
53
52
  end
data/test/teius_test.rb CHANGED
@@ -6,6 +6,9 @@ require 'tempfile'
6
6
  class TeiusTest < Test::Unit::TestCase
7
7
  include Teius
8
8
 
9
+ class SubTeius < Document
10
+ end
11
+
9
12
  def setup
10
13
  @xml_dir = File.join(File.dirname(__FILE__), '..', 'xml')
11
14
  @doc = Document.parse_file File.join(@xml_dir,
@@ -26,7 +29,13 @@ class TeiusTest < Test::Unit::TestCase
26
29
  assert_equal 'xt.3608787-update-post-event', el.value
27
30
  assert_equal 'doc-id', el.name
28
31
  end
29
-
32
+
33
+ def test_inheritance
34
+ doc = SubTeius.parse_file File.join(@xml_dir,
35
+ 'xt.3608787-update-post-event.xml')
36
+ assert_kind_of SubTeius, doc
37
+ end
38
+
30
39
  def test_relative_paths
31
40
  meta = @doc.find :first, '/sports-content/sports-metadata'
32
41
  assert_not_nil meta
@@ -135,6 +144,12 @@ class TeiusTest < Test::Unit::TestCase
135
144
  sibs = e.siblings
136
145
  assert_equal 9, sibs.size
137
146
  end
147
+
148
+ def test_children
149
+ e = @doc.find :first, '//sports-content-codes'
150
+ children = e.children
151
+ assert_equal 10, children.size
152
+ end
138
153
 
139
154
  def test_xslt
140
155
  current_dir = File.dirname(__FILE__)
@@ -142,10 +157,17 @@ class TeiusTest < Test::Unit::TestCase
142
157
  xsl_path = File.join(current_dir, 'test.xsl')
143
158
  doc = Document.parse_file test_doc_path
144
159
  xsl = Stylesheet.parse_file xsl_path
160
+ assert_equal 'xml', xsl.output_method
145
161
  assert_no_match %r{menu}, doc.to_s
146
162
  assert_match %r{menu}, xsl.transform(doc)
147
163
  end
148
164
 
165
+ def test_bogus_xslt
166
+ assert_raise(ParseError) {
167
+ xsl = Stylesheet.parse_file 'bogus'
168
+ }
169
+ end
170
+
149
171
  def test_xslt_write_to_file
150
172
  current_dir = File.dirname(__FILE__)
151
173
  test_doc_path = File.join(current_dir, 'input.xml')
@@ -193,4 +215,17 @@ class TeiusTest < Test::Unit::TestCase
193
215
  assert_equal "<library>\n <book/>\n</library>", content
194
216
  end
195
217
 
218
+ def test_node_type
219
+ node = @doc.find :first, '//team-metadata'
220
+ assert_equal :element, node.type
221
+ assert_equal :document, @doc.type
222
+ end
223
+
224
+ def test_text_node
225
+ title = @doc.find :first, '/sports-content/sports-metadata/sports-title'
226
+ text = title.children.first
227
+ assert_equal :text, text.type
228
+ assert_equal "Score Update: Chicago vs. Green Bay (Final)", text.value
229
+ end
230
+
196
231
  end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.11
2
+ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: teius
5
5
  version: !ruby/object:Gem::Version
6
- version: "0.5"
7
- date: 2006-06-28 00:00:00 +03:00
6
+ version: "0.12"
7
+ date: 2006-07-27 00:00:00 +03:00
8
8
  summary: Light-weight Ruby API to LibXML.
9
9
  require_paths:
10
10
  - lib
@@ -26,6 +26,7 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
26
26
  platform: mswin32
27
27
  signing_key:
28
28
  cert_chain:
29
+ post_install_message:
29
30
  authors:
30
31
  - Joshua Harvey
31
32
  files: