RXAAL 0.0.1

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 (74) hide show
  1. data/COPYING +674 -0
  2. data/README +0 -0
  3. data/RXAAL.gemspec +15 -0
  4. data/Rakefile +60 -0
  5. data/lib/angle.rb +9 -0
  6. data/lib/arc.rb +13 -0
  7. data/lib/arrow.rb +23 -0
  8. data/lib/attribute.rb +13 -0
  9. data/lib/bound_array.rb +56 -0
  10. data/lib/center.rb +7 -0
  11. data/lib/circle.rb +11 -0
  12. data/lib/circle_segment.rb +9 -0
  13. data/lib/contents.rb +7 -0
  14. data/lib/coordinate.rb +20 -0
  15. data/lib/core_ext/class.rb +17 -0
  16. data/lib/core_ext/module.rb +23 -0
  17. data/lib/core_ext/object.rb +7 -0
  18. data/lib/core_ext/string.rb +11 -0
  19. data/lib/ellipse.rb +8 -0
  20. data/lib/enum.rb +8 -0
  21. data/lib/enum/anchor.rb +16 -0
  22. data/lib/enum/color_name.rb +24 -0
  23. data/lib/enum/offset_mode.rb +9 -0
  24. data/lib/enum/stroke_type.rb +9 -0
  25. data/lib/enum/text_alignment.rb +9 -0
  26. data/lib/font.rb +25 -0
  27. data/lib/generic_color.rb +7 -0
  28. data/lib/graphic_prim.rb +25 -0
  29. data/lib/line.rb +9 -0
  30. data/lib/metadata.rb +78 -0
  31. data/lib/metadata_mod.rb +34 -0
  32. data/lib/named_color.rb +16 -0
  33. data/lib/node_prim.rb +15 -0
  34. data/lib/ns_container.rb +30 -0
  35. data/lib/offset.rb +63 -0
  36. data/lib/operation.rb +5 -0
  37. data/lib/par.rb +25 -0
  38. data/lib/par_container.rb +2 -0
  39. data/lib/point.rb +8 -0
  40. data/lib/polygon.rb +22 -0
  41. data/lib/polyline.rb +29 -0
  42. data/lib/privtest.rb +24 -0
  43. data/lib/r_xaal_error.rb +2 -0
  44. data/lib/r_xaal_object.rb +5 -0
  45. data/lib/radius.rb +5 -0
  46. data/lib/rectangle.rb +10 -0
  47. data/lib/rgb_color.rb +20 -0
  48. data/lib/rxaal.rb +28 -0
  49. data/lib/seq.rb +31 -0
  50. data/lib/serializable.rb +11 -0
  51. data/lib/shape.rb +5 -0
  52. data/lib/show_hide.rb +27 -0
  53. data/lib/square.rb +35 -0
  54. data/lib/stroke.rb +27 -0
  55. data/lib/style.rb +91 -0
  56. data/lib/style_container.rb +5 -0
  57. data/lib/style_mod.rb +63 -0
  58. data/lib/text.rb +34 -0
  59. data/lib/top_level_elem.rb +12 -0
  60. data/lib/triangle.rb +9 -0
  61. data/lib/xaal_doc.rb +93 -0
  62. data/lib/xaal_element.rb +77 -0
  63. data/lib/xaalns.rb +14 -0
  64. data/test/arrow_test.rb +43 -0
  65. data/test/attribute_test.rb +10 -0
  66. data/test/bound_array_test.rb +54 -0
  67. data/test/metadata_test.rb +35 -0
  68. data/test/module_test.rb +36 -0
  69. data/test/ns_container_test.rb +18 -0
  70. data/test/serializable_test.rb +19 -0
  71. data/test/style_test.rb +64 -0
  72. data/test/test_base.rb +19 -0
  73. data/test/xaal_element_test.rb +47 -0
  74. metadata +145 -0
