rd2odt 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/FUTURE +63 -0
  2. data/LICENSE +21 -0
  3. data/NEWS +42 -0
  4. data/README +78 -0
  5. data/Rakefile +51 -0
  6. data/bin/rd2odt +4 -0
  7. data/doc/sample/body-text.rd +5 -0
  8. data/doc/sample/enum-list-over-headline-multi-level.rd +10 -0
  9. data/doc/sample/enum-list-over-headline.rd +9 -0
  10. data/doc/sample/enum-list-over-item-list-multi-level-2.rd +9 -0
  11. data/doc/sample/enum-list-over-item-list-multi-level.rd +8 -0
  12. data/doc/sample/enum-list-over-item-list.rd +7 -0
  13. data/doc/sample/headline.rd +60 -0
  14. data/doc/sample/include-file-figure.odt +0 -0
  15. data/doc/sample/include-file-ole-object.odt +0 -0
  16. data/doc/sample/include-file-original-styled-text.odt +0 -0
  17. data/doc/sample/include-file-shape.odt +0 -0
  18. data/doc/sample/include-file-simple-styled-text.odt +0 -0
  19. data/doc/sample/include-file-simple-text.odt +0 -0
  20. data/doc/sample/include-file-table.odt +0 -0
  21. data/doc/sample/include.rd +21 -0
  22. data/doc/sample/list.rd +22 -0
  23. data/doc/sample/multi-paragraph.rd +12 -0
  24. data/doc/sample/page-break.odt +0 -0
  25. data/doc/sample/verbatim.rd +8 -0
  26. data/doc/sample.rd.ja +75 -0
  27. data/doc/sample.rd.ja.ott +0 -0
  28. data/doc/sample.rd.ja.pdf +0 -0
  29. data/doc/specification.ja.rd +35 -0
  30. data/lib/rd2odt/rdtool/NOTICE.rd2odt +8 -0
  31. data/lib/rd2odt/rdtool/README.rd +50 -0
  32. data/lib/rd2odt/rdtool/README.rd.ja +53 -0
  33. data/lib/rd2odt/rdtool/rd/block-element.rb +114 -0
  34. data/lib/rd2odt/rdtool/rd/complex-list-item.rb +65 -0
  35. data/lib/rd2odt/rdtool/rd/desclist.rb +55 -0
  36. data/lib/rd2odt/rdtool/rd/document-struct.rb +46 -0
  37. data/lib/rd2odt/rdtool/rd/element.rb +160 -0
  38. data/lib/rd2odt/rdtool/rd/filter.rb +255 -0
  39. data/lib/rd2odt/rdtool/rd/inline-element.rb +233 -0
  40. data/lib/rd2odt/rdtool/rd/labeled-element.rb +14 -0
  41. data/lib/rd2odt/rdtool/rd/list.rb +57 -0
  42. data/lib/rd2odt/rdtool/rd/loose-struct.rb +11 -0
  43. data/lib/rd2odt/rdtool/rd/methodlist.rb +57 -0
  44. data/lib/rd2odt/rdtool/rd/output-format-visitor.rb +28 -0
  45. data/lib/rd2odt/rdtool/rd/package.rb +4 -0
  46. data/lib/rd2odt/rdtool/rd/parser-util.rb +14 -0
  47. data/lib/rd2odt/rdtool/rd/rbl-file.rb +69 -0
  48. data/lib/rd2odt/rdtool/rd/rbl-suite.rb +37 -0
  49. data/lib/rd2odt/rdtool/rd/rd-struct.rb +86 -0
  50. data/lib/rd2odt/rdtool/rd/rd2html-lib.rb +490 -0
  51. data/lib/rd2odt/rdtool/rd/rd2html-opt.rb +67 -0
  52. data/lib/rd2odt/rdtool/rd/rd2man-lib.rb +241 -0
  53. data/lib/rd2odt/rdtool/rd/rd2rdo-lib.rb +19 -0
  54. data/lib/rd2odt/rdtool/rd/rd2rmi-lib.rb +32 -0
  55. data/lib/rd2odt/rdtool/rd/rdblockparser.tab.rb +1050 -0
  56. data/lib/rd2odt/rdtool/rd/rdfmt.rb +15 -0
  57. data/lib/rd2odt/rdtool/rd/rdinlineparser.tab.rb +1243 -0
  58. data/lib/rd2odt/rdtool/rd/rdvisitor.rb +214 -0
  59. data/lib/rd2odt/rdtool/rd/reference-resolver.rb +114 -0
  60. data/lib/rd2odt/rdtool/rd/search-file.rb +14 -0
  61. data/lib/rd2odt/rdtool/rd/tree.rb +103 -0
  62. data/lib/rd2odt/rdtool/rd/version.rb +39 -0
  63. data/lib/rd2odt/rdtool/rd/visitor.rb +86 -0
  64. data/lib/rd2odt.rb +603 -0
  65. data/rd2odt.gemspec +108 -0
  66. data/setup.rb +1585 -0
  67. data/test/functional/rd2odt-spec.rb +733 -0
  68. data/test/test-helper.rb +93 -0
  69. data/test/unit/rd2odt-spec.rb +831 -0
  70. metadata +122 -0
