nitro 0.31.0 → 0.40.0

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 (174) hide show
  1. data/bin/nitro +135 -37
  2. data/doc/CHANGELOG.1 +108 -108
  3. data/doc/CHANGELOG.2 +89 -89
  4. data/doc/CHANGELOG.3 +105 -105
  5. data/{CHANGELOG → doc/CHANGELOG.4} +509 -509
  6. data/doc/{AUTHORS → CONTRIBUTORS} +49 -37
  7. data/doc/LIBRARIES +13 -0
  8. data/doc/LICENSE +2 -3
  9. data/doc/MIGRATION +45 -0
  10. data/doc/RELEASES +131 -11
  11. data/doc/TODO +67 -0
  12. data/lib/glue/magick.rb +0 -3
  13. data/lib/glue/sweeper.rb +30 -15
  14. data/lib/glue/thumbnails.rb +0 -2
  15. data/lib/glue/webfile.rb +23 -11
  16. data/lib/nitro.rb +37 -44
  17. data/lib/nitro/adapter/cgi.rb +0 -3
  18. data/lib/nitro/adapter/console.rb +0 -2
  19. data/lib/nitro/adapter/fastcgi.rb +6 -3
  20. data/lib/nitro/adapter/mongrel.rb +97 -58
  21. data/lib/nitro/adapter/script.rb +4 -6
  22. data/lib/nitro/adapter/webrick.rb +33 -87
  23. data/lib/nitro/adapter/webrick/vcr.rb +85 -0
  24. data/lib/nitro/caching.rb +0 -2
  25. data/lib/nitro/caching/actions.rb +0 -2
  26. data/lib/nitro/caching/fragments.rb +0 -2
  27. data/lib/nitro/caching/output.rb +45 -16
  28. data/lib/nitro/caching/proxy.rb +49 -0
  29. data/lib/nitro/cgi.rb +3 -6
  30. data/lib/nitro/cgi/cookie.rb +0 -3
  31. data/lib/nitro/cgi/request.rb +67 -24
  32. data/lib/nitro/cgi/response.rb +0 -2
  33. data/lib/nitro/cgi/{sendfile.rb → send_file.rb} +7 -6
  34. data/lib/nitro/compiler.rb +62 -55
  35. data/lib/nitro/compiler/cleanup.rb +0 -3
  36. data/lib/nitro/compiler/elements.rb +31 -28
  37. data/lib/nitro/compiler/errors.rb +2 -5
  38. data/lib/nitro/compiler/include.rb +10 -8
  39. data/lib/nitro/compiler/layout.rb +0 -2
  40. data/lib/nitro/compiler/localization.rb +0 -2
  41. data/lib/nitro/compiler/markup.rb +14 -6
  42. data/lib/nitro/compiler/morphing.rb +1 -5
  43. data/lib/nitro/compiler/script.rb +2 -4
  44. data/lib/nitro/compiler/squeeze.rb +0 -2
  45. data/lib/nitro/compiler/xslt.rb +0 -2
  46. data/lib/nitro/context.rb +10 -5
  47. data/lib/nitro/control.rb +18 -0
  48. data/lib/nitro/control/attribute.rb +88 -0
  49. data/lib/nitro/control/attribute/checkbox.rb +19 -0
  50. data/lib/nitro/control/attribute/datetime.rb +21 -0
  51. data/lib/nitro/control/attribute/file.rb +20 -0
  52. data/lib/nitro/control/attribute/fixnum.rb +26 -0
  53. data/lib/nitro/control/attribute/float.rb +26 -0
  54. data/lib/nitro/control/attribute/options.rb +38 -0
  55. data/lib/nitro/control/attribute/password.rb +16 -0
  56. data/lib/nitro/control/attribute/text.rb +16 -0
  57. data/lib/nitro/control/attribute/textarea.rb +16 -0
  58. data/lib/nitro/control/none.rb +16 -0
  59. data/lib/nitro/control/relation.rb +53 -0
  60. data/lib/nitro/control/relation/belongs_to.rb +0 -0
  61. data/lib/nitro/control/relation/has_many.rb +97 -0
  62. data/lib/nitro/control/relation/joins_many.rb +0 -0
  63. data/lib/nitro/control/relation/many_to_many.rb +0 -0
  64. data/lib/nitro/control/relation/refers_to.rb +29 -0
  65. data/lib/nitro/controller.rb +7 -296
  66. data/lib/nitro/dispatcher.rb +72 -34
  67. data/lib/nitro/element.rb +36 -10
  68. data/lib/nitro/element/javascript.rb +0 -2
  69. data/lib/nitro/flash.rb +23 -10
  70. data/lib/nitro/global.rb +36 -11
  71. data/lib/nitro/helper.rb +22 -8
  72. data/lib/nitro/helper/benchmark.rb +0 -2
  73. data/lib/nitro/helper/buffer.rb +0 -3
  74. data/lib/nitro/helper/css.rb +12 -0
  75. data/lib/nitro/helper/debug.rb +1 -3
  76. data/lib/nitro/helper/default.rb +1 -0
  77. data/lib/nitro/helper/feed.rb +400 -386
  78. data/lib/nitro/helper/form.rb +246 -116
  79. data/lib/nitro/helper/javascript.rb +28 -2
  80. data/lib/nitro/helper/javascript/morphing.rb +0 -2
  81. data/lib/nitro/helper/javascript/prototype.rb +0 -2
  82. data/lib/nitro/helper/javascript/scriptaculous.rb +0 -1
  83. data/lib/nitro/helper/layout.rb +0 -2
  84. data/lib/nitro/helper/navigation.rb +87 -0
  85. data/lib/nitro/helper/pager.rb +11 -22
  86. data/lib/nitro/helper/table.rb +9 -32
  87. data/lib/nitro/helper/url.rb +104 -0
  88. data/lib/nitro/helper/xhtml.rb +20 -4
  89. data/lib/nitro/helper/xml.rb +0 -2
  90. data/lib/nitro/markup.rb +131 -0
  91. data/lib/nitro/part.rb +52 -7
  92. data/lib/nitro/publishable.rb +328 -0
  93. data/lib/nitro/render.rb +30 -61
  94. data/lib/nitro/router.rb +12 -4
  95. data/lib/nitro/sanitize.rb +48 -0
  96. data/lib/nitro/scaffold.rb +9 -11
  97. data/lib/nitro/scaffold/controller.rb +25 -0
  98. data/lib/nitro/scaffold/model.rb +150 -0
  99. data/lib/nitro/scaffolding.rb +1 -3
  100. data/lib/nitro/server.rb +57 -32
  101. data/lib/nitro/server/drb.rb +16 -2
  102. data/lib/nitro/server/runner.rb +80 -102
  103. data/lib/nitro/service.rb +0 -1
  104. data/lib/nitro/service/xmlrpc.rb +0 -2
  105. data/lib/nitro/session.rb +26 -18
  106. data/lib/nitro/session/drb.rb +2 -16
  107. data/lib/nitro/session/memory.rb +0 -2
  108. data/lib/nitro/template.rb +219 -0
  109. data/lib/nitro/test/assertions.rb +1 -3
  110. data/lib/nitro/test/context.rb +0 -1
  111. data/lib/nitro/test/testcase.rb +0 -1
  112. data/lib/nitro/version.rb +6 -0
  113. data/lib/part/admin.rb +16 -0
  114. data/lib/part/admin/controller.rb +19 -0
  115. data/lib/part/admin/helper.rb +30 -0
  116. data/lib/part/admin/og/controller.rb +114 -0
  117. data/lib/part/admin/og/customize.rb +4 -0
  118. data/lib/part/admin/og/template/index.xhtml +27 -0
  119. data/lib/part/admin/og/template/list.xhtml +38 -0
  120. data/lib/part/admin/og/template/search.xhtml +20 -0
  121. data/lib/part/admin/og/template/update.xhtml +25 -0
  122. data/lib/part/admin/skin.rb +207 -0
  123. data/lib/part/admin/template/denied.xhtml +13 -0
  124. data/lib/part/admin/template/index.xhtml +12 -0
  125. data/lib/part/admin/todo.txt +2 -0
  126. data/proto/public/error.xhtml +4 -2
  127. data/proto/run.rb +0 -2
  128. data/test/glue/tc_webfile.rb +1 -0
  129. data/test/nitro/cgi/tc_request.rb +23 -0
  130. data/test/nitro/helper/tc_feed.rb +0 -3
  131. data/test/nitro/helper/tc_navbar.rb +74 -0
  132. data/test/nitro/helper/tc_table.rb +2 -0
  133. data/test/nitro/tc_cgi.rb +72 -19
  134. data/test/nitro/tc_controller.rb +35 -26
  135. data/test/nitro/tc_controller_aspect.rb +1 -0
  136. data/test/nitro/tc_controller_params.rb +864 -0
  137. data/test/nitro/tc_dispatcher.rb +2 -2
  138. data/test/nitro/tc_element.rb +16 -16
  139. data/test/nitro/tc_flash.rb +3 -3
  140. data/test/nitro/tc_markup.rb +31 -0
  141. data/test/nitro/tc_render.rb +12 -14
  142. data/test/nitro/tc_session.rb +9 -7
  143. data/test/nitro/tc_template.rb +34 -0
  144. metadata +217 -198
  145. data/INSTALL +0 -121
  146. data/ProjectInfo +0 -74
  147. data/README +0 -555
  148. data/doc/apache.txt +0 -9
  149. data/doc/config.txt +0 -28
  150. data/doc/faq.txt +0 -7
  151. data/doc/lhttpd.txt +0 -7
  152. data/lib/nitro/adapter/scgi.rb +0 -239
  153. data/lib/nitro/helper/form/builder.rb +0 -144
  154. data/lib/nitro/helper/form/controls.rb +0 -389
  155. data/lib/nitro/helper/rss.rb +0 -72
  156. data/proto/conf/apache.conf +0 -51
  157. data/proto/public/scaffold/advanced_search.xhtml +0 -30
  158. data/proto/public/scaffold/edit.xhtml +0 -11
  159. data/proto/public/scaffold/form.xhtml +0 -1
  160. data/proto/public/scaffold/index.xhtml +0 -20
  161. data/proto/public/scaffold/list.xhtml +0 -32
  162. data/proto/public/scaffold/new.xhtml +0 -11
  163. data/proto/public/scaffold/search.xhtml +0 -29
  164. data/proto/public/scaffold/view.xhtml +0 -8
  165. data/proto/script/scgi_ctl +0 -221
  166. data/proto/script/scgi_service +0 -128
  167. data/setup.rb +0 -1585
  168. data/src/part/admin.rb +0 -16
  169. data/src/part/admin/controller.rb +0 -81
  170. data/src/part/admin/skin.rb +0 -21
  171. data/src/part/admin/system.css +0 -135
  172. data/src/part/admin/template/denied.xhtml +0 -1
  173. data/src/part/admin/template/index.xhtml +0 -43
  174. data/test/nitro/helper/tc_rss.rb +0 -24
