kwaff 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. data/COPYING +340 -0
  2. data/ChangeLog.txt +118 -0
  3. data/README.txt +96 -0
  4. data/bin/kwaff +131 -0
  5. data/doc/docstyle.css +307 -0
  6. data/doc/examples.html +1283 -0
  7. data/doc/users-guide.html +395 -0
  8. data/examples/Makefile +17 -0
  9. data/examples/ant/Makefile +7 -0
  10. data/examples/ant/build.kwaff +57 -0
  11. data/examples/hibernate/AuctionItem.hbm.kwaff +45 -0
  12. data/examples/hibernate/Bid.hbm.kwaff +42 -0
  13. data/examples/hibernate/Makefile +9 -0
  14. data/examples/hibernate/User.hbm.kwaff +65 -0
  15. data/examples/hibernate/hibernate.cfg.kwaff +17 -0
  16. data/examples/seasar2/Makefile +9 -0
  17. data/examples/seasar2/seasar2.kwaff +62 -0
  18. data/examples/servlet/Makefile +9 -0
  19. data/examples/servlet/web.kwaff +37 -0
  20. data/examples/spring/Makefile +9 -0
  21. data/examples/spring/applicationContext.kwaff +147 -0
  22. data/examples/xhtml/Makefile +9 -0
  23. data/examples/xhtml/README.kwaff +84 -0
  24. data/examples/xi/Makefile +9 -0
  25. data/examples/xi/bbs.kwaff +58 -0
  26. data/lib/kwaff.rb +85 -0
  27. data/lib/kwaff/doctype.rb +124 -0
  28. data/lib/kwaff/doctypes.yaml +138 -0
  29. data/lib/kwaff/errors.rb +26 -0
  30. data/lib/kwaff/node.rb +101 -0
  31. data/lib/kwaff/optparse.rb +101 -0
  32. data/lib/kwaff/orderedhash.rb +56 -0
  33. data/lib/kwaff/parser.rb +342 -0
  34. data/lib/kwaff/rexml.rb +394 -0
  35. data/lib/kwaff/translator.rb +275 -0
  36. data/setup.rb +1331 -0
  37. data/test/ex101.exp +10 -0
  38. data/test/ex101.in +8 -0
  39. data/test/ex102.exp +14 -0
  40. data/test/ex102.in +16 -0
  41. data/test/ex103.exp +13 -0
  42. data/test/ex103.in +13 -0
  43. data/test/ex104.exp +24 -0
  44. data/test/ex104.in +24 -0
  45. data/test/ex105.exp +12 -0
  46. data/test/ex105.in +18 -0
  47. data/test/ex106.exp +22 -0
  48. data/test/ex106.in +21 -0
  49. data/test/ex107.exp +14 -0
  50. data/test/ex107.in +14 -0
  51. data/test/ex111.exp +7 -0
  52. data/test/ex111.in +13 -0
  53. data/test/ex112.exp +15 -0
  54. data/test/ex112.in +16 -0
  55. data/test/ex113.exp +23 -0
  56. data/test/ex113.in +22 -0
  57. data/test/ex114.exp +12 -0
  58. data/test/ex114.in +17 -0
  59. data/test/ex115.exp +9 -0
  60. data/test/ex115.in +12 -0
  61. data/test/ex121.exp +10 -0
  62. data/test/ex121.in +8 -0
  63. data/test/ex122.exp +10 -0
  64. data/test/ex122.in +8 -0
  65. data/test/ex301.exp +13 -0
  66. data/test/ex301.in +14 -0
  67. data/test/ex302.exp +15 -0
  68. data/test/ex302.in +18 -0
  69. data/test/ex303.exp +15 -0
  70. data/test/ex303.in +16 -0
  71. data/test/ex304.exp +17 -0
  72. data/test/ex304.in +15 -0
  73. data/test/ex311.exp +18 -0
  74. data/test/ex311.in +32 -0
  75. data/test/ex312.exp +21 -0
  76. data/test/ex312.in +18 -0
  77. data/test/ex313.exp +20 -0
  78. data/test/ex313.in +33 -0
  79. data/test/ex314.exp +34 -0
  80. data/test/ex314.in +24 -0
  81. data/test/ex801.exp +16 -0
  82. data/test/ex801.in +15 -0
  83. data/test/test.rb +273 -0
  84. data/todo.txt +1 -0
  85. metadata +132 -0
