esod-client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. data/EXAMPLES +140 -0
  2. data/GEM_RELEASE +19 -0
  3. data/README +10 -0
  4. data/Rakefile +14 -0
  5. data/VERSION +1 -0
  6. data/esod-client.gemspec +118 -0
  7. data/esod-client.rb +35 -0
  8. data/lib/activesupport-2.2.2/CHANGELOG +1257 -0
  9. data/lib/activesupport-2.2.2/README +43 -0
  10. data/lib/activesupport-2.2.2/README.CFT +2 -0
  11. data/lib/activesupport-2.2.2/lib/active_support.rb +26 -0
  12. data/lib/activesupport-2.2.2/lib/active_support/base64.rb +33 -0
  13. data/lib/activesupport-2.2.2/lib/active_support/basic_object.rb +24 -0
  14. data/lib/activesupport-2.2.2/lib/active_support/buffered_logger.rb +122 -0
  15. data/lib/activesupport-2.2.2/lib/active_support/cache.rb +223 -0
  16. data/lib/activesupport-2.2.2/lib/active_support/cache/compressed_mem_cache_store.rb +20 -0
  17. data/lib/activesupport-2.2.2/lib/active_support/cache/drb_store.rb +15 -0
  18. data/lib/activesupport-2.2.2/lib/active_support/cache/file_store.rb +72 -0
  19. data/lib/activesupport-2.2.2/lib/active_support/cache/mem_cache_store.rb +127 -0
  20. data/lib/activesupport-2.2.2/lib/active_support/cache/memory_store.rb +52 -0
  21. data/lib/activesupport-2.2.2/lib/active_support/cache/synchronized_memory_store.rb +47 -0
  22. data/lib/activesupport-2.2.2/lib/active_support/callbacks.rb +280 -0
  23. data/lib/activesupport-2.2.2/lib/active_support/core_ext.rb +6 -0
  24. data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash.rb +14 -0
  25. data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/conversions.rb +259 -0
  26. data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/deep_merge.rb +23 -0
  27. data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/diff.rb +19 -0
  28. data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/except.rb +25 -0
  29. data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/indifferent_access.rb +137 -0
  30. data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/keys.rb +52 -0
  31. data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/reverse_merge.rb +35 -0
  32. data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/slice.rb +33 -0
  33. data/lib/activesupport-2.2.2/lib/active_support/vendor.rb +14 -0
  34. data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/blankslate.rb +113 -0
  35. data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder.rb +13 -0
  36. data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder/blankslate.rb +20 -0
  37. data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder/css.rb +250 -0
  38. data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder/xchar.rb +115 -0
  39. data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder/xmlbase.rb +139 -0
  40. data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder/xmlevents.rb +63 -0
  41. data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder/xmlmarkup.rb +328 -0
  42. data/lib/activesupport-2.2.2/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb +1021 -0
  43. data/lib/activesupport-2.2.2/lib/activesupport.rb +1 -0
  44. data/lib/esodclient/esodclient.rb +22 -0
  45. data/lib/hash.rb +22 -0
  46. data/lib/mime-types-1.16/History.txt +107 -0
  47. data/lib/mime-types-1.16/Install.txt +17 -0
  48. data/lib/mime-types-1.16/Licence.txt +15 -0
  49. data/lib/mime-types-1.16/Manifest.txt +12 -0
  50. data/lib/mime-types-1.16/README.txt +28 -0
  51. data/lib/mime-types-1.16/Rakefile +316 -0
  52. data/lib/mime-types-1.16/lib/mime/types.rb +751 -0
  53. data/lib/mime-types-1.16/lib/mime/types.rb.data +1324 -0
  54. data/lib/mime-types-1.16/mime-types.gemspec +43 -0
  55. data/lib/mime-types-1.16/setup.rb +1585 -0
  56. data/lib/mime-types-1.16/test/test_mime_type.rb +356 -0
  57. data/lib/mime-types-1.16/test/test_mime_types.rb +122 -0
  58. data/lib/rest-client-1.2.0/README.rdoc +102 -0
  59. data/lib/rest-client-1.2.0/Rakefile +57 -0
  60. data/lib/rest-client-1.2.0/VERSION +1 -0
  61. data/lib/rest-client-1.2.0/bin/restclient +87 -0
  62. data/lib/rest-client-1.2.0/lib/rest_client.rb +2 -0
  63. data/lib/rest-client-1.2.0/lib/restclient.rb +108 -0
  64. data/lib/rest-client-1.2.0/lib/restclient/exceptions.rb +89 -0
  65. data/lib/rest-client-1.2.0/lib/restclient/mixin/response.rb +48 -0
  66. data/lib/rest-client-1.2.0/lib/restclient/net_http_ext.rb +21 -0
  67. data/lib/rest-client-1.2.0/lib/restclient/payload.rb +178 -0
  68. data/lib/rest-client-1.2.0/lib/restclient/raw_response.rb +30 -0
  69. data/lib/rest-client-1.2.0/lib/restclient/request.rb +287 -0
  70. data/lib/rest-client-1.2.0/lib/restclient/resource.rb +146 -0
  71. data/lib/rest-client-1.2.0/lib/restclient/response.rb +20 -0
  72. data/lib/rest-client-1.2.0/spec/base.rb +10 -0
  73. data/lib/rest-client-1.2.0/spec/exceptions_spec.rb +65 -0
  74. data/lib/rest-client-1.2.0/spec/master_shake.jpg +0 -0
  75. data/lib/rest-client-1.2.0/spec/mixin/response_spec.rb +46 -0
  76. data/lib/rest-client-1.2.0/spec/payload_spec.rb +131 -0
  77. data/lib/rest-client-1.2.0/spec/raw_response_spec.rb +17 -0
  78. data/lib/rest-client-1.2.0/spec/request_spec.rb +521 -0
  79. data/lib/rest-client-1.2.0/spec/resource_spec.rb +75 -0
  80. data/lib/rest-client-1.2.0/spec/response_spec.rb +21 -0
  81. data/lib/rest-client-1.2.0/spec/restclient_spec.rb +53 -0
  82. data/lib/trollop/trollop.rb +735 -0
  83. metadata +137 -0
