nitro 0.31.0 → 0.40.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/nitro +135 -37
- data/doc/CHANGELOG.1 +108 -108
- data/doc/CHANGELOG.2 +89 -89
- data/doc/CHANGELOG.3 +105 -105
- data/{CHANGELOG → doc/CHANGELOG.4} +509 -509
- data/doc/{AUTHORS → CONTRIBUTORS} +49 -37
- data/doc/LIBRARIES +13 -0
- data/doc/LICENSE +2 -3
- data/doc/MIGRATION +45 -0
- data/doc/RELEASES +131 -11
- data/doc/TODO +67 -0
- data/lib/glue/magick.rb +0 -3
- data/lib/glue/sweeper.rb +30 -15
- data/lib/glue/thumbnails.rb +0 -2
- data/lib/glue/webfile.rb +23 -11
- data/lib/nitro.rb +37 -44
- data/lib/nitro/adapter/cgi.rb +0 -3
- data/lib/nitro/adapter/console.rb +0 -2
- data/lib/nitro/adapter/fastcgi.rb +6 -3
- data/lib/nitro/adapter/mongrel.rb +97 -58
- data/lib/nitro/adapter/script.rb +4 -6
- data/lib/nitro/adapter/webrick.rb +33 -87
- data/lib/nitro/adapter/webrick/vcr.rb +85 -0
- data/lib/nitro/caching.rb +0 -2
- data/lib/nitro/caching/actions.rb +0 -2
- data/lib/nitro/caching/fragments.rb +0 -2
- data/lib/nitro/caching/output.rb +45 -16
- data/lib/nitro/caching/proxy.rb +49 -0
- data/lib/nitro/cgi.rb +3 -6
- data/lib/nitro/cgi/cookie.rb +0 -3
- data/lib/nitro/cgi/request.rb +67 -24
- data/lib/nitro/cgi/response.rb +0 -2
- data/lib/nitro/cgi/{sendfile.rb → send_file.rb} +7 -6
- data/lib/nitro/compiler.rb +62 -55
- data/lib/nitro/compiler/cleanup.rb +0 -3
- data/lib/nitro/compiler/elements.rb +31 -28
- data/lib/nitro/compiler/errors.rb +2 -5
- data/lib/nitro/compiler/include.rb +10 -8
- data/lib/nitro/compiler/layout.rb +0 -2
- data/lib/nitro/compiler/localization.rb +0 -2
- data/lib/nitro/compiler/markup.rb +14 -6
- data/lib/nitro/compiler/morphing.rb +1 -5
- data/lib/nitro/compiler/script.rb +2 -4
- data/lib/nitro/compiler/squeeze.rb +0 -2
- data/lib/nitro/compiler/xslt.rb +0 -2
- data/lib/nitro/context.rb +10 -5
- data/lib/nitro/control.rb +18 -0
- data/lib/nitro/control/attribute.rb +88 -0
- data/lib/nitro/control/attribute/checkbox.rb +19 -0
- data/lib/nitro/control/attribute/datetime.rb +21 -0
- data/lib/nitro/control/attribute/file.rb +20 -0
- data/lib/nitro/control/attribute/fixnum.rb +26 -0
- data/lib/nitro/control/attribute/float.rb +26 -0
- data/lib/nitro/control/attribute/options.rb +38 -0
- data/lib/nitro/control/attribute/password.rb +16 -0
- data/lib/nitro/control/attribute/text.rb +16 -0
- data/lib/nitro/control/attribute/textarea.rb +16 -0
- data/lib/nitro/control/none.rb +16 -0
- data/lib/nitro/control/relation.rb +53 -0
- data/lib/nitro/control/relation/belongs_to.rb +0 -0
- data/lib/nitro/control/relation/has_many.rb +97 -0
- data/lib/nitro/control/relation/joins_many.rb +0 -0
- data/lib/nitro/control/relation/many_to_many.rb +0 -0
- data/lib/nitro/control/relation/refers_to.rb +29 -0
- data/lib/nitro/controller.rb +7 -296
- data/lib/nitro/dispatcher.rb +72 -34
- data/lib/nitro/element.rb +36 -10
- data/lib/nitro/element/javascript.rb +0 -2
- data/lib/nitro/flash.rb +23 -10
- data/lib/nitro/global.rb +36 -11
- data/lib/nitro/helper.rb +22 -8
- data/lib/nitro/helper/benchmark.rb +0 -2
- data/lib/nitro/helper/buffer.rb +0 -3
- data/lib/nitro/helper/css.rb +12 -0
- data/lib/nitro/helper/debug.rb +1 -3
- data/lib/nitro/helper/default.rb +1 -0
- data/lib/nitro/helper/feed.rb +400 -386
- data/lib/nitro/helper/form.rb +246 -116
- data/lib/nitro/helper/javascript.rb +28 -2
- data/lib/nitro/helper/javascript/morphing.rb +0 -2
- data/lib/nitro/helper/javascript/prototype.rb +0 -2
- data/lib/nitro/helper/javascript/scriptaculous.rb +0 -1
- data/lib/nitro/helper/layout.rb +0 -2
- data/lib/nitro/helper/navigation.rb +87 -0
- data/lib/nitro/helper/pager.rb +11 -22
- data/lib/nitro/helper/table.rb +9 -32
- data/lib/nitro/helper/url.rb +104 -0
- data/lib/nitro/helper/xhtml.rb +20 -4
- data/lib/nitro/helper/xml.rb +0 -2
- data/lib/nitro/markup.rb +131 -0
- data/lib/nitro/part.rb +52 -7
- data/lib/nitro/publishable.rb +328 -0
- data/lib/nitro/render.rb +30 -61
- data/lib/nitro/router.rb +12 -4
- data/lib/nitro/sanitize.rb +48 -0
- data/lib/nitro/scaffold.rb +9 -11
- data/lib/nitro/scaffold/controller.rb +25 -0
- data/lib/nitro/scaffold/model.rb +150 -0
- data/lib/nitro/scaffolding.rb +1 -3
- data/lib/nitro/server.rb +57 -32
- data/lib/nitro/server/drb.rb +16 -2
- data/lib/nitro/server/runner.rb +80 -102
- data/lib/nitro/service.rb +0 -1
- data/lib/nitro/service/xmlrpc.rb +0 -2
- data/lib/nitro/session.rb +26 -18
- data/lib/nitro/session/drb.rb +2 -16
- data/lib/nitro/session/memory.rb +0 -2
- data/lib/nitro/template.rb +219 -0
- data/lib/nitro/test/assertions.rb +1 -3
- data/lib/nitro/test/context.rb +0 -1
- data/lib/nitro/test/testcase.rb +0 -1
- data/lib/nitro/version.rb +6 -0
- data/lib/part/admin.rb +16 -0
- data/lib/part/admin/controller.rb +19 -0
- data/lib/part/admin/helper.rb +30 -0
- data/lib/part/admin/og/controller.rb +114 -0
- data/lib/part/admin/og/customize.rb +4 -0
- data/lib/part/admin/og/template/index.xhtml +27 -0
- data/lib/part/admin/og/template/list.xhtml +38 -0
- data/lib/part/admin/og/template/search.xhtml +20 -0
- data/lib/part/admin/og/template/update.xhtml +25 -0
- data/lib/part/admin/skin.rb +207 -0
- data/lib/part/admin/template/denied.xhtml +13 -0
- data/lib/part/admin/template/index.xhtml +12 -0
- data/lib/part/admin/todo.txt +2 -0
- data/proto/public/error.xhtml +4 -2
- data/proto/run.rb +0 -2
- data/test/glue/tc_webfile.rb +1 -0
- data/test/nitro/cgi/tc_request.rb +23 -0
- data/test/nitro/helper/tc_feed.rb +0 -3
- data/test/nitro/helper/tc_navbar.rb +74 -0
- data/test/nitro/helper/tc_table.rb +2 -0
- data/test/nitro/tc_cgi.rb +72 -19
- data/test/nitro/tc_controller.rb +35 -26
- data/test/nitro/tc_controller_aspect.rb +1 -0
- data/test/nitro/tc_controller_params.rb +864 -0
- data/test/nitro/tc_dispatcher.rb +2 -2
- data/test/nitro/tc_element.rb +16 -16
- data/test/nitro/tc_flash.rb +3 -3
- data/test/nitro/tc_markup.rb +31 -0
- data/test/nitro/tc_render.rb +12 -14
- data/test/nitro/tc_session.rb +9 -7
- data/test/nitro/tc_template.rb +34 -0
- metadata +217 -198
- data/INSTALL +0 -121
- data/ProjectInfo +0 -74
- data/README +0 -555
- data/doc/apache.txt +0 -9
- data/doc/config.txt +0 -28
- data/doc/faq.txt +0 -7
- data/doc/lhttpd.txt +0 -7
- data/lib/nitro/adapter/scgi.rb +0 -239
- data/lib/nitro/helper/form/builder.rb +0 -144
- data/lib/nitro/helper/form/controls.rb +0 -389
- data/lib/nitro/helper/rss.rb +0 -72
- data/proto/conf/apache.conf +0 -51
- data/proto/public/scaffold/advanced_search.xhtml +0 -30
- data/proto/public/scaffold/edit.xhtml +0 -11
- data/proto/public/scaffold/form.xhtml +0 -1
- data/proto/public/scaffold/index.xhtml +0 -20
- data/proto/public/scaffold/list.xhtml +0 -32
- data/proto/public/scaffold/new.xhtml +0 -11
- data/proto/public/scaffold/search.xhtml +0 -29
- data/proto/public/scaffold/view.xhtml +0 -8
- data/proto/script/scgi_ctl +0 -221
- data/proto/script/scgi_service +0 -128
- data/setup.rb +0 -1585
- data/src/part/admin.rb +0 -16
- data/src/part/admin/controller.rb +0 -81
- data/src/part/admin/skin.rb +0 -21
- data/src/part/admin/system.css +0 -135
- data/src/part/admin/template/denied.xhtml +0 -1
- data/src/part/admin/template/index.xhtml +0 -43
- data/test/nitro/helper/tc_rss.rb +0 -24
data/lib/nitro/helper/layout.rb
CHANGED
@@ -0,0 +1,87 @@
|
|
1
|
+
module Nitro
|
2
|
+
|
3
|
+
# A helper mixin for programmatically building Navigation Menus
|
4
|
+
# through easy to style XHTML.
|
5
|
+
# The code resulting from these methods is in line with that found in most examples at
|
6
|
+
# listamatic, thus you can use prebuilt CSS and Javascript to create horizontal or vertical menus.
|
7
|
+
# Basically it generates something like
|
8
|
+
# <div id="navcontainer">
|
9
|
+
# <ul id="navlist">
|
10
|
+
# <li id="active"> <a href="/foo" id="current"> Current Page </a></li>
|
11
|
+
# <li> <a href="/bar"> Other page </a> </li>
|
12
|
+
# </ul>
|
13
|
+
# </div>
|
14
|
+
#
|
15
|
+
# This helper takes care of setting of putting the special CSS
|
16
|
+
# identifiers for the current controller automatically.
|
17
|
+
# You could override menuitem_active_on(path)
|
18
|
+
# to change the behaviour that choose the active item,
|
19
|
+
# for example to keep the item "Wiki" active both for
|
20
|
+
# /wiki/pageone and /wiki/pagetwo
|
21
|
+
#
|
22
|
+
# Example of horizontal bar at listamatic:
|
23
|
+
# http://css.maxdesign.com.au/listamatic/horizontal26.htm
|
24
|
+
# Vertical example
|
25
|
+
# http://css.maxdesign.com.au/listamatic/vertical09.htm
|
26
|
+
#
|
27
|
+
# NOTE: No tests were made with Publishable objects which are not
|
28
|
+
# subclass of Nitro::Controller, but it _should_ work.
|
29
|
+
|
30
|
+
module NavigationHelper
|
31
|
+
|
32
|
+
TEMPLATE=<<Eof
|
33
|
+
<div id="navcontainer">
|
34
|
+
<ul id="navlist">
|
35
|
+
LIST
|
36
|
+
</ul>
|
37
|
+
</div>
|
38
|
+
Eof
|
39
|
+
|
40
|
+
# Takes a list of controllers and builds a menu
|
41
|
+
# using #mount_path as the url and the controller name as text.
|
42
|
+
# An eventual "Controller" suffix will be stripped, so i.e. for controllers
|
43
|
+
# named +HomeController+, +Pages+, +FeedCtl+ it will use
|
44
|
+
# +Home+, +Page+, +FeedCtl+.
|
45
|
+
#
|
46
|
+
# For more finegrained control you can pass a block to this function, each
|
47
|
+
# controller will be passed to it and the result will be used as the text
|
48
|
+
# for the menu item.
|
49
|
+
#
|
50
|
+
#
|
51
|
+
# Otherwise you can specify pairs of path/text using #navigation_for_hash
|
52
|
+
|
53
|
+
def menu_for(*controllers) #:yields:
|
54
|
+
hash= {}
|
55
|
+
controllers.each do |c|
|
56
|
+
hash[c.mount_path] = block_given? ? yield(c) : c.name.gsub(/Controller/,'')
|
57
|
+
end
|
58
|
+
menu_from_hash(hash)
|
59
|
+
end
|
60
|
+
|
61
|
+
# The argument must be an hash of pairs {'path'=>'text for menu item'},
|
62
|
+
# no control will be applied on these values, they will be used directly.
|
63
|
+
# You can use the method like
|
64
|
+
# navigation_for_hash '/foo/bar'=>'Page One', '/foo/baz'=>'Page Two'
|
65
|
+
#
|
66
|
+
# The method takes care of setting the CSS values as expected.
|
67
|
+
#
|
68
|
+
# To avoid specifying everything the method #navigation_menu can be used.
|
69
|
+
|
70
|
+
def menu_from_hash(hash)
|
71
|
+
list=hash.map do |path,name|
|
72
|
+
if menuitem_active_on?(path)
|
73
|
+
%{<li id="active"><a href="#{path}" id="current"> #{name} </a></li>}
|
74
|
+
else
|
75
|
+
%{<li><a href="#{path}"> #{name} </a></li>}
|
76
|
+
end
|
77
|
+
end.join("\n")
|
78
|
+
TEMPLATE.gsub("LIST",list)
|
79
|
+
end
|
80
|
+
|
81
|
+
def menuitem_active_on?(path)
|
82
|
+
path == request.path
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
data/lib/nitro/helper/pager.rb
CHANGED
@@ -24,10 +24,6 @@ class Pager
|
|
24
24
|
|
25
25
|
setting :key, :default => '_page', :doc => 'The request key'
|
26
26
|
|
27
|
-
# The nav link titles
|
28
|
-
|
29
|
-
setting :link_titles, :default => {:first => 'First', :previous => 'Previous', :last => 'Last', :next => 'Next'}, :doc => "Titles of pager links"
|
30
|
-
|
31
27
|
# The current page.
|
32
28
|
|
33
29
|
attr_accessor :page
|
@@ -44,10 +40,10 @@ class Pager
|
|
44
40
|
|
45
41
|
attr_accessor :total_count
|
46
42
|
|
47
|
-
def initialize(request, per_page, total_count, key = Pager.key
|
43
|
+
def initialize(request, per_page, total_count, key = Pager.key)
|
48
44
|
raise 'per_page should be > 0' unless per_page > 0
|
49
45
|
|
50
|
-
@request, @key
|
46
|
+
@request, @key = request, key
|
51
47
|
@page = request.query.fetch(key, 1).to_i
|
52
48
|
@per_page = per_page
|
53
49
|
set_count(total_count)
|
@@ -59,10 +55,6 @@ class Pager
|
|
59
55
|
@page_count = (@total_count.to_f / @per_page).ceil
|
60
56
|
end
|
61
57
|
|
62
|
-
def has_pages?
|
63
|
-
return @page_count > 1
|
64
|
-
end
|
65
|
-
|
66
58
|
# Return the first page index.
|
67
59
|
|
68
60
|
def first_page
|
@@ -196,18 +188,17 @@ class Pager
|
|
196
188
|
def navigation
|
197
189
|
nav = ""
|
198
190
|
|
199
|
-
return nav unless has_pages?
|
200
191
|
unless first_page?
|
201
192
|
nav << %{
|
202
|
-
<div class="first"><a href="#{first_page_href}"
|
203
|
-
<div class="previous"><a href="#{previous_page_href}"
|
193
|
+
<div class="first"><a href="#{first_page_href}">First</a></div>
|
194
|
+
<div class="previous"><a href="#{previous_page_href}">Previous</a></div>
|
204
195
|
}
|
205
196
|
end
|
206
197
|
|
207
198
|
unless last_page?
|
208
199
|
nav << %{
|
209
|
-
<div class="last"><a href="#{last_page_href}"
|
210
|
-
<div class="next"><a href="#{next_page_href}"
|
200
|
+
<div class="last"><a href="#{last_page_href}">Last</a></div>
|
201
|
+
<div class="next"><a href="#{next_page_href}">Next</a></div>
|
211
202
|
}
|
212
203
|
end
|
213
204
|
|
@@ -277,26 +268,26 @@ private
|
|
277
268
|
# #{pager.links}
|
278
269
|
|
279
270
|
def paginate(items, options = {})
|
280
|
-
per_page = options.delete(:per_page) || Pager.per_page
|
271
|
+
per_page = options.delete(:per_page) || options[:limit] || Pager.per_page
|
281
272
|
pager_key = options.delete(:pager_key) || Pager.key
|
282
|
-
|
273
|
+
|
283
274
|
case items
|
284
275
|
when Array
|
285
276
|
items = items.dup
|
286
|
-
pager = Pager.new(request, per_page, items.size, pager_key
|
277
|
+
pager = Pager.new(request, per_page, items.size, pager_key)
|
287
278
|
items = items.slice(pager.offset, pager.per_page) || []
|
288
279
|
return items, pager
|
289
280
|
|
290
281
|
when Og::Collection
|
291
282
|
collection = items
|
292
|
-
pager = Pager.new(request, per_page, collection.count, pager_key
|
283
|
+
pager = Pager.new(request, per_page, collection.count, pager_key)
|
293
284
|
options.update(pager.limit)
|
294
285
|
items = collection.reload(options)
|
295
286
|
return items, pager
|
296
287
|
|
297
288
|
when Class
|
298
289
|
klass = items
|
299
|
-
pager = Pager.new(request, per_page, klass.count(options), pager_key
|
290
|
+
pager = Pager.new(request, per_page, klass.count(options), pager_key)
|
300
291
|
options.update(pager.limit)
|
301
292
|
items = klass.all(options)
|
302
293
|
return items, pager
|
@@ -306,5 +297,3 @@ private
|
|
306
297
|
end
|
307
298
|
|
308
299
|
end
|
309
|
-
|
310
|
-
# * George Moschovitis <gm@navel.gr>
|
data/lib/nitro/helper/table.rb
CHANGED
@@ -37,6 +37,7 @@ module Nitro
|
|
37
37
|
#
|
38
38
|
#--
|
39
39
|
# TODO: legend, verbose... ?
|
40
|
+
# TODO, gmosx: Remove crappy, bloatware additions.
|
40
41
|
#++
|
41
42
|
|
42
43
|
module TableHelper
|
@@ -84,7 +85,7 @@ module TableHelper
|
|
84
85
|
def table_rows(options)
|
85
86
|
# also accept :items, :rows
|
86
87
|
options[:values] = options[:values] || options[:items] || options[:rows]
|
87
|
-
|
88
|
+
|
88
89
|
str = ''
|
89
90
|
str << table_header(options) if options[:headers]
|
90
91
|
str << table_footer(options) if options[:footers]
|
@@ -111,7 +112,7 @@ module TableHelper
|
|
111
112
|
str << '>'
|
112
113
|
|
113
114
|
for value in row
|
114
|
-
str << %|<td>#{
|
115
|
+
str << %|<td>#{value}</td>|
|
115
116
|
end
|
116
117
|
|
117
118
|
str << '</tr>'
|
@@ -131,7 +132,7 @@ module TableHelper
|
|
131
132
|
str << '>'
|
132
133
|
|
133
134
|
for value in row
|
134
|
-
str << %|<td>#{
|
135
|
+
str << %|<td>#{value}</td>|
|
135
136
|
end
|
136
137
|
|
137
138
|
str << '</tr>'
|
@@ -159,7 +160,6 @@ module TableHelper
|
|
159
160
|
str << '<tr>'
|
160
161
|
|
161
162
|
options[:headers].each_with_index do |header, index|
|
162
|
-
header = process(header)
|
163
163
|
if (options[:order] && options[:order][:values] &&
|
164
164
|
options[:order][:values][index])
|
165
165
|
order_by = options[:order][:values][index]
|
@@ -233,37 +233,14 @@ module TableHelper
|
|
233
233
|
return Glue::UriUtils.update_query_string(request.uri.to_s, params)
|
234
234
|
end
|
235
235
|
|
236
|
+
#--
|
237
|
+
# gmosx: Arrgh!! dangerous method, who added this?
|
238
|
+
#++
|
239
|
+
|
236
240
|
def create_tbody?(options)
|
237
|
-
options[:values][0]
|
238
|
-
end
|
239
|
-
|
240
|
-
# A simple hack to allow Localization-processing in the table-helper
|
241
|
-
# overwrite this method to make this happen
|
242
|
-
# Now you can just pass [[somestring]] to the tablehelper and it will
|
243
|
-
# be localized like the rest of the page.
|
244
|
-
# ATM it's only kicking in when the @lc is set.
|
245
|
-
#
|
246
|
-
# Example for the method:
|
247
|
-
# module Nitro
|
248
|
-
# module TableHelper
|
249
|
-
# def process(value)
|
250
|
-
# val = value.to_s.gsub(/\[\[(.*?)\]\]/){ @lc[$1] }
|
251
|
-
# return val == "" ? value : val
|
252
|
-
# end
|
253
|
-
# end
|
254
|
-
# end
|
255
|
-
|
256
|
-
def process(value)
|
257
|
-
if @lc
|
258
|
-
val = value.to_s.gsub(/\[\[(.*?)\]\]/){ @lc[$1] }
|
259
|
-
return val == "" ? value : val
|
260
|
-
end
|
261
|
-
return value
|
241
|
+
options[:values][0][0].respond_to?(:to_ary)
|
262
242
|
end
|
263
243
|
|
264
244
|
end
|
265
245
|
|
266
246
|
end
|
267
|
-
|
268
|
-
# * George Moschovitis <gm@navel.gr>
|
269
|
-
# * Kashia Buch <kashia@vfemail.net>
|
@@ -0,0 +1,104 @@
|
|
1
|
+
module Nitro
|
2
|
+
|
3
|
+
module URLHelper
|
4
|
+
|
5
|
+
# Encode controller, action, params into a valid url.
|
6
|
+
# Automatically respects nice urls and routing.
|
7
|
+
#
|
8
|
+
# Handles parameters either as a hash or as an array.
|
9
|
+
# Use the array method to pass parameters to 'nice' actions.
|
10
|
+
#
|
11
|
+
# Pass Controller, action, and (param_name, param_value)
|
12
|
+
# pairs.
|
13
|
+
#
|
14
|
+
# === Examples
|
15
|
+
#
|
16
|
+
# encode_url ForaController, :post, :title, 'Hello', :body, 'World'
|
17
|
+
# encode_url :post, :title, 'Hello', :body, 'World' # => implies controller == self
|
18
|
+
# encode_url :kick, :oid, 4
|
19
|
+
# encode_url article # => article.to_href
|
20
|
+
#
|
21
|
+
# Alternatively you can pass options with a hash:
|
22
|
+
#
|
23
|
+
# encode_url :controller => ForaController, :action => :delete, :params => { :title => 'Hello' }
|
24
|
+
# encode_url :action => :delete
|
25
|
+
#--
|
26
|
+
# FIXME: better implementation? optimize this?
|
27
|
+
# TODO: move elsewhere.
|
28
|
+
#++
|
29
|
+
|
30
|
+
def encode_url(*args)
|
31
|
+
f = args.first
|
32
|
+
|
33
|
+
# A standard url as string, return as is.
|
34
|
+
|
35
|
+
if f.is_a? String
|
36
|
+
return f
|
37
|
+
end
|
38
|
+
|
39
|
+
# If the passed param is an object that responds to :to_href
|
40
|
+
# returns the url to this object.
|
41
|
+
|
42
|
+
if f.respond_to? :to_href
|
43
|
+
return args.first.to_href
|
44
|
+
end
|
45
|
+
|
46
|
+
if f.is_a? Symbol
|
47
|
+
# no controller passed, imply controller == self!
|
48
|
+
args.unshift(self.class)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Try to encode using the router.
|
52
|
+
|
53
|
+
if url = Nitro.server.dispatcher.encode_route(*args)
|
54
|
+
return url
|
55
|
+
end
|
56
|
+
|
57
|
+
# No routing rule, manual encoding.
|
58
|
+
|
59
|
+
controller = args.shift
|
60
|
+
action = args.shift.to_sym
|
61
|
+
|
62
|
+
if action == :index
|
63
|
+
url = "#{controller.mount_path}"
|
64
|
+
else
|
65
|
+
mount_path = controller.mount_path
|
66
|
+
mount_path = nil if mount_path == '/'
|
67
|
+
url = "#{mount_path}/#{action}"
|
68
|
+
end
|
69
|
+
|
70
|
+
unless args.empty?
|
71
|
+
if controller.respond_to_action_or_template? action
|
72
|
+
param_count = controller.instance_method(action).arity
|
73
|
+
if param_count != 0
|
74
|
+
param_count.times do
|
75
|
+
args.shift # name
|
76
|
+
url << "/#{CGI.escape(args.shift.to_s)}"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
unless args.empty?
|
82
|
+
url << '?'
|
83
|
+
params = []
|
84
|
+
(args.size / 2).times do
|
85
|
+
params << "#{args.shift}=#{args.shift}"
|
86
|
+
end
|
87
|
+
url << params.join(';')
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
return url
|
92
|
+
end
|
93
|
+
alias R encode_url
|
94
|
+
|
95
|
+
# Just like encode_url, but generates an absolute url instead.
|
96
|
+
|
97
|
+
def encode_absolute_url(*args)
|
98
|
+
return "#{request.host_url}#{encode_url(*args)}"
|
99
|
+
end
|
100
|
+
alias RA encode_absolute_url
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
data/lib/nitro/helper/xhtml.rb
CHANGED
@@ -6,6 +6,9 @@ module Nitro
|
|
6
6
|
module XhtmlHelper
|
7
7
|
|
8
8
|
# Creates the href of an Object.
|
9
|
+
#--
|
10
|
+
# gmosx: this duplicates R functionality, merge!
|
11
|
+
#++
|
9
12
|
|
10
13
|
def href_of(obj, base = nil)
|
11
14
|
if obj.is_a?(Symbol) or obj.is_a?(String)
|
@@ -89,11 +92,25 @@ module XhtmlHelper
|
|
89
92
|
end
|
90
93
|
end
|
91
94
|
|
95
|
+
# Convert a collection of objects to options.
|
96
|
+
|
97
|
+
def objects_to_options(objs, params = {})
|
98
|
+
labels = []
|
99
|
+
values = []
|
100
|
+
for obj in objs
|
101
|
+
labels << obj.to_s
|
102
|
+
values << obj.pk
|
103
|
+
end
|
104
|
+
params[:labels] = labels
|
105
|
+
params[:values] = values
|
106
|
+
options(params)
|
107
|
+
end
|
108
|
+
|
92
109
|
# Render a hidden form input.
|
93
110
|
|
94
|
-
def hidden(
|
95
|
-
|
96
|
-
%[<input type="hidden" #{
|
111
|
+
def hidden(name, value)
|
112
|
+
# opts = options.collect { |k, v| %[#{k}="#{v}"] }.join(' ')
|
113
|
+
%[<input type="hidden" name="#{name}" value="#{value}" />]
|
97
114
|
end
|
98
115
|
|
99
116
|
# Render a submit input.
|
@@ -199,4 +216,3 @@ end
|
|
199
216
|
|
200
217
|
end
|
201
218
|
|
202
|
-
# * George Moschovitis <gm@navel.gr>
|
data/lib/nitro/helper/xml.rb
CHANGED
data/lib/nitro/markup.rb
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'redcloth'
|
3
|
+
require 'cgi'
|
4
|
+
|
5
|
+
require 'facets/core/module/class_extension'
|
6
|
+
|
7
|
+
require 'nitro/sanitize'
|
8
|
+
|
9
|
+
module Nitro
|
10
|
+
|
11
|
+
# Generalised Markup transformations.
|
12
|
+
#
|
13
|
+
# The expand methods evaluate (expand) the markup
|
14
|
+
# code to produce the final content. The compact
|
15
|
+
# methods reverse this process to create the original
|
16
|
+
# markup code. Not all markup transformations are
|
17
|
+
# reversible.
|
18
|
+
#
|
19
|
+
# When this library is included, the default PropertyUtils
|
20
|
+
# implementation is overriden to add markup support.
|
21
|
+
#
|
22
|
+
# === Examples
|
23
|
+
#
|
24
|
+
# Define your custom markup methods like this:
|
25
|
+
#
|
26
|
+
# module Markup
|
27
|
+
# def markup_simple
|
28
|
+
# ...
|
29
|
+
# end
|
30
|
+
# def markup_special
|
31
|
+
# ...
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# # maps the {{..}} macro
|
35
|
+
# alias_method :sanitize, :markup_simple
|
36
|
+
# # maps the {|..|} macro
|
37
|
+
# alias_method :markup, :markup_special
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
# here comes the #{obj.body} # => prints the expanded version.
|
41
|
+
#
|
42
|
+
# obj.body = markup(@params['body'])
|
43
|
+
|
44
|
+
module Markup
|
45
|
+
|
46
|
+
private
|
47
|
+
# The default markup method. You should override this method
|
48
|
+
# in your application to call your custom markup
|
49
|
+
# methods.
|
50
|
+
|
51
|
+
def expand(str)
|
52
|
+
if str
|
53
|
+
xstr = str.dup
|
54
|
+
xstr.gsub!(/</, '<')
|
55
|
+
xstr.gsub!(/>/, '>')
|
56
|
+
xstr.gsub!(/\r/, '<br />')
|
57
|
+
return String.sanitize(xstr)
|
58
|
+
end
|
59
|
+
return nil
|
60
|
+
end
|
61
|
+
alias_method :sanitize, :expand
|
62
|
+
|
63
|
+
# ...
|
64
|
+
begin
|
65
|
+
require 'redcloth'
|
66
|
+
# Translates a String with Textile/Markdown formatting
|
67
|
+
# into XHTML. Depends on the RedCloth gem to work properly
|
68
|
+
|
69
|
+
def expand_redcloth(str)
|
70
|
+
if str
|
71
|
+
return RedCloth.new(expand(str)).to_html
|
72
|
+
end
|
73
|
+
return nil
|
74
|
+
end
|
75
|
+
rescue LoadError
|
76
|
+
def expand_redcloth(str) # :nodoc:
|
77
|
+
"You called expand_redcloth(), but it needs RedCloth installed to work"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
alias_method :markup, :expand_redcloth
|
81
|
+
|
82
|
+
# Compact (reverse) the content to the origial markup
|
83
|
+
# code. Not all markup transformations are reversible.
|
84
|
+
# You should override this method in your application
|
85
|
+
# to call your custom markup methods.
|
86
|
+
#
|
87
|
+
# NOT IMPLEMENTED.
|
88
|
+
|
89
|
+
def compact(str, meth = nil)
|
90
|
+
end
|
91
|
+
|
92
|
+
# Remove markup code from the input string.
|
93
|
+
#
|
94
|
+
# NOT IMPLEMENTED.
|
95
|
+
|
96
|
+
def clear(str)
|
97
|
+
end
|
98
|
+
|
99
|
+
def escape(str)
|
100
|
+
CGI.escape(str.gsub(/ /, '_'))
|
101
|
+
end
|
102
|
+
|
103
|
+
def unescape(str)
|
104
|
+
CGI.unescape(str.gsub(/_/, ' '))
|
105
|
+
end
|
106
|
+
|
107
|
+
class_extension do
|
108
|
+
# Helper method for manipulating the sanitize transformation.
|
109
|
+
|
110
|
+
def setup_sanitize_transform(&block)
|
111
|
+
self.send :define_method, :sanitize, block
|
112
|
+
end
|
113
|
+
alias_method :setup_sanitize_transformation, :setup_sanitize_transform
|
114
|
+
|
115
|
+
# Helper method for manipulating the markup transformation.
|
116
|
+
|
117
|
+
def setup_markup_transform(&block)
|
118
|
+
self.send :define_method, :markup, block
|
119
|
+
end
|
120
|
+
alias_method :setup_markup_transformation, :setup_markup_transform
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
# An abstract Markup class.
|
125
|
+
|
126
|
+
class MarkupKit
|
127
|
+
extend Markup
|
128
|
+
include Markup
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|