@@ -0,0 +1,9 @@
1
+ ALL = README.xhtml
2
+
3
+ all: $(ALL)
4
+
5
+ %.xhtml: %.kwaff
6
+ kwaff $< > $@
7
+
8
+ clean:
9
+ rm -f $(ALL)
@@ -0,0 +1,84 @@
1
+ ? encoding = UTF-8
2
+ ? doctype = @xhtml
3
+
4
+ * html
5
+ - lang = en
6
+
7
+ * head
8
+
9
+ * title = README
10
+ * meta
11
+ - http-equiv = Content-Type
12
+ - content = text/xhtml
13
+
14
+ * body
15
+
16
+ * h1 = What is Kwaff?
17
+ * p
18
+ . Kwaff is a simplified and structured data format.
19
+ . See examples directory for detail.
20
+ * p
21
+ . Name of 'Kwaff' is derived from "kwa's friendly formatter".
22
+
23
+ * h1 = Installation
24
+ * p
25
+ . There are two ways to install Kwaff.
26
+ * dl
27
+ * dt = If you can be root user:
28
+ * dd
29
+ * pre = <<<END
30
+ $ ruby setup.rb config
31
+ $ ruby setup.rb setup
32
+ $ su
33
+ # ruby setup.rb install
34
+ END
35
+ * dt = If you cannot be root user:
36
+ * dd
37
+ * pre = <<<END
38
+ ### copy command file to appropriate directory.
39
+ $ cp bin/kwaff $HOME/bin/
40
+ ### copy library files to appropriate directory.
41
+ $ mkdir -p $HOME/lib/ruby
42
+ $ cp -r lib/kwaff* $HOME/lib/ruby
43
+ ### set environment variable RUBYLIB
44
+ $ export RUBYLIB=$HOME/lib/ruby
45
+ END
46
+
47
+ * h1 = Usage
48
+ * p
49
+ . You can convert Kwaff document into XML document.
50
+ * pre
51
+ . $ kwaff example.kwaff > example.xml
52
+ * p
53
+ . You can also convert XML document into Kwaff document.
54
+ * pre
55
+ . $ kwaff -r example.xml > example.kwaff
56
+ * p
57
+ . Type `kwaff -h' for detail.
58
+
59
+ * h1 = Manifest
60
+ * dl
61
+ * dt = README.txt
62
+ * dd = This file.
63
+ * dt = COPYING
64
+ * dd = GPL file.
65
+ * dt = CangeLog.txt
66
+ * dd = Change log file.
67
+ * dt = setup.rb
68
+ * dd = Setup file for installation.
69
+ * dt = bin/kwaff
70
+ * dd = Command file.
71
+ * dt = lib/kwaff.rb, lib/kwaff/*.rb
72
+ * dd = Library file.
73
+ * dt = examples/*
74
+ * dd = Examples of Kwaff.
75
+ * dt = doc/users-guide.html
76
+ * dd = Users' Guide.
77
+ * dt = test/test.rb, test/ex*.*
78
+ * dd = Unit test script and test data.
79
+
80
+ * h1 = License
81
+ * p = GPL (GNU General Public License) ver 2.
82
+
83
+ * h1 = Author
84
+ * p = kwatch <kwa.at.kuwata-lab.com>
@@ -0,0 +1,9 @@
1
+ ALL = bbs.xi
2
+
3
+ all: $(ALL)
4
+
5
+ %.xi: %.kwaff
6
+ kwaff $< > $@
7
+
8
+ clean:
9
+ rm -f $(ALL)
@@ -0,0 +1,58 @@
1
+ //
2
+ // from http://dock.baykit.org/xi13?Tutorial
3
+ //
4
+
5
+ * xi:program
6
+ - xmlns:xi = http://www.baykit.org/Xi/1.1
7
+
8
+ # declare variable 'BBS-DATA' with initial data
9
+ * xi:variable
10
+ - name = BBS-DATA
11
+ * bbs
12
+ * message = Welcom to mini-bbs
13
+
14
+ # if file 'bbs.xml' is exists, then load it into 'BBS-DATA'
15
+ * xi:if
16
+ - test = $FS.exists('bbs.xml')
17
+ * xi:set
18
+ - out = $BBS-DATA
19
+ - select = $IO.loadXml('bbs.xml')
20
+
21
+ # if new_message is on param, add it to end of BBS-DATA
22
+ * xi:if
23
+ - test = $Web.parameters.new_message != ''
24
+ * xi:set
25
+ - out = $BBS-DATA
26
+ * bbs
27
+ * xi:copy-of
28
+ - select = $BBS-DATA/bbs/*
29
+ * message
30
+ * xi:value-of
31
+ - select = $Web.parameters.new_message
32
+ * xi:exec
33
+ - select = $IO.saveXml('bbs.xml', $BBS-DATA)
34
+
35
+ * HTML
36
+ * BODY
37
+
38
+ # display bbs message.
39
+ * UL
40
+ * xi:for-each
41
+ - item = message
42
+ - select = $BBS-DATA/bbs/*
43
+ * LI
44
+ * xi:value-of
45
+ - select = $message
46
+
47
+ # FORM for posting bbs message.
48
+ * HR
49
+ * FORM
50
+ - METHOD = post
51
+ - ACTION = bbs.xi
52
+ .
53
+ . Message to post:
54
+ * BR
55
+ * TEXTAREA
56
+ - NAME = new_message
57
+ * INPUT
58
+ - TYPE = submit
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/ruby
2
+
3
+ ##
4
+ ## kwaff.rb - kwa's friendly format
5
+ ##
6
+ ## ex. Kwaff => XML or REXML
7
+ ## kwaff_str = <<END
8
+ ## ?xml-version = 1.0
9
+ ## ?encoding = ISO-8859-1
10
+ ## ?doctype = @xhtml
11
+ ## * html
12
+ ## * body
13
+ ## - bgcolor = white
14
+ ## - style = font-size:small
15
+ ## * ul
16
+ ## ! xml commet
17
+ ## # kwaff comment (ignored)
18
+ ## * li = foo
19
+ ## * li = bar
20
+ ## * li = baz
21
+ ## END
22
+ ##
23
+ ## # Kwaff string to XML string
24
+ ## include 'kwaff'
25
+ ## xml_str = Kwaff::convert(kwaff_str)
26
+ ##
27
+ ## # XML string to Kwaff string
28
+ ## include 'kwaff'
29
+ ## include 'kwaff/rexml'
30
+ ## kwaff_str = Kwaff::Rexml::revert(xml_str)
31
+ ##
32
+ ## # Kwaff string to REXML::Document
33
+ ## include 'kwaff'
34
+ ## include 'kwaff/rexml'
35
+ ## xml_document = Kwaff::Rexml::convert(kwaff_str)
36
+ ##
37
+ ## # REXML::Document to Kwaff string
38
+ ## include 'kwaff'
39
+ ## include 'kwaff/rexml'
40
+ ## translator = Kwaff::Rexml::KwaffTranslator.new
41
+ ## kwaff_str = translator.translate(rexml_document)
42
+ ##
43
+ ## # Kwaff string to Kwaff::Document
44
+ ## include 'kwaff'
45
+ ## kwaff_document = Kwaff::parse_document(kwaff_str)
46
+ ##
47
+ ##
48
+ ## $Id: kwaff.rb 7 2005-05-18 14:33:37Z kwatch $
49
+ ## $Release: 1.0.0 $
50
+ ## copyright(c) 2005 kuwata-lab.com all rights reserved
51
+ ##
52
+
53
+ #require 'kwaff/errors'
54
+ #require 'kwaff/orderedhash'
55
+ require 'kwaff/node'
56
+ require 'kwaff/parser'
57
+ require 'kwaff/translator'
58
+ require 'kwaff/doctype'
59
+ #require 'kwaff/rexml'
60
+
61
+
62
+ module Kwaff
63
+
64
+ VERSION = ('$Rev: 7 $' =~ /\d+(?:\.\d+)*/ && $&)
65
+ LAST_UPDATE = ('$Date: 2005-05-18 23:33:37 +0900 (Wed, 18 May 2005) $' =~ /\d\d\d\d[-\/]\d\d[-\/]\d\d/ && $&)
66
+
67
+ end
68
+
69
+
70
+ #begin
71
+ # require 'kwaff/local-setup'
72
+ #rescue LoadError => ex
73
+ # # do nothing
74
+ #end
75
+
76
+
77
+ if $0 == __FILE__
78
+ input = ARGF.read
79
+ parser = Kwaff::Parser.new(input)
80
+ document = parser.parse_document()
81
+ toppings = { :newline => parser.newline }
82
+ #print document.to_xml(toppings)
83
+ translator = Kwaff::XmlTranslator.new(toppings)
84
+ print translator.translate(document)
85
+ end
@@ -0,0 +1,124 @@
1
+ ##
2
+ ## represents XML Dcoument Type
3
+ ##
4
+ ## document_type ::= '<!DOCUTYPE' element_name external_subset [ internal_subset ] '>'
5
+ ## external_subset ::= 'PUBLIC' pubic_id system_id | 'SYSTEM' system_id
6
+ ## public_id ::= '"' string '"'
7
+ ## sytem_id ::= '"' uri '"'
8
+ ##
9
+ ## XML Specification:
10
+ ## doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S? ('[' intSubset ']' S?)? '>'
11
+ ## ExternalID ::= 'SYSTEM' S SystemLiteral | 'PUBLIC' S PubidLiteral S SystemLiteral
12
+ ##
13
+ ## $Id: doctype.rb 11 2005-06-09 12:32:33Z kwatch $
14
+ ## $Release: 1.0.0 $
15
+ ## copyright(c) 2005 kuwata-lab.com all rights reserved
16
+ ##
17
+
18
+ require 'yaml'
19
+
20
+ module Kwaff
21
+ class DocType
22
+ ## ex.
23
+ ## root_tag = 'html'
24
+ ## public_id = '-//W3C//DTD XHTML 1.0 Transitional//EN'
25
+ ## system_id = 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'
26
+ ## doctype = DocType.new(root_tag, public_id, system_id)
27
+ ## or
28
+ ## str = <<END
29
+ ## <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
30
+ ## "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
31
+ ## END
32
+ ## doctype = DocType.new()
33
+ ## doctype.doctype = str
34
+
35
+ def initialize(root_tag, public_id, system_id, desc=nil)
36
+ @root_tag = root_tag
37
+ @public_id = public_id
38
+ @system_id = system_id
39
+ @desc = desc
40
+ @_str = nil
41
+ @@instances << self
42
+ end
43
+ attr_accessor :root_tag, :public_id, :system_id, :desc
44
+
45
+ attr_accessor :names
46
+
47
+
48
+ ## convert to "<!DOCTYPE ...>"
49
+ def to_s
50
+ if ! @_str
51
+ @_str = "<!DOCTYPE #{@root_tag}"
52
+ if @public_id
53
+ @_str << " PUBLIC \"#{@public_id}\"\n\t"
54
+ else
55
+ @_str << " SYSTEM "
56
+ end
57
+ @_str << "\"#{@system_id}\"" if @system_id
58
+ @_str << ">"
59
+ end
60
+ return @_str
61
+ end
62
+
63
+ @@instances = []
64
+ def self.instances
65
+ @@instances
66
+ end
67
+
68
+ @@registered = {}
69
+
70
+ #def self.registered
71
+ # @@registered
72
+ #end
73
+
74
+ def self.register(nickname, doctype)
75
+ @@registered[nickname] = doctype
76
+ end
77
+
78
+ def self.get(nickname)
79
+ @@registered[nickname]
80
+ end
81
+
82
+ def self.find(&block)
83
+ return @@instances.find(&block)
84
+ end
85
+
86
+ def self.nickname(doctype)
87
+ @@registered.each do |nickname, dtype|
88
+ return nickname if dtype.public_id == doctype.public_id
89
+ end
90
+ return nil
91
+ end
92
+
93
+ def self._read_file(filename)
94
+ s = ''
95
+ File.open(filename) do |f|
96
+ while line = f.gets()
97
+ s << line.gsub(/([^\t]{8})|([^\t]*)\t/n){[$+].pack("A8")}
98
+ end
99
+ end
100
+ return s
101
+ end
102
+
103
+ ## load doctype definition
104
+ input = ''
105
+ filename = File::dirname(__FILE__) + "/doctypes.yaml"
106
+ input << _read_file(filename) if test(?f, filename)
107
+ filename = ENV['HOME'] + "/.doctypes.yaml"
108
+ input << _read_file(filename) if test(?f, filename)
109
+ context = YAML::load(input)
110
+ hash_list = context['doctypes']
111
+ hash_list.each do |hash|
112
+ doctype = DocType.new(hash['root-tag'], hash['public-id'], hash['system-id'], hash['desc'])
113
+ unless hash['names']
114
+ raise "`names' is not specified. (doctype=#{doctype.to_yaml})"
115
+ end
116
+ doctype.names = hash['names']
117
+ hash['names'].each do |name|
118
+ DocType.register(name, doctype)
119
+ end
120
+ end if hash_list
121
+
122
+ end
123
+
124
+ end
@@ -0,0 +1,138 @@
1
+
2
+ ## $Id: doctypes.yaml 9 2005-06-09 08:44:11Z kwatch $
3
+ ## $Release: 1.0.0 $
4
+ ## copyright(c) 2005 kuwata-lab.com all rights reserved
5
+
6
+ doctypes:
7
+
8
+
9
+ - desc: XHTML1.0 Transitional
10
+ root-tag: html
11
+ public-id: '-//W3C//DTD XHTML 1.0 Transitional//EN'
12
+ system-id: 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'
13
+ names:
14
+ - @xhtml10-transitional
15
+ - @xhtml-transitional
16
+ - @xhtml10
17
+ - @xhtml
18
+
19
+
20
+ - desc: XHTML1.0 Strict
21
+ root-tag: html
22
+ public-id: '-//W3C//DTD XHTML 1.0 Strict//EN'
23
+ system-id: 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'
24
+ names:
25
+ - @xhtml10-strict
26
+ - @xhtml-strict
27
+
28
+
29
+ - desc: Deployment Descriptor 2.3
30
+ root-tag: web-app
31
+ public-id: '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN'
32
+ system-id: 'http://java.sun.com/dtd/web-app_2_3.dtd'
33
+ names:
34
+ - @web-app23
35
+ - @web-app
36
+
37
+
38
+ - desc: EJB2.0
39
+ root-tag: ejb-jar
40
+ public-id: '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN'
41
+ system-id: 'http://java.sun.com/dtd/ejb-jar_2_0.dtd'
42
+ names:
43
+ - @ejb-jar20
44
+ - @ejb-jar
45
+
46
+
47
+ - desc: SVG (Scalable Vector Graphics) 1.1
48
+ root-tag: svg
49
+ public-id: '-//W3C//DTD SVG 1.1//EN'
50
+ system-id: 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'
51
+ names:
52
+ - @svg11
53
+ - @svg
54
+
55
+
56
+ - desc: Spring Framework
57
+ root-tag: beans
58
+ public-id: '-//SPRING//DTD BEAN//EN'
59
+ system-id: 'http://www.springframework.org/dtd/spring-beans.dtd'
60
+ names:
61
+ - @spring-beans
62
+
63
+
64
+ - desc: Struts
65
+ root-tag: struts-config
66
+ public-id: '-//Apache Software Foundation//DTD Struts Configuration 1.0//EN'
67
+ system-id: 'http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd'
68
+ names:
69
+ - @struts-config10
70
+ - @struts-config
71
+
72
+
73
+ - desc: BayServer
74
+ root-tag: system
75
+ public-id: '-//Yokohama Baykit//DTD BayServer 1.3//EN'
76
+ system-id: 'http://www.baykit.org/bserv/system_1_3.dtd'
77
+ names:
78
+ - @bserv13
79
+ - @bserv14
80
+
81
+
82
+ - desc: Hibernate configuration
83
+ root-tag: hibernate-configuration
84
+ public-id: '-//Hibernate/Hibernate Configuration DTD//EN'
85
+ system-id: 'http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd'
86
+ names:
87
+ - @hibernate-config20
88
+ - @hibernate-configuration20
89
+ #- @hibernate-config
90
+ #- @hibernate-configuration
91
+
92
+
93
+ - desc: Hibernate configuration
94
+ root-tag: hibernate-configuration
95
+ public-id: '-//Hibernate/Hibernate Configuration DTD 3.0//EN'
96
+ system-id: 'http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd'
97
+ names:
98
+ - @hibernate-config30
99
+ - @hibernate-configuration30
100
+ - @hibernate-config
101
+ - @hibernate-configuration
102
+
103
+
104
+ - desc: Hibernate mapping
105
+ root-tag: hibernate-mapping
106
+ public-id: '-//Hibernate/Hibernate Mapping DTD//EN'
107
+ system-id: 'http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd'
108
+ names:
109
+ - @hibernate-mapping20
110
+ #- @hibernate-mapping
111
+
112
+
113
+ - desc: Hibernate mapping
114
+ root-tag: hibernate-mapping
115
+ public-id: '-//Hibernate/Hibernate Mapping DTD 3.0//EN'
116
+ system-id: 'http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd'
117
+ names:
118
+ - @hibernate-mapping30
119
+ - @hibernate-mapping
120
+
121
+
122
+ - desc: Seasar2
123
+ root-tag: components
124
+ public-id: "-//SEASAR2.1//DTD S2Container//EN"
125
+ system-id: "http://www.seasar.org/dtd/components21.dtd"
126
+ names:
127
+ - @seasar21
128
+ - @seasar2
129
+
130
+
131
+ # - desc: Deployment Descriptor 2.4
132
+ # root-tag: web-app
133
+ # schema: xml-schema
134
+ # attrs:
135
+ # xmlns: "http://java.sun.com/xml/ns/j2ee"
136
+ # xmlns:xsi: "http://www.w3.org/2001/XMLSchema-instance"
137
+ # xsi:schemaLocation: "http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
138
+ # version: "2.4"