raw 0.49.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.
- data/doc/CONTRIBUTORS +106 -0
- data/doc/LICENSE +32 -0
- data/doc/coding_conventions.txt +11 -0
- data/lib/raw.rb +42 -0
- data/lib/raw/adapter.rb +113 -0
- data/lib/raw/adapter/cgi.rb +41 -0
- data/lib/raw/adapter/fastcgi.rb +48 -0
- data/lib/raw/adapter/mongrel.rb +146 -0
- data/lib/raw/adapter/script.rb +94 -0
- data/lib/raw/adapter/webrick.rb +144 -0
- data/lib/raw/adapter/webrick/vcr.rb +91 -0
- data/lib/raw/cgi.rb +323 -0
- data/lib/raw/cgi/cookie.rb +47 -0
- data/lib/raw/cgi/http.rb +62 -0
- data/lib/raw/compiler.rb +138 -0
- data/lib/raw/compiler/filter/cleanup.rb +21 -0
- data/lib/raw/compiler/filter/elements.rb +166 -0
- data/lib/raw/compiler/filter/elements/element.rb +210 -0
- data/lib/raw/compiler/filter/localization.rb +23 -0
- data/lib/raw/compiler/filter/markup.rb +32 -0
- data/lib/raw/compiler/filter/morph.rb +123 -0
- data/lib/raw/compiler/filter/morph/each.rb +34 -0
- data/lib/raw/compiler/filter/morph/for.rb +11 -0
- data/lib/raw/compiler/filter/morph/if.rb +26 -0
- data/lib/raw/compiler/filter/morph/selected_if.rb +43 -0
- data/lib/raw/compiler/filter/morph/standard.rb +55 -0
- data/lib/raw/compiler/filter/morph/times.rb +27 -0
- data/lib/raw/compiler/filter/script.rb +116 -0
- data/lib/raw/compiler/filter/squeeze.rb +16 -0
- data/lib/raw/compiler/filter/static_include.rb +74 -0
- data/lib/raw/compiler/filter/template.rb +121 -0
- data/lib/raw/compiler/reloader.rb +96 -0
- data/lib/raw/context.rb +154 -0
- data/lib/raw/context/flash.rb +157 -0
- data/lib/raw/context/global.rb +88 -0
- data/lib/raw/context/request.rb +338 -0
- data/lib/raw/context/response.rb +57 -0
- data/lib/raw/context/session.rb +198 -0
- data/lib/raw/context/session/drb.rb +11 -0
- data/lib/raw/context/session/file.rb +15 -0
- data/lib/raw/context/session/memcached.rb +13 -0
- data/lib/raw/context/session/memory.rb +12 -0
- data/lib/raw/context/session/og.rb +15 -0
- data/lib/raw/context/session/pstore.rb +13 -0
- data/lib/raw/control.rb +18 -0
- data/lib/raw/control/attribute.rb +91 -0
- data/lib/raw/control/attribute/checkbox.rb +25 -0
- data/lib/raw/control/attribute/datetime.rb +21 -0
- data/lib/raw/control/attribute/file.rb +20 -0
- data/lib/raw/control/attribute/fixnum.rb +26 -0
- data/lib/raw/control/attribute/float.rb +26 -0
- data/lib/raw/control/attribute/options.rb +38 -0
- data/lib/raw/control/attribute/password.rb +16 -0
- data/lib/raw/control/attribute/text.rb +16 -0
- data/lib/raw/control/attribute/textarea.rb +16 -0
- data/lib/raw/control/none.rb +16 -0
- data/lib/raw/control/relation.rb +59 -0
- data/lib/raw/control/relation/belongs_to.rb +0 -0
- data/lib/raw/control/relation/has_many.rb +97 -0
- data/lib/raw/control/relation/joins_many.rb +0 -0
- data/lib/raw/control/relation/many_to_many.rb +0 -0
- data/lib/raw/control/relation/refers_to.rb +29 -0
- data/lib/raw/controller.rb +37 -0
- data/lib/raw/controller/publishable.rb +160 -0
- data/lib/raw/dispatcher.rb +209 -0
- data/lib/raw/dispatcher/format.rb +108 -0
- data/lib/raw/dispatcher/format/atom.rb +31 -0
- data/lib/raw/dispatcher/format/css.rb +0 -0
- data/lib/raw/dispatcher/format/html.rb +42 -0
- data/lib/raw/dispatcher/format/json.rb +31 -0
- data/lib/raw/dispatcher/format/rss.rb +33 -0
- data/lib/raw/dispatcher/format/xoxo.rb +31 -0
- data/lib/raw/dispatcher/mounter.rb +60 -0
- data/lib/raw/dispatcher/router.rb +111 -0
- data/lib/raw/errors.rb +19 -0
- data/lib/raw/helper.rb +86 -0
- data/lib/raw/helper/benchmark.rb +23 -0
- data/lib/raw/helper/buffer.rb +60 -0
- data/lib/raw/helper/cookie.rb +32 -0
- data/lib/raw/helper/debug.rb +28 -0
- data/lib/raw/helper/default.rb +16 -0
- data/lib/raw/helper/feed.rb +451 -0
- data/lib/raw/helper/form.rb +284 -0
- data/lib/raw/helper/javascript.rb +59 -0
- data/lib/raw/helper/layout.rb +40 -0
- data/lib/raw/helper/navigation.rb +87 -0
- data/lib/raw/helper/pager.rb +305 -0
- data/lib/raw/helper/table.rb +247 -0
- data/lib/raw/helper/xhtml.rb +218 -0
- data/lib/raw/helper/xml.rb +125 -0
- data/lib/raw/mixin/magick.rb +35 -0
- data/lib/raw/mixin/sweeper.rb +71 -0
- data/lib/raw/mixin/thumbnails.rb +1 -0
- data/lib/raw/mixin/webfile.rb +165 -0
- data/lib/raw/render.rb +271 -0
- data/lib/raw/render/builder.rb +26 -0
- data/lib/raw/render/caching.rb +81 -0
- data/lib/raw/render/call.rb +43 -0
- data/lib/raw/render/send_file.rb +46 -0
- data/lib/raw/render/stream.rb +39 -0
- data/lib/raw/scaffold.rb +13 -0
- data/lib/raw/scaffold/controller.rb +25 -0
- data/lib/raw/scaffold/model.rb +157 -0
- data/lib/raw/test.rb +5 -0
- data/lib/raw/test/assertions.rb +169 -0
- data/lib/raw/test/context.rb +55 -0
- data/lib/raw/test/testcase.rb +79 -0
- data/lib/raw/util/attr.rb +128 -0
- data/lib/raw/util/encode_uri.rb +149 -0
- data/lib/raw/util/html_filter.rb +538 -0
- data/lib/raw/util/markup.rb +130 -0
- data/test/glue/tc_webfile.rb +1 -0
- data/test/nitro/CONFIG.rb +3 -0
- data/test/nitro/adapter/raw_post1.bin +9 -0
- data/test/nitro/adapter/tc_webrick.rb +16 -0
- data/test/nitro/cgi/tc_cookie.rb +14 -0
- data/test/nitro/cgi/tc_request.rb +61 -0
- data/test/nitro/compiler/tc_client_morpher.rb +47 -0
- data/test/nitro/compiler/tc_compiler.rb +25 -0
- data/test/nitro/dispatcher/tc_mounter.rb +47 -0
- data/test/nitro/helper/tc_feed.rb +135 -0
- data/test/nitro/helper/tc_navbar.rb +74 -0
- data/test/nitro/helper/tc_pager.rb +35 -0
- data/test/nitro/helper/tc_table.rb +68 -0
- data/test/nitro/helper/tc_xhtml.rb +19 -0
- data/test/nitro/tc_caching.rb +19 -0
- data/test/nitro/tc_cgi.rb +222 -0
- data/test/nitro/tc_context.rb +17 -0
- data/test/nitro/tc_controller.rb +103 -0
- data/test/nitro/tc_controller_aspect.rb +32 -0
- data/test/nitro/tc_controller_params.rb +885 -0
- data/test/nitro/tc_dispatcher.rb +109 -0
- data/test/nitro/tc_element.rb +85 -0
- data/test/nitro/tc_flash.rb +59 -0
- data/test/nitro/tc_helper.rb +47 -0
- data/test/nitro/tc_render.rb +119 -0
- data/test/nitro/tc_router.rb +61 -0
- data/test/nitro/tc_server.rb +35 -0
- data/test/nitro/tc_session.rb +66 -0
- data/test/nitro/tc_template.rb +71 -0
- data/test/nitro/util/tc_encode_url.rb +87 -0
- data/test/nitro/util/tc_markup.rb +31 -0
- data/test/public/blog/another/very_litle/index.xhtml +1 -0
- data/test/public/blog/inc1.xhtml +2 -0
- data/test/public/blog/inc2.xhtml +1 -0
- data/test/public/blog/list.xhtml +9 -0
- data/test/public/dummy_mailer/registration.xhtml +5 -0
- metadata +244 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require "facets/more/xoxo"
|
|
2
|
+
|
|
3
|
+
require "raw/dispatcher/format"
|
|
4
|
+
|
|
5
|
+
module Raw
|
|
6
|
+
|
|
7
|
+
class ATOMFormat < Format
|
|
8
|
+
|
|
9
|
+
def initialize
|
|
10
|
+
@name = "atom"
|
|
11
|
+
@content_type = "application/atom+xml" # "text/xml"
|
|
12
|
+
@extension = "atom"
|
|
13
|
+
@template_extension = "atomx"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def after_action(controller, context)
|
|
17
|
+
if controller.out.blank?
|
|
18
|
+
if model = controller.class.ann(:self, :model)
|
|
19
|
+
resource = model.to_s.demodulize.underscore
|
|
20
|
+
if collection = controller.instance_variable_get("@#{resource.plural}")
|
|
21
|
+
controller.send(:print, XOXO.dump(collection))
|
|
22
|
+
elsif resource = controller.instance_variable_get("@#{resource}")
|
|
23
|
+
controller.send(:print, XOXO.dump(resource))
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
File without changes
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require "raw/dispatcher/format"
|
|
2
|
+
require "raw/compiler/filter/template"
|
|
3
|
+
require "raw/compiler/filter/squeeze"
|
|
4
|
+
require "raw/compiler/filter/markup"
|
|
5
|
+
require "raw/compiler/filter/morph"
|
|
6
|
+
require "raw/compiler/filter/static_include"
|
|
7
|
+
require "raw/compiler/filter/elements"
|
|
8
|
+
require "raw/compiler/filter/cleanup"
|
|
9
|
+
|
|
10
|
+
module Raw
|
|
11
|
+
|
|
12
|
+
class HTMLFormat < Format
|
|
13
|
+
|
|
14
|
+
def initialize
|
|
15
|
+
@name = "html"
|
|
16
|
+
@content_type = "text/html"
|
|
17
|
+
@extension = "html"
|
|
18
|
+
@template_extension = "htmlx"
|
|
19
|
+
@template_filters = [
|
|
20
|
+
StaticIncludeFilter.new,
|
|
21
|
+
ElementsFilter.new,
|
|
22
|
+
MorphFilter.new,
|
|
23
|
+
CleanupFilter.new,
|
|
24
|
+
MarkupFilter.new,
|
|
25
|
+
# SqueezeFilter.new,
|
|
26
|
+
TemplateFilter.new
|
|
27
|
+
]
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def filter_template(source)
|
|
31
|
+
return if source.blank?
|
|
32
|
+
|
|
33
|
+
for filter in @template_filters
|
|
34
|
+
source = filter.apply(source)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
return source
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require "facets/more/json"
|
|
2
|
+
|
|
3
|
+
require "raw/dispatcher/format"
|
|
4
|
+
|
|
5
|
+
module Raw
|
|
6
|
+
|
|
7
|
+
class JSONFormat < Format
|
|
8
|
+
|
|
9
|
+
def initialize
|
|
10
|
+
@name = "json"
|
|
11
|
+
@content_type = "application/json"
|
|
12
|
+
@extension = "json"
|
|
13
|
+
@template_extension = "jsonx"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def after_action(controller, context)
|
|
17
|
+
if controller.out.blank?
|
|
18
|
+
if model = controller.class.ann(:self, :model)
|
|
19
|
+
resource = model.to_s.demodulize.underscore
|
|
20
|
+
if collection = controller.instance_variable_get("@#{resource.plural}")
|
|
21
|
+
controller.send(:print, collection.to_json)
|
|
22
|
+
elsif resource = controller.instance_variable_get("@#{resource}")
|
|
23
|
+
controller.send(:print, resource.to_json)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require "facets/more/xoxo"
|
|
2
|
+
|
|
3
|
+
require "raw/dispatcher/format"
|
|
4
|
+
|
|
5
|
+
module Raw
|
|
6
|
+
|
|
7
|
+
class RSSFormat < Format
|
|
8
|
+
|
|
9
|
+
def initialize
|
|
10
|
+
@name = "rss"
|
|
11
|
+
@content_type = "text/xml"
|
|
12
|
+
@extension = "xml"
|
|
13
|
+
@template_extension = "xmlx"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def after_action(controller)
|
|
17
|
+
=begin
|
|
18
|
+
if controller.out.blank?
|
|
19
|
+
if model = controller.class.ann(:self, :model)
|
|
20
|
+
resource = model.to_s.demodulize.underscore
|
|
21
|
+
if collection = controller.instance_variable_get("@#{resource.plural}")
|
|
22
|
+
controller.send(:print, XOXO.dump(collection))
|
|
23
|
+
elsif resource = controller.instance_variable_get("@#{resource}")
|
|
24
|
+
controller.send(:print, XOXO.dump(resource))
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
=end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require "facets/more/xoxo"
|
|
2
|
+
|
|
3
|
+
require "raw/dispatcher/format"
|
|
4
|
+
|
|
5
|
+
module Raw
|
|
6
|
+
|
|
7
|
+
class XOXOFormat < Format
|
|
8
|
+
|
|
9
|
+
def initialize
|
|
10
|
+
@name = "xoxo"
|
|
11
|
+
@content_type = "application/xoxo+xml"
|
|
12
|
+
@extension = "xoxo"
|
|
13
|
+
@template_extension = "xoxox"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def after_action(controller, context)
|
|
17
|
+
if controller.out.blank?
|
|
18
|
+
if model = controller.class.ann(:self, :model)
|
|
19
|
+
resource = model.to_s.demodulize.underscore
|
|
20
|
+
if collection = controller.instance_variable_get("@#{resource.plural}")
|
|
21
|
+
controller.send(:print, XOXO.dump(collection))
|
|
22
|
+
elsif resource = controller.instance_variable_get("@#{resource}")
|
|
23
|
+
controller.send(:print, XOXO.dump(resource))
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require "raw/dispatcher"
|
|
2
|
+
|
|
3
|
+
module Raw
|
|
4
|
+
|
|
5
|
+
class Dispatcher
|
|
6
|
+
|
|
7
|
+
# A Helper class used for CherryPy-style publishing. This is
|
|
8
|
+
# the prefered way to mount (publish) controllers to
|
|
9
|
+
# paths as it automatically defines a controller hierarchy.
|
|
10
|
+
|
|
11
|
+
class Mounter # :nodoc: all
|
|
12
|
+
|
|
13
|
+
def initialize(dispatcher, parent)
|
|
14
|
+
@dispatcher, @parent = dispatcher, parent
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def method_missing(sym, *args)
|
|
18
|
+
name = sym.to_s
|
|
19
|
+
if name =~ /=$/
|
|
20
|
+
name = name.chop
|
|
21
|
+
if controller = args.first
|
|
22
|
+
# Store the hierarchical parent of this controller.
|
|
23
|
+
# Useful for sitemaps etc.
|
|
24
|
+
controller.ann(:self, :parent => @parent)
|
|
25
|
+
@dispatcher[path(name)] = controller
|
|
26
|
+
end
|
|
27
|
+
else
|
|
28
|
+
if controller = @dispatcher[path(name)]
|
|
29
|
+
Mounter.new(@dispatcher, controller)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def path(name)
|
|
35
|
+
"#{@parent.mount_path}/#{name}".squeeze("/")
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# An alternative mounting mechanism (CherryPy like).
|
|
41
|
+
#
|
|
42
|
+
# === Example
|
|
43
|
+
#
|
|
44
|
+
# dispatcher.root = RootController
|
|
45
|
+
# dispatcher.root.users = User::Controller
|
|
46
|
+
# dispatcher.root.users.comments = User::Comment::Controller
|
|
47
|
+
|
|
48
|
+
def root=(controller)
|
|
49
|
+
self["/"] = resolve_controller(controller)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def root
|
|
53
|
+
if controller = self["/"]
|
|
54
|
+
Mounter.new(self, controller)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
end
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
require "cgi"
|
|
2
|
+
|
|
3
|
+
module Raw
|
|
4
|
+
|
|
5
|
+
# Routing (path rewriting) functionality. Due to the power of
|
|
6
|
+
# Nitro's intelligent dispatching mechanism, routing is almost
|
|
7
|
+
# never used! It is only needed for really special urls.
|
|
8
|
+
|
|
9
|
+
module RouterMixin
|
|
10
|
+
|
|
11
|
+
# The routing rules.
|
|
12
|
+
|
|
13
|
+
attr_accessor :rules
|
|
14
|
+
|
|
15
|
+
# Add a routing rule
|
|
16
|
+
#
|
|
17
|
+
# === Examples
|
|
18
|
+
#
|
|
19
|
+
# r.add_rule(:match => %r{^~(.*)}, :controller => User::Controller, :action => view, :params => [:name])
|
|
20
|
+
|
|
21
|
+
def add_rule(rule)
|
|
22
|
+
@rules ||= []
|
|
23
|
+
@rules << rule
|
|
24
|
+
end
|
|
25
|
+
alias_method :<<, :add_rule
|
|
26
|
+
alias_method :add_route, :add_rule
|
|
27
|
+
|
|
28
|
+
# Generate the transformer string for the match gsub.
|
|
29
|
+
|
|
30
|
+
def rule_transformer(rule)
|
|
31
|
+
transformer = "#{rule[:controller].mount_path}/#{rule[:action]}"
|
|
32
|
+
|
|
33
|
+
if params = rule[:params]
|
|
34
|
+
params.size.times do |i|
|
|
35
|
+
transformer << "/#{i+1}"
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
return transformer
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Convert routes defined with annotations to normal routes.
|
|
43
|
+
# Typically called after a new Controller is mounted.
|
|
44
|
+
#
|
|
45
|
+
# === Example of routing through annotations
|
|
46
|
+
#
|
|
47
|
+
# def view_user
|
|
48
|
+
# "params: #{request[:id]} and #{request[:mode]}"
|
|
49
|
+
# end
|
|
50
|
+
# ann :view_user, :match => /user_(\d*)_(*?)\.html/, :params => [:id, :mode]
|
|
51
|
+
|
|
52
|
+
def add_rules_from_annotations(controller)
|
|
53
|
+
for m in controller.action_methods
|
|
54
|
+
m = m.to_sym
|
|
55
|
+
if match = controller.ann(m, :match)
|
|
56
|
+
add_rule(:match => match, :controller => controller, :action => m, :params => controller.ann(m, :params))
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Try to decode the given path by applying routing rules. If
|
|
62
|
+
# routing is possible return the transformed path, else return
|
|
63
|
+
# the input path.
|
|
64
|
+
|
|
65
|
+
def decode_route(path)
|
|
66
|
+
# Front end server (for example Apache) some times escape
|
|
67
|
+
# the uri. REMOVE THIS: unescape in the adapter!!
|
|
68
|
+
path = CGI.unescape(path)
|
|
69
|
+
|
|
70
|
+
for rule in @rules
|
|
71
|
+
unless transformer = rule[:transformer]
|
|
72
|
+
transformer = rule[:transformer] = rule_transformer(rule)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
if path.gsub!(rule[:match], transformer)
|
|
76
|
+
Logger.debug "Rewriting '#{path}'." if $DBG
|
|
77
|
+
break;
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
return path
|
|
82
|
+
end
|
|
83
|
+
alias_method :route, :decode_route
|
|
84
|
+
|
|
85
|
+
# Encodes a [controller, action, params] tupple into a path.
|
|
86
|
+
# Returns false if no encoding is possible.
|
|
87
|
+
|
|
88
|
+
def encode_route(controller, action, *params)
|
|
89
|
+
if rule = @rules.find { |r| (r[:controller] == controller) and (r[:action] == action) }
|
|
90
|
+
path = rule[:match].source
|
|
91
|
+
|
|
92
|
+
(params.size / 2).times do |i|
|
|
93
|
+
val = params[i + i + 1]
|
|
94
|
+
path.sub!(/\(.*?\)/, val.to_s)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
return path
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
return false
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# An abstract router.
|
|
106
|
+
|
|
107
|
+
class Router
|
|
108
|
+
include RouterMixin
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
end
|
data/lib/raw/errors.rb
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Raw
|
|
2
|
+
|
|
3
|
+
# The base class for all Nitro emmited errors and exceptions.
|
|
4
|
+
|
|
5
|
+
class RawError < StandardError
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
# 4XX class errors (Client errors). Typically rendered when
|
|
9
|
+
# a valid action cannot be found for a path.
|
|
10
|
+
|
|
11
|
+
class ActionError < RawError
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# 5XX class errors.
|
|
15
|
+
|
|
16
|
+
class ServerError < RawError
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
data/lib/raw/helper.rb
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
require "facets/core/kernel/constant"
|
|
2
|
+
require "facets/core/string/camelize"
|
|
3
|
+
|
|
4
|
+
module Raw
|
|
5
|
+
|
|
6
|
+
# Helpers are standard Ruby modules that contain utility
|
|
7
|
+
# methods. By using the special 'helper'
|
|
8
|
+
# macro provided by Helpers, the utility methods are
|
|
9
|
+
# included as private methods.
|
|
10
|
+
#
|
|
11
|
+
# The helper also requires the ruby file.
|
|
12
|
+
#
|
|
13
|
+
# === Examples
|
|
14
|
+
#
|
|
15
|
+
# class MyController < Nitro::Controller
|
|
16
|
+
# helper :xhtml # == include Nitro::XhtmlHelper
|
|
17
|
+
# end
|
|
18
|
+
|
|
19
|
+
module Helpers
|
|
20
|
+
|
|
21
|
+
module Utils
|
|
22
|
+
|
|
23
|
+
#--
|
|
24
|
+
# gmosx: dont name constant to avoid loop.
|
|
25
|
+
#++
|
|
26
|
+
|
|
27
|
+
def self.const(mod)
|
|
28
|
+
return constant(mod)
|
|
29
|
+
rescue NameError => ex
|
|
30
|
+
return nil
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def self.append_features(base)
|
|
35
|
+
super
|
|
36
|
+
base.module_eval do
|
|
37
|
+
def self.helper(*modules)
|
|
38
|
+
for mod in modules
|
|
39
|
+
|
|
40
|
+
# If the mod is a string or symbol, also try to
|
|
41
|
+
# auto require the source file.
|
|
42
|
+
#--
|
|
43
|
+
# gmosx, FIXME: temp solution, will fix!
|
|
44
|
+
#++
|
|
45
|
+
|
|
46
|
+
if mod.is_a?(String) or mod.is_a?(Symbol)
|
|
47
|
+
begin
|
|
48
|
+
# gmosx: dont interpolate (RDoc fix).
|
|
49
|
+
require("app/helper/" + mod.to_s)
|
|
50
|
+
rescue LoadError #do not hide SyntaxError, NameError
|
|
51
|
+
|
|
52
|
+
# you can do helper "foo" to load a module withouth requiring
|
|
53
|
+
begin
|
|
54
|
+
require("raw/helper/" + mod.to_s)
|
|
55
|
+
rescue LoadError
|
|
56
|
+
# Drink it!
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
unless mod.is_a? Module
|
|
62
|
+
modname = mod.to_s.camelize
|
|
63
|
+
# gmosx: check xxxHelper before xxx.
|
|
64
|
+
mod = Utils.const("#{modname}Helper") ||
|
|
65
|
+
Utils.const("Raw::#{modname}Helper") ||
|
|
66
|
+
Utils.const(modname)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# name mismatch
|
|
70
|
+
|
|
71
|
+
unless mod
|
|
72
|
+
raise "helper #{modname} not found (module not defined), check name"
|
|
73
|
+
end
|
|
74
|
+
symbols = mod.instance_methods.collect { |m| m.to_sym }
|
|
75
|
+
|
|
76
|
+
self.send(:include, mod)
|
|
77
|
+
self.send(:private, *symbols)
|
|
78
|
+
# self.send(:private, mod.to_s[/[^:]+$/].to_sym)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
end
|