swivel 0.0.146 → 0.0.149

Sign up to get free protection for your applications and to get access to all the features.
Files changed (183) hide show
  1. data/README +4 -1
  2. data/Rakefile +1 -1
  3. data/lib/swivel.rb +1 -1
  4. data/lib/swivel2/benchmarking.rb +1 -0
  5. data/lib/swivel2/config.rb +45 -0
  6. data/lib/swivel2/connection.rb +89 -0
  7. data/lib/swivel2/formats.rb +11 -0
  8. data/lib/swivel2/logging.rb +1 -0
  9. data/lib/swivel2/performance.rb +21 -0
  10. data/lib/swivel2/response.rb +5 -0
  11. data/lib/swivel2/swivelrc.default +5 -0
  12. data/vendor/activeresource-2.0.2-/CHANGELOG +223 -0
  13. data/vendor/activeresource-2.0.2-/README +165 -0
  14. data/vendor/activeresource-2.0.2-/Rakefile +133 -0
  15. data/vendor/activeresource-2.0.2-/lib/active_resource.rb +47 -0
  16. data/vendor/activeresource-2.0.2-/lib/active_resource/base.rb +872 -0
  17. data/vendor/activeresource-2.0.2-/lib/active_resource/connection.rb +172 -0
  18. data/vendor/activeresource-2.0.2-/lib/active_resource/custom_methods.rb +105 -0
  19. data/vendor/activeresource-2.0.2-/lib/active_resource/formats.rb +14 -0
  20. data/vendor/activeresource-2.0.2-/lib/active_resource/formats/json_format.rb +23 -0
  21. data/vendor/activeresource-2.0.2-/lib/active_resource/formats/xml_format.rb +34 -0
  22. data/vendor/activeresource-2.0.2-/lib/active_resource/http_mock.rb +147 -0
  23. data/vendor/activeresource-2.0.2-/lib/active_resource/validations.rb +288 -0
  24. data/vendor/activeresource-2.0.2-/lib/active_resource/version.rb +9 -0
  25. data/vendor/activeresource-2.0.2-/lib/activeresource.rb +1 -0
  26. data/vendor/activeresource-2.0.2-/test/abstract_unit.rb +10 -0
  27. data/vendor/activeresource-2.0.2-/test/authorization_test.rb +82 -0
  28. data/vendor/activeresource-2.0.2-/test/base/custom_methods_test.rb +96 -0
  29. data/vendor/activeresource-2.0.2-/test/base/equality_test.rb +43 -0
  30. data/vendor/activeresource-2.0.2-/test/base/load_test.rb +111 -0
  31. data/vendor/activeresource-2.0.2-/test/base_errors_test.rb +48 -0
  32. data/vendor/activeresource-2.0.2-/test/base_test.rb +454 -0
  33. data/vendor/activeresource-2.0.2-/test/connection_test.rb +170 -0
  34. data/vendor/activeresource-2.0.2-/test/fixtures/beast.rb +14 -0
  35. data/vendor/activeresource-2.0.2-/test/fixtures/person.rb +3 -0
  36. data/vendor/activeresource-2.0.2-/test/fixtures/street_address.rb +4 -0
  37. data/vendor/activeresource-2.0.2-/test/format_test.rb +42 -0
  38. data/vendor/activeresource-2.0.2-/test/setter_trap.rb +27 -0
  39. data/vendor/activesupport-2.0.2-/CHANGELOG +986 -0
  40. data/vendor/activesupport-2.0.2-/README +43 -0
  41. data/vendor/activesupport-2.0.2-/lib/active_support.rb +49 -0
  42. data/vendor/activesupport-2.0.2-/lib/active_support/basic_object.rb +5 -0
  43. data/vendor/activesupport-2.0.2-/lib/active_support/buffered_logger.rb +107 -0
  44. data/vendor/activesupport-2.0.2-/lib/active_support/clean_logger.rb +127 -0
  45. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext.rb +4 -0
  46. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/array.rb +13 -0
  47. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/array/access.rb +28 -0
  48. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/array/conversions.rb +94 -0
  49. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/array/extract_options.rb +19 -0
  50. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/array/grouping.rb +68 -0
  51. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/array/random_access.rb +12 -0
  52. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/bigdecimal.rb +2 -0
  53. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/bigdecimal/conversions.rb +6 -0
  54. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/blank.rb +50 -0
  55. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/cgi.rb +5 -0
  56. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb +14 -0
  57. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/class.rb +4 -0
  58. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/class/attribute_accessors.rb +48 -0
  59. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/class/delegating_attributes.rb +40 -0
  60. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/class/inheritable_attributes.rb +140 -0
  61. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/class/removal.rb +24 -0
  62. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/date.rb +10 -0
  63. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/date/behavior.rb +13 -0
  64. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/date/calculations.rb +188 -0
  65. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/date/conversions.rb +98 -0
  66. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/date_time.rb +10 -0
  67. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/date_time/calculations.rb +77 -0
  68. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/date_time/conversions.rb +74 -0
  69. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/duplicable.rb +37 -0
  70. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/enumerable.rb +63 -0
  71. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/exception.rb +33 -0
  72. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/file.rb +21 -0
  73. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/float.rb +5 -0
  74. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/float/rounding.rb +24 -0
  75. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash.rb +13 -0
  76. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash/conversions.rb +242 -0
  77. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash/diff.rb +19 -0
  78. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash/except.rb +24 -0
  79. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash/indifferent_access.rb +102 -0
  80. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash/keys.rb +54 -0
  81. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash/reverse_merge.rb +25 -0
  82. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash/slice.rb +28 -0
  83. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/integer.rb +7 -0
  84. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/integer/even_odd.rb +24 -0
  85. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/integer/inflections.rb +21 -0
  86. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/kernel.rb +5 -0
  87. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/kernel/agnostics.rb +11 -0
  88. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/kernel/daemonizing.rb +15 -0
  89. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/kernel/debugger.rb +13 -0
  90. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/kernel/reporting.rb +51 -0
  91. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/kernel/requires.rb +24 -0
  92. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/load_error.rb +38 -0
  93. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/logger.rb +16 -0
  94. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module.rb +8 -0
  95. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/aliasing.rb +70 -0
  96. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/attr_accessor_with_default.rb +31 -0
  97. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/attr_internal.rb +31 -0
  98. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/attribute_accessors.rb +48 -0
  99. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/delegation.rb +62 -0
  100. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/inclusion.rb +11 -0
  101. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/introspection.rb +35 -0
  102. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/loading.rb +13 -0
  103. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/name_error.rb +17 -0
  104. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/numeric.rb +7 -0
  105. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/numeric/bytes.rb +44 -0
  106. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/numeric/time.rb +91 -0
  107. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/object.rb +4 -0
  108. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/object/conversions.rb +14 -0
  109. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/object/extending.rb +58 -0
  110. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/object/instance_variables.rb +22 -0
  111. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/object/misc.rb +59 -0
  112. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/pathname.rb +7 -0
  113. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/pathname/clean_within.rb +14 -0
  114. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/proc.rb +12 -0
  115. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/range.rb +11 -0
  116. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/range/blockless_step.rb +22 -0
  117. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/range/conversions.rb +23 -0
  118. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/range/include_range.rb +22 -0
  119. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/range/overlaps.rb +12 -0
  120. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string.rb +23 -0
  121. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string/access.rb +58 -0
  122. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string/conversions.rb +28 -0
  123. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string/inflections.rb +153 -0
  124. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string/iterators.rb +17 -0
  125. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string/starts_ends_with.rb +27 -0
  126. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string/unicode.rb +42 -0
  127. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string/xchar.rb +11 -0
  128. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/symbol.rb +14 -0
  129. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/test.rb +1 -0
  130. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/test/unit/assertions.rb +62 -0
  131. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/time.rb +19 -0
  132. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/time/behavior.rb +13 -0
  133. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/time/calculations.rb +224 -0
  134. data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/time/conversions.rb +94 -0
  135. data/vendor/activesupport-2.0.2-/lib/active_support/dependencies.rb +540 -0
  136. data/vendor/activesupport-2.0.2-/lib/active_support/deprecation.rb +204 -0
  137. data/vendor/activesupport-2.0.2-/lib/active_support/duration.rb +96 -0
  138. data/vendor/activesupport-2.0.2-/lib/active_support/inflections.rb +53 -0
  139. data/vendor/activesupport-2.0.2-/lib/active_support/inflector.rb +282 -0
  140. data/vendor/activesupport-2.0.2-/lib/active_support/json.rb +31 -0
  141. data/vendor/activesupport-2.0.2-/lib/active_support/json/decoding.rb +60 -0
  142. data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/date.rb +5 -0
  143. data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/date_time.rb +5 -0
  144. data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/enumerable.rb +12 -0
  145. data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/false_class.rb +5 -0
  146. data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/hash.rb +50 -0
  147. data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/nil_class.rb +5 -0
  148. data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/numeric.rb +5 -0
  149. data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/object.rb +6 -0
  150. data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/regexp.rb +5 -0
  151. data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/string.rb +30 -0
  152. data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/symbol.rb +5 -0
  153. data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/time.rb +5 -0
  154. data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/true_class.rb +5 -0
  155. data/vendor/activesupport-2.0.2-/lib/active_support/json/encoding.rb +38 -0
  156. data/vendor/activesupport-2.0.2-/lib/active_support/json/variable.rb +10 -0
  157. data/vendor/activesupport-2.0.2-/lib/active_support/multibyte.rb +9 -0
  158. data/vendor/activesupport-2.0.2-/lib/active_support/multibyte/chars.rb +141 -0
  159. data/vendor/activesupport-2.0.2-/lib/active_support/multibyte/generators/generate_tables.rb +149 -0
  160. data/vendor/activesupport-2.0.2-/lib/active_support/multibyte/handlers/passthru_handler.rb +9 -0
  161. data/vendor/activesupport-2.0.2-/lib/active_support/multibyte/handlers/utf8_handler.rb +564 -0
  162. data/vendor/activesupport-2.0.2-/lib/active_support/multibyte/handlers/utf8_handler_proc.rb +43 -0
  163. data/vendor/activesupport-2.0.2-/lib/active_support/option_merger.rb +25 -0
  164. data/vendor/activesupport-2.0.2-/lib/active_support/ordered_options.rb +49 -0
  165. data/vendor/activesupport-2.0.2-/lib/active_support/test_case.rb +5 -0
  166. data/vendor/activesupport-2.0.2-/lib/active_support/testing.rb +1 -0
  167. data/vendor/activesupport-2.0.2-/lib/active_support/testing/default.rb +12 -0
  168. data/vendor/activesupport-2.0.2-/lib/active_support/values/time_zone.rb +181 -0
  169. data/vendor/activesupport-2.0.2-/lib/active_support/values/unicode_tables.dat +0 -0
  170. data/vendor/activesupport-2.0.2-/lib/active_support/vendor.rb +14 -0
  171. data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/blankslate.rb +113 -0
  172. data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/builder.rb +13 -0
  173. data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/builder/blankslate.rb +20 -0
  174. data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/builder/css.rb +250 -0
  175. data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/builder/xchar.rb +115 -0
  176. data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/builder/xmlbase.rb +139 -0
  177. data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/builder/xmlevents.rb +63 -0
  178. data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/builder/xmlmarkup.rb +328 -0
  179. data/vendor/activesupport-2.0.2-/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb +1021 -0
  180. data/vendor/activesupport-2.0.2-/lib/active_support/version.rb +9 -0
  181. data/vendor/activesupport-2.0.2-/lib/active_support/whiny_nil.rb +38 -0
  182. data/vendor/activesupport-2.0.2-/lib/activesupport.rb +1 -0
  183. metadata +222 -2
