xamplr 1.3.15 → 1.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.
Files changed (163) hide show
  1. data/.gitignore +1 -0
  2. data/COPYING +160 -656
  3. data/LICENSE +1 -1
  4. data/README.md +33 -0
  5. data/Rakefile +2 -2
  6. data/VERSION.yml +2 -2
  7. data/lib/xamplr.rb +1 -0
  8. data/lib/xamplr/iterator.rb +123 -0
  9. data/lib/xamplr/xml-text.rb +5 -5
  10. data/xamplr.gemspec +9 -204
  11. metadata +13 -203
  12. data/README.rdoc +0 -46
  13. data/README.rdoc.orig +0 -118
  14. data/bin/xampl-gen +0 -17
  15. data/docs/intro/.gitignore +0 -1
  16. data/docs/intro/example1/example1.rb +0 -6
  17. data/docs/intro/example1/xml/hello.xml +0 -1
  18. data/docs/intro/example2/example2.rb +0 -38
  19. data/docs/intro/example2/project-generator.rb +0 -22
  20. data/docs/intro/example2/xml/hello.xml +0 -2
  21. data/docs/intro/example3/example3.rb +0 -30
  22. data/docs/intro/example3/example3a.rb +0 -16
  23. data/docs/intro/example3/generated.png +0 -0
  24. data/docs/intro/example3/grab-yuml.rb +0 -10
  25. data/docs/intro/example3/greeter.rb +0 -15
  26. data/docs/intro/example3/greeting.rb +0 -9
  27. data/docs/intro/example3/project-generator.rb +0 -25
  28. data/docs/intro/example3/xml/greeter.xml +0 -6
  29. data/docs/intro/example4/example4.rb +0 -27
  30. data/docs/intro/example4/example4a.rb +0 -19
  31. data/docs/intro/example4/grab-yuml.rb +0 -10
  32. data/docs/intro/example4/greeter.rb +0 -15
  33. data/docs/intro/example4/greeting.rb +0 -9
  34. data/docs/intro/example4/project-generator.rb +0 -25
  35. data/docs/intro/example4/xml/greeter.xml +0 -6
  36. data/docs/intro/grab-yuml.rb +0 -10
  37. data/docs/intro/project-generator.rb +0 -51
  38. data/docs/intro/xampl.lyx +0 -1494
  39. data/docs/intro/xampl.pdf +0 -0
  40. data/examples/employees/final-xampl/xampl-gen.rb +0 -38
  41. data/examples/employees/final-xampl/xml/ddd-final-xampl.xml +0 -86
  42. data/examples/employees/final/xampl-gen.rb +0 -38
  43. data/examples/employees/final/xml/ddd-final.xml +0 -86
  44. data/examples/employees/first/xampl-gen.rb +0 -38
  45. data/examples/employees/first/xml/ddd-first.xml +0 -48
  46. data/examples/employees/twist/twist.graphml +0 -333
  47. data/examples/employees/twist/xampl-gen.rb +0 -38
  48. data/examples/employees/twist/xml/twist.xml +0 -90
  49. data/examples/employees/xamplr-twist.xml +0 -2
  50. data/examples/employees/yuml-diagrams/DDD-final-approach.graphml +0 -393
  51. data/examples/employees/yuml-diagrams/DDD-final-xampl-approach.graphml +0 -265
  52. data/examples/employees/yuml-diagrams/DDD-ideal-final-approach.graphml +0 -357
  53. data/examples/employees/yuml-diagrams/ddd-final.png +0 -0
  54. data/examples/employees/yuml-diagrams/ddd-final.yuml +0 -8
  55. data/examples/employees/yuml-diagrams/ddd-first.png +0 -0
  56. data/examples/employees/yuml-diagrams/ddd-first.yuml +0 -7
  57. data/examples/employees/yuml-diagrams/final-yed.png +0 -0
  58. data/examples/employees/yuml-diagrams/first-yed.png +0 -0
  59. data/examples/employees/yuml-diagrams/twist.png +0 -0
  60. data/examples/employees/yuml-diagrams/twist.yuml +0 -12
  61. data/examples/employees/yuml-diagrams/xamplr-final-no-mixins.png +0 -0
  62. data/examples/employees/yuml-diagrams/xamplr-final-simplified.png +0 -0
  63. data/examples/employees/yuml-diagrams/xamplr-final-with-mixins.png +0 -0
  64. data/examples/employees/yuml-diagrams/yuml-simplified.txt +0 -19
  65. data/examples/employees/yuml-diagrams/yuml-with-mixins.txt +0 -53
  66. data/examples/employees/yuml-diagrams/yuml.txt +0 -27
  67. data/examples/hobbies/Makefile +0 -5
  68. data/examples/hobbies/hobbies.rb +0 -193
  69. data/examples/hobbies/project-generator.rb +0 -25
  70. data/examples/hobbies/xampl-gen.rb +0 -38
  71. data/examples/hobbies/xml/hobby.xml +0 -3
  72. data/examples/hobbies/xml/people.xml +0 -5
  73. data/examples/random-people-shared-addresses/.gitignore +0 -2
  74. data/examples/random-people-shared-addresses/Makefile +0 -15
  75. data/examples/random-people-shared-addresses/batch-load-users-profiled.rb +0 -91
  76. data/examples/random-people-shared-addresses/batch-load-users-safe.rb +0 -81
  77. data/examples/random-people-shared-addresses/batch-load-users.rb +0 -79
  78. data/examples/random-people-shared-addresses/find-mentions.rb +0 -47
  79. data/examples/random-people-shared-addresses/find-people-by-address.rb +0 -104
  80. data/examples/random-people-shared-addresses/optimise.rb +0 -16
  81. data/examples/random-people-shared-addresses/people.rb +0 -35
  82. data/examples/random-people-shared-addresses/query.rb +0 -75
  83. data/examples/random-people-shared-addresses/query2.rb +0 -73
  84. data/examples/random-people-shared-addresses/random-names.csv +0 -10000
  85. data/examples/random-people-shared-addresses/settings.rb +0 -3
  86. data/examples/random-people-shared-addresses/what-to-query-on.rb +0 -82
  87. data/examples/random-people-shared-addresses/xampl-gen.rb +0 -38
  88. data/examples/random-people-shared-addresses/xml/people.xml +0 -14
  89. data/examples/random-people/.gitignore +0 -2
  90. data/examples/random-people/Makefile +0 -20
  91. data/examples/random-people/batch-load-users.rb +0 -61
  92. data/examples/random-people/optimise.rb +0 -16
  93. data/examples/random-people/people.rb +0 -22
  94. data/examples/random-people/query.rb +0 -73
  95. data/examples/random-people/query2.rb +0 -73
  96. data/examples/random-people/random-names.csv +0 -10000
  97. data/examples/random-people/rawtc.rb +0 -91
  98. data/examples/random-people/settings.rb +0 -3
  99. data/examples/random-people/what-to-query-on.rb +0 -80
  100. data/examples/random-people/xampl-gen.rb +0 -39
  101. data/examples/random-people/xml/people.xml +0 -11
  102. data/examples/read-testing/.gitignore +0 -2
  103. data/examples/read-testing/Makefile +0 -10
  104. data/examples/read-testing/load.rb +0 -65
  105. data/examples/read-testing/read.rb +0 -51
  106. data/examples/read-testing/rrr.rb +0 -88
  107. data/examples/read-testing/settings.rb +0 -2
  108. data/examples/read-testing/xampl-gen.rb +0 -38
  109. data/examples/read-testing/xml/text.xml +0 -8
  110. data/examples/tokyo-cabinet-experimental/.gitignore +0 -2
  111. data/examples/tokyo-cabinet-experimental/expt-query.rb +0 -42
  112. data/examples/tokyo-cabinet-experimental/expt-query2.rb +0 -42
  113. data/examples/tokyo-cabinet-experimental/expt-query3.rb +0 -41
  114. data/examples/tokyo-cabinet-experimental/expt-reader.rb +0 -32
  115. data/examples/tokyo-cabinet-experimental/expt.rb +0 -61
  116. data/examples/tokyo-cabinet-experimental/xampl-gen.rb +0 -38
  117. data/examples/tokyo-cabinet-experimental/xml/tcx.xml +0 -6
  118. data/examples/write-testing/README +0 -4
  119. data/examples/write-testing/RESULTS.home +0 -33
  120. data/examples/write-testing/RESULTS.raconteur +0 -33
  121. data/examples/write-testing/write-speed-test.rb +0 -40
  122. data/lib/xampl-generator.rb +0 -3
  123. data/lib/xamplr-generator.rb +0 -9
  124. data/lib/xamplr/gen-elements.xml +0 -6230
  125. data/lib/xamplr/gen.elements.xml +0 -108
  126. data/lib/xamplr/generate-elements.rb +0 -15
  127. data/lib/xamplr/generator.rb +0 -5
  128. data/lib/xamplr/graphml-out.rb +0 -451
  129. data/lib/xamplr/handwritten/example.rb +0 -698
  130. data/lib/xamplr/handwritten/hand-example.rb +0 -533
  131. data/lib/xamplr/handwritten/test-handwritten.rb +0 -873
  132. data/lib/xamplr/my.gen.elements.xml +0 -461
  133. data/lib/xamplr/obsolete/fsdb.rb +0 -62
  134. data/lib/xamplr/simpleTemplate/danger.rx +0 -4
  135. data/lib/xamplr/simpleTemplate/obsolete/input-c.r4 +0 -35
  136. data/lib/xamplr/simpleTemplate/obsolete/play.r6.txt +0 -12
  137. data/lib/xamplr/simpleTemplate/obsolete/play_more.r6.txt +0 -20
  138. data/lib/xamplr/simpleTemplate/obsolete/test001.r5 +0 -8
  139. data/lib/xamplr/simpleTemplate/obsolete/test002.r5 +0 -13
  140. data/lib/xamplr/simpleTemplate/obsolete/test003.r5 +0 -37
  141. data/lib/xamplr/simpleTemplate/old/r6.000.rb +0 -122
  142. data/lib/xamplr/simpleTemplate/old/r6.001.rb +0 -145
  143. data/lib/xamplr/simpleTemplate/play.r6 +0 -12
  144. data/lib/xamplr/simpleTemplate/play_more.r6 +0 -20
  145. data/lib/xamplr/simpleTemplate/play_noblanks.r6 +0 -21
  146. data/lib/xamplr/simpleTemplate/playq.r6 +0 -16
  147. data/lib/xamplr/simpleTemplate/r6.rb +0 -87
  148. data/lib/xamplr/simpleTemplate/simple-template.rb +0 -75
  149. data/lib/xamplr/templates/.cvsignore +0 -3
  150. data/lib/xamplr/templates/child.template +0 -47
  151. data/lib/xamplr/templates/child_indexed.template +0 -89
  152. data/lib/xamplr/templates/child_modules.template +0 -5
  153. data/lib/xamplr/templates/element_classes.template +0 -11
  154. data/lib/xamplr/templates/element_data.template +0 -283
  155. data/lib/xamplr/templates/element_empty.template +0 -277
  156. data/lib/xamplr/templates/element_mixed.template +0 -278
  157. data/lib/xamplr/templates/element_simple.template +0 -277
  158. data/lib/xamplr/templates/package.template +0 -38
  159. data/lib/xamplr/xampl-cl-gen.rb +0 -89
  160. data/lib/xamplr/xampl-generator.rb +0 -569
  161. data/lib/xamplr/xampl-hand-generated.rb +0 -1535
  162. data/lib/xamplr/yEd-sample.graphml +0 -300
  163. data/lib/xamplr/yuml-out.rb +0 -129