data/README ADDED
File without changes
@@ -0,0 +1,15 @@
1
+ spec = Gem::Specification.new do |s|
2
+ s.name = 'RXAAL'
3
+ s.version = '0.0.1'
4
+ s.summary = "A library for creating eXtensible Algorithm Animation Language (XAAL) files."
5
+ s.description = %{A library for creating eXtensible Algorithm Animation Language (XAAL) files.}
6
+ s.files = Dir['lib/**/*.rb'] + Dir['test/**/*.rb']
7
+ s.require_path = 'lib'
8
+ s.has_rdoc = true
9
+ s.add_dependency("darkfish-rdoc")
10
+ s.extra_rdoc_files = Dir['[A-Z]*']
11
+ s.rdoc_options << '--title' << 'RXAAL' << 'darkfish'
12
+ s.author = "Eric Schultz"
13
+ s.email = "wwahammy@gmail.com"
14
+ s.rubyforge_project = 'RXAAL'
15
+ end
@@ -0,0 +1,60 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/gempackagetask'
4
+ require 'rake/rdoctask'
5
+
6
+
7
+ desc 'Default: run unit tests.'
8
+ task :default => :test
9
+
10
+ desc 'buildGenMod: build the general module'
11
+ task :buildGenMod do
12
+ classes = Hash.new
13
+ rbfiles = File.join(".", "*.rb")
14
+ Dir.glob(rbfiles).each { |filename|
15
+ puts filename
16
+ File.open(filename, 'r') { |io|
17
+ io.readlines.each {|line|
18
+ puts line
19
+ if (line =~ /\s*class\s+([A-Z]\w*)/)
20
+ classes[$1.to_sym] = filename.sub(/\.rb/, "").sub(/\.\//, "");
21
+ end
22
+ }
23
+ }
24
+ }
25
+
26
+ classes.each { |key, val|
27
+ puts key.inspect + " = " + val
28
+ }
29
+ end
30
+
31
+ desc 'Test.'
32
+ Rake::TestTask.new(:test) do |t|
33
+ t.pattern = 'test/*_test.rb'
34
+ t.verbose = true
35
+ end
36
+
37
+
38
+ spec = Gem::Specification.load("./rxaal.gemspec")
39
+ desc 'Gem.'
40
+ Rake::GemPackageTask.new(spec) do |pkg|
41
+ pkg.need_tar = true
42
+ end
43
+
44
+ BASE_RDOC_OPTIONS = [
45
+ '--line-numbers',
46
+ '--main', 'README',
47
+ '--title', 'Rake -- Ruby Make',
48
+ ]
49
+
50
+ desc 'RDoc'
51
+ Rake::RDocTask.new("rdoc") do |rdoc|
52
+ rdoc.rdoc_dir = 'html'
53
+ rdoc.title = "Rake -- Ruby Make"
54
+ rdoc.options = BASE_RDOC_OPTIONS.dup
55
+
56
+ rdoc.rdoc_files.include('README', 'COPYING')
57
+ rdoc.rdoc_files.include('lib/**/*.rb', 'doc/**/*.rdoc')
58
+ rdoc.rdoc_files.exclude(/\bcontrib\b/)
59
+ end
60
+
@@ -0,0 +1,9 @@
1
+ module RXaal
2
+ class Angle < GraphicPrim
3
+ attr_accessor_of_class Integer, :total, :start
4
+
5
+ def initialize(doc, id = nil, elem_ns=nil)
6
+ super(doc, id, elem_ns)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ require 'graphic_prim'
2
+ require 'coordinate'
3
+ require 'angle'
4
+ module RXaal
5
+ class Arc < GraphicPrim
6
+ attr_accessor_of_class Coordinate, :center, :radius
7
+ attr_accessor_of_class Angle, :angle
8
+ attr_accessor_of_class Integer, :depth
9
+ def initialize(doc, id = nil, elem_ns=nil)
10
+ super(doc, id, elem_ns)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,23 @@
1
+ module RXaal
2
+ class Arrow < XaalElement
3
+
4
+ attr_accessor_of_boolean :forward, :backward
5
+ def initialize(doc, id = nil, elem_ns=nil)
6
+ super(doc, id, elem_ns)
7
+ end
8
+
9
+ def xaal_serialize(parent)
10
+ if forward != nil || backward != nil
11
+ e = REXML::Element.new "arrow"
12
+ parent.elements << e
13
+
14
+ if forward != nil
15
+ e.attributes["forward"] = forward
16
+ end
17
+ if backward != nil
18
+ e.attributes["backward"] = backward
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,13 @@
1
+ module RXaal
2
+ class Attribute
3
+ attr_accessor_of_class String, :name
4
+ attr_accessor_of_class XaalNS, :ns
5
+ attr_accessor_of_class Integer, :value
6
+
7
+ def initialize(_name, _ns, _value = nil)
8
+ self.name = _name
9
+ self.ns = _ns
10
+ @value = _value
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,56 @@
1
+ =begin
2
+ An array whose elements must be of the bound_class.
3
+ =end
4
+ require 'forwardable'
5
+ module RXaal
6
+
7
+ class BoundArray
8
+ extend Forwardable
9
+ attr_reader :bound_class
10
+ def_delegators :@inner_array, :&, :*
11
+ def_delegators :@inner_array, :delete, :delete_at, :delete_if
12
+ def_delegators :@inner_array, :each, :each_index
13
+ def_delegators :@inner_array, :fetch, :first, :include?, :index, :join, :length, :map, :pop
14
+ def_delegators :@inner_array, :reverse, :reverse!, :reverse_each, :rindex, :select, :shift, :slice!
15
+ def_delegators :@inner_array, :[], :sort, :sort!, :to_a, :uniq, :uniq!, :values_at
16
+
17
+ def initialize(klass)
18
+ @bound_class = klass
19
+ @inner_array = Array.new
20
+ end
21
+
22
+ def <<(obj)
23
+ type_confirmation(obj) {
24
+ return @inner_array << obj
25
+ }
26
+ end
27
+
28
+ def []=(index, obj)
29
+ type_confirmation(obj) {
30
+ return @inner_array[index] = obj
31
+ }
32
+ end
33
+
34
+ def +(other_array)
35
+ if (other_array.class == BoundArray && other_array.bound_class == @bound_class)
36
+ new_array = BoundArray.new(@bound_class)
37
+ [@inner_array,other_array.to_a].each {|a|
38
+ a.each {|real|
39
+ new_array << real
40
+ }
41
+ }
42
+ return new_array
43
+ end
44
+ return self
45
+ end
46
+
47
+ private
48
+
49
+ def type_confirmation (obj, &block)
50
+
51
+ if obj.class.hierarchy.include?(@bound_class)
52
+ return block.call
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,7 @@
1
+ module RXaal
2
+ class Center < Coordinate
3
+ def initialize(xpos, ypos)
4
+ super(xpos,ypos)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ require 'graphic_prim'
2
+ module RXaal
3
+ class Circle < GraphicPrim
4
+
5
+ attr_accessor_of_class Coordinate, :center, :radius
6
+ attr_accessor_of_class Integer, :depth
7
+ def initialize
8
+ super
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ require 'graphic_prim'
2
+ module RXaal
3
+ class CircleSegment < GraphicPrim
4
+
5
+ def initialize
6
+ super
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ require 'serializable'
2
+ module RXaal
3
+ class Contents
4
+ include Serializable
5
+ attr_accessor_of_class String, :text, :lang
6
+ end
7
+ end
@@ -0,0 +1,20 @@
1
+ module RXaal
2
+ class Coordinate < XaalElement
3
+ attr_accessor :xpos, :ypos
4
+ def initialize(doc, xpos, ypos, id= nil, elem_ns=nil)
5
+ super(doc, id, elem_ns)
6
+ @xpos= xpos
7
+ @ypos= ypos
8
+ end
9
+
10
+ def xaal_serialize(parent)
11
+ elem = Element.new "coordinate"
12
+ elem.attributes["x"] = @xpos.to_s
13
+ elem.attributes["y"] = @ypos.to_s
14
+ elem.attributes["id"] = self.id
15
+ parent.elements << elem
16
+
17
+ superclass_serialize(elem)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ class Class
2
+ def cattr_reader(*cvs)
3
+ cvs.each do |cv|
4
+ class_eval %Q[
5
+ def self.#{cv}; @@#{cv} end
6
+ ]
7
+ end
8
+ end
9
+
10
+ def hierarchy
11
+ (superclass ? superclass.hierarchy : []) << self
12
+ end
13
+
14
+ def name_minus_mod
15
+ return name.split("::").last
16
+ end
17
+ end
@@ -0,0 +1,23 @@
1
+ class Module
2
+ def attr_accessor_bool(name, &block)
3
+ define_method(name) do
4
+ instance_variable_get("@#{name}")
5
+ end
6
+
7
+ define_method("#{name}=") do |val|
8
+ if block.call(val)
9
+ instance_variable_set("@#{name}",val)
10
+ end
11
+ end
12
+ end
13
+ def attr_accessor_of_boolean(*accessor)
14
+ accessor.each {|a|
15
+ attr_accessor_bool(a) {|o| o.class == TrueClass || o.class == FalseClass}
16
+ }
17
+ end
18
+ def attr_accessor_of_class (klass, *accessor)
19
+ accessor.each {|a|
20
+ attr_accessor_bool(a) {|o| o.class == klass}
21
+ }
22
+ end
23
+ end
@@ -0,0 +1,7 @@
1
+ class Object
2
+ def smrt_autoload(*syms)
3
+ syms.each {|sym|
4
+ autoload(sym, sym.to_s.underscore + ".rb")
5
+ }
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ ##from ruby
2
+
3
+ class String
4
+ def underscore
5
+ self.gsub(/::/, '/').
6
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
7
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
8
+ tr("-", "_").
9
+ downcase
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ require 'node_prim'
2
+ module RXaal
3
+ class Ellipse < NodePrim
4
+ def initialize
5
+ super
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module RXaal
2
+ module Enum
3
+ autoload :Anchor, "enum/anchor"
4
+ autoload :ColorName, "enum/color_name"
5
+ autoload :OffsetMode, "enum/offset_mode"
6
+ autoload :StrokeType, "enum/stroke_type"
7
+ end
8
+ end
@@ -0,0 +1,16 @@
1
+ module RXaal
2
+ module Enum
3
+
4
+ class Anchor
5
+ NW = 'NW'
6
+ N = 'N'
7
+ NE = 'NE'
8
+ E = 'E'
9
+ SE = 'SE'
10
+ S = 'S'
11
+ SW = 'SW'
12
+ W = 'W'
13
+ C = 'C'
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,24 @@
1
+ module RXaal
2
+ module Enum
3
+
4
+ class ColorName
5
+ MAROON = "maroon"
6
+ RED = "red"
7
+ ORANGE = "orange"
8
+ YELLOW = "yellow"
9
+ OLIVE = "olive"
10
+ PURPLE = "purple"
11
+ FUCHSIA = "fuchsia"
12
+ WHITE = "white"
13
+ LIME = "lime"
14
+ GREEN = "green"
15
+ NAVY = "navy"
16
+ AQUA = "aqua"
17
+ TEAL = "teal"
18
+ BLACK = "black"
19
+ SILVER = "silver"
20
+ GRAY = "gray"
21
+ BLUE = "blue"
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,9 @@
1
+ module RXaal
2
+ module Enum
3
+ class OffsetMode
4
+ CENTER = "center"
5
+ START = "start"
6
+ END_MODE = "end"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module RXaal
2
+ module Enum
3
+ class StrokeType
4
+ SOLID = "solid"
5
+ DOTTED = "dotted"
6
+ DASHED = "dashed"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module RXaal
2
+ module Enum
3
+ class TextAlignment
4
+ LEFT = "left"
5
+ RIGHT = "right"
6
+ CENTERED = "centered"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,25 @@
1
+ module RXaal
2
+ class Font < XaalElement
3
+ attr_accessor_of_class Integer, :size
4
+ attr_accessor_of_class String, :family
5
+
6
+ def initialize (doc, id = nil)
7
+ super(doc, id, elem_ns)
8
+ end
9
+
10
+ def xaal_serialize(parent)
11
+ if size != nil || family!= nil
12
+ font = Element.new "font"
13
+ if @size != nil
14
+ font.attributes["size"] = @size
15
+ end
16
+ if @family != nil
17
+ font.attributes["family"] = @family
18
+ end
19
+ font.attributes["id"] = @id
20
+ parent.elements << font
21
+ end
22
+ end
23
+
24
+ end
25
+ end