@@ -1,153 +1,283 @@
1
- require 'facet/inflect'
1
+ require 'glue/builder/xml'
2
2
 
3
- require 'nitro/helper/form/controls'
4
- require 'nitro/helper/form/builder'
3
+ require 'nitro/control'
4
+ require 'nitro/control/none'
5
5
 
6
- module Nitro
6
+ require 'nitro/control/attribute/fixnum'
7
+ require 'nitro/control/attribute/float'
8
+ require 'nitro/control/attribute/text'
9
+ require 'nitro/control/attribute/password'
10
+ require 'nitro/control/attribute/textarea'
11
+ require 'nitro/control/attribute/checkbox'
12
+ require 'nitro/control/attribute/options'
13
+ require 'nitro/control/attribute/file'
7
14
 
8
- # A collection of useful helpers for creating and manipulating
9
- # Forms.
10
- #--
11
- # This helper may by applied at run time so try to optimize
12
- # this.
13
- #++
15
+ require 'nitro/control/relation/refers_to'
16
+ require 'nitro/control/relation/has_many'
14
17
 
15
- module FormHelper
18
+ module Nitro
16
19
 
17
- def self.included(base)
18
- super
19
- base.send :include, XhtmlHelper
20
- end
20
+ module FormHelper
21
21
 
