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
@@ -0,0 +1,7 @@
1
+ module RXaal
2
+ class GenericColor
3
+ include Serializable
4
+
5
+
6
+ end
7
+ end
@@ -0,0 +1,25 @@
1
+ require "rexml/element"
2
+ require 'xaal_element'
3
+
4
+ module RXaal
5
+ class GraphicPrim < XaalElement
6
+
7
+ attr_accessor_of_boolean :hidden
8
+
9
+ attr_accessor_of_class Float, :opacity
10
+ attr_accessor_of_class Style, :style
11
+
12
+ def initialize(doc, id = nil, elem_ns=nil)
13
+ super(doc, id, elem_ns)
14
+ end
15
+
16
+ def superclass_serialize(element)
17
+ super(element)
18
+ element.attributes["hidden"] = hidden.to_s
19
+ element.attributes["opacity"] = opacity
20
+ style.xaal_serialize(element)
21
+
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,9 @@
1
+
2
+ module RXaal
3
+ class Line < GraphicPrim
4
+
5
+ def initialize
6
+ super
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,78 @@
1
+ require "rexml/element"
2
+ module RXaal
3
+ class Metadata < TopLevelElem
4
+ include MetadataMod
5
+ @@DEFAULT_LANG = "en-us"
6
+
7
+ def initialize(doc)
8
+ super(doc)
9
+ @@DEFAULT_LANG.freeze
10
+ @titles = Hash.new
11
+ @subjects = Hash.new
12
+ @keywords = Hash.new
13
+ @descs = Hash.new
14
+ @serialize = false
15
+ end
16
+
17
+ serialize_accessor_of_class String, :auth_fname, :auth_lname, :auth_affil, :auth_email,
18
+ :app_name, :app_version
19
+
20
+ # we check if its actually a uri
21
+ attr_reader :app_homepage
22
+
23
+ def app_homepage=(uri)
24
+ if uri =~ /(^$)|(^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$)/ix
25
+ @app_homepage = uri
26
+ @serialize = true
27
+ end
28
+ end
29
+
30
+ def add_title(subject)
31
+ add_title(title, @@DEFAULT_LANG)
32
+ end
33
+
34
+ def add_title(title, lang)
35
+ @titles[lang] = title
36
+ @serialize = true
37
+ end
38
+
39
+ def add_subject(subject)
40
+ add_subject(subject, @@DEFAULT_LANG)
41
+ end
42
+
43
+ def add_subject(title, lang)
44
+ @subjects[lang] = subject
45
+ @serialize = true
46
+ end
47
+
48
+ def add_keyword(keyword)
49
+ add_keyword(keyword, @@DEFAULT_LANG)
50
+ end
51
+
52
+ def add_keyword(title, lang)
53
+ @keywords[lang] = keyword
54
+ @serialize = true
55
+ end
56
+
57
+ def add_desc(desc)
58
+ add_desc(desc, @@DEFAULT_LANG)
59
+ end
60
+
61
+ def add_desc(title, lang)
62
+ @descs[lang] = desc
63
+ @serialize = true
64
+ end
65
+
66
+ def xaal_serialize(parent)
67
+ if (serialize?)
68
+ metadata = Element.new "metadata"
69
+ parent.add metadata
70
+ end
71
+ end
72
+
73
+ private
74
+ def serialize?
75
+ return @serialize
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,34 @@
1
+ module RXaal
2
+ module MetadataMod
3
+ def self.included(base)
4
+ base.extend(ClassMethods)
5
+ end
6
+ module ClassMethods
7
+ def serialize_accessor(sym)
8
+ define_method(sym) do
9
+ instance_variable_get("@#{sym}")
10
+ end
11
+
12
+ define_method("#{sym}=") do |v|
13
+ instance_variable_set("@#{sym}", v)
14
+ instance_variable_set("@serialize", true)
15
+ end
16
+ end
17
+
18
+ def serialize_accessor_of_class(klass, *syms)
19
+ syms.each { |sym|
20
+ define_method(sym) do
21
+ instance_variable_get("@#{sym}")
22
+ end
23
+
24
+ define_method("#{sym}=") do |v|
25
+ if v.class == klass
26
+ instance_variable_set("@#{sym}", v)
27
+ instance_variable_set("@serialize", true)
28
+ end
29
+ end
30
+ }
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,16 @@
1
+ require "generic_color"
2
+ module RXaal
3
+ class NamedColor < GenericColor
4
+ attr_accessor_of_class String, :name
5
+ def initialize(_name)
6
+ super()
7
+ @name = _name
8
+ end
9
+ #must be style object
10
+ def xaal_serialize(parent)
11
+ elem = Element.new "color"
12
+ elem.attributes["name"] = @name
13
+ parent.elements << elem
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ require 'graphic_prim'
2
+ class NodePrim < GraphicPrim
3
+ attr_reader :coordinates
4
+ def initialize(doc, id = nil, elem_ns=nil)
5
+ super(doc, id, elem_ns)
6
+ @coordinates = BoundArray.new(Coordinate)
7
+ end
8
+
9
+ def superclass_serialize(element)
10
+ super(element)
11
+ coordinates.each {|c|
12
+ c.xaal_serialize(element)
13
+ }
14
+ end
15
+ end
@@ -0,0 +1,30 @@
1
+ require "xaalns"
2
+ module RXaal
3
+ class NSContainer
4
+ include Enumerable
5
+
6
+ attr_reader :namespaces, :name_to_ns, :uri_to_ns
7
+
8
+ def initialize
9
+ @namespaces = Array.new
10
+ @name_to_ns = Hash.new
11
+ @uri_to_ns = Hash.new
12
+ end
13
+
14
+ def add_ns (uri, prefix="")
15
+ ns = XaalNS.new(uri, prefix)
16
+ if @uri_to_ns[uri] != nil
17
+ namespaces = @namespaces.collect { |i| i != @uri_to_ns[uri]}
18
+ @namespaces = namespaces
19
+ end
20
+ @namespaces.push(ns)
21
+ @uri_to_ns[uri] = ns
22
+ @name_to_ns[prefix] = ns
23
+ return ns
24
+ end
25
+
26
+ def each
27
+ self.namespaces.each {|n| yield n}
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,63 @@
1
+ require "enum/offset_mode"
2
+ require "enum/anchor"
3
+ require "r_xaal_error"
4
+ require "xaal_element"
5
+
6
+ module RXaal
7
+ class Offset < XaalElement
8
+ attr_accessor_of_class Integer, :x, :y
9
+ attr_reader :no_base_object
10
+ attr_reader :base_object, :node, :base_location, :baseline_of
11
+
12
+ def initialize
13
+ super
14
+ @mode = Enum::OffsetMode::CENTER
15
+ @anchor = Enum::Anchor::C
16
+ @no_base_object = true
17
+ end
18
+
19
+ def no_base_object=(n)
20
+ @no_base_object = true
21
+
22
+ end
23
+
24
+ def base_object=(n)
25
+
26
+ end
27
+
28
+ def node=(n)
29
+ reset_base false
30
+ @node = n
31
+ end
32
+
33
+ def base_location=(n)
34
+ if (n.class != RXaal::Coordinate)
35
+ raise RXaalError("'n' was not of the type RXaal::Coordinate")
36
+ end
37
+ reset_base
38
+ @base_location = n
39
+ end
40
+
41
+ def baseline_of=(n)
42
+ if n.class != RXaal::Text
43
+ raise RXaalError("'n' was not of the type RXaal::Text")
44
+ end
45
+ reset_base
46
+ @baseline_of = n
47
+ end
48
+
49
+
50
+ private
51
+
52
+ def reset_base(include_base_obj = true)
53
+ if (include_base_obj)
54
+ @base_object = nil
55
+ end
56
+ @base_location = nil
57
+ @baseline_of = nil
58
+ @node = nil
59
+ end
60
+
61
+
62
+ end
63
+ end
@@ -0,0 +1,5 @@
1
+ module RXaal
2
+ class Operation < XaalElement
3
+
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ module RXaal
2
+ class Par < XaalElement
3
+ attr_reader :show, :hide
4
+ #attr_accessor_of_class :change_style
5
+
6
+ def initialize(doc)
7
+ super(doc)
8
+ @show = ShowHide.new(true)
9
+ @hide = ShowHide.new(false)
10
+ end
11
+
12
+ def xaal_serialize(parent)
13
+ e = Element.new "par"
14
+ parent << e
15
+ [:show, :hide].each {|sh|
16
+ temp = self.send(sh)
17
+ if temp.length > 0
18
+ temp.xaal_serialize(e)
19
+ end
20
+ }
21
+
22
+ superclass_serialize(e)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,2 @@
1
+ class ParContainer
2
+ end
@@ -0,0 +1,8 @@
1
+ require 'graphic_prim'
2
+ module RXaal
3
+ class Point < GraphicPrim
4
+ def initialize
5
+ super
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,22 @@
1
+ require "polyline"
2
+
3
+ module RXaal
4
+ class Polygon < Polyline
5
+
6
+ def initialize
7
+ super
8
+ self.closed=true
9
+ end
10
+
11
+ def closed
12
+ super
13
+ end
14
+
15
+ private
16
+
17
+
18
+ def closed=(new_value)
19
+ super
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,29 @@
1
+ require 'node_prim'
2
+ module RXaal
3
+ class Polyline < NodePrim
4
+ attr_accessor_of_class Integer, :depth
5
+ attr_accessor_of_boolean :closed
6
+
7
+ def initialize(doc, id = nil, elem_ns=nil)
8
+ super(doc, id, elem_ns)
9
+ end
10
+
11
+ def xaal_serialize(parent)
12
+ polyline = Element.new "polyline"
13
+ parent.elements << polyline
14
+ superclass_serialize(polyline)
15
+
16
+ if @depth != nil
17
+ depth_e = Element.new "depth"
18
+ depth_e.text = depth
19
+ polyline << depth_e
20
+ end
21
+
22
+ if @closed != nil
23
+ closed_e = Element.new "closed"
24
+ closed_e.text = closed
25
+ polyline.elements << closed_e
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,24 @@
1
+ require "rxaal"
2
+ include RXaal
3
+ doc = XaalDoc.new
4
+
5
+ inits = doc.initials
6
+
7
+ pl = Polyline.new(doc)
8
+ doc.initials << pl
9
+
10
+ pl.coordinates << Coordinate.new(doc, 0, 0) << Coordinate.new(doc, 50, 50)
11
+ pl.style = Style.new(doc)
12
+
13
+ pl.style.color = NamedColor.new(Enum::ColorName::RED)
14
+ pl.hidden = true
15
+ seq1 = Seq.new(doc)
16
+ doc.seqs << seq1
17
+ par1 = Par.new(doc)
18
+ seq1.pars << par1
19
+ par1.show << pl
20
+ par1.show.type = "selected"
21
+
22
+ str = doc.xaal_serialize
23
+
24
+ puts str
@@ -0,0 +1,2 @@
1
+ class RXaalError < StandardError
2
+ end
@@ -0,0 +1,5 @@
1
+ require 'rexml/element'
2
+ module RXaal
3
+ class RXaalObject
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module RXaal
2
+ class Radius < Center
3
+ attr_accessor_of_class Integer, :length
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ module RXaal
2
+ class Rectangle < GraphicPrim
3
+ attr_accessor_of_class Integer, :round_x, :round_y, :depth
4
+ attr_accessor_of_class Coordinate, :coor1, :coor2
5
+
6
+ def initialize
7
+ super
8
+ end
9
+ end
10
+ end