xamplr-gen 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.
- data/.document +5 -0
- data/.gitignore +22 -0
- data/COPYING +619 -0
- data/LICENSE +4 -0
- data/Makefile +11 -0
- data/README.md +33 -0
- data/Rakefile +66 -0
- data/VERSION +1 -0
- data/bin/xampl-gen +17 -0
- data/features/step_definitions/xamplr-gen_steps.rb +0 -0
- data/features/support/env.rb +6 -0
- data/features/xamplr-gen.feature +9 -0
- data/lib/xamplr-gen.rb +13 -0
- data/lib/xamplr-gen/.cvsignore +1 -0
- data/lib/xamplr-gen/graphml-out.rb +449 -0
- data/lib/xamplr-gen/my.gen.elements.xml +461 -0
- data/lib/xamplr-gen/simpleTemplate/danger.rx +4 -0
- data/lib/xamplr-gen/simpleTemplate/obsolete/input-c.r4 +35 -0
- data/lib/xamplr-gen/simpleTemplate/obsolete/play.r6.txt +12 -0
- data/lib/xamplr-gen/simpleTemplate/obsolete/play_more.r6.txt +20 -0
- data/lib/xamplr-gen/simpleTemplate/obsolete/test001.r5 +8 -0
- data/lib/xamplr-gen/simpleTemplate/obsolete/test002.r5 +13 -0
- data/lib/xamplr-gen/simpleTemplate/obsolete/test003.r5 +37 -0
- data/lib/xamplr-gen/simpleTemplate/old/r6.000.rb +122 -0
- data/lib/xamplr-gen/simpleTemplate/old/r6.001.rb +145 -0
- data/lib/xamplr-gen/simpleTemplate/play.r6 +12 -0
- data/lib/xamplr-gen/simpleTemplate/play_more.r6 +20 -0
- data/lib/xamplr-gen/simpleTemplate/play_noblanks.r6 +21 -0
- data/lib/xamplr-gen/simpleTemplate/playq.r6 +16 -0
- data/lib/xamplr-gen/simpleTemplate/r6.rb +87 -0
- data/lib/xamplr-gen/simpleTemplate/simple-template.rb +75 -0
- data/lib/xamplr-gen/templates/.cvsignore +3 -0
- data/lib/xamplr-gen/templates/child.template +47 -0
- data/lib/xamplr-gen/templates/child_indexed.template +89 -0
- data/lib/xamplr-gen/templates/child_modules.template +5 -0
- data/lib/xamplr-gen/templates/element_classes.template +11 -0
- data/lib/xamplr-gen/templates/element_data.template +283 -0
- data/lib/xamplr-gen/templates/element_empty.template +277 -0
- data/lib/xamplr-gen/templates/element_mixed.template +278 -0
- data/lib/xamplr-gen/templates/element_simple.template +277 -0
- data/lib/xamplr-gen/templates/package.template +38 -0
- data/lib/xamplr-gen/xampl-cl-gen.rb +89 -0
- data/lib/xamplr-gen/xampl-generator.rb +561 -0
- data/lib/xamplr-gen/xampl-hand-generated.rb +1534 -0
- data/lib/xamplr-gen/yuml-out.rb +127 -0
- data/licence.rb +17 -0
- data/test/helper.rb +10 -0
- data/test/test_xamplr-gen.rb +7 -0
- data/xamplr-gen.gemspec +98 -0
- metadata +124 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
[1]
|
2
|
+
|
|
3
|
+
| some_number = 42
|
4
|
+
|# def gen_some_number
|
5
|
+
|# 42 + rand
|
6
|
+
|# end
|
7
|
+
|
|
8
|
+
[2]
|
9
|
+
[3]Hello there(play_noblanks)! #{@message}
|
10
|
+
[4]
|
11
|
+
|
|
12
|
+
| another_number = 99
|
13
|
+
| result << sprintf("execute gen: %d\n", gen_some_number)
|
14
|
+
|
|
15
|
+
[5]
|
16
|
+
[6] some number: [[[#{some_number}]]]
|
17
|
+
[7]gen some number: [[[#{gen_some_number}]]]
|
18
|
+
[8] another number: [[[#{another_number}]]]
|
19
|
+
[9]
|
20
|
+
[10]play_noblanks _____________________________________________________
|
21
|
+
[11]
|
@@ -0,0 +1,16 @@
|
|
1
|
+
|
|
2
|
+
| some_number = 42
|
3
|
+
| def gen_some_number
|
4
|
+
| 42 + rand
|
5
|
+
| end
|
6
|
+
|
|
7
|
+
|
8
|
+
Hello there (play)! #{@message}
|
9
|
+
|
10
|
+
one: 'one #{gen_some_number}'
|
11
|
+
two: "two #{gen_some_number}"
|
12
|
+
|
13
|
+
some number: [[[#{some_number}]]]
|
14
|
+
gen some number: [[[#{gen_some_number}]]]
|
15
|
+
play __________________________________________________________
|
16
|
+
|
@@ -0,0 +1,87 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
require "xamplr/simpleTemplate/simple-template"
|
4
|
+
|
5
|
+
###
|
6
|
+
### and this is how it can be used...
|
7
|
+
###
|
8
|
+
|
9
|
+
# Define a class to hold the template methods. Any attributes defined by this
|
10
|
+
# class will be available to be used by the templates when they are 'run'.
|
11
|
+
# These are expected to be set up by the template-invoking program. This
|
12
|
+
# class defines a single attribute 'message'
|
13
|
+
|
14
|
+
class R6_Template
|
15
|
+
include TemplateEngine
|
16
|
+
attr_accessor :message
|
17
|
+
end
|
18
|
+
|
19
|
+
# Now we need to get some templates into place. We are providing a list of
|
20
|
+
# files here, but it is possible to imagine using ARGS to get filenames from
|
21
|
+
# the command line. Simply pass the list to the compile_script method.
|
22
|
+
|
23
|
+
files = [ "play.r6", "play_more.r6", "playq.r6", "play_noblanks.r6"];
|
24
|
+
|
25
|
+
engine = R6_Template.new
|
26
|
+
engine.compile_scripts(files)
|
27
|
+
|
28
|
+
# For illustrative purposes, go over the file arguments and execute
|
29
|
+
# the corresponding method defined above. The file names are used by the
|
30
|
+
# Template Engine to create a method that, when called, will 'execute' the
|
31
|
+
# template. The method name will be chosen by removing the filename extension.
|
32
|
+
|
33
|
+
files.each { | script_name |
|
34
|
+
method_name = File::basename(script_name, ".*")
|
35
|
+
|
36
|
+
# just a silly message that identifies the script that is running
|
37
|
+
engine.message = sprintf("this is script '%s'", method_name)
|
38
|
+
|
39
|
+
puts "#{method_name}*******************"
|
40
|
+
what = engine.send(method_name);
|
41
|
+
puts "{{{#{what}}}}*******************"
|
42
|
+
}
|
43
|
+
|
44
|
+
# This time call the play method directly. There must be a template
|
45
|
+
# called 'play' for this to work.
|
46
|
+
|
47
|
+
engine.message = "this is script 'play' -- called explicitly"
|
48
|
+
puts "!!play!!*******************"
|
49
|
+
what = engine.play()
|
50
|
+
puts "{{{#{what}}}}*******************"
|
51
|
+
|
52
|
+
# Now do the same thing as the illustrative loop above but writing to a file
|
53
|
+
# with the script name and a ".out" extension.
|
54
|
+
|
55
|
+
files.each { | script_name |
|
56
|
+
method_name = File::basename(script_name, ".*")
|
57
|
+
engine.message = sprintf("this is script '%s'", method_name)
|
58
|
+
File.open(sprintf("%s.out", method_name), "w") { | file |
|
59
|
+
engine.send(method_name, file);
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
# Write to a file called "play-x.out", again, there must be a play template
|
64
|
+
# defined.
|
65
|
+
|
66
|
+
engine.message = "this is script 'play' -- called explicitly"
|
67
|
+
File.open("play-x.out", "w") { | file |
|
68
|
+
engine.play(file)
|
69
|
+
}
|
70
|
+
|
71
|
+
# Build up a single string by applying all the templates
|
72
|
+
long_string = ""
|
73
|
+
files.each { | script_name |
|
74
|
+
method_name = File::basename(script_name, ".*")
|
75
|
+
engine.message = sprintf("this is script '%s'", method_name)
|
76
|
+
what = engine.send(method_name, long_string);
|
77
|
+
}
|
78
|
+
puts "!!{{{#{long_string}}}}!!*******************"
|
79
|
+
|
80
|
+
# This will fail, because the template methods are only defined on the
|
81
|
+
# instance of the engine that compiled them.
|
82
|
+
#
|
83
|
+
#engine2 = R6_Template.new
|
84
|
+
#engine2.message = "this is script 'play' -- called explicitly"
|
85
|
+
#File.open("play-x.out", "w") { | file |
|
86
|
+
# engine2.play(file)
|
87
|
+
#}
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module TemplateEngine
|
2
|
+
attr_accessor :method_to_file_name, :file_name_to_method
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@method_to_file_name = Hash.new()
|
6
|
+
@file_name_to_method = Hash.new()
|
7
|
+
end
|
8
|
+
|
9
|
+
# def macro(name, &block)
|
10
|
+
# Kernel.send(:define_method, name) { |*args|
|
11
|
+
# puts block.call(args)
|
12
|
+
# }
|
13
|
+
# end
|
14
|
+
|
15
|
+
def build_script(template_file_name, method_name)
|
16
|
+
|
17
|
+
# Build the definition of a method (called 'method_name') that
|
18
|
+
# will execute the template (in the file 'template_file_name'). There will
|
19
|
+
# be an optional argument that defaults to the empty string (and so this
|
20
|
+
# method will, by default, build a new string representing the result). If
|
21
|
+
# the argument is supplied, it must respond to the "<<" (append) method.
|
22
|
+
#
|
23
|
+
# The result variable is available in the template. To write to the result
|
24
|
+
# from Ruby code, result << sprintf("hello %s", "world") in the template
|
25
|
+
# will get its output where expected.
|
26
|
+
|
27
|
+
found_template_file_name = nil
|
28
|
+
$LOAD_PATH.each{ | directory |
|
29
|
+
possible_template_file_name = File.join(directory, template_file_name)
|
30
|
+
if File.exists?(possible_template_file_name)
|
31
|
+
found_template_file_name = possible_template_file_name
|
32
|
+
end
|
33
|
+
}
|
34
|
+
return unless found_template_file_name
|
35
|
+
File.open(found_template_file_name) do | file |
|
36
|
+
tmp = ""
|
37
|
+
r = "
|
38
|
+
def #{method_name}(result=\"\")
|
39
|
+
result << \"\"
|
40
|
+
"
|
41
|
+
while line = file.gets
|
42
|
+
if line[0] == ?|
|
43
|
+
if (0 < tmp.length)
|
44
|
+
r << " result << \"#{tmp.gsub("\"", "\\\"")}\""
|
45
|
+
tmp = ""
|
46
|
+
end
|
47
|
+
r << " #{line[1..-1]}"
|
48
|
+
else
|
49
|
+
#tmp << line.chomp << "\n"
|
50
|
+
tmp << line
|
51
|
+
end
|
52
|
+
end
|
53
|
+
r << " result << \"#{tmp.gsub("\"", "\\\"")}\""
|
54
|
+
r << "
|
55
|
+
result
|
56
|
+
end
|
57
|
+
"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def compile_scripts(files)
|
62
|
+
files.each { | script_name |
|
63
|
+
method_name = File::basename(script_name, ".*")
|
64
|
+
#puts "COMPILE: [[#{method_name}]]"
|
65
|
+
|
66
|
+
@method_to_file_name[method_name] = script_name;
|
67
|
+
@file_name_to_method[script_name] = method_name;
|
68
|
+
|
69
|
+
the_script = build_script(script_name, method_name)
|
70
|
+
#puts the_script
|
71
|
+
instance_eval(the_script, "SCRIPT:#{script_name}", 1)
|
72
|
+
}
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
@@ -0,0 +1,47 @@
|
|
1
|
+
|
2
|
+
module #{element.class_name}AsChild
|
3
|
+
def #{element.attribute_name}_child
|
4
|
+
accessed
|
5
|
+
@#{element.attribute_name}_child
|
6
|
+
end
|
7
|
+
|
8
|
+
def #{element.attribute_name}_child=(v)
|
9
|
+
accessed
|
10
|
+
@#{element.attribute_name}_child = v
|
11
|
+
end
|
12
|
+
|
13
|
+
alias #{element.attribute_name} #{element.attribute_name}_child
|
14
|
+
alias #{element.attribute_name}= #{element.attribute_name}_child=
|
15
|
+
|
16
|
+
def init_#{element.attribute_name}_as_child
|
17
|
+
@#{element.attribute_name}_child = []
|
18
|
+
end
|
19
|
+
|
20
|
+
def add_#{element.attribute_name}(#{element.attribute_name})
|
21
|
+
accessed
|
22
|
+
@children << #{element.attribute_name}
|
23
|
+
@#{element.attribute_name}_child << #{element.attribute_name}
|
24
|
+
#{element.attribute_name}.add_parent(self)
|
25
|
+
changed
|
26
|
+
return #{element.attribute_name}
|
27
|
+
end
|
28
|
+
|
29
|
+
def new_#{element.attribute_name}
|
30
|
+
accessed
|
31
|
+
#{element.attribute_name} = #{element.class_name}.new
|
32
|
+
yield(#{element.attribute_name}) if block_given?
|
33
|
+
return add_#{element.attribute_name}(#{element.attribute_name})
|
34
|
+
end
|
35
|
+
|
36
|
+
def ensure_#{element.attribute_name}
|
37
|
+
accessed
|
38
|
+
new_#{element.attribute_name} if 0 == #{element.attribute_name}.size
|
39
|
+
end
|
40
|
+
|
41
|
+
def remove_#{element.attribute_name}(#{element.attribute_name})
|
42
|
+
accessed
|
43
|
+
changed
|
44
|
+
@#{element.attribute_name}_child.delete(#{element.attribute_name})
|
45
|
+
@children.delete(#{element.attribute_name})
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
|
2
|
+
module #{element.class_name}AsChild
|
3
|
+
require "xamplr/indexed-array"
|
4
|
+
|
5
|
+
def #{element.attribute_name}_child
|
6
|
+
accessed
|
7
|
+
@#{element.attribute_name}_child
|
8
|
+
end
|
9
|
+
|
10
|
+
def #{element.attribute_name}_child=(v)
|
11
|
+
accessed
|
12
|
+
@#{element.attribute_name}_child = v
|
13
|
+
end
|
14
|
+
|
15
|
+
alias #{element.attribute_name} #{element.attribute_name}_child
|
16
|
+
alias #{element.attribute_name}= #{element.attribute_name}_child=
|
17
|
+
|
18
|
+
def init_#{element.attribute_name}_as_child
|
19
|
+
@#{element.attribute_name}_child = IndexedArray.new
|
20
|
+
end
|
21
|
+
|
22
|
+
def add_#{element.attribute_name}(#{element.attribute_name})
|
23
|
+
accessed
|
24
|
+
index = #{element.attribute_name}.get_the_index
|
25
|
+
if(nil == index) then
|
26
|
+
raise Xampl::XamplException.new("no value for the index '#{element.indexed_by_attr}' of #{element.attribute_name} defined in : " << #{element.attribute_name}.pp_xml)
|
27
|
+
end
|
28
|
+
|
29
|
+
existing = @#{element.attribute_name}_child[index]
|
30
|
+
|
31
|
+
return existing if existing == #{element.attribute_name}
|
32
|
+
|
33
|
+
self.remove_#{element.attribute_name}(index) if existing
|
34
|
+
|
35
|
+
@children << #{element.attribute_name}
|
36
|
+
@#{element.attribute_name}_child[index] = #{element.attribute_name}
|
37
|
+
|
38
|
+
#{element.attribute_name}.add_parent(self)
|
39
|
+
|
40
|
+
changed
|
41
|
+
return #{element.attribute_name}
|
42
|
+
end
|
43
|
+
|
44
|
+
def new_#{element.attribute_name}(index)
|
45
|
+
accessed
|
46
|
+
|
47
|
+
#{element.attribute_name} = nil
|
48
|
+
|
|
49
|
+
|if @element.persisted then
|
50
|
+
|
|
51
|
+
#{element.attribute_name} = #{element.class_name}.lookup(index) if Xampl.persister and Xampl.persister.automatic
|
52
|
+
|
|
53
|
+
|end
|
54
|
+
|
|
55
|
+
#{element.attribute_name} = #{element.class_name}.new(index) unless #{element.attribute_name}
|
56
|
+
|
57
|
+
yield(#{element.attribute_name}) if block_given?
|
58
|
+
return add_#{element.attribute_name}(#{element.attribute_name})
|
59
|
+
end
|
60
|
+
|
61
|
+
def ensure_#{element.attribute_name}(index)
|
62
|
+
accessed
|
63
|
+
|
64
|
+
#{element.attribute_name} = @#{element.attribute_name}_child[index]
|
65
|
+
return #{element.attribute_name} if #{element.attribute_name}
|
66
|
+
|
67
|
+
|
|
68
|
+
|if @element.persisted then
|
69
|
+
|
|
70
|
+
#{element.attribute_name} = #{element.class_name}.lookup(index) if Xampl.persister and Xampl.persister.automatic
|
71
|
+
|
|
72
|
+
|end
|
73
|
+
|
|
74
|
+
#{element.attribute_name} = #{element.class_name}.new(index) unless #{element.attribute_name}
|
75
|
+
|
76
|
+
yield(#{element.attribute_name}) if block_given?
|
77
|
+
return add_#{element.attribute_name}(#{element.attribute_name})
|
78
|
+
end
|
79
|
+
|
80
|
+
def remove_#{element.attribute_name}(index)
|
81
|
+
accessed
|
82
|
+
changed
|
83
|
+
unless String === index or Symbol === index then
|
84
|
+
index = index.get_the_index
|
85
|
+
end
|
86
|
+
#{element.attribute_name} = @#{element.attribute_name}_child.delete(index) if index
|
87
|
+
@children.delete(#{element.attribute_name})
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
| if "empty" == @element.kind then
|
2
|
+
| element_empty(result)
|
3
|
+
| elsif "simple" == @element.kind then
|
4
|
+
| element_simple(result)
|
5
|
+
| elsif "data" == @element.kind then
|
6
|
+
| element_data(result)
|
7
|
+
| elsif "mixed" == @element.kind then
|
8
|
+
| element_mixed(result)
|
9
|
+
| else
|
10
|
+
| raise Xampl::XamplException.new(:unkown_kind_of_element, "unknown element kind: '#{@element.kind}'")
|
11
|
+
| end
|
@@ -0,0 +1,283 @@
|
|
1
|
+
|
2
|
+
|
|
3
|
+
class #{@element.class_name}
|
4
|
+
|
|
5
|
+
|if @element.persisted then
|
6
|
+
|
|
7
|
+
include Xampl::XamplPersistedObject
|
8
|
+
|
9
|
+
#supports class based over-ride of persister format
|
10
|
+
@@default_persister_format = nil
|
11
|
+
|
12
|
+
def default_persister_format
|
13
|
+
@@default_persister_format
|
14
|
+
end
|
15
|
+
def #{@element.class_name}.default_persister_format
|
16
|
+
@@default_persister_format
|
17
|
+
end
|
18
|
+
def #{@element.class_name}.set_default_persister_format(format)
|
19
|
+
@@default_persister_format = format
|
20
|
+
end
|
21
|
+
|
22
|
+
def #{@element.class_name}.find_by_query
|
23
|
+
things = Xampl.find_xampl do | q |
|
24
|
+
q.add_condition('class', :equals, self.name)
|
25
|
+
yield(q)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
|
|
31
|
+
|else
|
32
|
+
|
|
33
|
+
include Xampl::XamplObject
|
34
|
+
|
|
35
|
+
|end
|
36
|
+
|
|
37
|
+
include Xampl::XamplWithDataContent
|
38
|
+
|
39
|
+
@@tag = "#{@element.name}"
|
40
|
+
@@ns = "#{@element.namespace}"
|
41
|
+
@@ns_tag = "{#{@element.namespace}}#{@element.name}"
|
42
|
+
@@module_name = "#{@package_name}"
|
43
|
+
@@safe_name = "#{@package_name}_#{@element.attribute_name}"
|
44
|
+
@@attributes = [
|
45
|
+
|
|
46
|
+
|@element.attribute_child.each{ | attribute |
|
47
|
+
| if attribute.namespace then
|
48
|
+
|
|
49
|
+
[ :@#{attribute.name}, "#{attribute.tag_name}", "#{attribute.namespace}" ],
|
50
|
+
|
|
51
|
+
| else
|
52
|
+
|
|
53
|
+
[ :@#{attribute.name}, "#{attribute.tag_name}" ],
|
54
|
+
|
|
55
|
+
| end
|
56
|
+
|}
|
57
|
+
|
|
58
|
+
]
|
59
|
+
|
|
60
|
+
|@element.child_element_child.each{ | child_element |
|
61
|
+
| element_class_name = @lookup_element[child_element.name].class_name
|
62
|
+
| element_package = @lookup_element[child_element.name].package
|
63
|
+
|
|
64
|
+
include #{element_package}::#{element_class_name}AsChild
|
65
|
+
|
|
66
|
+
|}
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
70
|
+
|
|
71
|
+
|if @element.persisted then
|
72
|
+
|
|
73
|
+
|
74
|
+
def #{@element.class_name}.lookup(pid)
|
75
|
+
Xampl.lookup(#{@element.class_name}, pid)
|
76
|
+
end
|
77
|
+
|
78
|
+
def #{@element.class_name}.[](pid)
|
79
|
+
Xampl.lookup(#{@element.class_name}, pid)
|
80
|
+
end
|
81
|
+
|
|
82
|
+
|end
|
83
|
+
|
|
84
|
+
|@element.attribute_child.each{ | attribute |
|
85
|
+
| if attribute.name == @element.indexed_by_attr and @element.persisted then
|
86
|
+
|
|
87
|
+
|
88
|
+
def #{attribute.name}
|
89
|
+
@#{attribute.name}
|
90
|
+
end
|
91
|
+
|
92
|
+
def #{attribute.name}=(v)
|
93
|
+
accessed
|
94
|
+
# This is kind of optimistic, I think you are in trouble if you do this
|
95
|
+
Xampl.auto_uncache(self) if @#{attribute.name}
|
96
|
+
@#{attribute.name} = v
|
97
|
+
changed
|
98
|
+
Xampl.auto_cache(self) if v
|
99
|
+
end
|
100
|
+
|
|
101
|
+
| else
|
102
|
+
|
|
103
|
+
|
104
|
+
def #{attribute.name}
|
105
|
+
accessed
|
106
|
+
@#{attribute.name}
|
107
|
+
end
|
108
|
+
|
109
|
+
def #{attribute.name}=(v)
|
110
|
+
accessed
|
111
|
+
changed
|
112
|
+
@#{attribute.name} = v
|
113
|
+
end
|
114
|
+
|
|
115
|
+
| end
|
116
|
+
|}
|
117
|
+
|
|
118
|
+
| if @element.indexed_by_attr then
|
119
|
+
|
|
120
|
+
|
121
|
+
def initialize(index=nil)
|
122
|
+
@#{@element.indexed_by_attr} = index if index
|
123
|
+
super()
|
124
|
+
|
|
125
|
+
| else
|
126
|
+
|
|
127
|
+
|
128
|
+
def initialize
|
129
|
+
super
|
130
|
+
|
|
131
|
+
|end
|
132
|
+
|
|
133
|
+
|if 0 < @element.attribute_child.size then
|
134
|
+
|
|
135
|
+
|
136
|
+
|
|
137
|
+
|end
|
138
|
+
|
|
139
|
+
|@element.attribute_child.each{ | attribute |
|
140
|
+
|
|
141
|
+
@#{attribute.name} = nil if not defined? @#{attribute.name}
|
142
|
+
|
|
143
|
+
|}
|
144
|
+
|
|
145
|
+
|
146
|
+
init_xampl_object
|
147
|
+
init_data_content
|
148
|
+
|
|
149
|
+
|@element.child_element_child.each{ | child_element |
|
150
|
+
| element_attribute_name = @lookup_element[child_element.name].attribute_name
|
151
|
+
|
|
152
|
+
init_#{element_attribute_name}_as_child
|
153
|
+
|
|
154
|
+
|}
|
155
|
+
|
|
156
|
+
|
157
|
+
yield(self) if block_given?
|
158
|
+
init_hook
|
159
|
+
|
160
|
+
changed
|
161
|
+
end
|
162
|
+
|
163
|
+
def clear_non_persistent_index_attributes
|
164
|
+
|
|
165
|
+
|@element.attribute_child.each{ | attribute |
|
166
|
+
| unless attribute.name == @element.indexed_by_attr and @element.persisted then
|
167
|
+
|
|
168
|
+
@#{attribute.name} = nil
|
169
|
+
|
|
170
|
+
| end
|
171
|
+
|}
|
172
|
+
|
|
173
|
+
end
|
174
|
+
|
175
|
+
def append_to(other)
|
176
|
+
other.add_#{@element.attribute_name}(self)
|
177
|
+
end
|
178
|
+
|
179
|
+
|
|
180
|
+
|if @element.persisted then
|
181
|
+
|
|
182
|
+
def #{@element.class_name}.persisted?
|
183
|
+
return :#{@element.indexed_by_attr}
|
184
|
+
end
|
185
|
+
|
186
|
+
def persisted?
|
187
|
+
return :#{@element.indexed_by_attr}
|
188
|
+
end
|
189
|
+
|
190
|
+
|
|
191
|
+
|else
|
192
|
+
|
|
193
|
+
def #{@element.class_name}.persisted?
|
194
|
+
return nil
|
195
|
+
end
|
196
|
+
|
197
|
+
def persisted?
|
198
|
+
return nil
|
199
|
+
end
|
200
|
+
|
201
|
+
|
|
202
|
+
|end
|
203
|
+
|
|
204
|
+
def #{@element.class_name}.tag
|
205
|
+
@@tag
|
206
|
+
end
|
207
|
+
|
208
|
+
def #{@element.class_name}.ns
|
209
|
+
@@ns
|
210
|
+
end
|
211
|
+
|
212
|
+
def #{@element.class_name}.ns_tag
|
213
|
+
@@ns_tag
|
214
|
+
end
|
215
|
+
|
216
|
+
def #{@element.class_name}.safe_name
|
217
|
+
@@safe_name
|
218
|
+
end
|
219
|
+
|
220
|
+
def #{@element.class_name}.module_name
|
221
|
+
@@module_name
|
222
|
+
end
|
223
|
+
|
224
|
+
def tag
|
225
|
+
@@tag
|
226
|
+
end
|
227
|
+
|
228
|
+
def ns
|
229
|
+
@@ns
|
230
|
+
end
|
231
|
+
|
232
|
+
def ns_tag
|
233
|
+
@@ns_tag
|
234
|
+
end
|
235
|
+
|
236
|
+
def safe_name
|
237
|
+
@@safe_name
|
238
|
+
end
|
239
|
+
|
240
|
+
def module_name
|
241
|
+
@@module_name
|
242
|
+
end
|
243
|
+
|
244
|
+
def attributes
|
245
|
+
@@attributes
|
246
|
+
end
|
247
|
+
|
|
248
|
+
|if @element.indexed_by_attr
|
249
|
+
|
|
250
|
+
|
251
|
+
def indexed_by
|
252
|
+
:#{@element.indexed_by_attr}
|
253
|
+
end
|
254
|
+
|
255
|
+
def get_the_index
|
256
|
+
@#{@element.indexed_by_attr}
|
257
|
+
end
|
258
|
+
|
259
|
+
def set_the_index(index)
|
260
|
+
@#{@element.indexed_by_attr} = index
|
261
|
+
end
|
262
|
+
|
|
263
|
+
|end
|
264
|
+
|
|
265
|
+
|
266
|
+
def substitute_in_visit(visitor)
|
267
|
+
return visitor.substitute_in_visit_#{@element.attribute_name}(self) || self
|
268
|
+
end
|
269
|
+
|
270
|
+
def before_visit(visitor)
|
271
|
+
visitor.before_visit_#{@element.attribute_name}(self)
|
272
|
+
end
|
273
|
+
|
274
|
+
def visit(visitor)
|
275
|
+
visitor.visit_#{@element.attribute_name}(self)
|
276
|
+
end
|
277
|
+
|
278
|
+
def after_visit(visitor)
|
279
|
+
visitor.after_visit_#{@element.attribute_name}(self)
|
280
|
+
end
|
281
|
+
|
282
|
+
Xampl::FromXML::register(#{@element.class_name}::tag, #{@element.class_name}::ns_tag, #{@element.class_name})
|
283
|
+
end
|