22
- # Override these methods to customize the rendering.
23
- #
24
- # An alternative schema could be:
25
- #
26
- # <dl>
27
- # <dt class="#{prop.symbol}">#{label(prop)}</dt>
28
- # <dd class="#{prop.symbol}">#{html}</dd>
29
- # </dl>
22
+ # A specialized Builder for dynamically building of forms.
23
+ # Provides extra support for forms backed by managed objects
24
+ # (entities).
25
+ #--
26
+ # TODO: allow multiple objects per form.
27
+ # TODO: use more generalized controls.
28
+ #++
30
29
 
31
- module FormBuilder
32
- class << self
33
- # Emit form prologue.
34
-
35
- def prologue
36
- ''
37
- end
38
-
39
- # Emit form epilogue.
30
+ class FormXmlBuilder < ::Glue::XmlBuilder
31
+
32
+ # Mappings of control names to controls.
33
+
34
+ setting :control_map, :doc => 'Mappings of control names to controls', :default => {
35
+ :fixnum => FixnumControl,
36
+ :integer => FixnumControl,
37
+ :float => FloatControl,
38
+ :true_class => CheckboxControl,
39
+ :boolean => CheckboxControl,
40
+ :checkbox => CheckboxControl,
41
+ :string => TextControl,
42
+ :password => PasswordControl,
43
+ :textarea => TextareaControl,
44
+ :file => FileControl,
45
+ :webfile => FileControl,
46
+ =begin
47
+ :array => ArrayControl,
48
+ =end
49
+ :options => OptionsControl,
50
+ :refers_to => RefersToControl,
51
+ :has_one => RefersToControl,
52
+ :belongs_to => RefersToControl,
53
+ :has_many => HasManyControl,
54
+ :many_to_many => HasManyControl,
55
+ :joins_many => HasManyControl
56
+ }
57
+
58
+ # Returns a control for the given objects attribute.
59
+
60
+ def self.control_for(obj, a, anno, options)
61
+ name = anno[:control] || anno[:class].to_s.demodulize.underscore.to_sym
62
+ control_class = self.control_map.fetch(name, NoneControl)
63
+ return control_class.new(obj, a, options)
64
+ end
65
+
66
+ # Returns a control for the given objects relation.
67
+
68
+ def self.control_for_relation(obj, rel, options)
69
+ name = rel[:control] || rel.class.to_s.demodulize.underscore.to_sym
70
+ control_class = self.control_map.fetch(name, NoneControl)
71
+ return control_class.new(obj, rel, options)
72
+ end
40
73
 