@@ -0,0 +1,93 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ $top_srcdir = File.join(File.dirname(__FILE__), "..")
4
+ $LOAD_PATH << File.join($top_srcdir, "lib")
5
+
6
+ $KCODE = "u" if RUBY_VERSION < "1.9.0"
7
+
8
+ require "rd2odt"
9
+ require "tempfile"
10
+
11
+ module XmlMatchers
12
+ class BeSameAsThisXml
13
+ def initialize(expected)
14
+ @expected = expected
15
+ if String === expected || Symbol === expected
16
+ @expected_dom = to_dom(expected.to_s)
17
+ end
18
+ end
19
+
20
+ def matches?(actual)
21
+ @actual = actual
22
+ if String === actual || Symbol === actual
23
+ @actual_dom = to_dom(actual.to_s)
24
+ end
25
+ return expected_dom.to_s == actual_dom.to_s
26
+ end
27
+
28
+ def failure_message
29
+ return "difference: #{diff}"
30
+ end
31
+
32
+ alias negative_failure_message failure_message
33
+
34
+ private
35
+
36
+ DOM_PREFIX = <<EOF
37
+ <?xml version='1.0' encoding='UTF-8'?>
38
+
39
+ <office:document-content xmlns:script='urn:oasis:names:tc:opendocument:xmlns:script:1.0' xmlns:oooc='http://openoffice.org/2004/calc' xmlns:number='urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0' xmlns:dr3d='urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0' xmlns:math='http://www.w3.org/1998/Math/MathML' xmlns:dom='http://www.w3.org/2001/xml-events' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:text='urn:oasis:names:tc:opendocument:xmlns:text:1.0' xmlns:svg='urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0' xmlns:ooo='http://openoffice.org/2004/office' xmlns:xforms='http://www.w3.org/2002/xforms' xmlns:table='urn:oasis:names:tc:opendocument:xmlns:table:1.0' xmlns:meta='urn:oasis:names:tc:opendocument:xmlns:meta:1.0' xmlns:form='urn:oasis:names:tc:opendocument:xmlns:form:1.0' xmlns:field='urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:field:1.0' xmlns:draw='urn:oasis:names:tc:opendocument:xmlns:drawing:1.0' office:version='1.1' xmlns:office='urn:oasis:names:tc:opendocument:xmlns:office:1.0' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns:fo='urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:style='urn:oasis:names:tc:opendocument:xmlns:style:1.0' xmlns:ooow='http://openoffice.org/2004/writer' xmlns:chart='urn:oasis:names:tc:opendocument:xmlns:chart:1.0'>
40
+
41
+
42
+ EOF
43
+
44
+ DOM_SUFFIX = <<EOF
45
+
46
+
47
+ </office:document-content>
48
+ EOF
49
+
50
+ def expected_dom
51
+ return (@expected_dom ||= to_dom(RD2ODT.ah_to_xml(@expected)))
52
+ end
53
+
54
+ def actual_dom
55
+ return (@actual_dom ||= to_dom(RD2ODT.ah_to_xml(@expected)))
56
+ end
57
+
58
+ def to_dom(s)
59
+ root = REXML::Document.new(DOM_PREFIX + s + DOM_SUFFIX)
60
+ result = root[2][1] # `result' is only XML from `s'.
61
+ return result
62
+ end
63
+
64
+ def diff
65
+ Tempfile.open("rd2odt-test") do |expected_file|
66
+ Tempfile.open("rd2odt-test") do |actual_file|
67
+ expected_file.puts(expected_dom.to_s)
68
+ expected_file.close
69
+ actual_file.puts(actual_dom.to_s)
70
+ actual_file.close
71
+
72
+ result = `docdiff --utf8 --char --tty #{expected_file.path} #{actual_file.path}`
73
+ return result
74
+ end
75
+ end
76
+ end
77
+ end
78
+
79
+ def be_same_as_this_xml(expected)
80
+ return BeSameAsThisXml.new(expected)
81
+ end
82
+ end
83
+
84
+ # for test on Ruby 1.8.6.
85
+ if RUBY_VERSION < "1.8.7"
86
+ class Hash
87
+ def each
88
+ keys.sort.each do |k|
89
+ yield(k, self[k])
90
+ end
91
+ end
92
+ end
93
+ end