@@ -1,17 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #!/usr/bin/env ruby -w -I..
3
-
4
- require 'xamplr-generator'
5
- require 'xamplr/xampl-cl-gen'
6
-
7
- include XamplGenerator
8
- include Xampl
9
-
10
- project_specialisations = File.join(%w{ . project-generator.rb })
11
- if File.exists?(project_specialisations) then
12
- load project_specialisations
13
- end
14
-
15
- generator = ProjectGenerator.new
16
- generator.generate
17
-
@@ -1 +0,0 @@
1
- *.yuml
@@ -1,6 +0,0 @@
1
- require 'xampl_generated_code/XamplAdHoc.rb'
2
-
3
- Xampl.transaction("example1") do
4
- h = HelloWorld.new
5
- puts h.to_xml
6
- end
@@ -1 +0,0 @@
1
- <hello-world/>
@@ -1,38 +0,0 @@
1
- require 'xampl_generated_code/Example2.rb'
2
-
3
- include Example2
4
-
5
- class Hello
6
- def to_s
7
- "Hello #{ who ? who : 'hello?' }!"
8
- end
9
- end
10
-
11
- Xampl.transaction("example2") do
12
- h = Hello.new
13
-
14
- puts "haven't set the who attribute yet..."
15
- puts h.to_xml
16
- puts h
17
-
18
- h.who = 'world'
19
-
20
- puts "\nhave set the who attribute to 'world'..."
21
- puts h.to_xml
22
- puts h.pp_xml
23
- puts h
24
-
25
- h2 = Hello.new
26
- h2.who = 'there'
27
-
28
- all = [ h, h2 ]
29
-
30
- puts "\nthere are two Hello things now..."
31
- puts h
32
- puts h2
33
-
34
- puts "\nprint an array of the two Hello things..."
35
- puts all
36
- puts "\ninspect an array of the two Hello things..."
37
- puts all.inspect
38
- end
@@ -1,22 +0,0 @@
1
- class ProjectGenerator
2
-
3
- def resolve_namespaces
4
- # any array of arrays
5
- # each sub-array:
6
- # 0: a string or an array of strings, containing xml namespaces found
7
- # in the example xml files an empty string is the default namespace
8
- # 1: a ruby Module name (get the character cases right)
9
- # 2: a namespace prefix used when writing xml, optional. A generated
10
- # prefix will be used otherwise.
11
-
12
- #[]
13
-
14
- [
15
- [ 'com.xampl.intro.example2', 'Example2', 'ex2']
16
- ]
17
-
18
-
19
- end
20
-
21
- end
22
-
@@ -1,2 +0,0 @@
1
- <hello who='world'
2
- xmlns='com.xampl.intro.example2'/>
@@ -1,30 +0,0 @@
1
- require 'greeter'
2
- require 'greeting'
3
-
4
- ##include Example3 -- nope, not this time
5
-
6
- Xampl.transaction("example3") do
7
- greeter = Example3::Greeter.new
8
-
9
- greeting1 = Example3::Greeting.new('has-name')
10
- greeting1.content = "Hello $$$, how are you?"
11
- greeter << greeting1
12
-
13
- greeter.new_who.name = 'world'
14
- greeter.new_who.name = 'there'
15
-
16
- greeting2 = greeter.new_greeting('no-name')
17
- greeting2.content = "Hello hello? Someone there?"
18
-
19
- greeter.new_who
20
-
21
- puts greeter.to_xml
22
- puts greeter.pp_xml
23
-
24
- puts "\nAnd now extend our greetings..."
25
-
26
- greeter.extend_greetings
27
-
28
- puts "\nwriting the xml representation of our greeter..."
29
- File.open('greeter.xml', 'w') { |f| f.write greeter.to_xml }
30
- end
@@ -1,16 +0,0 @@
1
- require 'greeter'
2
- require 'greeting'
3
-
4
- unless File.exists? "greeter.xml" then
5
- puts "run example3 before running this one"
6
- exit
7
- end
8
-
9
- xml = File.open("greeter.xml") { | f | f.read }
10
-
11
- Xampl.transaction("example3") do
12
- greeter = Xampl.from_xml_string(xml)
13
-
14
- puts "\nAnd now extend our greetings..."
15
- greeter.extend_greetings
16
- end
@@ -1,10 +0,0 @@
1
-
2
- diagram = ""
3
- File.open("./generated.yuml") do | f |
4
- f.each do | line |
5
- diagram << line.chomp
6
- end
7
- end
8
- wget = "wget 'http://yuml.me/diagram/scruffy/class/#{diagram}' -O 'generated.png'"
9
- #wget = "wget 'http://yuml.me/diagram/scruffy/class/#{diagram}.pdf' -O 'generated.pdf'"
10
- `#{wget}`
@@ -1,15 +0,0 @@
1
- require 'xampl_generated_code/Example3.rb'
2
-
3
- module Example3
4
- class Greeter
5
- def extend_greetings
6
- who.each do | who |
7
- if who.name then
8
- puts greeting['has-name'].extend_greeting(who.name)
9
- else
10
- puts greeting['no-name'].extend_greeting
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,9 +0,0 @@
1
- require 'xampl_generated_code/Example3.rb'
2
-
3
- module Example3
4
- class Greeting
5
- def extend_greeting(name=nil)
6
- content.gsub(/\$\$\$/){ name }
7
- end
8
- end
9
- end
@@ -1,25 +0,0 @@
1
- class ProjectGenerator
2
-
3
- def print_options
4
- # return an array containing any (or none) of:
5
- # :schema -- a schema-like xml representation of the generated code
6
- # :graphml -- a graphml file describing the class model (compatible with yEd)
7
- # :yuml -- a yuml file that represents a simplified class model (compatible with yUML)
8
-
9
- [ :yuml ]
10
- end
11
-
12
- def resolve_namespaces
13
- # any array of arrays
14
- # each sub-array:
15
- # 0: a string or an array of strings, containing xml namespaces found
16
- # in the example xml files an empty string is the default namespace
17
- # 1: a ruby Module name (get the character cases right)
18
- # 2: a namespace prefix used when writing xml, optional. A generated
19
- # prefix will be used otherwise.
20
-
21
- [
22
- [ 'com.xampl.intro.example3', 'Example3', 'ex3']
23
- ]
24
- end
25
- end
@@ -1,6 +0,0 @@
1
- <greeter xmlns='com.xampl.intro.example3'>
2
- <greeting id='greeting name'>
3
- Hello $$$, how are you?
4
- </greeting>
5
- <who name='world'/>
6
- </greeter>
@@ -1,27 +0,0 @@
1
- require 'greeter'
2
- require 'greeting'
3
-
4
- ##include Example3 -- nope, not this time
5
-
6
- Xampl.transaction("example3") do
7
- greeter = Example3::Greeter.new
8
-
9
- greeting1 = Example3::Greeting.new('has-name')
10
- greeting1.content = "Hello $$$, how are you?"
11
- greeter << greeting1
12
-
13
- greeter.new_who.name = 'world'
14
- greeter.new_who.name = 'there'
15
-
16
- greeting2 = greeter.new_greeting('no-name')
17
- greeting2.content = "Hello hello? Someone there?"
18
-
19
- greeter.new_who
20
-
21
- puts greeter.to_xml
22
- puts greeter.pp_xml
23
-
24
- puts "\nAnd now extend our greetings..."
25
-
26
- greeter.extend_greetings
27
- end
@@ -1,19 +0,0 @@
1
- require 'greeter'
2
- require 'greeting'
3
-
4
- xml = <<EOX
5
- <ex3:greeter xmlns:ex3='com.xampl.intro.example3'>
6
- <ex3:greeting id='has-name'>Hello $$$, how are you?</ex3:greeting>
7
- <ex3:who name='world'/>
8
- <ex3:who name='there'/>
9
- <ex3:greeting id='no-name'>Hello hello? Someone there?</ex3:greeting>
10
- <ex3:who/></ex3:greeter>
11
- EOX
12
-
13
- Xampl.transaction("example3") do
14
- greeter = Xampl.from_xml_string(xml)
15
- puts greeter.pp_xml
16
-
17
- puts "\nAnd now extend our greetings..."
18
- greeter.extend_greetings
19
- end
@@ -1,10 +0,0 @@
1
-
2
- diagram = ""
3
- File.open("./generated.yuml") do | f |
4
- f.each do | line |
5
- diagram << line.chomp
6
- end
7
- end
8
- wget = "wget 'http://yuml.me/diagram/scruffy/class/#{diagram}' -O 'generated.png'"
9
- #wget = "wget 'http://yuml.me/diagram/scruffy/class/#{diagram}.pdf' -O 'generated.pdf'"
10
- `#{wget}`
@@ -1,15 +0,0 @@
1
- require 'xampl_generated_code/Example3.rb'
2
-
3
- module Example3
4
- class Greeter
5
- def extend_greetings
6
- who.each do | who |
7
- if who.name then
8
- puts greeting['has-name'].extend_greeting(who.name)
9
- else
10
- puts greeting['no-name'].extend_greeting
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,9 +0,0 @@
1
- require 'xampl_generated_code/Example3.rb'
2
-
3
- module Example3
4
- class Greeting
5
- def extend_greeting(name=nil)
6
- name ? content.gsub(/\$\$\$/){ name } : ''
7
- end
8
- end
9
- end
@@ -1,25 +0,0 @@
1
- class ProjectGenerator
2
-
3
- def print_options
4
- # return an array containing any (or none) of:
5
- # :schema -- a schema-like xml representation of the generated code
6
- # :graphml -- a graphml file describing the class model (compatible with yEd)
7
- # :yuml -- a yuml file that represents a simplified class model (compatible with yUML)
8
-
9
- [ :yuml ]
10
- end
11
-
12
- def resolve_namespaces
13
- # any array of arrays
14
- # each sub-array:
15
- # 0: a string or an array of strings, containing xml namespaces found
16
- # in the example xml files an empty string is the default namespace
17
- # 1: a ruby Module name (get the character cases right)
18
- # 2: a namespace prefix used when writing xml, optional. A generated
19
- # prefix will be used otherwise.
20
-
21
- [
22
- [ 'com.xampl.intro.example3', 'Example3', 'ex3']
23
- ]
24
- end
25
- end
@@ -1,6 +0,0 @@
1
- <greeter xmlns='com.xampl.intro.example3'>
2
- <greeting id='greeting name'>
3
- Hello $$$, how are you?
4
- </greeting>
5
- <who name='world'/>
6
- </greeter>
@@ -1,10 +0,0 @@
1
-
2
- diagram = ""
3
- File.open("./generated-elements.yuml") do | f |
4
- f.each do | line |
5
- diagram << line.chomp
6
- end
7
- end
8
- wget = "wget 'http://yuml.me/diagram/scruffy/class/#{diagram}' -O 'generated-elements.png'"
9
- #wget = "wget 'http://yuml.me/diagram/scruffy/class/#{diagram}.pdf' -O 'generated-elements.pdf'"
10
- `#{wget}`
@@ -1,51 +0,0 @@
1
- class ProjectGenerator
2
-
3
- # def directory
4
- # File.join(%w{ . xampl_generated_code })
5
- # end
6
- #
7
- # def filenames
8
- # Dir.glob("./xml/**/*.xml")
9
- # end
10
- #
11
- # def print_base_filename
12
- # File.join(%w{ . generated })
13
- # end
14
- #
15
- # def print_options
16
- # # return an array containing any (or none) of:
17
- # # :schema -- a schema-like xml representation of the generated code
18
- # # :graphml -- a graphml file describing the class model (compatible with yEd)
19
- # # :yuml -- a yuml file that represents a simplified class model (compatible with yUML)
20
- #
21
- # # [:schema, :graphml, :yuml]
22
- # []
23
- # end
24
- #
25
- # def persisted_attributes
26
- # %w{ pid }
27
- # end
28
- #
29
- # def indexed_attributes
30
- # %w{ id }
31
- # end
32
-
33
- def resolve_namespaces
34
- # any array of arrays
35
- # each sub-array:
36
- # 0: a string or an array of strings, containing xml namespaces found in the example xml files
37
- # an empty string is the default namespace
38
- # 1: a ruby Module name (get the character cases right)
39
- # 2: a namespace prefix used when writing xml, optional. A generated prefix will be used otherwise.
40
-
41
- #[]
42
-
43
- [
44
- [ '', 'Example1']
45
- ]
46
-
47
-
48
- end
49
-
50
- end
51
-
@@ -1,1494 +0,0 @@
1
- #LyX 1.6.4.1 created this file. For more info see http://www.lyx.org/
2
- \lyxformat 345
3
- \begin_document
4
- \begin_header
5
- \textclass book
6
- \begin_preamble
7
- \usepackage{color}
8
- \usepackage{alltt}
9
-
10
-
11
- \newcommand{\hlstd}[1]{\textcolor[rgb]{0,0,0}{#1}}
12
- \newcommand{\hlnum}[1]{\textcolor[rgb]{0.16,0.16,1}{#1}}
13
- \newcommand{\hlesc}[1]{\textcolor[rgb]{1,0,1}{#1}}
14
- \newcommand{\hlstr}[1]{\textcolor[rgb]{1,0,0}{#1}}
15
- \newcommand{\hldstr}[1]{\textcolor[rgb]{0.51,0.51,0}{#1}}
16
- \newcommand{\hlslc}[1]{\textcolor[rgb]{0.51,0.51,0.51}{\it{#1}}}
17
- \newcommand{\hlcom}[1]{\textcolor[rgb]{0.51,0.51,0.51}{\it{#1}}}
18
- \newcommand{\hldir}[1]{\textcolor[rgb]{0,0.51,0}{#1}}
19
- \newcommand{\hlsym}[1]{\textcolor[rgb]{0,0,0}{#1}}
20
- \newcommand{\hlline}[1]{\textcolor[rgb]{0.33,0.33,0.33}{#1}}
21
- \newcommand{\hlkwa}[1]{\textcolor[rgb]{0,0,0}{\bf{#1}}}
22
- \newcommand{\hlkwb}[1]{\textcolor[rgb]{0.51,0,0}{#1}}
23
- \newcommand{\hlkwc}[1]{\textcolor[rgb]{0,0,0}{\bf{#1}}}
24
- \newcommand{\hlkwd}[1]{\textcolor[rgb]{0,0,0.51}{#1}}
25
- \end_preamble
26
- \use_default_options true
27
- \language british
28
- \inputencoding auto
29
- \font_roman default
30
- \font_sans default
31
- \font_typewriter default
32
- \font_default_family default
33
- \font_sc false
34
- \font_osf false
35
- \font_sf_scale 100
36
- \font_tt_scale 100
37
-
38
- \graphics default
39
- \float_placement h
40
- \paperfontsize default
41
- \spacing single
42
- \use_hyperref true
43
- \pdf_bookmarks true
44
- \pdf_bookmarksnumbered false
45
- \pdf_bookmarksopen false
46
- \pdf_bookmarksopenlevel 1
47
- \pdf_breaklinks true
48
- \pdf_pdfborder true
49
- \pdf_colorlinks true
50
- \pdf_backref false
51
- \pdf_pdfusetitle true
52
- \papersize default
53
- \use_geometry false
54
- \use_amsmath 1
55
- \use_esint 1
56
- \cite_engine basic
57
- \use_bibtopic false
58
- \paperorientation portrait
59
- \secnumdepth 3
60
- \tocdepth 3
61
- \paragraph_separation skip
62
- \defskip medskip
63
- \quotes_language english
64
- \papercolumns 1
65
- \papersides 1
66
- \paperpagestyle default
67
- \tracking_changes false
68
- \output_changes false
69
- \author ""
70
- \author ""
71
- \end_header
72
-
73
- \begin_body
74
-
75
- \begin_layout Title
76
- Xampl
77
- \end_layout
78
-
79
- \begin_layout Author
80
- Bob Hutchison
81
- \end_layout
82
-
83
- \begin_layout Standard
84
- \begin_inset CommandInset toc
85
- LatexCommand tableofcontents
86
-
87
- \end_inset
88
-
89
-
90
- \end_layout
91
-
92
- \begin_layout Part
93
- Introduction
94
- \end_layout
95
-
96
- \begin_layout Chapter
97
- Installing Xampl
98
- \end_layout
99
-
100
- \begin_layout Part
101
- Xampl by Example
102
- \end_layout
103
-
104
- \begin_layout Chapter
105
- A Little Background
106
- \end_layout
107
-
108
- \begin_layout Standard
109
- Over the last ten or eleven years I've taught a bunch of programmers how
110
- to use xampl.
111
- It normally takes about 45 minutes to get them going… and then an extended
112
- period of intermittent answering questions and making suggestions.
113
- To do this I took advantage of the shared context of a project we both
114
- were working on.
115
- \end_layout
116
-
117
- \begin_layout Standard
118
- Xampl has never been documented, though several attempts have been made.
119
- This time I'm serious.
120
- \end_layout
121
-
122
- \begin_layout Standard
123
- I think teaching technique won't translate very well to print and example
124
- code.
125
- I suppose I could try simulate this and choose some well understood domain,
126
- like weblogs, and work that through\SpecialChar \ldots{}
127
- and hope that'd work.
128
- It might if I was sitting beside you, but I'm not.
129
- And I have to do something, so I'm going to take a bunch of passes at writing
130
- a progressively more complex 'Hello World' program.
131
- A bit of a stretch, but\SpecialChar \ldots{}
132
-
133
- \end_layout
134
-
135
- \begin_layout Chapter
136
- Hello World
137
- \end_layout
138
-
139
- \begin_layout Section
140
- Hello World, Take One
141
- \end_layout
142
-
143
- \begin_layout Subsection
144
- The Experiment
145
- \end_layout
146
-
147
- \begin_layout Standard
148
- Let's see if we can get a start with xampl by using it to print hello-world
149
- on the screen.
150
- Then I'll explain what happened.
151
- \end_layout
152
-
153
- \begin_layout Standard
154
- \noindent
155
- You'll need to create a directory somewhere in which to place the files
156
- associated with this project.
157
- I'll be defining path names using
158
- \family typewriter
159
- .
160
-
161
- \family default
162
- to mean this directory, so you might want to open a terminal and change
163
- directories to it.
164
- The source for this example is distributed in the xampl gem and is located
165
- at
166
- \family typewriter
167
- <path to the xampl gem>/docs/intro/example1
168
- \family default
169
- which will likely be read-only and so should be copied someplace else
170
- \begin_inset Foot
171
- status open
172
-
173
- \begin_layout Plain Layout
174
- If you are lazy, which is possibly one of the very good reasons you are
175
- interested in xampl, then you can simply untar the file
176
- \family typewriter
177
- <path to the xampl gem>/docs/intro/examples.tgz
178
- \family default
179
- (or unzip
180
- \family typewriter
181
- <path to the xampl gem>/docs/intro/examples.zip
182
- \family default
183
- ) to someplace convenient.
184
- \end_layout
185
-
186
- \end_inset
187
-
188
- .
189
- \end_layout
190
-
191
- \begin_layout Standard
192
- Xampl works by inspecting a collection of XML files and deriving a class
193
- model from what it finds.
194
- We'll only need one XML file right now:
195
- \end_layout
196
-
197
- \begin_layout Standard
198
- \begin_inset Float figure
199
- wide false
200
- sideways false
201
- status collapsed
202
-
203
- \begin_layout Plain Layout
204
- \begin_inset External
205
- template XMLCode
206
- filename example1/xml/hello.xml
207
-
208
- \end_inset
209
-
210
-
211
- \end_layout
212
-
213
- \begin_layout Plain Layout
214
- \begin_inset Caption
215
-
216
- \begin_layout Plain Layout
217
- ./xml/hello.xml
218
- \end_layout
219
-
220
- \end_inset
221
-
222
-
223
- \end_layout
224
-
225
- \begin_layout Plain Layout
226
-
227
- \end_layout
228
-
229
- \end_inset
230
-
231
-
232
- \end_layout
233
-
234
- \begin_layout Standard
235
- To make this happen and generate the xampl code, run
236
- \begin_inset Marginal
237
- status collapsed
238
-
239
- \begin_layout Plain Layout
240
- Are you in the right directory?
241
- \end_layout
242
-
243
- \end_inset
244
-
245
- :
246
- \end_layout
247
-
248
- \begin_layout Standard
249
- \begin_inset listings
250
- lstparams "numbers=left"
251
- inline false
252
- status open
253
-
254
- \begin_layout Plain Layout
255
-
256
- [working] >> xampl-gen
257
- \end_layout
258
-
259
- \begin_layout Plain Layout
260
-
261
- comprehend file ./xml/hello.xml
262
- \end_layout
263
-
264
- \begin_layout Plain Layout
265
-
266
- WRITE TO FILE: ./xampl_generated_code/XamplAdHoc.rb
267
- \end_layout
268
-
269
- \end_inset
270
-
271
-
272
- \end_layout
273
-
274
- \begin_layout Standard
275
- That's how I'll show a command line session―a mix of commands (with the
276
-
277
- \family typewriter
278
- [working] >> prefix
279
- \family default
280
- like line 1) and the rest output.
281
- \end_layout
282
-
283
- \begin_layout Standard
284
-
285
- \family typewriter
286
- Xampl-gen
287
- \family default
288
- will print a line like line 2 for every xml file it finds, meaning that
289
- xampl is have a look at it and analysing it.
290
- By default
291
- \family typewriter
292
- xampl-gen
293
- \family default
294
- will analyse all files that match the pattern
295
- \family typewriter
296
- ./xml/**/*.xml
297
- \begin_inset Foot
298
- status open
299
-
300
- \begin_layout Plain Layout
301
- all files in ./xml and and all sub-directories for files with the extension
302
-
303
- \family typewriter
304
- .xml
305
- \end_layout
306
-
307
- \end_inset
308
-
309
-
310
- \family default
311
- .
312
- The xml files
313
- \emph on
314
- must
315
- \emph default
316
- be well-formed and xampl-gen will choke if they are not.
317
- \end_layout
318
-
319
- \begin_layout Standard
320
- Xampl-gen will write something like line 3 for each file it generates.
321
- In this example there is only one, and it is called XamplAdHoc.
322
- This is xampl-gen's default output file, and we haven't told it anything
323
- better, so try to suppress your gag-reflex until I show you how to deal
324
- with this.
325
- But, maybe to calm you down a bit, it is considered
326
- \emph on
327
- very
328
- \emph default
329
- bad form to allow xampl to generate code into this file for production
330
- use.
331
- \end_layout
332
-
333
- \begin_layout Standard
334
- For the moment, lets just ignore what's in the XamplAdHoc.rb file.
335
- It's a little frightening.
336
- \end_layout
337
-
338
- \begin_layout Standard
339
- To do something with this, let's run this short little ruby program:
340
- \end_layout
341
-
342
- \begin_layout Standard
343
- \begin_inset Float figure
344
- wide false
345
- sideways false
346
- status collapsed
347
-
348
- \begin_layout Plain Layout
349
- \begin_inset External
350
- template RubyCode
351
- filename example1/example1.rb
352
-
353
- \end_inset
354
-
355
-
356
- \end_layout
357
-
358
- \begin_layout Plain Layout
359
- \begin_inset Caption
360
-
361
- \begin_layout Plain Layout
362
- ./example1.rb
363
- \end_layout
364
-
365
- \end_inset
366
-
367
-
368
- \end_layout
369
-
370
- \begin_layout Plain Layout
371
-
372
- \end_layout
373
-
374
- \end_inset
375
-
376
-
377
- \end_layout
378
-
379
- \begin_layout Standard
380
- And this is what we get when we run it:
381
- \end_layout
382
-
383
- \begin_layout Standard
384
- \begin_inset listings
385
- lstparams "numbers=left,tabsize=2"
386
- inline false
387
- status open
388
-
389
- \begin_layout Plain Layout
390
-
391
- [working] >> ruby example1.rb
392
- \end_layout
393
-
394
- \begin_layout Plain Layout
395
-
396
- <hello-world/>
397
- \end_layout
398
-
399
- \end_inset
400
-
401
-
402
- \end_layout
403
-
404
- \begin_layout Standard
405
- And by golly! I see a hello world right there on line 2.
406
- \end_layout
407
-
408
- \begin_layout Standard
409
- How'd that happen? The file we just generated was included on line 1.
410
- In line 3 we start a transaction, called example1.
411
- These transactions are necessary, but in this example doesn't buy us a
412
- lot, it is mostly just overhead
413
- \begin_inset Foot
414
- status collapsed
415
-
416
- \begin_layout Plain Layout
417
- Yes, I know\SpecialChar \ldots{}
418
- for such a simple program this seems like gross overkill.
419
- It is I suppose, but it isn't often that xampl is used on simple programs
420
- like this.
421
- \end_layout
422
-
423
- \end_inset
424
-
425
- .
426
- For now just remember that when you create or change a xampl object you
427
- have to be in a transaction or a Xampl::UnmanagedChange exception will
428
- be raised and that involves a rollback.
429
- I'll be covering transactions in pretty thorough detail, and there is a
430
- prolonged discussion in chapter
431
- \begin_inset CommandInset ref
432
- LatexCommand vref
433
- reference "sec:Transactions"
434
-
435
- \end_inset
436
-
437
- .
438
- Line 4 creates a new instance of the class
439
- \family typewriter
440
- HelloWorld
441
- \family default
442
- .
443
- Line 5 calls the
444
- \family typewriter
445
- to_xml
446
- \family default
447
- method and prints the result.
448
- \end_layout
449
-
450
- \begin_layout Standard
451
- HelloWorld is a class generated by xampl.
452
- The name is derived from the XML element name using rules described in
453
-
454
- \begin_inset CommandInset ref
455
- LatexCommand vref
456
- reference "sec:Name-Generation"
457
-
458
- \end_inset
459
-
460
- .
461
- \end_layout
462
-
463
- \begin_layout Subsection
464
- What Did xampl Do?
465
- \end_layout
466
-
467
- \begin_layout Standard
468
- You can look in the generated code yourself and you'll find that one class
469
- and one module were generated and a surprising 150 or more lines of code.
470
- The class has 20 methods, and the module has 7.
471
- The module and none of the methods are interesting to us right now, all
472
- of them will be soon.
473
- And all for this near-trivial example.
474
- \end_layout
475
-
476
- \begin_layout Standard
477
- The class is called
478
- \family typewriter
479
- HelloWorld
480
- \family default
481
- .
482
- It mixes in two modules:
483
- \family typewriter
484
- Xampl::XamplObject
485
- \family default
486
- , and
487
- \family typewriter
488
- Xampl::XamplWithoutContent
489
- \family default
490
- , and inherits nothing.
491
- The mixin
492
- \family typewriter
493
- Xampl::XamplObject
494
- \family default
495
- means that his is a xampl object, and it carries a bunch of methods, including
496
- the
497
- \family typewriter
498
- to_xml
499
- \family default
500
- method used in the example.
501
- The mixin
502
- \family typewriter
503
- Xampl::XamplWithoutContent
504
- \family default
505
- means that
506
- \family typewriter
507
- HelloWorld
508
- \family default
509
- has no content and no references to any other xampl managed objects (like
510
- an empty XML element).
511
- \end_layout
512
-
513
- \begin_layout Subsection
514
- Summary
515
- \end_layout
516
-
517
- \begin_layout Itemize
518
- basic structure of a xampl project on disk
519
- \end_layout
520
-
521
- \begin_layout Itemize
522
- basic usage of the xampl-gen program
523
- \end_layout
524
-
525
- \begin_layout Itemize
526
- a simple example of using the generated code
527
- \end_layout
528
-
529
- \begin_layout Itemize
530
- xampl has some kind of way of dealing with name incompatibilities between
531
- XML and Ruby
532
- \end_layout
533
-
534
- \begin_layout Itemize
535
- xampl creates a Ruby class for each XML elements discovered
536
- \end_layout
537
-
538
- \begin_layout Section
539
- Hello hello?!
540
- \end_layout
541
-
542
- \begin_layout Subsection
543
- The Experiment
544
- \end_layout
545
-
546
- \begin_layout Standard
547
- Carrying on from the previous experiment\SpecialChar \ldots{}
548
- That was nice but it could only
549
- say hello to the world, and then only if we squinted.
550
- What if we wanted to say hello to more than just the world? What if we
551
- wanted to have objects that behaved differently? What if we wanted to say
552
- it nicer? What if we wanted to get rid of that horribly ugly XamplAdHoc.rb
553
- file and actually put the generated code in modules?
554
- \end_layout
555
-
556
- \begin_layout Standard
557
- \noindent
558
- \align left
559
- The code for this experiment is in the directory:
560
- \family typewriter
561
- <path to the xampl gem>/docs/intro/example2
562
- \end_layout
563
-
564
- \begin_layout Standard
565
- Okay, so lets look at this xml file, Figure
566
- \begin_inset CommandInset ref
567
- LatexCommand ref
568
- reference "fig:./xml/example2.xml"
569
-
570
- \end_inset
571
-
572
- ,
573
- \end_layout
574
-
575
- \begin_layout Standard
576
- \begin_inset Float figure
577
- wide false
578
- sideways false
579
- status open
580
-
581
- \begin_layout Plain Layout
582
- \begin_inset External
583
- template XMLCode
584
- filename example2/xml/hello.xml
585
-
586
- \end_inset
587
-
588
-
589
- \end_layout
590
-
591
- \begin_layout Plain Layout
592
- \begin_inset Caption
593
-
594
- \begin_layout Plain Layout
595
- ./xml/example2.xml
596
- \begin_inset CommandInset label
597
- LatexCommand label
598
- name "fig:./xml/example2.xml"
599
-
600
- \end_inset
601
-
602
-
603
- \end_layout
604
-
605
- \end_inset
606
-
607
-
608
- \end_layout
609
-
610
- \end_inset
611
-
612
-
613
- \end_layout
614
-
615
- \begin_layout Standard
616
- There are two important differences between this xml file and the one for
617
- the first example:
618
- \end_layout
619
-
620
- \begin_layout Itemize
621
- there is an attribute, who, associated with the element hello (no more hello-wor
622
- ld).
623
- The value of the attribute is just for example, it does not find its way
624
- into the generated code, it could have been anything including ''.
625
- \end_layout
626
-
627
- \begin_layout Itemize
628
- There is a namespace defined, in this case com.xampl.intro.example2
629
- \end_layout
630
-
631
- \begin_layout Standard
632
- As soon as we have a namespace defined, then we can map them to Ruby modules.
633
- This is done in a ruby file called
634
- \family typewriter
635
- project-generator.rb
636
- \family default
637
- .
638
- It is always called that and is located in the directory from where the
639
-
640
- \family typewriter
641
- xampl-gen
642
- \family default
643
- command is run.
644
- This is what it looks like Figure
645
- \begin_inset CommandInset ref
646
- LatexCommand vref
647
- reference "fig:./project-generator.rb"
648
-
649
- \end_inset
650
-
651
- .
652
- This file is loaded by the xampl-gen command if it exists.
653
- It re-opens
654
- \begin_inset Foot
655
- status collapsed
656
-
657
- \begin_layout Plain Layout
658
- xampl re-opens classes routinely and profits greatly by the technique.
659
- There's a term,
660
- \emph on
661
- monkey-patching,
662
- \emph default
663
- applied to this technique that is intended to be derogatory, but it isn't
664
- taken that way in the Ruby community.
665
- \end_layout
666
-
667
- \end_inset
668
-
669
- the class
670
- \family typewriter
671
- ProjectGenerator
672
- \family default
673
- (line 1) and re-defines the method
674
- \family typewriter
675
- resolve-namespaces
676
- \family default
677
- (line 3).
678
- An array of arrays is expected.
679
- What line 15 is doing is saying that the namespace com.xampl.intro.example2
680
- should be mapped to the Ruby module
681
- \family typewriter
682
- Example2
683
- \family default
684
- , and when writing XML xampl should prefer the prefix ex2 to identify the
685
- namespace.
686
- \end_layout
687
-
688
- \begin_layout Standard
689
- \begin_inset Float figure
690
- wide false
691
- sideways false
692
- status open
693
-
694
- \begin_layout Plain Layout
695
- \begin_inset External
696
- template RubyCode
697
- filename example2/project-generator.rb
698
-
699
- \end_inset
700
-
701
-
702
- \end_layout
703
-
704
- \begin_layout Plain Layout
705
- \begin_inset Caption
706
-
707
- \begin_layout Plain Layout
708
- ./project-generator.rb
709
- \begin_inset CommandInset label
710
- LatexCommand label
711
- name "fig:./project-generator.rb"
712
-
713
- \end_inset
714
-
715
-
716
- \end_layout
717
-
718
- \end_inset
719
-
720
-
721
- \end_layout
722
-
723
- \begin_layout Plain Layout
724
-
725
- \end_layout
726
-
727
- \end_inset
728
-
729
-
730
- \end_layout
731
-
732
- \begin_layout Standard
733
- So run xampl-gen and you should see something like:
734
- \end_layout
735
-
736
- \begin_layout Standard
737
- \begin_inset listings
738
- inline false
739
- status open
740
-
741
- \begin_layout Plain Layout
742
-
743
- [working] >> xampl-gen
744
- \end_layout
745
-
746
- \begin_layout Plain Layout
747
-
748
- comprehend file ./xml/hello.xml
749
- \end_layout
750
-
751
- \begin_layout Plain Layout
752
-
753
- WRITE TO FILE: ./xampl_generated_code/Example2.rb
754
- \end_layout
755
-
756
- \end_inset
757
-
758
-
759
- \end_layout
760
-
761
- \begin_layout Standard
762
- You'll note that the XamplAdHoc.rb file is gone, replaced by Exampl2.rb.
763
- Xampl will place all code generated for a module into a single file named
764
- after the module.
765
- If you open up the generated Ruby file you'll see that the code is now
766
- inside the module Example2.
767
- \end_layout
768
-
769
- \begin_layout Standard
770
- So, lets do something with this.
771
- Have a look at this Figure
772
- \begin_inset CommandInset ref
773
- LatexCommand vref
774
- reference "fig:./example2.rb"
775
-
776
- \end_inset
777
-
778
- and its output.
779
- \end_layout
780
-
781
- \begin_layout Standard
782
- \begin_inset Float figure
783
- wide false
784
- sideways false
785
- status open
786
-
787
- \begin_layout Plain Layout
788
- \begin_inset External
789
- template RubyCode
790
- filename /Users/hutch/GIT-public/xamplr/docs/intro/example2/example2.rb
791
-
792
- \end_inset
793
-
794
-
795
- \end_layout
796
-
797
- \begin_layout Plain Layout
798
- \begin_inset Caption
799
-
800
- \begin_layout Plain Layout
801
- ./example2.rb
802
- \begin_inset CommandInset label
803
- LatexCommand label
804
- name "fig:./example2.rb"
805
-
806
- \end_inset
807
-
808
-
809
- \end_layout
810
-
811
- \end_inset
812
-
813
-
814
- \end_layout
815
-
816
- \end_inset
817
-
818
-
819
- \end_layout
820
-
821
- \begin_layout Standard
822
- \begin_inset listings
823
- lstparams "float,language=bash,numbers=left"
824
- inline false
825
- status open
826
-
827
- \begin_layout Plain Layout
828
-
829
- [working] >> ruby example2.rb
830
- \end_layout
831
-
832
- \begin_layout Plain Layout
833
-
834
- haven't set the who attribute yet...
835
- \end_layout
836
-
837
- \begin_layout Plain Layout
838
-
839
- <ex2:hello xmlns:ex2="com.xampl.intro.example2"/>
840
- \end_layout
841
-
842
- \begin_layout Plain Layout
843
-
844
- Hello hello?!
845
- \end_layout
846
-
847
- \begin_layout Plain Layout
848
-
849
- \end_layout
850
-
851
- \begin_layout Plain Layout
852
-
853
- have set the who attribute to 'world'...
854
-
855
- \end_layout
856
-
857
- \begin_layout Plain Layout
858
-
859
- <ex2:hello who="world" xmlns:ex2="com.xampl.intro.example2"/>
860
- \end_layout
861
-
862
- \begin_layout Plain Layout
863
-
864
- \end_layout
865
-
866
- \begin_layout Plain Layout
867
-
868
- <ex2:hello who='world'
869
- \end_layout
870
-
871
- \begin_layout Plain Layout
872
-
873
- xmlns:ex2='com.xampl.intro.example2'/>
874
- \end_layout
875
-
876
- \begin_layout Plain Layout
877
-
878
- Hello world!
879
- \end_layout
880
-
881
- \begin_layout Plain Layout
882
-
883
- \end_layout
884
-
885
- \begin_layout Plain Layout
886
-
887
- there are two Hello things now...
888
-
889
- \end_layout
890
-
891
- \begin_layout Plain Layout
892
-
893
- Hello world!
894
- \end_layout
895
-
896
- \begin_layout Plain Layout
897
-
898
- Hello there!
899
- \end_layout
900
-
901
- \begin_layout Plain Layout
902
-
903
- \end_layout
904
-
905
- \begin_layout Plain Layout
906
-
907
- print an array of the two Hello things...
908
-
909
- \end_layout
910
-
911
- \begin_layout Plain Layout
912
-
913
- Hello world!
914
- \end_layout
915
-
916
- \begin_layout Plain Layout
917
-
918
- Hello there!
919
- \end_layout
920
-
921
- \begin_layout Plain Layout
922
-
923
- \end_layout
924
-
925
- \begin_layout Plain Layout
926
-
927
- inspect an array of the two Hello things...
928
-
929
- \end_layout
930
-
931
- \begin_layout Plain Layout
932
-
933
- [ <ex2:hello who='world'
934
- \end_layout
935
-
936
- \begin_layout Plain Layout
937
-
938
- xmlns:ex2='com.xampl.intro.example2'/>,
939
- \end_layout
940
-
941
- \begin_layout Plain Layout
942
-
943
- <ex2:hello who='there'
944
- \end_layout
945
-
946
- \begin_layout Plain Layout
947
-
948
- xmlns:ex2='com.xampl.intro.example2'/>]
949
- \end_layout
950
-
951
- \end_inset
952
-
953
-
954
- \end_layout
955
-
956
- \begin_layout Standard
957
- So what's happening here? Line 1 requires the generated Ruby code, line
958
- 3 includes the module
959
- \family typewriter
960
- Example2
961
- \family default
962
- so we don't have to keep specifying the module name.
963
- Line 5 re-opens the class
964
- \family typewriter
965
- Hello
966
- \family default
967
- and defines a
968
- \family typewriter
969
- to_s
970
- \family default
971
- method.
972
- Line 11 starts one of those transactions again.
973
- \end_layout
974
-
975
- \begin_layout Standard
976
- Line 12 creates a new instance of
977
- \family typewriter
978
- Hello
979
- \family default
980
- ,
981
- \family typewriter
982
- h
983
- \family default
984
- , and prints it's XML and string representation on lines 15-16 (see lines
985
- 3-4 of the output listing).
986
- Line 18 sets the value of
987
- \family typewriter
988
- h
989
- \family default
990
- 's who attribute to '
991
- \family typewriter
992
- world
993
- \family default
994
- ' then prints some stuff resulting in output lines 6-11.
995
- \end_layout
996
-
997
- \begin_layout Standard
998
- Line 25-28 creates another, different, instance of
999
- \family typewriter
1000
- Hello
1001
- \family default
1002
- ,
1003
- \family typewriter
1004
- h2
1005
- \family default
1006
- , and an array,
1007
- \family typewriter
1008
- all
1009
- \family default
1010
- , that contains
1011
- \family typewriter
1012
- h
1013
- \family default
1014
- and
1015
- \family typewriter
1016
- h2
1017
- \family default
1018
- .
1019
- Lines 30-37 generate the output lines 17-25.
1020
- \end_layout
1021
-
1022
- \begin_layout Standard
1023
- There's a new method being used called
1024
- \family typewriter
1025
- pp_xml
1026
- \family default
1027
- .
1028
- It is similar to
1029
- \family typewriter
1030
- to_xml
1031
- \family default
1032
- in that it prints XML, but it does in a prettier way
1033
- \begin_inset Foot
1034
- status collapsed
1035
-
1036
- \begin_layout Plain Layout
1037
- the 'pp' in
1038
- \family typewriter
1039
- pp_xml
1040
- \family default
1041
- stands for pretty-print.
1042
- \end_layout
1043
-
1044
- \end_inset
1045
-
1046
- .
1047
- There is another significant difference that we'll get to when we talk
1048
- about persistence.
1049
- \end_layout
1050
-
1051
- \begin_layout Subsection
1052
- What Did xampl do?
1053
- \end_layout
1054
-
1055
- \begin_layout Standard
1056
- Pretty much the same thing as the first experiment.
1057
- Except that the file is named after a module, and the generated code is
1058
- in that module.
1059
- There is also code to support an attribute.
1060
- \end_layout
1061
-
1062
- \begin_layout Subsection
1063
- Summary
1064
- \end_layout
1065
-
1066
- \begin_layout Itemize
1067
- how to map XML namespaces to Ruby modules
1068
- \end_layout
1069
-
1070
- \begin_layout Itemize
1071
- how an XML attribute maps to a Ruby instance variable
1072
- \end_layout
1073
-
1074
- \begin_layout Itemize
1075
- that there can be more than one instance of xampl objects created
1076
- \end_layout
1077
-
1078
- \begin_layout Itemize
1079
- the values taken by instance variables are in no way constrained to the
1080
- values found in the XML files the code was generated from
1081
- \begin_inset Foot
1082
- status collapsed
1083
-
1084
- \begin_layout Plain Layout
1085
- This has proved to be incredibly difficult for some programmers to grasp.
1086
- The xml files used to generate xampl objects are
1087
- \family typewriter
1088
- \emph on
1089
- not
1090
- \family default
1091
- \emph default
1092
- schemas, they are examples.
1093
- \end_layout
1094
-
1095
- \end_inset
1096
-
1097
-
1098
- \end_layout
1099
-
1100
- \begin_layout Itemize
1101
- there is a xampl build-in method,
1102
- \family typewriter
1103
- pp_xml
1104
- \family default
1105
- , that prints xml from a xampl object in a prettier way than that of
1106
- \family typewriter
1107
- to_xml
1108
- \end_layout
1109
-
1110
- \begin_layout Section
1111
- The Greeter
1112
- \end_layout
1113
-
1114
- \begin_layout Subsection
1115
- The Experiment
1116
- \end_layout
1117
-
1118
- \begin_layout Standard
1119
- xml goes here
1120
- \begin_inset CommandInset ref
1121
- LatexCommand ref
1122
- reference "fig:./xml/greeter.xml"
1123
-
1124
- \end_inset
1125
-
1126
- , blah
1127
- \end_layout
1128
-
1129
- \begin_layout Standard
1130
- \begin_inset Float figure
1131
- wide false
1132
- sideways false
1133
- status open
1134
-
1135
- \begin_layout Plain Layout
1136
- \begin_inset External
1137
- template XMLCode
1138
- filename example3/xml/greeter.xml
1139
-
1140
- \end_inset
1141
-
1142
-
1143
- \end_layout
1144
-
1145
- \begin_layout Plain Layout
1146
- \begin_inset Caption
1147
-
1148
- \begin_layout Plain Layout
1149
- ./xml/greeter.xml
1150
- \begin_inset CommandInset label
1151
- LatexCommand label
1152
- name "fig:./xml/greeter.xml"
1153
-
1154
- \end_inset
1155
-
1156
-
1157
- \end_layout
1158
-
1159
- \end_inset
1160
-
1161
-
1162
- \end_layout
1163
-
1164
- \begin_layout Plain Layout
1165
-
1166
- \end_layout
1167
-
1168
- \end_inset
1169
-
1170
-
1171
- \end_layout
1172
-
1173
- \begin_layout Standard
1174
- object diagram
1175
- \begin_inset CommandInset ref
1176
- LatexCommand ref
1177
- reference "fig:./generated3.yuml"
1178
-
1179
- \end_inset
1180
-
1181
- , blah
1182
- \end_layout
1183
-
1184
- \begin_layout Standard
1185
- \begin_inset Float figure
1186
- wide false
1187
- sideways false
1188
- status open
1189
-
1190
- \begin_layout Plain Layout
1191
- \begin_inset Graphics
1192
- filename example3/generated.png
1193
-
1194
- \end_inset
1195
-
1196
-
1197
- \end_layout
1198
-
1199
- \begin_layout Plain Layout
1200
- \begin_inset Caption
1201
-
1202
- \begin_layout Plain Layout
1203
- ./generated.yuml
1204
- \begin_inset CommandInset label
1205
- LatexCommand label
1206
- name "fig:./generated3.yuml"
1207
-
1208
- \end_inset
1209
-
1210
-
1211
- \end_layout
1212
-
1213
- \end_inset
1214
-
1215
-
1216
- \end_layout
1217
-
1218
- \begin_layout Plain Layout
1219
-
1220
- \end_layout
1221
-
1222
- \end_inset
1223
-
1224
-
1225
- \end_layout
1226
-
1227
- \begin_layout Standard
1228
- greeter
1229
- \begin_inset CommandInset ref
1230
- LatexCommand ref
1231
- reference "fig:./greeter3.rb"
1232
-
1233
- \end_inset
1234
-
1235
- , blah
1236
- \end_layout
1237
-
1238
- \begin_layout Standard
1239
- \begin_inset Float figure
1240
- wide false
1241
- sideways false
1242
- status open
1243
-
1244
- \begin_layout Plain Layout
1245
- \begin_inset External
1246
- template RubyCode
1247
- filename example3/greeter.rb
1248
-
1249
- \end_inset
1250
-
1251
-
1252
- \end_layout
1253
-
1254
- \begin_layout Plain Layout
1255
- \begin_inset Caption
1256
-
1257
- \begin_layout Plain Layout
1258
- ./greeter.rb
1259
- \begin_inset CommandInset label
1260
- LatexCommand label
1261
- name "fig:./greeter3.rb"
1262
-
1263
- \end_inset
1264
-
1265
-
1266
- \end_layout
1267
-
1268
- \end_inset
1269
-
1270
-
1271
- \end_layout
1272
-
1273
- \begin_layout Plain Layout
1274
-
1275
- \end_layout
1276
-
1277
- \end_inset
1278
-
1279
-
1280
- \end_layout
1281
-
1282
- \begin_layout Standard
1283
- greeting
1284
- \begin_inset CommandInset ref
1285
- LatexCommand ref
1286
- reference "fig:./greeting3.rb"
1287
-
1288
- \end_inset
1289
-
1290
- , blah
1291
- \end_layout
1292
-
1293
- \begin_layout Standard
1294
- \begin_inset Float figure
1295
- wide false
1296
- sideways false
1297
- status open
1298
-
1299
- \begin_layout Plain Layout
1300
- \begin_inset External
1301
- template RubyCode
1302
- filename example3/greeting.rb
1303
-
1304
- \end_inset
1305
-
1306
-
1307
- \end_layout
1308
-
1309
- \begin_layout Plain Layout
1310
- \begin_inset Caption
1311
-
1312
- \begin_layout Plain Layout
1313
- ./greeting.rb
1314
- \begin_inset CommandInset label
1315
- LatexCommand label
1316
- name "fig:./greeting3.rb"
1317
-
1318
- \end_inset
1319
-
1320
-
1321
- \end_layout
1322
-
1323
- \end_inset
1324
-
1325
-
1326
- \end_layout
1327
-
1328
- \begin_layout Plain Layout
1329
-
1330
- \end_layout
1331
-
1332
- \end_inset
1333
-
1334
-
1335
- \end_layout
1336
-
1337
- \begin_layout Standard
1338
- example3
1339
- \begin_inset CommandInset ref
1340
- LatexCommand ref
1341
- reference "fig:./example3.rb"
1342
-
1343
- \end_inset
1344
-
1345
- , blah
1346
- \end_layout
1347
-
1348
- \begin_layout Standard
1349
- \begin_inset Float figure
1350
- wide false
1351
- sideways false
1352
- status open
1353
-
1354
- \begin_layout Plain Layout
1355
- \begin_inset External
1356
- template RubyCode
1357
- filename example3/example3.rb
1358
-
1359
- \end_inset
1360
-
1361
-
1362
- \end_layout
1363
-
1364
- \begin_layout Plain Layout
1365
- \begin_inset Caption
1366
-
1367
- \begin_layout Plain Layout
1368
- ./example3.rb
1369
- \begin_inset CommandInset label
1370
- LatexCommand label
1371
- name "fig:./example3.rb"
1372
-
1373
- \end_inset
1374
-
1375
-
1376
- \end_layout
1377
-
1378
- \end_inset
1379
-
1380
-
1381
- \end_layout
1382
-
1383
- \begin_layout Plain Layout
1384
-
1385
- \end_layout
1386
-
1387
- \end_inset
1388
-
1389
-
1390
- \end_layout
1391
-
1392
- \begin_layout Standard
1393
- example3a
1394
- \begin_inset CommandInset ref
1395
- LatexCommand ref
1396
- reference "fig:./example3a.rb"
1397
-
1398
- \end_inset
1399
-
1400
- , blah
1401
- \end_layout
1402
-
1403
- \begin_layout Standard
1404
- \begin_inset Float figure
1405
- wide false
1406
- sideways false
1407
- status collapsed
1408
-
1409
- \begin_layout Plain Layout
1410
- \begin_inset External
1411
- template RubyCode
1412
- filename example3/example3a.rb
1413
-
1414
- \end_inset
1415
-
1416
-
1417
- \end_layout
1418
-
1419
- \begin_layout Plain Layout
1420
- \begin_inset Caption
1421
-
1422
- \begin_layout Plain Layout
1423
- ./example3a.rb
1424
- \begin_inset CommandInset label
1425
- LatexCommand label
1426
- name "fig:./example3a.rb"
1427
-
1428
- \end_inset
1429
-
1430
-
1431
- \end_layout
1432
-
1433
- \end_inset
1434
-
1435
-
1436
- \end_layout
1437
-
1438
- \begin_layout Plain Layout
1439
-
1440
- \end_layout
1441
-
1442
- \end_inset
1443
-
1444
-
1445
- \end_layout
1446
-
1447
- \begin_layout Standard
1448
- blather blather
1449
- \end_layout
1450
-
1451
- \begin_layout Part
1452
- Programming Manual
1453
- \end_layout
1454
-
1455
- \begin_layout Chapter
1456
- Code Generation
1457
- \end_layout
1458
-
1459
- \begin_layout Section
1460
- Name Generation
1461
- \begin_inset CommandInset label
1462
- LatexCommand label
1463
- name "sec:Name-Generation"
1464
-
1465
- \end_inset
1466
-
1467
-
1468
- \end_layout
1469
-
1470
- \begin_layout Chapter
1471
- Persistence
1472
- \end_layout
1473
-
1474
- \begin_layout Section
1475
- Transactions
1476
- \begin_inset CommandInset label
1477
- LatexCommand label
1478
- name "sec:Transactions"
1479
-
1480
- \end_inset
1481
-
1482
-
1483
- \end_layout
1484
-
1485
- \begin_layout Section
1486
- Repositories
1487
- \end_layout
1488
-
1489
- \begin_layout Section
1490
- Persistence Managers
1491
- \end_layout
1492
-
1493
- \end_body
1494
- \end_document