41
- def epilogue
42
- ''
74
+ def initialize(buffer = '', options = {})
75
+ super
76
+ @obj = options[:object]
77
+ @errors = options[:errors]
78
+ end
79
+
80
+ # Render a control+label for the given property of the form
81
+ # object.
82
+
83
+ def attribute(a, options = {})
84
+ if anno = @obj.class.ann[a]
85
+ control = self.class.control_for(@obj, a, anno, options)
86
+ print element(a, anno, control.render)
87
+ else
88
+ raise "Undefined attribute '#{a}' for class '#{@obj.class}'."
43
89
  end
90
+ end
91
+ alias attr attribute
44
92
 
45
- # Emit a label.
46
-
47
- def label(prop)
48
- %{<label for="#{prop.name}">#{prop[:title] || prop.name.to_s.humanize}</label>}
93
+ # Render controls for all attributes of the form object.
94
+ # It only considers serializable attributes.
95
+
96
+ def all_attributes(options = {})
97
+ for a in @obj.class.serializable_attributes
98
+ prop = @obj.class.ann(a)
99
+ unless options[:all]
100
+ next if a == @obj.class.primary_key or prop[:control] == :none or prop[:relation] or [options[:exclude]].flatten.include?(a)
101
+ end
102
+ attribute a, options
49
103
  end
104
+ end
105
+ alias attributes all_attributes
106
+ alias serializable_attributes all_attributes
107
+
108
+ # === Input
109
+ #
110
+ # * rel = The relation name as symbol, or the actual
111
+ # relation object.
112
+ #--
113
+ # FIXME: Fix the mismatch with the attributes.
114
+ #++
115
+
116
+ def relation(rel, options = {})
117
+ # If the relation name is passed, lookup the actual
118
+ # relation.
50
119
 
51
- # Emit a form element.
52
-
53
- def element(prop, html)
54
- %{
55
- <p class="form_#{prop.symbol}">
56
- <div>#{label(prop)}</div>
57
- #{html}
58
- </p>
59
- }
120
+ if rel.is_a? Symbol
121
+ rel = @obj.class.relation(rel)
60
122
  end
123
+
124
+ control = self.class.control_for_relation(@obj, rel, options)
125
+ print element(rel[:symbol], rel, control.render)
61
126
  end
62
- end
127
+ alias rel relation
63
128
 
64
- # Render a standard form for the given object.
65
- #--
66
- # RETHINK this method.
67
- #++
129
+ # Render controls for all relations of the form object.
130
+
131
+ def all_relations(options = {})
132
+ for rel in @obj.class.relations
133
+ unless options[:all]
134
+ # Ignore polymorphic_marker relations.
135
+ #--
136
+ # gmosx: should revisit the handling of polymorphic
137
+ # relations, feels hacky.
138
+ #++
139
+ next if (rel[:control] == :none) or rel.polymorphic_marker?
140
+ end
141
+ relation rel, options
142
+ end
143
+ end
144
+ alias relations all_relations
68
145
 
69
- def form_for(obj, options = {})
70
- str = ''
146
+ # Renders a control to select a file for upload.
71
147
 
72
- name = obj.class.name.underscore
73
-
74
- method = options.fetch(:method, 'post')
75
- action = options.fetch(:action, "save_#{obj.class.name.underscore}")
76
- submit = options.fetch(:submit, 'Save')
77
- cancel = options.fetch(:cancel, "#@base/#{Scaffolding.class_to_list(obj.class)}")
148
+ def select_file(name, options = {})
149
+ print %|<input type="file" name="#{name}" />|
150
+ end
151
+
152
+ # If flash[:ERRORS] is filled with errors structured as
153
+ # name/message pairs the method creates a div containing them,
154
+ # otherwise it returns an empty string.
155
+ #
156
+ # So you can write code like
157
+ # #{form_errors}
158
+ # <form>... </form>
159
+ #
160
+ # and redirect the user to the form in case of errors, thus
161
+ # allowing him to see what was wrong.
78
162
 
79
- if enctype = options.fetch(:enctype, nil)
80
- enctype_attribute = " enctype=\"#{enctype}\""
81
- else
82
- enctype_attribute = ''
83
- for prop in obj.class.properties.values
84
- if prop.klass.ancestors.include? Og::Blob
85
- enctype_attribute = ' enctype="multipart/form-data"'
163
+ def form_errors
164
+ res = ''
165
+
166
+ unless @errors.empty?
167
+ res << %{<div class="error">\n<ul>\n}
168
+ for err in @errors
169
+ if err.is_a? Array
170
+ res << "<li><strong>#{err[0].to_s.humanize}</strong>: #{err[1]}</li>\n"
171
+ else
172
+ res << "<li>#{err}</li>\n"
173
+ end
86
174
  end
175
+ res << %{</ul>\n</div>\n}
87
176
  end
177
+
178
+ print(res)
88
179
  end
180
+
181
+ private
182
+
183
+ # Emit a form element. Override this method to customize the
184
+ # rendering for your application needs.
89
185
 
90
- if action == :self
91
- str << %{<form method="post"#{enctype_attribute}>}
92
- else
93
- action = "#{@base}/#{action}" unless action =~ /\//
94
- str << %{<form action="#{action}" method="post"#{enctype_attribute}>}
186
+ def element(a, anno, html)
187
+ # TODO: give better form id!
188
+ %{
189
+ <p id="form_#{a}">
190
+ #{html}
191
+ </p>
192
+ }
95
193
  end
96
-
97
- str << %{<input type="hidden" name="oid" value="#{obj.oid}" />} if obj.oid
98
- str << controls_for(obj, options)
99
- str << %{<input type="submit" value="#{submit}" />}
100
- str << %{ or <a href="#{cancel}">Cancel</a>} if cancel
101
- str << %{</form>}
102
-
103
- return str
194
+
104
195
  end
105
196
 
106
- # Render the controls for the given object.
197
+ private
198
+
199
+ # A sophisticated form generation helper method.
200
+ # If no block is provided, render all attributes.
201
+ #
202
+ # === Options
203
+ #
204
+ # * :object, :entity, :class = The object that acts as model
205
+ # for this form. If you pass a class an empty object is
206
+ # instantiated.
207
+ #
208
+ # * :action = The action of this form. The parameter is
209
+ # passed through the R operator (encode_url) to support
210
+ # advanced url encoding.
211
+ #
212
+ # * :errors = An optional collection of errors.
213
+ #
214
+ # === Example
215
+ #
216
+ # #{form(:object => @owner, :action => :save_profile) do |f|
217
+ # f.property :name, :editable => false
218
+ # f.property :password
219
+ # f.br
220
+ # f.submit 'Update'
221
+ # end}
222
+
223
+ def form(options = {}, &block)
224
+ obj = (options[:object] ||= options[:entity] || options[:class])
107
225
 
108
- def controls_for(obj, options = {})
109
- str = FormBuilder.prologue
110
-
111
- controls_for_properties(str, obj, options)
226
+ # If the passed obj is a Class instantiate an empty object
227
+ # of this class.
112
228
 
113
- unless options[:no_relations]
114
- controls_for_relations(str, obj, options)
229
+ if obj.is_a? Class
230
+ obj = options[:object] = obj.allocate
115
231
  end
232
+
233
+ # Convert virtual :multipart method to method="post",
234
+ # enctype="multipart/form-data"
116
235
 
117
- str << FormBuilder.epilogue
118
-
119
- return str
120
- end
236
+ if options[:method] == :multipart
237
+ options[:method] = 'POST'
238
+ options[:enctype] = 'multipart/form-data'
239
+ end
121
240
 
122
- # Render the controls for the properties of the given object.
123
-
124
- def controls_for_properties(str, obj, options = {})
125
- for prop in obj.class.properties.values
126
- unless options[:all]
127
- next if prop.symbol == obj.class.primary_key.symbol or prop[:control] == :none or prop[:relation]
241
+ options[:errors] ||= []
242
+
243
+ if errors = flash[:ERRORS]
244
+ if errors.is_a? Array
245
+ options[:errors].concat(errors)
246
+ elsif errors.is_a? Glue::Validation::Errors
247
+ options[:errors].concat(errors.to_a)
248
+ else
249
+ options[:errors] << errors
128
250
  end
129
- control = Form::Control.fetch(obj, prop, options).render
130
- str << FormBuilder.element(prop, control)
131
251
  end
252
+
253
+ if obj and errors = obj.errors
254
+ options[:errors].concat(errors.to_a)
255
+ end
256
+
257
+ b = FormXmlBuilder.new('', options)
258
+
259
+ b << '<form'
260
+ b << %| action="#{R options[:action]}"| if options[:action]
261
+ b << %| method="#{options[:method]}"| if options[:method]
262
+ b << %| accept-charset="#{options[:charset]}"| if options[:charset]
263
+ b << %| enctype="#{options[:enctype]}"| if options[:enctype]
264
+ b << '>'
265
+
266
+ b.hidden(:oid, obj.oid) if obj and obj.saved?
267
+
268
+ # If no block is provided, render all attributes.
269
+
270
+ if block_given?
271
+ yield b
272
+ else
273
+ b.all_attributes
274
+ end
275
+
276
+ b << '</form>'
277
+
278
+ return b
132
279
  end
133
280
 
134
- # Render the controls for the relations of the given object.
135
-
136
- def controls_for_relations(str, obj, options = {})
137
- for rel in obj.class.relations
138
- unless options[:all]
139
- next if rel[:control] == :none
140
- end
141
- control = Form::Control.fetch(obj, rel, options).render
142
- str << FormBuilder.element(rel, control)
143
- end
144
- end
145
-
146
281
  end
147
282
 
148
283
  end
149
-
150
- # * George Moschovitis <gm@navel.gr>
151
- # * Chris Farmiloe <chris.farmiloe@farmiloe.com>
152
- # * Rob Pitt <rob@motionpath.co.uk>
153
-
@@ -1,11 +1,31 @@
1
+ #--
2
+ # WARNING: most of the code here is deprecated and will be
3
+ # replaced. Use with caution.
4
+ #++
5
+
1
6
  require 'facet/inflect'
2
7
 
3
8
  module Nitro
4
9
 
10
+ # Javascript code manager.
11
+ #--
12
+ # TODO: Add support for synthesizing compound Javascript files from
13
+ # multiple smaller files.
14
+ #++
15
+
5
16
  module Javascript
17
+
6
18
  # The javascript files to auto include.
7
19
 
8
20
  setting :required_files, :default => [], :doc => 'The javascript files to auto include'
21
+
22
+ # The root directory where javascript files reside.
23
+
24
+ setting :root_dir, :default => 'public/js', :doc => 'The root directory where javascript files reside'
25
+
26
+ def self.require path
27
+ end
28
+
9
29
  end
10
30
 
11
31
  # Javascript utilities.
@@ -17,6 +37,7 @@ private
17
37
  def escape_javascript(js)
18
38
  (js || '').gsub(/\r\n|\n|\r/, "\\n").gsub(/["']/) { |m| "\\#{m}" }
19
39
  end
40
+ alias escape escape_javascript
20
41
 
21
42
  # Converts a Ruby hash to a Javascript hash.
22
43
 
@@ -30,6 +51,13 @@ private
30
51
  def name_to_jsfile(name)
31
52
  "/js/#{name}.js"
32
53
  end
54
+
55
+ # Generate javascript confirm code for links.
56
+
57
+ def confirm(text = 'Are you sure?')
58
+ %|onclick="return confirm('#{text}')"|
59
+ end
60
+
33
61
  end
34
62
 
35
63
  # Generates cliend side javascript.
@@ -404,5 +432,3 @@ module JavascriptHelper
404
432
  end
405
433
 
406
434
  end
407
-
408
- # * George Moschovitis <gm@navel.gr>