rad_core 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +10 -0
- data/lib/rad/controller/abstract_controller/micelaneous.rb +31 -0
- data/lib/rad/controller/abstract_controller/render.rb +160 -0
- data/lib/rad/controller/abstract_controller/responder.rb +17 -0
- data/lib/rad/controller/abstract_controller.rb +64 -0
- data/lib/rad/controller/controller_context.rb +15 -0
- data/lib/rad/controller/http_controller.rb +48 -0
- data/lib/rad/controller/processors/controller_caller.rb +28 -0
- data/lib/rad/controller/processors/controller_error_handling.rb +51 -0
- data/lib/rad/controller/processors/controller_logger.rb +12 -0
- data/lib/rad/controller.rb +28 -0
- data/lib/rad/conveyor/conveyor.rb +74 -0
- data/lib/rad/conveyor/conveyors.rb +20 -0
- data/lib/rad/conveyor/params.rb +14 -0
- data/lib/rad/conveyor/processor.rb +68 -0
- data/lib/rad/conveyor/processors/conveyor_logger.rb +25 -0
- data/lib/rad/conveyor/workspace.rb +36 -0
- data/lib/rad/conveyor.rb +29 -0
- data/lib/rad/environment/config.rb +111 -0
- data/lib/rad/environment/dependency_resolver.rb +107 -0
- data/lib/rad/environment/environment.rb +29 -0
- data/lib/rad/environment/files_helper.rb +55 -0
- data/lib/rad/environment/logger.rb +21 -0
- data/lib/rad/environment.rb +55 -0
- data/lib/rad/html/flash.rb +42 -0
- data/lib/rad/html/helpers/basic_html_helper.rb +83 -0
- data/lib/rad/html/helpers/flash_helper.rb +5 -0
- data/lib/rad/html/helpers/form_helper.rb +115 -0
- data/lib/rad/html/helpers/html_helper.rb +5 -0
- data/lib/rad/html/helpers/javascript_helper.rb +18 -0
- data/lib/rad/html/helpers/model_helper.rb +135 -0
- data/lib/rad/html/include_into_controller.rb +0 -0
- data/lib/rad/html/processors/prepare_flash.rb +26 -0
- data/lib/rad/html/processors/scoped_params.rb +26 -0
- data/lib/rad/html.rb +26 -0
- data/lib/rad/http/http.rb +21 -0
- data/lib/rad/http/http_adapter.rb +36 -0
- data/lib/rad/http/middleware/static_files.rb +21 -0
- data/lib/rad/http/processors/evaluate_format.rb +22 -0
- data/lib/rad/http/processors/http_logger.rb +15 -0
- data/lib/rad/http/processors/http_writer.rb +30 -0
- data/lib/rad/http/processors/prepare_params.rb +22 -0
- data/lib/rad/http/support/rack/fixes.rb +36 -0
- data/lib/rad/http/support/rack/rack_adapter.rb +67 -0
- data/lib/rad/http/support/rack/request.rb +42 -0
- data/lib/rad/http/support/rack/response.rb +86 -0
- data/lib/rad/http.rb +48 -0
- data/lib/rad/integration/controller_micelaneous_helper.rb +19 -0
- data/lib/rad/integration/router/abstract_routing_helper.rb +22 -0
- data/lib/rad/integration/router/controller_routing_helper.rb +58 -0
- data/lib/rad/integration/router/view_routing_helper.rb +104 -0
- data/lib/rad/integration.rb +30 -0
- data/lib/rad/mail/letter.rb +30 -0
- data/lib/rad/mail/mail_controller.rb +31 -0
- data/lib/rad/mail/mailer.rb +23 -0
- data/lib/rad/mail/processors/letter_builder.rb +36 -0
- data/lib/rad/mail.rb +15 -0
- data/lib/rad/profiles/mail.rb +16 -0
- data/lib/rad/profiles/web.rb +68 -0
- data/lib/rad/profiles/web_require.rb +5 -0
- data/lib/rad/remote/processors/remote_caller.rb +54 -0
- data/lib/rad/remote/processors/remote_logger.rb +13 -0
- data/lib/rad/remote/remote.rb +15 -0
- data/lib/rad/remote.rb +9 -0
- data/lib/rad/router/core/configurator.rb +25 -0
- data/lib/rad/router/core/core_routing_helper.rb +41 -0
- data/lib/rad/router/core/default_format_processor.rb +12 -0
- data/lib/rad/router/core/processors/router.rb +29 -0
- data/lib/rad/router/core/router.rb +271 -0
- data/lib/rad/router/core/simple_router.rb +23 -0
- data/lib/rad/router/routers/abstract_router.rb +62 -0
- data/lib/rad/router/routers/alias_router.rb +113 -0
- data/lib/rad/router/routers/restful_router.rb +113 -0
- data/lib/rad/router.rb +29 -0
- data/lib/rad/spec/controller.rb +41 -0
- data/lib/rad/spec/environment.rb +51 -0
- data/lib/rad/spec/http.rb +93 -0
- data/lib/rad/spec/mail.rb +31 -0
- data/lib/rad/spec/remote.rb +9 -0
- data/lib/rad/spec/router.rb +18 -0
- data/lib/rad/spec/template.rb +12 -0
- data/lib/rad/spec/view.rb +10 -0
- data/lib/rad/spec/xhtml.rb +33 -0
- data/lib/rad/spec.rb +11 -0
- data/lib/rad/support/active_support/locales/en/actionpack.yml +154 -0
- data/lib/rad/support/active_support/locales/en/activesupport.yml +36 -0
- data/lib/rad/support/active_support/micelaneous.rb +2 -0
- data/lib/rad/support/active_support/time.rb +105 -0
- data/lib/rad/support/active_support.rb +49 -0
- data/lib/rad/support/addressable.rb +45 -0
- data/lib/rad/support/buffered_logger.rb +44 -0
- data/lib/rad/support/callbacks.rb +168 -0
- data/lib/rad/support/exception.rb +31 -0
- data/lib/rad/support/filters.rb +34 -0
- data/lib/rad/support/format.rb +17 -0
- data/lib/rad/support/hacks_and_fixes.rb +23 -0
- data/lib/rad/support/micon.rb +13 -0
- data/lib/rad/support/mime.rb +13 -0
- data/lib/rad/support/module.rb +48 -0
- data/lib/rad/support/rson.rb +53 -0
- data/lib/rad/support/ruby_ext_with_active_support.rb +4 -0
- data/lib/rad/support/string.rb +26 -0
- data/lib/rad/support.rb +63 -0
- data/lib/rad/template/support/tilt.rb +68 -0
- data/lib/rad/template/support/tilt_fixes.rb +17 -0
- data/lib/rad/template/template.rb +250 -0
- data/lib/rad/template/template_context.rb +62 -0
- data/lib/rad/template.rb +25 -0
- data/lib/rad_core/gems.rb +31 -0
- data/readme.md +33 -0
- data/spec/controller/abstract_controller_spec/views/OperationsOrderSpec/action.erb +1 -0
- data/spec/controller/abstract_controller_spec/views/ViewVariablesSpec/action.erb +11 -0
- data/spec/controller/abstract_controller_spec.rb +132 -0
- data/spec/controller/controller_context_spec/views/ItemSpec/actions.erb +4 -0
- data/spec/controller/controller_context_spec/views/ItemSpec/show.erb +0 -0
- data/spec/controller/controller_context_spec/views/ItemSpec/update.erb +0 -0
- data/spec/controller/controller_context_spec/views/NamespaceSpec/ClassSpec/show.erb +0 -0
- data/spec/controller/controller_context_spec/views/PageSpec/actions.erb +3 -0
- data/spec/controller/controller_context_spec/views/PageSpec/show.erb +0 -0
- data/spec/controller/controller_context_spec/views/namespace_spec/class_spec/update.erb +0 -0
- data/spec/controller/controller_context_spec.rb +123 -0
- data/spec/controller/controller_helper_spec/views/HelperMethodSpec/action.erb +1 -0
- data/spec/controller/controller_helper_spec/views/HelperSpec/action.erb +1 -0
- data/spec/controller/controller_helper_spec.rb +53 -0
- data/spec/controller/controller_render_spec/views/AlreadyRenderedSpec/action.erb +1 -0
- data/spec/controller/controller_render_spec/views/AlreadyRenderedSpec/custom_template.erb +1 -0
- data/spec/controller/controller_render_spec/views/AnotherActionSpec/another_action.erb +1 -0
- data/spec/controller/controller_render_spec/views/AnotherLayout/action.erb +1 -0
- data/spec/controller/controller_render_spec/views/ForbidPartialAsActionSpec/_action.erb +1 -0
- data/spec/controller/controller_render_spec/views/FormatSpec/action.html.erb +1 -0
- data/spec/controller/controller_render_spec/views/FormatSpec/action.js.erb +1 -0
- data/spec/controller/controller_render_spec/views/LayoutFiltersSpec/action_with_layout.erb +1 -0
- data/spec/controller/controller_render_spec/views/LayoutFiltersSpec/action_without_layout.erb +1 -0
- data/spec/controller/controller_render_spec/views/LayoutSpec/action.erb +1 -0
- data/spec/controller/controller_render_spec/views/MultipleActions/actions.haml +7 -0
- data/spec/controller/controller_render_spec/views/layouts/admin.erb +1 -0
- data/spec/controller/controller_render_spec/views/layouts/app.html.erb +1 -0
- data/spec/controller/controller_render_spec/views/layouts/app.js.erb +1 -0
- data/spec/controller/controller_render_spec/views/rem ExplicitRenderSpec/action.erb +1 -0
- data/spec/controller/controller_render_spec/views/rem ExplicitRenderSpec/another_action.erb +1 -0
- data/spec/controller/controller_render_spec/views/some_template.erb +1 -0
- data/spec/controller/controller_render_spec/views/standalone.html.erb +1 -0
- data/spec/controller/controller_render_spec.rb +217 -0
- data/spec/controller/error_handling_spec/views/diferrent_error_handling_spec/a.erb +1 -0
- data/spec/controller/error_handling_spec/views/diferrent_error_handling_spec/b.erb +1 -0
- data/spec/controller/error_handling_spec/views/diferrent_error_handling_spec/c.erb +1 -0
- data/spec/controller/error_handling_spec.rb +117 -0
- data/spec/controller/http_controller_spec.rb +130 -0
- data/spec/controller/spec_helper.rb +19 -0
- data/spec/conveyor/conveyor_spec.rb +124 -0
- data/spec/conveyor/spec_helper.rb +3 -0
- data/spec/environment/config_spec/config.default.yml +3 -0
- data/spec/environment/config_spec/config.development.yml +3 -0
- data/spec/environment/config_spec/config.yml +5 -0
- data/spec/environment/config_spec.rb +30 -0
- data/spec/environment/environment_spec/path1/file1 +0 -0
- data/spec/environment/environment_spec/path1/some_folder/some_file +0 -0
- data/spec/environment/environment_spec/path2/file2 +0 -0
- data/spec/environment/environment_spec/path2/some_folder/some_file +0 -0
- data/spec/environment/environment_spec.rb +65 -0
- data/spec/environment/logger_spec.rb +19 -0
- data/spec/environment/minimal_app_spec/app.rb +1 -0
- data/spec/environment/minimal_app_spec.rb +25 -0
- data/spec/environment/spec_helper.rb +1 -0
- data/spec/environment/standard_app_spec/app/lib/app/init.rb +3 -0
- data/spec/environment/standard_app_spec/plugin_a/lib/plugin_a/init.rb +1 -0
- data/spec/environment/standard_app_spec/plugin_b/lib/emptygit +0 -0
- data/spec/environment/standard_app_spec.rb +48 -0
- data/spec/html/basic_html_helper_spec.rb +29 -0
- data/spec/html/form_helper_spec.rb +63 -0
- data/spec/html/javascript_helper_spec.rb +15 -0
- data/spec/html/model_helper_spec.rb +81 -0
- data/spec/html/scoped_params_spec.rb +15 -0
- data/spec/html/spec_helper.rb +28 -0
- data/spec/http/http_spec/app/lib/app/init.rb +10 -0
- data/spec/http/http_spec/app/runtime/public/emptygit +0 -0
- data/spec/http/http_spec/plugin_a/lib/plugin_a/init.rb +0 -0
- data/spec/http/http_spec/plugin_b/lib/plugin_b/init.rb +5 -0
- data/spec/http/http_spec/plugin_b/static/emptygit +0 -0
- data/spec/http/http_spec.rb +51 -0
- data/spec/http/micelaneous_spec.rb +13 -0
- data/spec/http/spec_helper.rb +5 -0
- data/spec/integration/basic_spec/views/smoke_test_spec/action.erb +1 -0
- data/spec/integration/basic_spec.rb +79 -0
- data/spec/integration/controller_routing_helper_spec.rb +84 -0
- data/spec/integration/flash_spec.rb +206 -0
- data/spec/integration/spec_helper.rb +5 -0
- data/spec/integration/spec_helper_spec.rb +63 -0
- data/spec/integration/view_routing_helper_spec.rb +134 -0
- data/spec/mail/mail_controller_spec/views/body_template_spec/signup.erb +1 -0
- data/spec/mail/mail_controller_spec.rb +61 -0
- data/spec/mail/spec_helper.rb +7 -0
- data/spec/remote/remote_spec.rb +75 -0
- data/spec/remote/spec_helper.rb +17 -0
- data/spec/router/alias_router_spec.rb +98 -0
- data/spec/router/basic_spec.rb +111 -0
- data/spec/router/configurator_spec.rb +18 -0
- data/spec/router/integration_spec.rb +42 -0
- data/spec/router/persistent_params_spec.rb +65 -0
- data/spec/router/restful_router_spec.rb +120 -0
- data/spec/router/routing_helper_spec.rb +55 -0
- data/spec/router/spec_helper.rb +20 -0
- data/spec/support/callbacks_spec.rb +157 -0
- data/spec/support/filters_spec.rb +60 -0
- data/spec/support/spec_helper.rb +4 -0
- data/spec/template/spec_helper.rb +6 -0
- data/spec/template/template_spec/file.erb +1 -0
- data/spec/template/template_spec/views/basic/custom_context.erb +1 -0
- data/spec/template/template_spec/views/basic/extension.erb +1 -0
- data/spec/template/template_spec/views/basic/general.html.erb +5 -0
- data/spec/template/template_spec/views/basic/non_existing_format.html.erb +0 -0
- data/spec/template/template_spec/views/format/format.erb +1 -0
- data/spec/template/template_spec/views/format/format.html.erb +1 -0
- data/spec/template/template_spec/views/format/format.js.erb +1 -0
- data/spec/template/template_spec/views/format_for_partials/_form.html.erb +1 -0
- data/spec/template/template_spec/views/format_for_partials/dialog.js.erb +1 -0
- data/spec/template/template_spec/views/layout/basic/content.erb +1 -0
- data/spec/template/template_spec/views/layout/basic/layout.erb +1 -0
- data/spec/template/template_spec/views/layout/content_for/content.erb +3 -0
- data/spec/template/template_spec/views/layout/content_for/layout.erb +3 -0
- data/spec/template/template_spec/views/layout/format/content.html.erb +1 -0
- data/spec/template/template_spec/views/layout/format/content.js.erb +1 -0
- data/spec/template/template_spec/views/layout/format/layout.html.erb +1 -0
- data/spec/template/template_spec/views/layout/format/layout.js.erb +1 -0
- data/spec/template/template_spec/views/layout/nested_yield/a.erb +1 -0
- data/spec/template/template_spec/views/layout/nested_yield/layout.erb +1 -0
- data/spec/template/template_spec/views/layout/nested_yield/layout_b.erb +1 -0
- data/spec/template/template_spec/views/layout/same_context/a.erb +1 -0
- data/spec/template/template_spec/views/layout/same_context/b.erb +1 -0
- data/spec/template/template_spec/views/layout/same_context/layout.erb +1 -0
- data/spec/template/template_spec/views/nested/format/a.erb +1 -0
- data/spec/template/template_spec/views/nested/format/b.erb +1 -0
- data/spec/template/template_spec/views/nested/relative/a.erb +1 -0
- data/spec/template/template_spec/views/nested/relative/b.erb +1 -0
- data/spec/template/template_spec/views/nested/relative/c.erb +1 -0
- data/spec/template/template_spec/views/nested/shared/c.erb +1 -0
- data/spec/template/template_spec/views/nesting_format/_edit.html.erb +1 -0
- data/spec/template/template_spec/views/nesting_format/_form.html.erb +1 -0
- data/spec/template/template_spec/views/nesting_format/dialog.js.erb +1 -0
- data/spec/template/template_spec/views/other/template.erb +1 -0
- data/spec/template/template_spec/views/prefixes/_underscored.erb +1 -0
- data/spec/template/template_spec/views/prefixes/without_prefix.erb +1 -0
- data/spec/template/template_spec.rb +204 -0
- data/spec/template/tilt_spec/views/concat_and_capture.erb +1 -0
- data/spec/template/tilt_spec/views/concat_and_capture.haml +3 -0
- data/spec/template/tilt_spec/views/encoding/erb.erb +1 -0
- data/spec/template/tilt_spec/views/encoding/haml.haml +1 -0
- data/spec/template/tilt_spec/views/errors.erb +3 -0
- data/spec/template/tilt_spec/views/errors.haml +3 -0
- data/spec/template/tilt_spec/views/mixed_templates/broken_erb_concat_erb.erb +4 -0
- data/spec/template/tilt_spec/views/mixed_templates/broken_erb_concat_haml.haml +1 -0
- data/spec/template/tilt_spec/views/mixed_templates/broken_haml_concat_erb.erb +1 -0
- data/spec/template/tilt_spec/views/mixed_templates/broken_haml_concat_haml.haml +2 -0
- data/spec/template/tilt_spec/views/nested_capture_and_concat.haml +3 -0
- data/spec/template/tilt_spec/views/ugly.haml +3 -0
- data/spec/template/tilt_spec/views/yield.erb +1 -0
- data/spec/template/tilt_spec.rb +98 -0
- metadata +531 -0
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module Rad
|
2
|
+
module AbstractController
|
3
|
+
module Micelaneous
|
4
|
+
#
|
5
|
+
# respond_to
|
6
|
+
#
|
7
|
+
def respond_to &block
|
8
|
+
@_responder.must_be.nil
|
9
|
+
@_responder = Responder.new
|
10
|
+
block.call @_responder
|
11
|
+
handler = @_responder.handlers[params.format]
|
12
|
+
raise "can't respond to '#{params.format}' format!" unless handler
|
13
|
+
handler.call
|
14
|
+
end
|
15
|
+
|
16
|
+
module ClassMethods
|
17
|
+
#
|
18
|
+
# filter_parameter_logging
|
19
|
+
#
|
20
|
+
inheritable_accessor :filter_parameter_logging, []
|
21
|
+
def filter_parameter_logging_with_sugar *parameters
|
22
|
+
if parameters.empty?
|
23
|
+
filter_parameter_logging_without_sugar
|
24
|
+
else
|
25
|
+
filter_parameter_logging_without_sugar.push *parameters.collect(&:to_s)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,160 @@
|
|
1
|
+
module Rad
|
2
|
+
module AbstractController
|
3
|
+
module Render
|
4
|
+
SPECIAL_FORMAT_HANDLERS = {
|
5
|
+
json: lambda{|o| o.to_json},
|
6
|
+
xml: lambda{|o| o.to_xml},
|
7
|
+
js: lambda{|o| o},
|
8
|
+
}
|
9
|
+
|
10
|
+
# SPECIAL_CASES_HANDLERS = [
|
11
|
+
# ['inline', lambda{|o| o}],
|
12
|
+
# ]
|
13
|
+
|
14
|
+
def _layout tname = nil
|
15
|
+
if tname
|
16
|
+
@_layout = tname
|
17
|
+
else
|
18
|
+
@_layout
|
19
|
+
end
|
20
|
+
end
|
21
|
+
def _layout= layout
|
22
|
+
@_layout = layout
|
23
|
+
end
|
24
|
+
|
25
|
+
def render *args
|
26
|
+
options = Template.parse_arguments *args
|
27
|
+
content = render_with_parsed_arguments options, args
|
28
|
+
throw :halt_render, content
|
29
|
+
end
|
30
|
+
|
31
|
+
protected
|
32
|
+
def render_action options
|
33
|
+
options = options.to_openobject
|
34
|
+
options.format ||= params.format
|
35
|
+
|
36
|
+
render_options = {
|
37
|
+
context_class: self.class.controller_context_class,
|
38
|
+
format: params.format,
|
39
|
+
action: true # this willn't allow to render partial starting with _
|
40
|
+
}.to_openobject
|
41
|
+
|
42
|
+
# rendering content
|
43
|
+
content, context = render_content render_options, options
|
44
|
+
|
45
|
+
render_options.merge!(
|
46
|
+
content: content,
|
47
|
+
context: context
|
48
|
+
)
|
49
|
+
|
50
|
+
# rendering layout
|
51
|
+
render_layout render_options, options
|
52
|
+
end
|
53
|
+
|
54
|
+
def render_layout render_options, options
|
55
|
+
layout = options.include?(:layout) ? options.layout : self._layout
|
56
|
+
if layout
|
57
|
+
Template.render_layout layout, render_options
|
58
|
+
else
|
59
|
+
render_options.content
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def render_content render_options, options
|
64
|
+
template = options.template || self.class.template_name_for(options.action, options)
|
65
|
+
template = '/rad_default_templates/blank_template' unless Template.exist? template, format: options.format
|
66
|
+
|
67
|
+
instance_variables = {}
|
68
|
+
instance_variable_names.each do |name|
|
69
|
+
instance_variables[name[1..-1]] = instance_variable_get name unless name =~ /^@_/
|
70
|
+
end
|
71
|
+
|
72
|
+
instance_variables.merge!(
|
73
|
+
action_name: (options.action || workspace.action).to_sym,
|
74
|
+
controller_name: self.class.controller_name
|
75
|
+
)
|
76
|
+
|
77
|
+
render_options.merge!(
|
78
|
+
template: template,
|
79
|
+
instance_variables: instance_variables
|
80
|
+
)
|
81
|
+
|
82
|
+
content, context = Template.basic_render render_options
|
83
|
+
return content, context
|
84
|
+
end
|
85
|
+
|
86
|
+
def render_with_parsed_arguments options, original_args
|
87
|
+
if special_format = SPECIAL_FORMAT_HANDLERS.keys.find{|f| options.include? f}
|
88
|
+
handler = SPECIAL_FORMAT_HANDLERS[special_format]
|
89
|
+
if special_format.to_s != params.format
|
90
|
+
raise "You trying responing with '#{special_format}' to the '#{params.format}' requested format!"
|
91
|
+
end
|
92
|
+
handler.call options[special_format]
|
93
|
+
elsif options.include? :inline
|
94
|
+
options.inline
|
95
|
+
# elsif special_format_handler = SPECIAL_CASES_HANDLERS.find{|key, handler| options.include? key}
|
96
|
+
# key, handler = special_format_handler
|
97
|
+
# handler.call options[key]
|
98
|
+
else
|
99
|
+
render_action options
|
100
|
+
# Template.basic_render(options).first
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
module ClassMethods
|
107
|
+
def layout layout, options = {}
|
108
|
+
before options do |controller|
|
109
|
+
controller._layout = layout
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def template_name_for action, options = {}
|
114
|
+
action.must_be.a Symbol
|
115
|
+
|
116
|
+
return _template_name_for(action, options) if config.development?
|
117
|
+
|
118
|
+
@template_name_for ||= {}
|
119
|
+
|
120
|
+
key = %(#{action}#{":#{options[:format]}" if options[:format]})
|
121
|
+
unless tname = @template_name_for[key]
|
122
|
+
tname = _template_name_for(action, options)
|
123
|
+
@template_name_for[key] = tname
|
124
|
+
end
|
125
|
+
|
126
|
+
tname
|
127
|
+
end
|
128
|
+
|
129
|
+
protected
|
130
|
+
def _template_name_for action, options = {}
|
131
|
+
# instance_methods.must.include(action)
|
132
|
+
own_tnames = [
|
133
|
+
"/#{controller_name.gsub('::', '/')}/#{action}",
|
134
|
+
"/#{controller_name.underscore}/#{action}"
|
135
|
+
]
|
136
|
+
|
137
|
+
own_actions_tnames = [
|
138
|
+
"/#{controller_name.gsub('::', '/')}/actions",
|
139
|
+
"/#{controller_name.underscore}/actions"
|
140
|
+
]
|
141
|
+
|
142
|
+
action_template_exist = lambda do |tname|
|
143
|
+
Rad::Template.exist?(tname) and
|
144
|
+
(Rad::Template.read(tname) =~ /^.*when.+[^_a-zA-Z0-9]#{action}[^_a-zA-Z0-9].*$/)
|
145
|
+
end
|
146
|
+
|
147
|
+
if existing_template = own_tnames.find{|tname| Rad::Template.exist?(tname, format: options[:format])}
|
148
|
+
existing_template
|
149
|
+
elsif existing_action_template = own_actions_tnames.find(&action_template_exist)
|
150
|
+
existing_action_template
|
151
|
+
elsif parent = ancestors[1..-1].find{|a| a.respond_to?(:template_name_for) and a.instance_methods.include?(action)}
|
152
|
+
parent.template_name_for(action, options)
|
153
|
+
else
|
154
|
+
own_tnames.first
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Rad
|
2
|
+
module AbstractController
|
3
|
+
class Responder < BasicObject
|
4
|
+
attr_reader :handlers
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@handlers = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
protected
|
11
|
+
def method_missing m, *args, &block
|
12
|
+
args.must_be.empty
|
13
|
+
handlers[m.to_s] = block.must_be.defined
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Rad
|
2
|
+
module AbstractController
|
3
|
+
inherit Filters
|
4
|
+
inherit AbstractController::Render, AbstractController::Micelaneous
|
5
|
+
|
6
|
+
inject(
|
7
|
+
workspace: :workspace,
|
8
|
+
logger: :logger,
|
9
|
+
config: :config
|
10
|
+
)
|
11
|
+
|
12
|
+
def params
|
13
|
+
workspace.params
|
14
|
+
end
|
15
|
+
|
16
|
+
# def response
|
17
|
+
# workspace.response
|
18
|
+
# end
|
19
|
+
|
20
|
+
module ClassMethods
|
21
|
+
inject(
|
22
|
+
workspace: :workspace,
|
23
|
+
logger: :logger,
|
24
|
+
config: :config
|
25
|
+
)
|
26
|
+
|
27
|
+
def controller_name
|
28
|
+
self.namespace ? "#{self.namespace.name}::#{self.alias}" : self.alias
|
29
|
+
end
|
30
|
+
|
31
|
+
def controller_context_class
|
32
|
+
unless @controller_context_class
|
33
|
+
parent_context_class = nil
|
34
|
+
ancestors[1..-1].each do |anc|
|
35
|
+
break if parent_context_class = anc.respond_to(:controller_context_class)
|
36
|
+
end
|
37
|
+
parent_context_class ||= Rad::ControllerContext
|
38
|
+
|
39
|
+
class_name = "#{self.name}::#{self.name.split('::').last}ControllerContext"
|
40
|
+
|
41
|
+
# raise "Tempate context #{class_name} already defined!" if Object.const_defined? class_name
|
42
|
+
eval "class #{class_name} < #{parent_context_class}; end", TOPLEVEL_BINDING, __FILE__, __LINE__
|
43
|
+
@controller_context_class = class_name.constantize
|
44
|
+
end
|
45
|
+
@controller_context_class
|
46
|
+
end
|
47
|
+
|
48
|
+
def helper *args
|
49
|
+
args.to_a.each do |mod|
|
50
|
+
mod.must_be.a Module
|
51
|
+
controller_context_class.inherit mod
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def helper_method *args
|
56
|
+
args = args.first if args.size == 1 and args.first.is_a?(Array)
|
57
|
+
# args.each{|m| m.to_s.must_be.in self.instance_methods}
|
58
|
+
args.each do |m|
|
59
|
+
controller_context_class.delegate m, to: :controller
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Rad
|
2
|
+
class ControllerContext < TemplateContext
|
3
|
+
def controller
|
4
|
+
workspace.controller.must_be.defined
|
5
|
+
end
|
6
|
+
|
7
|
+
def controller_name
|
8
|
+
@controller_name #workspace.controller.class.controller_name
|
9
|
+
end
|
10
|
+
|
11
|
+
def action_name
|
12
|
+
@action_name #workspace.action.to_sym
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Rad
|
2
|
+
module HttpController
|
3
|
+
inherit AbstractController
|
4
|
+
|
5
|
+
# def response
|
6
|
+
# workspace.response
|
7
|
+
# end
|
8
|
+
|
9
|
+
protected
|
10
|
+
def render_with_parsed_arguments options, original_args
|
11
|
+
response = workspace.response
|
12
|
+
response.set!(
|
13
|
+
status: options.status || :ok,
|
14
|
+
content_type: options.content_type || Mime[params.format]
|
15
|
+
)
|
16
|
+
|
17
|
+
if original_args.size == 1 and (status = Rad::Response.decode_status_message(original_args.first))
|
18
|
+
response.set! status: status
|
19
|
+
throw :halt_render, ""
|
20
|
+
elsif options.location?
|
21
|
+
redirect_to options.location
|
22
|
+
else
|
23
|
+
super
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
module ClassMethods
|
28
|
+
inheritable_accessor :actions_allowed_for_get_request, []
|
29
|
+
|
30
|
+
def allow_get_for *methods
|
31
|
+
enable_protection_from_get_requests!
|
32
|
+
actions_allowed_for_get_request.push *methods
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
def enable_protection_from_get_requests!
|
37
|
+
unless respond_to? :protect_from_get_request
|
38
|
+
define_method :protect_from_get_request do
|
39
|
+
if workspace.request.get? and !self.class.actions_allowed_for_get_request.include?(workspace.action)
|
40
|
+
raise "Get requests not allowed for :#{workspace.action} action!"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
before :protect_from_get_request
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Rad
|
2
|
+
module Processors
|
3
|
+
class ControllerCaller < Processor
|
4
|
+
def call
|
5
|
+
# prepare
|
6
|
+
response = workspace.response.must_be.defined
|
7
|
+
klass = workspace.class.must_be.present
|
8
|
+
raise "The controller class #{klass} must be a Rad::AbstractController!" unless klass.is? Rad::AbstractController
|
9
|
+
controller = workspace.controller = klass.new
|
10
|
+
action = workspace.action = workspace.method_name
|
11
|
+
format = workspace.params.format
|
12
|
+
|
13
|
+
# call
|
14
|
+
|
15
|
+
workspace.content = catch :halt_render do
|
16
|
+
controller.run_callbacks :action, method: action do
|
17
|
+
# call controller
|
18
|
+
controller.send action
|
19
|
+
|
20
|
+
# render view
|
21
|
+
controller.render action: action
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Rad
|
2
|
+
module Processors
|
3
|
+
class ControllerErrorHandling < Processor
|
4
|
+
def call
|
5
|
+
workspace.response.must_be.defined
|
6
|
+
|
7
|
+
begin
|
8
|
+
next_processor.call
|
9
|
+
rescue StandardError => e
|
10
|
+
if config.test?
|
11
|
+
e.set_backtrace e.backtrace.sfilter(Exception.common_filters)
|
12
|
+
raise e
|
13
|
+
elsif config.production?
|
14
|
+
error_shown_to_user = StandardError.new "Internal error!"
|
15
|
+
error_shown_to_user.set_backtrace []
|
16
|
+
else
|
17
|
+
error_shown_to_user = e
|
18
|
+
end
|
19
|
+
|
20
|
+
workspace.response.clear if workspace.response?
|
21
|
+
format = workspace.params.format
|
22
|
+
handler = SPECIAL_ERROR_HANDLERS[format] || DEFAULT_ERROR_HANDLER
|
23
|
+
workspace.content = handler.call error_shown_to_user, format
|
24
|
+
|
25
|
+
|
26
|
+
logger.error e
|
27
|
+
logger.info "\n"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
SPECIAL_ERROR_HANDLERS = {
|
32
|
+
'json' => lambda{|e, format|
|
33
|
+
{error: e.message}.to_json
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
DEFAULT_ERROR_HANDLER = lambda{|e, format|
|
38
|
+
tname = rad.config["#{rad.config.environment!}_error_template", nil]
|
39
|
+
|
40
|
+
if tname and Template.exist?(tname, format: format, exact_format: true)
|
41
|
+
data = Template.render(tname,
|
42
|
+
format: format,
|
43
|
+
locals: {error: e}
|
44
|
+
)
|
45
|
+
else
|
46
|
+
e.message
|
47
|
+
end
|
48
|
+
}
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Rad
|
2
|
+
module Processors
|
3
|
+
class ControllerLogger < Processor
|
4
|
+
def call
|
5
|
+
if (klass = workspace.class) and (method = workspace.method_name)
|
6
|
+
logger.info " Processing #{klass.name}.#{method} with #{workspace.params.inspect}"
|
7
|
+
end
|
8
|
+
next_processor.call
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rad/conveyor'
|
2
|
+
require 'rad/template'
|
3
|
+
|
4
|
+
%w(
|
5
|
+
abstract_controller/render
|
6
|
+
abstract_controller/responder
|
7
|
+
abstract_controller/micelaneous
|
8
|
+
abstract_controller
|
9
|
+
controller_context
|
10
|
+
|
11
|
+
processors/controller_logger
|
12
|
+
processors/controller_caller
|
13
|
+
processors/controller_error_handling
|
14
|
+
).each{|f| require "rad/controller/#{f}"}
|
15
|
+
|
16
|
+
module Rad
|
17
|
+
autoload :HttpController, 'rad/controller/http_controller'
|
18
|
+
end
|
19
|
+
|
20
|
+
#
|
21
|
+
# Initialization
|
22
|
+
#
|
23
|
+
Rad::Config::DEFAULTS.merge!(
|
24
|
+
development_error_template: "/rad_default_templates/development/error",
|
25
|
+
production_error_template: nil,
|
26
|
+
test_error_template: "/rad_default_templates/development/error",
|
27
|
+
)
|
28
|
+
Rad::Config::DEFAULTS[:default_method] ||= 'call'
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Rad
|
2
|
+
class Conveyor
|
3
|
+
inject workspace: :workspace
|
4
|
+
|
5
|
+
def definitions
|
6
|
+
@definitions ||= []
|
7
|
+
end
|
8
|
+
|
9
|
+
def use processor_class, *initialization_arguments
|
10
|
+
definitions << [processor_class, initialization_arguments]
|
11
|
+
end
|
12
|
+
|
13
|
+
def build!
|
14
|
+
@chain = lambda{}
|
15
|
+
definitions.reverse.collect do |klass, args|
|
16
|
+
klass.must_be.a Class
|
17
|
+
@chain = klass.new @chain, *args
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def call workspace_content = {}, &block
|
22
|
+
build! unless @chain
|
23
|
+
|
24
|
+
rad.activate :cycle, {} do
|
25
|
+
self.workspace = Workspace.new
|
26
|
+
workspace.merge! workspace_content
|
27
|
+
|
28
|
+
if block
|
29
|
+
block.call(@chain)
|
30
|
+
else
|
31
|
+
@chain.call
|
32
|
+
end
|
33
|
+
|
34
|
+
workspace
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def inspect
|
39
|
+
definitions.inspect
|
40
|
+
end
|
41
|
+
|
42
|
+
# def trace name, &block
|
43
|
+
# start_time = Time.now
|
44
|
+
# block.call
|
45
|
+
# (workspace.trace ||= []) << [name, Time.now - start_time]
|
46
|
+
# end
|
47
|
+
|
48
|
+
protected
|
49
|
+
# def build_chain
|
50
|
+
# next_processor_call = nil
|
51
|
+
# chain = reverse.collect do |processor|
|
52
|
+
# next_processor_call = if next_processor_call
|
53
|
+
# lambda{processor.call next_processor}
|
54
|
+
# else
|
55
|
+
# lambda{processor.call lambda{}}
|
56
|
+
# end
|
57
|
+
# end
|
58
|
+
# next_processor_call
|
59
|
+
# end
|
60
|
+
|
61
|
+
|
62
|
+
# def add_before key, *processors
|
63
|
+
# index = index{|processor| processor.name == key or processor.class == key}
|
64
|
+
# raise "Can't find Processor '#{name}'!" unless index
|
65
|
+
# insert index, *Array(processors)
|
66
|
+
# end
|
67
|
+
#
|
68
|
+
# def add_after key, *processors
|
69
|
+
# index = rindex{|processor| processor.name == key or processor.class == key}
|
70
|
+
# raise "Can't find Processor '#{name}'!" unless index
|
71
|
+
# insert index + 1, *Array(processors)
|
72
|
+
# end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Rad
|
2
|
+
class Conveyors
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@hash = {}
|
6
|
+
end
|
7
|
+
|
8
|
+
def [] conveyor_name
|
9
|
+
@hash[conveyor_name.to_s] ||= Rad::Conveyor.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def method_missing m, &block
|
13
|
+
if block
|
14
|
+
block.call self[m]
|
15
|
+
else
|
16
|
+
self[m]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Rad
|
2
|
+
class Processor
|
3
|
+
inject(
|
4
|
+
config: :config,
|
5
|
+
workspace: :workspace,
|
6
|
+
logger: :logger
|
7
|
+
)
|
8
|
+
|
9
|
+
attr_accessor :next_processor
|
10
|
+
|
11
|
+
def initialize next_processor
|
12
|
+
@next_processor = next_processor
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.inspect
|
16
|
+
self.name.split('::').last
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
#
|
21
|
+
# # def call
|
22
|
+
# # if workspace.error?
|
23
|
+
# # respond_to :on_error
|
24
|
+
# # else
|
25
|
+
# # begin
|
26
|
+
# # trace self.inspect do
|
27
|
+
# # respond_to :process
|
28
|
+
# # end
|
29
|
+
# # rescue Exception => e
|
30
|
+
# # workspace.error = e
|
31
|
+
# # respond_to :on_error
|
32
|
+
# # end
|
33
|
+
# # end
|
34
|
+
# # end
|
35
|
+
#
|
36
|
+
#
|
37
|
+
#
|
38
|
+
# #
|
39
|
+
# # Unwrapping Call Stack
|
40
|
+
# #
|
41
|
+
# def result_error= error
|
42
|
+
# @result_error = error
|
43
|
+
# end
|
44
|
+
#
|
45
|
+
# def result!
|
46
|
+
# @result_called.must_be.false
|
47
|
+
# @result_called = true
|
48
|
+
# raise @result_error if @result_error
|
49
|
+
# end
|
50
|
+
#
|
51
|
+
# def result_called?
|
52
|
+
# @result_called
|
53
|
+
# end
|
54
|
+
# attr_writer :result_called
|
55
|
+
#
|
56
|
+
# attr_accessor :after_block
|
57
|
+
# def after &block
|
58
|
+
# # @after_called.must_be.false
|
59
|
+
# @after_block = block.must_be.defined
|
60
|
+
# # @after_called = true
|
61
|
+
# end
|
62
|
+
#
|
63
|
+
# # def after_called?
|
64
|
+
# # @after_called
|
65
|
+
# # end
|
66
|
+
#
|
67
|
+
# end
|
68
|
+
# end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Rad
|
2
|
+
module Processors
|
3
|
+
class ConveyorLogger < Processor
|
4
|
+
def call
|
5
|
+
begin
|
6
|
+
start_time = Time.now
|
7
|
+
next_processor.call
|
8
|
+
|
9
|
+
# if workspace.trace?
|
10
|
+
# total_time = workspace.trace.inject(0){|memo, pair| memo += pair.last}
|
11
|
+
# max_pair = workspace.trace.max_by{|pair| pair.last}
|
12
|
+
# logger.info "Completed in #{(total_time * 1000).round} ms (#{(max_pair.last * 1000).round} ms taken by #{max_pair.first})\n\n"
|
13
|
+
# else
|
14
|
+
logger.info " Completed in #{((Time.now - start_time) * 1000).round} ms\n\n"
|
15
|
+
# end
|
16
|
+
rescue StandardError => e
|
17
|
+
raise e if config.test?
|
18
|
+
|
19
|
+
logger.error e
|
20
|
+
logger.info "\n"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|