xamplr-gen 1.9.0 → 1.9.2

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/README.md CHANGED
@@ -2,17 +2,19 @@
2
2
 
3
3
  xamplr-gen is part of a set of software tools that supports development of ruby applications.
4
4
 
5
- It consists of three gems hosted on gem cutter, source code on
6
- github.
5
+ It consists of three gems hosted on gemcutter, source code on github.
7
6
 
8
- * xamplr-pp -- this is a pure ruby pull parser
9
- * xamplr -- this is the xampl runtime
10
- * xamplr-gen -- this is the code generator
7
+ * [xamplr-pp](http://github.com/hutch/xamplr-pp) -- this is a pure ruby pull parser
8
+ * [xamplr](http://github.com/hutch/xamplr) -- this is the xampl runtime
9
+ * [xamplr-gen](http://github.com/hutch/xamplr-gen) -- this is the code generator
11
10
 
12
11
  There is an additional fourth github repository containing
13
12
  examples and documentation that will be coming soon.
14
13
 
15
- Yes, that means that there's no documentation. And no examples. I agree, this is a very bad situation.
14
+ Yes, that means that there's no documentation. And no examples. I agree,
15
+ this is a very bad situation.
16
+
17
+ For more information, see [the xampl page on xampl.com](http://xampl.com/so/xampl/), and/or [the weblog 'So.'](http://xampl.com/so/)
16
18
 
17
19
  ## Installation:
18
20
 
@@ -20,6 +22,12 @@ Yes, that means that there's no documentation. And no examples. I agree, this is
20
22
 
21
23
  This will install all three gems.
22
24
 
25
+ NOTE: if you have installed hutch-xamplr or hutch-xamplr-pp then
26
+ you should uninstall them. For some reason, in certain circumstances,
27
+ these might be loaded or partially loaded when trying to use xampl.
28
+ If you don't you'll experience strange exceptions with hutch-xamplr
29
+ or hutch-xamplr-pp on the stack trace.
30
+
23
31
 
24
32
  ## License:
25
33
 
data/Rakefile CHANGED
@@ -13,7 +13,7 @@ begin
13
13
  gem.add_development_dependency "cucumber", ">= 0"
14
14
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
15
 
16
- gem.add_dependency('xamplr', '>=1.9.0')
16
+ gem.add_dependency('xamplr', '>=1.9.1')
17
17
  end
18
18
  Jeweler::GemcutterTasks.new
19
19
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.9.0
1
+ 1.9.2
data/bin/xampl-gen CHANGED
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- #!/usr/bin/env ruby -w -I..
3
2
 
4
3
  require 'xamplr-gen'
5
4
  require 'xamplr-gen/xampl-cl-gen'
@@ -8,10 +7,12 @@ include XamplGenerator
8
7
  include Xampl
9
8
 
10
9
  project_specialisations = File.join(%w{ . project-generator.rb })
10
+ specialised = false
11
11
  if File.exists?(project_specialisations) then
12
12
  load project_specialisations
13
+ specialised = true
13
14
  end
14
15
 
15
- generator = ProjectGenerator.new
16
+ generator = ProjectGenerator.new(specialised)
16
17
  generator.generate
17
18
 
@@ -1,13 +1,16 @@
1
-
2
- #require 'xampl-generator'
1
+ require 'optparse'
3
2
 
4
3
  include XamplGenerator
5
4
  include Xampl
6
5
 
7
6
  class ProjectGenerator
8
7
 
8
+ def initialize(specialised=true)
9
+ @specialised = specialised
10
+ end
11
+
9
12
  def directory
10
- File.join(%w{ . xampl_generated_code })
13
+ File.join(%w{ . xampl-generated-code })
11
14
  end
12
15
 
13
16
  def filenames
@@ -50,14 +53,97 @@ class ProjectGenerator
50
53
  []
51
54
  end
52
55
 
56
+ @@specialisation_file_content = <<_EOF_
57
+ class ProjectGenerator
58
+
59
+ def print_options
60
+ # return an array containing any (or none) of:
61
+ # :schema -- a schema-like xml representation of the generated code
62
+ # :graphml -- a graphml file describing the class model (compatible with yEd)
63
+ # :yuml -- a yuml file that represents a simplified class model (compatible with yUML)
64
+
65
+ [ :yuml ]
66
+ end
67
+
68
+ def directory
69
+ # return the path name to the generator's output directory
70
+ File.join(%w{ . xampl-generated-code })
71
+ end
72
+
73
+ def resolve_namespaces
74
+ # any array of arrays
75
+ # each sub-array:
76
+ # 0: a string or an array of strings, containing xml namespaces found
77
+ # in the example xml files an empty string is the default namespace
78
+ # 1: a ruby Module name (get the character cases right)
79
+ # 2: a namespace prefix used when writing xml, optional. A generated
80
+ # prefix will be used otherwise.
81
+
82
+ [
83
+ {{MAPPING}}
84
+ ]
85
+ end
86
+ end
87
+ _EOF_
88
+
89
+ def write_specialisation_file(element_map)
90
+ filename = './project-generator.rb'
91
+ return if File.exists? filename
92
+
93
+ mappings = []
94
+ count = 0
95
+ element_map.each do | ns, elements |
96
+ module_name = elements.element.first.package || 'XamplAdHoc'
97
+ count += 1
98
+ mappings << [ ns, module_name, "ns#{ count }" ]
99
+ end
100
+
101
+ text = @@specialisation_file_content.gsub(/{{MAPPING}}/) do
102
+ insert = []
103
+ mappings.each do | ns, module_name, prefix |
104
+ insert << " ['#{ ns }', '#{ module_name }', '#{ prefix }'],"
105
+ end
106
+ insert.join("\n")
107
+ end
108
+
109
+ File.open(filename, 'w') do | out |
110
+ out.write text
111
+ end
112
+ end
113
+
53
114
  def generate
54
115
 
116
+ cl_options = {}
117
+ OptionParser.new do |opts|
118
+ opts.banner = "Usage: junk.rb [options]"
119
+
120
+ opts.on("--download-yuml-png [FILENAME]", "Download the yuml png file if possible.") do | filename |
121
+ cl_options[:download_yuml_png] = filename || true
122
+ end
123
+ opts.on("--download-yuml-pdf [FILENAME]", "Download the yuml pdf file if possible.") do | filename |
124
+ cl_options[:download_yuml_pdf] = filename || true
125
+ end
126
+ end.parse!
127
+
55
128
  # Xampl.set_default_persister_kind(:simple)
56
129
  Xampl.set_default_persister_kind(:in_memory)
57
130
  # Xampl.set_default_persister_kind(:filesystem)
58
131
  # Xampl.set_default_persister_kind(:tokyo_cabinet)
59
132
  # Xampl.set_default_persister_format(:xml_format)
60
133
 
134
+ dirname = self.directory
135
+ if File.directory? dirname then
136
+ begin
137
+ FileUtils.rm_rf([ dirname ])
138
+ rescue => e
139
+ puts "could not clean up #{ dirname } -- #{ e }"
140
+ return
141
+ end
142
+ elsif File.exists? dirname then
143
+ puts "please move #{ dirname } out of the way of xampl-gen"
144
+ return
145
+ end
146
+
61
147
  Xampl.transaction("project-generation") do
62
148
 
63
149
  options = Options.new do | opts |
@@ -81,6 +167,72 @@ class ProjectGenerator
81
167
  :directory => directory)
82
168
 
83
169
  puts generator.print_elements(print_base_filename, print_options)
170
+ self.write_specialisation_file(generator.elements_map)
171
+
172
+ generated_files = Dir.glob("#{ self.directory }/*.rb")
173
+ if 0 < generated_files.size then
174
+ all = []
175
+ abs = []
176
+ generated_files.each do | filename |
177
+ all << "require '#{ File.dirname(filename)[2..-1] }/#{ File.basename(filename, '.rb') }'"
178
+ abs_filename = File.expand_path(filename)
179
+ abs << "require '#{ File.dirname(abs_filename) }/#{ File.basename(abs_filename, '.rb') }'"
180
+ end
181
+
182
+ out_filename = "#{ self.directory }/all.rb"
183
+ File.open(out_filename, 'w') do | out |
184
+ out.puts all.join("\n")
185
+ end
186
+ puts "WRITE TO FILE: #{ out_filename }"
187
+
188
+ out_filename = "#{ self.directory }/all-absolute.rb"
189
+ File.open(out_filename, 'w') do | out |
190
+ out.puts abs.join("\n")
191
+ end
192
+ puts "WRITE TO FILE: #{ out_filename }"
193
+
194
+ if File.exists?('./generated.yuml') && (cl_options[:download_yuml_png] || cl_options[:download_yuml_pdf]) then
195
+ diagram = ""
196
+ File.open("./generated.yuml") do | f |
197
+ f.each do | line |
198
+ diagram << line.chomp
199
+ end
200
+ end
201
+
202
+
203
+ okay = false
204
+ if cl_options[:download_yuml_png] then
205
+ begin
206
+ filename = (true == cl_options[:download_yuml_png]) ? 'generated.png' : cl_options[:download_yuml_png]
207
+ wget = "wget 'http://yuml.me/diagram/scruffy/class/#{diagram}' -O '#{filename}'"
208
+ okay = system(wget)
209
+ if okay then
210
+ puts "downloaded yuml png"
211
+ else
212
+ puts "could not get the yuml png file -- #{ $? }"
213
+ end
214
+ rescue => e
215
+ puts "could not get the yuml png file -- #{ e }"
216
+ end
217
+ end
218
+
219
+ if cl_options[:download_yuml_pdf] then
220
+ begin
221
+ filename = (true == cl_options[:download_yuml_png]) ? 'generated.png' : cl_options[:download_yuml_png]
222
+ wget = "wget 'http://yuml.me/diagram/scruffy/class/#{diagram}.pdf' -O '#{filename}'"
223
+ okay = system(wget)
224
+ puts "downloaded yuml pdf"
225
+ if okay then
226
+ puts "downloaded yuml pdf"
227
+ else
228
+ puts "could not get the yuml pdf file -- #{ $? }"
229
+ end
230
+ rescue => e
231
+ puts "could not get the yuml pdf file -- #{ e }"
232
+ end
233
+ end
234
+ end
235
+ end
84
236
 
85
237
  Xampl.rollback
86
238
  end
@@ -278,7 +278,6 @@ module XamplGenerator
278
278
  if directory_name then
279
279
  output_filename = File.join(directory_name, "#{package_name}.rb")
280
280
  puts "WRITE TO FILE: #{output_filename}"
281
- #puts package_definition
282
281
  File.open(output_filename, "w") do |file|
283
282
  file.puts package_definition
284
283
  end
data/xamplr-gen.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{xamplr-gen}
8
- s.version = "1.9.0"
8
+ s.version = "1.9.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Bob Hutchison"]
12
- s.date = %q{2009-12-27}
12
+ s.date = %q{2010-01-13}
13
13
  s.default_executable = %q{xampl-gen}
14
14
  s.description = %q{This is the xampl code generator for Ruby.}
15
15
  s.email = %q{hutch@xampl.com}
@@ -85,14 +85,14 @@ Gem::Specification.new do |s|
85
85
 
86
86
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
87
87
  s.add_development_dependency(%q<cucumber>, [">= 0"])
88
- s.add_runtime_dependency(%q<xamplr>, [">= 1.9.0"])
88
+ s.add_runtime_dependency(%q<xamplr>, [">= 1.9.1"])
89
89
  else
90
90
  s.add_dependency(%q<cucumber>, [">= 0"])
91
- s.add_dependency(%q<xamplr>, [">= 1.9.0"])
91
+ s.add_dependency(%q<xamplr>, [">= 1.9.1"])
92
92
  end
93
93
  else
94
94
  s.add_dependency(%q<cucumber>, [">= 0"])
95
- s.add_dependency(%q<xamplr>, [">= 1.9.0"])
95
+ s.add_dependency(%q<xamplr>, [">= 1.9.1"])
96
96
  end
97
97
  end
98
98
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xamplr-gen
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0
4
+ version: 1.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Hutchison
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-27 00:00:00 -05:00
12
+ date: 2010-01-13 00:00:00 -05:00
13
13
  default_executable: xampl-gen
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -30,7 +30,7 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 1.9.0
33
+ version: 1.9.1
34
34
  version:
35
35
  description: This is the xampl code generator for Ruby.
36
36
  email: hutch@xampl.com