@@ -0,0 +1,13 @@
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
+ require 'builder/xmlevents'
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ #--
3
+ # Copyright 2004, 2006 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
+ require 'blankslate'
12
+
13
+ ######################################################################
14
+ # BlankSlate has been promoted to a top level name and is now
15
+ # available as a standalone gem. We make the name available in the
16
+ # Builder namespace for compatibility.
17
+ #
18
+ module Builder
19
+ BlankSlate = ::BlankSlate
20
+ end
@@ -0,0 +1,250 @@
1
+ #!/usr/bin/env ruby
2
+ #--
3
+ # Copyright 2004, 2005 by Jim Weirich (jim@weirichhouse.org).
4
+ # Copyright 2005 by Scott Barron (scott@elitists.net).
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
+ # Much of this is taken from Jim's work in xmlbase.rb and xmlmarkup.rb.
12
+ # Documentation has also been copied and pasted and modified to reflect
13
+ # that we're building CSS here instead of XML. Jim is conducting the
14
+ # orchestra here and I'm just off in the corner playing a flute.
15
+ #++
16
+
17
+ # Provide a flexible and easy to use Builder for creating Cascading
18
+ # Style Sheets (CSS).
19
+
20
+
21
+ require 'builder/blankslate'
22
+
23
+ module Builder
24
+
25
+ # Create a Cascading Style Sheet (CSS) using Ruby.
26
+ #
27
+ # Example usage:
28
+ #
29
+ # css = Builder::CSS.new
30
+ #
31
+ # text_color = '#7F7F7F'
32
+ # preferred_fonts = 'Helvetica, Arial, sans_serif'
33
+ #
34
+ # css.comment! 'This is our stylesheet'
35
+ # css.body {
36
+ # background_color '#FAFAFA'
37
+ # font_size 'small'
38
+ # font_family preferred_fonts
39
+ # color text_color
40
+ # }
41
+ #
42
+ # css.id!('navbar') {
43
+ # width '500px'
44
+ # }
45
+ #
46
+ # css.class!('navitem') {
47
+ # color 'red'
48
+ # }
49
+ #
50
+ # css.a :hover {
51
+ # text_decoration 'underline'
52
+ # }
53
+ #
54
+ # css.div(:id => 'menu') {
55
+ # background 'green'
56
+ # }
57
+ #
58
+ # css.div(:class => 'foo') {
59
+ # background 'red'
60
+ # }
61
+ #
62
+ # This will yield the following stylesheet:
63
+ #
64
+ # /* This is our stylesheet */
65
+ # body {
66
+ # background_color: #FAFAFA;
67
+ # font_size: small;
68
+ # font_family: Helvetica, Arial, sans_serif;
69
+ # color: #7F7F7F;
70
+ # }
71
+ #
72
+ # #navbar {
73
+ # width: 500px;
74
+ # }
75
+ #
76
+ # .navitem {
77
+ # color: red;
78
+ # }
79
+ #
80
+ # a:hover {
81
+ # text_decoration: underline;
82
+ # }
83
+ #
84
+ # div#menu {
85
+ # background: green;
86
+ # }
87
+ #
88
+ # div.foo {
89
+ # background: red;
90
+ # }
91
+ #
92
+ class CSS < BlankSlate
93
+
94
+ # Create a CSS builder.
95
+ #
96
+ # out:: Object receiving the markup.1 +out+ must respond to
97
+ # <tt><<</tt>.
98
+ # indent:: Number of spaces used for indentation (0 implies no
99
+ # indentation and no line breaks).
100
+ #
101
+ def initialize(indent=2)
102
+ @indent = indent
103
+ @target = []
104
+ @parts = []
105
+ @library = {}
106
+ end
107
+
108
+ def +(part)
109
+ _join_with_op! '+'
110
+ self
111
+ end
112
+
113
+ def >>(part)
114
+ _join_with_op! ''
115
+ self
116
+ end
117
+
118
+ def >(part)
119
+ _join_with_op! '>'
120
+ self
121
+ end
122
+
123
+ def |(part)
124
+ _join_with_op! ','
125
+ self
126
+ end
127
+
128
+ # Return the target of the builder
129
+ def target!
130
+ @target * ''
131
+ end
132
+
133
+ # Create a comment string in the output.
134
+ def comment!(comment_text)
135
+ @target << "/* #{comment_text} */\n"
136
+ end
137
+
138
+ def id!(arg, &block)
139
+ _start_container('#'+arg.to_s, nil, block_given?)
140
+ _css_block(block) if block
141
+ _unify_block
142
+ self
143
+ end
144
+
145
+ def class!(arg, &block)
146
+ _start_container('.'+arg.to_s, nil, block_given?)
147
+ _css_block(block) if block
148
+ _unify_block
149
+ self
150
+ end
151
+
152
+ def store!(sym, &block)
153
+ @library[sym] = block.to_proc
154
+ end
155
+
156
+ def group!(*args, &block)
157
+ args.each do |arg|
158
+ if arg.is_a?(Symbol)
159
+ instance_eval(&@library[arg])
160
+ else
161
+ instance_eval(&arg)
162
+ end
163
+ _text ', ' unless arg == args.last
164
+ end
165
+ if block
166
+ _css_block(block)
167
+ _unify_block
168
+ end
169
+ end
170
+
171
+ def method_missing(sym, *args, &block)
172
+ sym = "#{sym}:#{args.shift}" if args.first.kind_of?(Symbol)
173
+ if block
174
+ _start_container(sym, args.first)
175
+ _css_block(block)
176
+ _unify_block
177
+ elsif @in_block
178
+ _indent
179
+ _css_line(sym, *args)
180
+ _newline
181
+ return self
182
+ else
183
+ _start_container(sym, args.first, false)
184
+ _unify_block
185
+ end
186
+ self
187
+ end
188
+
189
+ # "Cargo culted" from Jim who also "cargo culted" it. See xmlbase.rb.
190
+ def nil?
191
+ false
192
+ end
193
+
194
+ private
195
+ def _unify_block
196
+ @target << @parts * ''
197
+ @parts = []
198
+ end
199
+
200
+ def _join_with_op!(op)
201
+ rhs, lhs = @target.pop, @target.pop
202
+ @target << "#{lhs} #{op} #{rhs}"
203
+ end
204
+
205
+ def _text(text)
206
+ @parts << text
207
+ end
208
+
209
+ def _css_block(block)
210
+ _newline
211
+ _nested_structures(block)
212
+ _end_container
213
+ _end_block
214
+ end
215
+
216
+ def _end_block
217
+ _newline
218
+ _newline
219
+ end
220
+
221
+ def _newline
222
+ _text "\n"
223
+ end
224
+
225
+ def _indent
226
+ _text ' ' * @indent
227
+ end
228
+
229
+ def _nested_structures(block)
230
+ @in_block = true
231
+ self.instance_eval(&block)
232
+ @in_block = false
233
+ end
234
+
235
+ def _start_container(sym, atts = {}, with_bracket = true)
236
+ selector = sym.to_s
237
+ selector << ".#{atts[:class]}" if atts && atts[:class]
238
+ selector << '#' + "#{atts[:id]}" if atts && atts[:id]
239
+ @parts << "#{selector}#{with_bracket ? ' {' : ''}"
240
+ end
241
+
242
+ def _end_container
243
+ @parts << "}"
244
+ end
245
+
246
+ def _css_line(sym, *args)
247
+ _text("#{sym.to_s.gsub('_','-')}: #{args * ' '};")
248
+ end
249
+ end
250
+ end
@@ -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 => '&amp;', # ampersand
70
+ 60 => '&lt;', # left angle bracket
71
+ 62 => '&gt;', # 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