@@ -0,0 +1,115 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # The XChar library is provided courtesy of Sam Ruby (See
4
+ # http://intertwingly.net/stories/2005/09/28/xchar.rb)
5
+
6
+ # --------------------------------------------------------------------
7
+
8
+ # If the Builder::XChar module is not currently defined, fail on any
9
+ # name clashes in standard library classes.
10
+
11
+ module Builder
12
+ def self.check_for_name_collision(klass, method_name, defined_constant=nil)
13
+ if klass.instance_methods.include?(method_name.to_s)
14
+ fail RuntimeError,
15
+ "Name Collision: Method '#{method_name}' is already defined in #{klass}"
16
+ end
17
+ end
18
+ end
19
+
20
+ if ! defined?(Builder::XChar)
21
+ Builder.check_for_name_collision(String, "to_xs")
22
+ Builder.check_for_name_collision(Fixnum, "xchr")
23
+ end
24
+
25
+ ######################################################################
26
+ module Builder
27
+
28
+ ####################################################################
29
+ # XML Character converter, from Sam Ruby:
30
+ # (see http://intertwingly.net/stories/2005/09/28/xchar.rb).
31
+ #
32
+ module XChar # :nodoc:
33
+
34
+ # See
35
+ # http://intertwingly.net/stories/2004/04/14/i18n.html#CleaningWindows
36
+ # for details.
37
+ CP1252 = { # :nodoc:
38
+ 128 => 8364, # euro sign
39
+ 130 => 8218, # single low-9 quotation mark
40
+ 131 => 402, # latin small letter f with hook
41
+ 132 => 8222, # double low-9 quotation mark
42
+ 133 => 8230, # horizontal ellipsis
43
+ 134 => 8224, # dagger
44
+ 135 => 8225, # double dagger
45
+ 136 => 710, # modifier letter circumflex accent
46
+ 137 => 8240, # per mille sign
47
+ 138 => 352, # latin capital letter s with caron
48
+ 139 => 8249, # single left-pointing angle quotation mark
49
+ 140 => 338, # latin capital ligature oe
50
+ 142 => 381, # latin capital letter z with caron
51
+ 145 => 8216, # left single quotation mark
52
+ 146 => 8217, # right single quotation mark
53
+ 147 => 8220, # left double quotation mark
54
+ 148 => 8221, # right double quotation mark
55
+ 149 => 8226, # bullet
56
+ 150 => 8211, # en dash
57
+ 151 => 8212, # em dash
58
+ 152 => 732, # small tilde
59
+ 153 => 8482, # trade mark sign
60
+ 154 => 353, # latin small letter s with caron
61
+ 155 => 8250, # single right-pointing angle quotation mark
62
+ 156 => 339, # latin small ligature oe
63
+ 158 => 382, # latin small letter z with caron
64
+ 159 => 376, # latin capital letter y with diaeresis
65
+ }
66
+
67
+ # See http://www.w3.org/TR/REC-xml/#dt-chardata for details.
68
+ PREDEFINED = {
69
+ 38 => '&', # ampersand
70
+ 60 => '<', # left angle bracket
71
+ 62 => '>', # right angle bracket
72
+ }
73
+
74
+ # See http://www.w3.org/TR/REC-xml/#charsets for details.
75
+ VALID = [
76
+ 0x9, 0xA, 0xD,
77
+ (0x20..0xD7FF),
78
+ (0xE000..0xFFFD),
79
+ (0x10000..0x10FFFF)
80
+ ]
81
+ end
82
+
83
+ end
84
+
85
+
86
+ ######################################################################
87
+ # Enhance the Fixnum class with a XML escaped character conversion.
88
+ #
89
+ class Fixnum
90
+ XChar = Builder::XChar if ! defined?(XChar)
91
+
92
+ # XML escaped version of chr
93
+ def xchr
94
+ n = XChar::CP1252[self] || self
95
+ case n when *XChar::VALID
96
+ XChar::PREDEFINED[n] or (n<128 ? n.chr : "&##{n};")
97
+ else
98
+ '*'
99
+ end
100
+ end
101
+ end
102
+
103
+
104
+ ######################################################################
105
+ # Enhance the String class with a XML escaped character version of
106
+ # to_s.
107
+ #
108
+ class String
109
+ # XML escaped version of to_s
110
+ def to_xs
111
+ unpack('U*').map {|n| n.xchr}.join # ASCII, UTF-8
112
+ rescue
113
+ unpack('C*').map {|n| n.xchr}.join # ISO-8859-1, WIN-1252
114
+ end
115
+ end
@@ -0,0 +1,139 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'builder/blankslate'
4
+
5
+ module Builder
6
+
7
+ # Generic error for builder
8
+ class IllegalBlockError < RuntimeError; end
9
+
10
+ # XmlBase is a base class for building XML builders. See
11
+ # Builder::XmlMarkup and Builder::XmlEvents for examples.
12
+ class XmlBase < BlankSlate
13
+
14
+ # Create an XML markup builder.
15
+ #
16
+ # out:: Object receiving the markup. +out+ must respond to
17
+ # <tt><<</tt>.
18
+ # indent:: Number of spaces used for indentation (0 implies no
19
+ # indentation and no line breaks).
20
+ # initial:: Level of initial indentation.
21
+ #
22
+ def initialize(indent=0, initial=0)
23
+ @indent = indent
24
+ @level = initial
25
+ end
26
+
27
+ # Create a tag named +sym+. Other than the first argument which
28
+ # is the tag name, the arguments are the same as the tags
29
+ # implemented via <tt>method_missing</tt>.
30
+ def tag!(sym, *args, &block)
31
+ method_missing(sym.to_sym, *args, &block)
32
+ end
33
+
34
+ # Create XML markup based on the name of the method. This method
35
+ # is never invoked directly, but is called for each markup method
36
+ # in the markup block.
37
+ def method_missing(sym, *args, &block)
38
+ text = nil
39
+ attrs = nil
40
+ sym = "#{sym}:#{args.shift}" if args.first.kind_of?(Symbol)
41
+ args.each do |arg|
42
+ case arg
43
+ when Hash
44
+ attrs ||= {}
45
+ attrs.merge!(arg)
46
+ else
47
+ text ||= ''
48
+ text << arg.to_s
49
+ end
50
+ end
51
+ if block
52
+ unless text.nil?
53
+ raise ArgumentError, "XmlMarkup cannot mix a text argument with a block"
54
+ end
55
+ _indent
56
+ _start_tag(sym, attrs)
57
+ _newline
58
+ _nested_structures(block)
59
+ _indent
60
+ _end_tag(sym)
61
+ _newline
62
+ elsif text.nil?
63
+ _indent
64
+ _start_tag(sym, attrs, true)
65
+ _newline
66
+ else
67
+ _indent
68
+ _start_tag(sym, attrs)
69
+ text! text
70
+ _end_tag(sym)
71
+ _newline
72
+ end
73
+ @target
74
+ end
75
+
76
+ # Append text to the output target. Escape any markup. May be
77
+ # used within the markup brackets as:
78
+ #
79
+ # builder.p { |b| b.br; b.text! "HI" } #=> <p><br/>HI</p>
80
+ def text!(text)
81
+ _text(_escape(text))
82
+ end
83
+
84
+ # Append text to the output target without escaping any markup.
85
+ # May be used within the markup brackets as:
86
+ #
87
+ # builder.p { |x| x << "<br/>HI" } #=> <p><br/>HI</p>
88
+ #
89
+ # This is useful when using non-builder enabled software that
90
+ # generates strings. Just insert the string directly into the
91
+ # builder without changing the inserted markup.
92
+ #
93
+ # It is also useful for stacking builder objects. Builders only
94
+ # use <tt><<</tt> to append to the target, so by supporting this
95
+ # method/operation builders can use other builders as their
96
+ # targets.
97
+ def <<(text)
98
+ _text(text)
99
+ end
100
+
101
+ # For some reason, nil? is sent to the XmlMarkup object. If nil?
102
+ # is not defined and method_missing is invoked, some strange kind
103
+ # of recursion happens. Since nil? won't ever be an XML tag, it
104
+ # is pretty safe to define it here. (Note: this is an example of
105
+ # cargo cult programming,
106
+ # cf. http://fishbowl.pastiche.org/2004/10/13/cargo_cult_programming).
107
+ def nil?
108
+ false
109
+ end
110
+
111
+ private
112
+
113
+ require 'builder/xchar'
114
+ def _escape(text)
115
+ text.to_xs
116
+ end
117
+
118
+ def _escape_quote(text)
119
+ _escape(text).gsub(%r{"}, '&quot;') # " WART
120
+ end
121
+
122
+ def _newline
123
+ return if @indent == 0
124
+ text! "\n"
125
+ end
126
+
127
+ def _indent
128
+ return if @indent == 0 || @level == 0
129
+ text!(" " * (@level * @indent))
130
+ end
131
+
132
+ def _nested_structures(block)
133
+ @level += 1
134
+ block.call(self)
135
+ ensure
136
+ @level -= 1
137
+ end
138
+ end
139
+ end
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #--
4
+ # Copyright 2004 by Jim Weirich (jim@weirichhouse.org).
5
+ # All rights reserved.
6
+
7
+ # Permission is granted for use, copying, modification, distribution,
8
+ # and distribution of modified versions of this work as long as the
9
+ # above copyright notice is included.
10
+ #++
11
+
12
+ require 'builder/xmlmarkup'
13
+
14
+ module Builder
15
+
16
+ # Create a series of SAX-like XML events (e.g. start_tag, end_tag)
17
+ # from the markup code. XmlEvent objects are used in a way similar
18
+ # to XmlMarkup objects, except that a series of events are generated
19
+ # and passed to a handler rather than generating character-based
20
+ # markup.
21
+ #
22
+ # Usage:
23
+ # xe = Builder::XmlEvents.new(handler)
24
+ # xe.title("HI") # Sends start_tag/end_tag/text messages to the handler.
25
+ #
26
+ # Indentation may also be selected by providing value for the
27
+ # indentation size and initial indentation level.
28
+ #
29
+ # xe = Builder::XmlEvents.new(handler, indent_size, initial_indent_level)
30
+ #
31
+ # == XML Event Handler
32
+ #
33
+ # The handler object must expect the following events.
34
+ #
35
+ # [<tt>start_tag(tag, attrs)</tt>]
36
+ # Announces that a new tag has been found. +tag+ is the name of
37
+ # the tag and +attrs+ is a hash of attributes for the tag.
38
+ #
39
+ # [<tt>end_tag(tag)</tt>]
40
+ # Announces that an end tag for +tag+ has been found.
41
+ #
42
+ # [<tt>text(text)</tt>]
43
+ # Announces that a string of characters (+text+) has been found.
44
+ # A series of characters may be broken up into more than one
45
+ # +text+ call, so the client cannot assume that a single
46
+ # callback contains all the text data.
47
+ #
48
+ class XmlEvents < XmlMarkup
49
+ def text!(text)
50
+ @target.text(text)
51
+ end
52
+
53
+ def _start_tag(sym, attrs, end_too=false)
54
+ @target.start_tag(sym, attrs)
55
+ _end_tag(sym) if end_too
56
+ end
57
+
58
+ def _end_tag(sym)
59
+ @target.end_tag(sym)
60
+ end
61
+ end
62
+
63
+ end
@@ -0,0 +1,328 @@
1
+ #!/usr/bin/env ruby
2
+ #--
3
+ # Copyright 2004, 2005 by Jim Weirich (jim@weirichhouse.org).
4
+ # All rights reserved.
5
+
6
+ # Permission is granted for use, copying, modification, distribution,
7
+ # and distribution of modified versions of this work as long as the
8
+ # above copyright notice is included.
9
+ #++
10
+
11
+ # Provide a flexible and easy to use Builder for creating XML markup.
12
+ # See XmlBuilder for usage details.
13
+
14
+ require 'builder/xmlbase'
15
+
16
+ module Builder
17
+
18
+ # Create XML markup easily. All (well, almost all) methods sent to
19
+ # an XmlMarkup object will be translated to the equivalent XML
20
+ # markup. Any method with a block will be treated as an XML markup
21
+ # tag with nested markup in the block.
22
+ #
23
+ # Examples will demonstrate this easier than words. In the
24
+ # following, +xm+ is an +XmlMarkup+ object.
25
+ #
26
+ # xm.em("emphasized") # => <em>emphasized</em>
27
+ # xm.em { xmm.b("emp & bold") } # => <em><b>emph &amp; bold</b></em>
28
+ # xm.a("A Link", "href"=>"http://onestepback.org")
29
+ # # => <a href="http://onestepback.org">A Link</a>
30
+ # xm.div { br } # => <div><br/></div>
31
+ # xm.target("name"=>"compile", "option"=>"fast")
32
+ # # => <target option="fast" name="compile"\>
33
+ # # NOTE: order of attributes is not specified.
34
+ #
35
+ # xm.instruct! # <?xml version="1.0" encoding="UTF-8"?>
36
+ # xm.html { # <html>
37
+ # xm.head { # <head>
38
+ # xm.title("History") # <title>History</title>
39
+ # } # </head>
40
+ # xm.body { # <body>
41
+ # xm.comment! "HI" # <! -- HI -->
42
+ # xm.h1("Header") # <h1>Header</h1>
43
+ # xm.p("paragraph") # <p>paragraph</p>
44
+ # } # </body>
45
+ # } # </html>
46
+ #
47
+ # == Notes:
48
+ #
49
+ # * The order that attributes are inserted in markup tags is
50
+ # undefined.
51
+ #
52
+ # * Sometimes you wish to insert text without enclosing tags. Use
53
+ # the <tt>text!</tt> method to accomplish this.
54
+ #
55
+ # Example:
56
+ #
57
+ # xm.div { # <div>
58
+ # xm.text! "line"; xm.br # line<br/>
59
+ # xm.text! "another line"; xmbr # another line<br/>
60
+ # } # </div>
61
+ #
62
+ # * The special XML characters <, >, and & are converted to &lt;,
63
+ # &gt; and &amp; automatically. Use the <tt><<</tt> operation to
64
+ # insert text without modification.
65
+ #
66
+ # * Sometimes tags use special characters not allowed in ruby
67
+ # identifiers. Use the <tt>tag!</tt> method to handle these
68
+ # cases.
69
+ #
70
+ # Example:
71
+ #
72
+ # xml.tag!("SOAP:Envelope") { ... }
73
+ #
74
+ # will produce ...
75
+ #
76
+ # <SOAP:Envelope> ... </SOAP:Envelope>"
77
+ #
78
+ # <tt>tag!</tt> will also take text and attribute arguments (after
79
+ # the tag name) like normal markup methods. (But see the next
80
+ # bullet item for a better way to handle XML namespaces).
81
+ #
82
+ # * Direct support for XML namespaces is now available. If the
83
+ # first argument to a tag call is a symbol, it will be joined to
84
+ # the tag to produce a namespace:tag combination. It is easier to
85
+ # show this than describe it.
86
+ #
87
+ # xml.SOAP :Envelope do ... end
88
+ #
89
+ # Just put a space before the colon in a namespace to produce the
90
+ # right form for builder (e.g. "<tt>SOAP:Envelope</tt>" =>
91
+ # "<tt>xml.SOAP :Envelope</tt>")
92
+ #
93
+ # * XmlMarkup builds the markup in any object (called a _target_)
94
+ # that accepts the <tt><<</tt> method. If no target is given,
95
+ # then XmlMarkup defaults to a string target.
96
+ #
97
+ # Examples:
98
+ #
99
+ # xm = Builder::XmlMarkup.new
100
+ # result = xm.title("yada")
101
+ # # result is a string containing the markup.
102
+ #
103
+ # buffer = ""
104
+ # xm = Builder::XmlMarkup.new(buffer)
105
+ # # The markup is appended to buffer (using <<)
106
+ #
107
+ # xm = Builder::XmlMarkup.new(STDOUT)
108
+ # # The markup is written to STDOUT (using <<)
109
+ #
110
+ # xm = Builder::XmlMarkup.new
111
+ # x2 = Builder::XmlMarkup.new(:target=>xm)
112
+ # # Markup written to +x2+ will be send to +xm+.
113
+ #
114
+ # * Indentation is enabled by providing the number of spaces to
115
+ # indent for each level as a second argument to XmlBuilder.new.
116
+ # Initial indentation may be specified using a third parameter.
117
+ #
118
+ # Example:
119
+ #
120
+ # xm = Builder.new(:indent=>2)
121
+ # # xm will produce nicely formatted and indented XML.
122
+ #
123
+ # xm = Builder.new(:indent=>2, :margin=>4)
124
+ # # xm will produce nicely formatted and indented XML with 2
125
+ # # spaces per indent and an over all indentation level of 4.
126
+ #
127
+ # builder = Builder::XmlMarkup.new(:target=>$stdout, :indent=>2)
128
+ # builder.name { |b| b.first("Jim"); b.last("Weirich) }
129
+ # # prints:
130
+ # # <name>
131
+ # # <first>Jim</first>
132
+ # # <last>Weirich</last>
133
+ # # </name>
134
+ #
135
+ # * The instance_eval implementation which forces self to refer to
136
+ # the message receiver as self is now obsolete. We now use normal
137
+ # block calls to execute the markup block. This means that all
138
+ # markup methods must now be explicitly send to the xml builder.
139
+ # For instance, instead of
140
+ #
141
+ # xml.div { strong("text") }
142
+ #
143
+ # you need to write:
144
+ #
145
+ # xml.div { xml.strong("text") }
146
+ #
147
+ # Although more verbose, the subtle change in semantics within the
148
+ # block was found to be prone to error. To make this change a
149
+ # little less cumbersome, the markup block now gets the markup
150
+ # object sent as an argument, allowing you to use a shorter alias
151
+ # within the block.
152
+ #
153
+ # For example:
154
+ #
155
+ # xml_builder = Builder::XmlMarkup.new
156
+ # xml_builder.div { |xml|
157
+ # xml.stong("text")
158
+ # }
159
+ #
160
+ class XmlMarkup < XmlBase
161
+
162
+ # Create an XML markup builder. Parameters are specified by an
163
+ # option hash.
164
+ #
165
+ # :target=><em>target_object</em>::
166
+ # Object receiving the markup. +out+ must respond to the
167
+ # <tt><<</tt> operator. The default is a plain string target.
168
+ #
169
+ # :indent=><em>indentation</em>::
170
+ # Number of spaces used for indentation. The default is no
171
+ # indentation and no line breaks.
172
+ #
173
+ # :margin=><em>initial_indentation_level</em>::
174
+ # Amount of initial indentation (specified in levels, not
175
+ # spaces).
176
+ #
177
+ # :escape_attrs=><b>OBSOLETE</em>::
178
+ # The :escape_attrs option is no longer supported by builder
179
+ # (and will be quietly ignored). String attribute values are
180
+ # now automatically escaped. If you need unescaped attribute
181
+ # values (perhaps you are using entities in the attribute
182
+ # values), then give the value as a Symbol. This allows much
183
+ # finer control over escaping attribute values.
184
+ #
185
+ def initialize(options={})
186
+ indent = options[:indent] || 0
187
+ margin = options[:margin] || 0
188
+ super(indent, margin)
189
+ @target = options[:target] || ""
190
+ end
191
+
192
+ # Return the target of the builder.
193
+ def target!
194
+ @target
195
+ end
196
+
197
+ def comment!(comment_text)
198
+ _ensure_no_block block_given?
199
+ _special("<!-- ", " -->", comment_text, nil)
200
+ end
201
+
202
+ # Insert an XML declaration into the XML markup.
203
+ #
204
+ # For example:
205
+ #
206
+ # xml.declare! :ELEMENT, :blah, "yada"
207
+ # # => <!ELEMENT blah "yada">
208
+ def declare!(inst, *args, &block)
209
+ _indent
210
+ @target << "<!#{inst}"
211
+ args.each do |arg|
212
+ case arg
213
+ when String
214
+ @target << %{ "#{arg}"} # " WART
215
+ when Symbol
216
+ @target << " #{arg}"
217
+ end
218
+ end
219
+ if block_given?
220
+ @target << " ["
221
+ _newline
222
+ _nested_structures(block)
223
+ @target << "]"
224
+ end
225
+ @target << ">"
226
+ _newline
227
+ end
228
+
229
+ # Insert a processing instruction into the XML markup. E.g.
230
+ #
231
+ # For example:
232
+ #
233
+ # xml.instruct!
234
+ # #=> <?xml version="1.0" encoding="UTF-8"?>
235
+ # xml.instruct! :aaa, :bbb=>"ccc"
236
+ # #=> <?aaa bbb="ccc"?>
237
+ #
238
+ def instruct!(directive_tag=:xml, attrs={})
239
+ _ensure_no_block block_given?
240
+ if directive_tag == :xml
241
+ a = { :version=>"1.0", :encoding=>"UTF-8" }
242
+ attrs = a.merge attrs
243
+ end
244
+ _special(
245
+ "<?#{directive_tag}",
246
+ "?>",
247
+ nil,
248
+ attrs,
249
+ [:version, :encoding, :standalone])
250
+ end
251
+
252
+ # Insert a CDATA section into the XML markup.
253
+ #
254
+ # For example:
255
+ #
256
+ # xml.cdata!("text to be included in cdata")
257
+ # #=> <![CDATA[text to be included in cdata]]>
258
+ #
259
+ def cdata!(text)
260
+ _ensure_no_block block_given?
261
+ _special("<![CDATA[", "]]>", text, nil)
262
+ end
263
+
264
+ private
265
+
266
+ # NOTE: All private methods of a builder object are prefixed when
267
+ # a "_" character to avoid possible conflict with XML tag names.
268
+
269
+ # Insert text directly in to the builder's target.
270
+ def _text(text)
271
+ @target << text
272
+ end
273
+
274
+ # Insert special instruction.
275
+ def _special(open, close, data=nil, attrs=nil, order=[])
276
+ _indent
277
+ @target << open
278
+ @target << data if data
279
+ _insert_attributes(attrs, order) if attrs
280
+ @target << close
281
+ _newline
282
+ end
283
+
284
+ # Start an XML tag. If <tt>end_too</tt> is true, then the start
285
+ # tag is also the end tag (e.g. <br/>
286
+ def _start_tag(sym, attrs, end_too=false)
287
+ @target << "<#{sym}"
288
+ _insert_attributes(attrs)
289
+ @target << "/" if end_too
290
+ @target << ">"
291
+ end
292
+
293
+ # Insert an ending tag.
294
+ def _end_tag(sym)
295
+ @target << "</#{sym}>"
296
+ end
297
+
298
+ # Insert the attributes (given in the hash).
299
+ def _insert_attributes(attrs, order=[])
300
+ return if attrs.nil?
301
+ order.each do |k|
302
+ v = attrs[k]
303
+ @target << %{ #{k}="#{_attr_value(v)}"} if v # " WART
304
+ end
305
+ attrs.each do |k, v|
306
+ @target << %{ #{k}="#{_attr_value(v)}"} unless order.member?(k) # " WART
307
+ end
308
+ end
309
+
310
+ def _attr_value(value)
311
+ case value
312
+ when Symbol
313
+ value.to_s
314
+ else
315
+ _escape_quote(value.to_s)
316
+ end
317
+ end
318
+
319
+ def _ensure_no_block(got_block)
320
+ if got_block
321
+ fail IllegalBlockError,
322
+ "Blocks are not allowed on XML instructions"
323
+ end
324
+ end
325
+
326
+ end
327
+
328
+ end