rad_core 0.0.13 → 0.0.14
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +4 -3
- data/lib/components/config.rb +6 -0
- data/lib/components/controller.rb +5 -0
- data/lib/components/controller.yml +3 -0
- data/lib/components/conveyors.rb +7 -0
- data/lib/components/environment.rb +5 -0
- data/lib/components/environment.yml +3 -0
- data/lib/components/flash.rb +5 -0
- data/lib/components/html.rb +4 -0
- data/lib/components/html.yml +3 -0
- data/lib/components/http.rb +6 -0
- data/lib/components/http.yml +13 -0
- data/lib/components/logger.rb +5 -0
- data/lib/components/mailer.rb +9 -0
- data/lib/components/remote.rb +4 -0
- data/lib/components/router.rb +13 -0
- data/lib/components/router.yml +2 -0
- data/lib/components/template.rb +8 -0
- data/lib/components/template.yml +1 -0
- data/lib/components/web.rb +8 -0
- data/lib/components/workspace.rb +1 -0
- data/lib/rad/{support → _support}/active_support/locales/en/actionpack.yml +0 -0
- data/lib/rad/{support → _support}/active_support/locales/en/activesupport.yml +0 -0
- data/lib/rad/_support/active_support/locales/ru/actionview.yml +162 -0
- data/lib/rad/_support/active_support/locales/ru/activesupport.yml +16 -0
- data/lib/rad/_support/active_support/locales/ru/datetime.yml +49 -0
- data/lib/rad/{support → _support}/active_support/micelaneous.rb +0 -0
- data/lib/rad/{support → _support}/active_support/time.rb +0 -0
- data/lib/rad/{support → _support}/active_support.rb +14 -2
- data/lib/rad/{support → _support}/addressable.rb +0 -0
- data/lib/rad/_support/callbacks.rb +166 -0
- data/lib/rad/_support/class_loader.rb +9 -0
- data/lib/rad/_support/encoding.rb +3 -0
- data/lib/rad/_support/exception.rb +45 -0
- data/lib/rad/_support/extensions.rb +20 -0
- data/lib/rad/_support/filters.rb +32 -0
- data/lib/rad/{support → _support}/hacks_and_fixes.rb +0 -0
- data/lib/rad/{support → _support}/mime.rb +6 -0
- data/lib/rad/{support → _support}/module.rb +7 -9
- data/lib/rad/_support/require.rb +62 -0
- data/lib/rad/{support → _support}/rson.rb +0 -0
- data/lib/rad/{support → _support}/ruby_ext_with_active_support.rb +0 -0
- data/lib/rad/{support → _support}/string.rb +9 -1
- data/lib/rad/controller/_abstract/micelaneous.rb +27 -0
- data/lib/rad/controller/_abstract/render.rb +159 -0
- data/lib/rad/controller/_abstract/responder.rb +13 -0
- data/lib/rad/controller/_abstract.rb +37 -0
- data/lib/rad/controller/_context.rb +15 -0
- data/lib/rad/controller/_http.rb +50 -0
- data/lib/rad/controller/_require.rb +19 -0
- data/lib/rad/controller/abstract.rb +1 -0
- data/lib/rad/controller/context.rb +1 -0
- data/lib/rad/controller/http.rb +1 -0
- data/lib/rad/controller/processors/controller_caller.rb +22 -24
- data/lib/rad/controller/processors/controller_error_handling.rb +46 -48
- data/lib/rad/controller/processors/controller_logger.rb +7 -9
- data/lib/rad/controller.rb +1 -28
- data/lib/rad/conveyors/_conveyor.rb +73 -0
- data/lib/rad/conveyors/_conveyors.rb +19 -0
- data/lib/rad/conveyors/_params.rb +10 -0
- data/lib/rad/conveyors/_processor.rb +13 -0
- data/lib/rad/conveyors/_require.rb +10 -0
- data/lib/rad/conveyors/_workspace.rb +34 -0
- data/lib/rad/conveyors/params.rb +1 -0
- data/lib/rad/conveyors/processor.rb +1 -0
- data/lib/rad/conveyors/processors/conveyor_logger.rb +23 -0
- data/lib/rad/conveyors/workspace.rb +1 -0
- data/lib/rad/conveyors.rb +1 -0
- data/lib/rad/core_web/_controller_micelaneous_helper.rb +17 -0
- data/lib/rad/core_web/_require.rb +25 -0
- data/lib/rad/core_web/_router/abstract_routing_helper.rb +20 -0
- data/lib/rad/core_web/_router/controller_routing_helper.rb +56 -0
- data/lib/rad/core_web/_router/view_routing_helper.rb +57 -0
- data/lib/rad/environment/_config.rb +27 -0
- data/lib/rad/environment/_environment.rb +17 -0
- data/lib/rad/environment/_files_helper.rb +55 -0
- data/lib/rad/environment/_logger.rb +53 -0
- data/lib/rad/environment/_require.rb +24 -0
- data/lib/rad/environment/config.rb +1 -111
- data/lib/rad/environment.rb +1 -55
- data/lib/{rad_core → rad}/gems.rb +2 -3
- data/lib/rad/html/_flash.rb +40 -0
- data/lib/rad/html/_helpers/basic_html_helper.rb +72 -0
- data/lib/rad/html/_helpers/flash_helper.rb +3 -0
- data/lib/rad/html/_helpers/form_helper.rb +114 -0
- data/lib/rad/html/_helpers/html_helper.rb +3 -0
- data/lib/rad/html/_helpers/javascript_helper.rb +27 -0
- data/lib/rad/html/_helpers/model_helper.rb +143 -0
- data/lib/rad/html/_require.rb +15 -0
- data/lib/rad/html/processors/prepare_flash.rb +22 -23
- data/lib/rad/html/processors/scoped_params.rb +18 -21
- data/lib/rad/html.rb +1 -26
- data/lib/rad/http/_http.rb +11 -0
- data/lib/rad/http/_http_adapter.rb +44 -0
- data/lib/rad/http/_request.rb +50 -0
- data/lib/rad/http/_require.rb +33 -0
- data/lib/rad/http/_response.rb +84 -0
- data/lib/rad/http/{support → _support}/rack/fixes.rb +0 -0
- data/lib/rad/http/_support/rack/rack_adapter.rb +57 -0
- data/lib/rad/http/processors/evaluate_format.rb +16 -19
- data/lib/rad/http/processors/http_logger.rb +10 -12
- data/lib/rad/http/processors/http_writer.rb +24 -26
- data/lib/rad/http/processors/prepare_params.rb +19 -18
- data/lib/rad/http/request.rb +1 -0
- data/lib/rad/http/response.rb +1 -0
- data/lib/rad/http.rb +1 -48
- data/lib/rad/mailer/_letter.rb +28 -0
- data/lib/rad/mailer/_mailer.rb +13 -0
- data/lib/rad/mailer/_mailer_controller.rb +38 -0
- data/lib/rad/mailer/_require.rb +7 -0
- data/lib/rad/mailer/mailer_controller.rb +1 -0
- data/lib/rad/mailer/processors/letter_builder.rb +34 -0
- data/lib/rad/mailer.rb +1 -0
- data/lib/rad/profiles/mailer.rb +5 -0
- data/lib/rad/profiles/web.rb +29 -52
- data/lib/rad/remote/_remote_controller.rb +9 -0
- data/lib/rad/remote/_require.rb +6 -0
- data/lib/rad/remote/processors/remote_caller.rb +44 -46
- data/lib/rad/remote/processors/remote_logger.rb +8 -10
- data/lib/rad/remote/remote_controller.rb +1 -0
- data/lib/rad/remote.rb +1 -9
- data/lib/rad/router/_abstract_router.rb +50 -0
- data/lib/rad/router/_alias_router.rb +124 -0
- data/lib/rad/router/_basic_router.rb +72 -0
- data/lib/rad/router/_configurator.rb +19 -0
- data/lib/rad/router/_core_routing_helper.rb +39 -0
- data/lib/rad/router/_default_format_processor.rb +10 -0
- data/lib/rad/router/_object_router.rb +184 -0
- data/lib/rad/router/_require.rb +31 -0
- data/lib/rad/router/_restful_router.rb +124 -0
- data/lib/rad/router/_router.rb +294 -0
- data/lib/rad/router/_simple_router.rb +21 -0
- data/lib/rad/router/abstract_router.rb +1 -0
- data/lib/rad/router/alias_router.rb +1 -0
- data/lib/rad/router/configurator.rb +1 -0
- data/lib/rad/router/micelaneous_router.rb +1 -0
- data/lib/rad/router/object_router.rb +1 -0
- data/lib/rad/router/processors/router.rb +23 -0
- data/lib/rad/router/restful_router.rb +1 -0
- data/lib/rad/{html/include_into_controller.rb → router/simple_router.rb} +0 -0
- data/lib/rad/router.rb +1 -29
- data/lib/rad/spec/controller.rb +20 -11
- data/lib/rad/spec/environment.rb +22 -38
- data/lib/rad/spec/http.rb +13 -86
- data/lib/rad/spec/http_controller.rb +105 -0
- data/lib/rad/spec/mailer.rb +27 -0
- data/lib/rad/spec/remote.rb +2 -2
- data/lib/rad/spec/router.rb +9 -11
- data/lib/rad/spec/template.rb +8 -2
- data/lib/rad/spec/xhtml.rb +0 -2
- data/lib/rad/spec.rb +4 -2
- data/lib/rad/template/_context.rb +92 -0
- data/lib/rad/template/_relative_path_resolver.rb +8 -0
- data/lib/rad/template/_require.rb +15 -0
- data/lib/rad/template/{support → _support}/tilt.rb +0 -0
- data/lib/rad/template/{support → _support}/tilt_fixes.rb +0 -0
- data/lib/rad/template/_template.rb +175 -0
- data/lib/rad/template/template_context.rb +1 -62
- data/lib/rad/template.rb +1 -25
- data/lib/rad.rb +8 -0
- data/readme.md +40 -12
- data/spec/controller/{abstract_controller_spec → abstract_spec}/views/OperationsOrderSpec/action.erb +0 -0
- data/spec/controller/{abstract_controller_spec → abstract_spec}/views/ViewVariablesSpec/action.erb +0 -0
- data/spec/controller/abstract_spec.rb +126 -0
- data/spec/controller/{controller_context_spec/views/ItemSpec → context_spec/views/NamespaceSpec/ClassSpec}/show.erb +0 -0
- data/spec/controller/{controller_context_spec/views/ItemSpec → context_spec/views/item_spec}/actions.erb +0 -0
- data/spec/controller/{controller_context_spec/views/NamespaceSpec/ClassSpec → context_spec/views/item_spec}/show.erb +0 -0
- data/spec/controller/{controller_context_spec/views/ItemSpec → context_spec/views/item_spec}/update.erb +0 -0
- data/spec/controller/{controller_context_spec → context_spec}/views/namespace_spec/class_spec/update.erb +0 -0
- data/spec/controller/{controller_context_spec/views/PageSpec → context_spec/views/page_spec}/actions.erb +0 -0
- data/spec/controller/{controller_context_spec/views/PageSpec → context_spec/views/page_spec}/show.erb +0 -0
- data/spec/controller/context_spec.rb +123 -0
- data/spec/controller/error_handling_spec.rb +21 -27
- data/spec/controller/{controller_helper_spec → helper_spec}/views/HelperMethodSpec/action.erb +0 -0
- data/spec/controller/{controller_helper_spec → helper_spec}/views/HelperSpec/action.erb +0 -0
- data/spec/controller/{controller_helper_spec.rb → helper_spec.rb} +7 -13
- data/spec/controller/{http_controller_spec.rb → http_spec.rb} +17 -23
- data/spec/controller/{controller_render_spec/views/AlreadyRenderedSpec → render_spec/views/already_rendered_spec}/action.erb +0 -0
- data/spec/controller/{controller_render_spec/views/AlreadyRenderedSpec → render_spec/views/already_rendered_spec}/custom_template.erb +0 -0
- data/spec/controller/{controller_render_spec/views/AnotherActionSpec → render_spec/views/another_action_spec}/another_action.erb +0 -0
- data/spec/controller/{controller_render_spec/views/AnotherLayout → render_spec/views/another_layout}/action.erb +0 -0
- data/spec/controller/{controller_render_spec/views/ForbidPartialAsActionSpec → render_spec/views/forbid_partial_as_action_spec}/_action.erb +0 -0
- data/spec/controller/{controller_render_spec/views/FormatSpec → render_spec/views/format_spec}/action.html.erb +0 -0
- data/spec/controller/{controller_render_spec/views/FormatSpec → render_spec/views/format_spec}/action.js.erb +0 -0
- data/spec/controller/{controller_render_spec/views/LayoutFiltersSpec → render_spec/views/layout_filters_spec}/action_with_layout.erb +0 -0
- data/spec/controller/{controller_render_spec/views/LayoutFiltersSpec → render_spec/views/layout_filters_spec}/action_without_layout.erb +0 -0
- data/spec/controller/{controller_render_spec/views/LayoutSpec → render_spec/views/layout_spec}/action.erb +0 -0
- data/spec/controller/{controller_render_spec → render_spec}/views/layouts/admin.erb +0 -0
- data/spec/controller/{controller_render_spec → render_spec}/views/layouts/app.html.erb +0 -0
- data/spec/controller/{controller_render_spec → render_spec}/views/layouts/app.js.erb +0 -0
- data/spec/controller/{controller_render_spec/views/MultipleActions → render_spec/views/multiple_actions}/actions.haml +0 -0
- data/spec/controller/render_spec/views/relative_spec/a/form.erb +1 -0
- data/spec/controller/render_spec/views/relative_spec/a/show.erb +1 -0
- data/spec/controller/render_spec/views/relative_spec/b/form.erb +1 -0
- data/spec/controller/{controller_render_spec → render_spec}/views/some_template.erb +0 -0
- data/spec/controller/{controller_render_spec → render_spec}/views/standalone.html.erb +0 -0
- data/spec/controller/{controller_render_spec.rb → render_spec.rb} +37 -27
- data/spec/{conveyor/conveyor_spec.rb → conveyors/conveyors_spec.rb} +36 -14
- data/spec/environment/config_spec.rb +13 -21
- data/spec/environment/environment_spec.rb +14 -41
- data/spec/environment/logger_spec.rb +4 -13
- data/spec/environment/minimal_app_spec/app.rb +1 -1
- data/spec/environment/minimal_app_spec.rb +12 -14
- data/spec/environment/standard_app_spec/app/lib/app/init.rb +1 -1
- data/spec/environment/standard_app_spec/plugin_a/lib/plugin_a/init.rb +1 -1
- data/spec/environment/standard_app_spec.rb +17 -25
- data/spec/html/basic_html_helper_spec.rb +7 -4
- data/spec/html/form_helper_spec.rb +5 -5
- data/spec/html/javascript_helper_spec.rb +9 -5
- data/spec/html/model_helper_spec.rb +9 -6
- data/spec/html/scoped_params_spec.rb +2 -2
- data/spec/html/spec_helper.rb +16 -24
- data/spec/http/http_spec.rb +14 -35
- data/spec/http/micelaneous_spec.rb +3 -3
- data/spec/{mail → mailer}/mail_controller_spec/views/body_template_spec/signup.erb +0 -0
- data/spec/{mail → mailer}/mail_controller_spec.rb +36 -12
- data/spec/mailer/spec_helper.rb +5 -0
- data/spec/remote/remote_spec.rb +23 -8
- data/spec/router/alias_router_spec.rb +29 -30
- data/spec/router/basic_router_spec.rb +44 -0
- data/spec/router/configurator_spec.rb +9 -6
- data/spec/router/integration_spec.rb +10 -7
- data/spec/router/object_router_spec.rb +186 -0
- data/spec/router/persistent_params_spec.rb +4 -4
- data/spec/router/restful_router_spec.rb +61 -53
- data/spec/router/{basic_spec.rb → router_spec.rb} +26 -23
- data/spec/router/routing_helper_spec.rb +5 -6
- data/spec/spec_helper.rb +4 -0
- data/spec/support/callbacks_spec.rb +1 -1
- data/spec/support/filters_spec.rb +2 -2
- data/spec/support/spec_helper.rb +1 -1
- data/spec/template/template_spec/views/format_for_partials/dialog.js.erb +1 -1
- data/spec/template/template_spec/views/nested/format/a.erb +1 -1
- data/spec/template/template_spec/views/nested/format/b.js.erb +1 -0
- data/spec/template/template_spec/views/nesting_format/dialog.js.erb +1 -1
- data/spec/template/template_spec.rb +62 -48
- data/spec/template/tilt_spec/views/concat_and_capture.erb +1 -1
- data/spec/template/tilt_spec/views/concat_and_capture.haml +1 -1
- data/spec/template/tilt_spec.rb +17 -19
- data/spec/{integration → web}/basic_spec/views/smoke_test_spec/action.erb +0 -0
- data/spec/{integration → web}/basic_spec.rb +31 -12
- data/spec/{integration → web}/controller_routing_helper_spec.rb +13 -11
- data/spec/{integration → web}/flash_spec.rb +57 -42
- data/spec/{integration → web}/spec_helper_spec.rb +11 -10
- data/spec/{integration → web}/view_routing_helper_spec.rb +44 -36
- metadata +338 -318
- data/lib/rad/controller/abstract_controller/micelaneous.rb +0 -31
- data/lib/rad/controller/abstract_controller/render.rb +0 -160
- data/lib/rad/controller/abstract_controller/responder.rb +0 -17
- data/lib/rad/controller/abstract_controller.rb +0 -64
- data/lib/rad/controller/controller_context.rb +0 -15
- data/lib/rad/controller/http_controller.rb +0 -48
- data/lib/rad/conveyor/conveyor.rb +0 -74
- data/lib/rad/conveyor/conveyors.rb +0 -20
- data/lib/rad/conveyor/params.rb +0 -14
- data/lib/rad/conveyor/processor.rb +0 -68
- data/lib/rad/conveyor/processors/conveyor_logger.rb +0 -25
- data/lib/rad/conveyor/workspace.rb +0 -36
- data/lib/rad/conveyor.rb +0 -29
- data/lib/rad/environment/dependency_resolver.rb +0 -107
- data/lib/rad/environment/environment.rb +0 -29
- data/lib/rad/environment/files_helper.rb +0 -55
- data/lib/rad/environment/logger.rb +0 -21
- data/lib/rad/html/flash.rb +0 -42
- data/lib/rad/html/helpers/basic_html_helper.rb +0 -83
- data/lib/rad/html/helpers/flash_helper.rb +0 -5
- data/lib/rad/html/helpers/form_helper.rb +0 -115
- data/lib/rad/html/helpers/html_helper.rb +0 -5
- data/lib/rad/html/helpers/javascript_helper.rb +0 -18
- data/lib/rad/html/helpers/model_helper.rb +0 -135
- data/lib/rad/http/http.rb +0 -21
- data/lib/rad/http/http_adapter.rb +0 -36
- data/lib/rad/http/middleware/static_files.rb +0 -21
- data/lib/rad/http/support/rack/rack_adapter.rb +0 -67
- data/lib/rad/http/support/rack/request.rb +0 -42
- data/lib/rad/http/support/rack/response.rb +0 -86
- data/lib/rad/integration/controller_micelaneous_helper.rb +0 -19
- data/lib/rad/integration/router/abstract_routing_helper.rb +0 -22
- data/lib/rad/integration/router/controller_routing_helper.rb +0 -58
- data/lib/rad/integration/router/view_routing_helper.rb +0 -104
- data/lib/rad/integration.rb +0 -30
- data/lib/rad/mail/letter.rb +0 -30
- data/lib/rad/mail/mail_controller.rb +0 -31
- data/lib/rad/mail/mailer.rb +0 -23
- data/lib/rad/mail/processors/letter_builder.rb +0 -36
- data/lib/rad/mail.rb +0 -15
- data/lib/rad/profiles/mail.rb +0 -16
- data/lib/rad/profiles/web_require.rb +0 -5
- data/lib/rad/remote/remote.rb +0 -15
- data/lib/rad/router/core/configurator.rb +0 -25
- data/lib/rad/router/core/core_routing_helper.rb +0 -41
- data/lib/rad/router/core/default_format_processor.rb +0 -12
- data/lib/rad/router/core/processors/router.rb +0 -29
- data/lib/rad/router/core/router.rb +0 -271
- data/lib/rad/router/core/simple_router.rb +0 -23
- data/lib/rad/router/routers/abstract_router.rb +0 -62
- data/lib/rad/router/routers/alias_router.rb +0 -113
- data/lib/rad/router/routers/restful_router.rb +0 -113
- data/lib/rad/spec/mail.rb +0 -31
- data/lib/rad/spec/view.rb +0 -10
- data/lib/rad/support/buffered_logger.rb +0 -44
- data/lib/rad/support/callbacks.rb +0 -168
- data/lib/rad/support/exception.rb +0 -31
- data/lib/rad/support/filters.rb +0 -34
- data/lib/rad/support/format.rb +0 -17
- data/lib/rad/support/micon.rb +0 -13
- data/lib/rad/support.rb +0 -63
- data/lib/rad/template/template.rb +0 -250
- data/spec/controller/abstract_controller_spec.rb +0 -132
- data/spec/controller/controller_context_spec.rb +0 -123
- data/spec/controller/controller_render_spec/views/rem ExplicitRenderSpec/action.erb +0 -1
- data/spec/controller/controller_render_spec/views/rem ExplicitRenderSpec/another_action.erb +0 -1
- data/spec/controller/spec_helper.rb +0 -19
- data/spec/conveyor/spec_helper.rb +0 -3
- data/spec/environment/config_spec/config.default.yml +0 -3
- data/spec/environment/config_spec/config.development.yml +0 -3
- data/spec/environment/config_spec/config.yml +0 -5
- data/spec/environment/spec_helper.rb +0 -1
- data/spec/http/http_spec/app/lib/app/init.rb +0 -10
- 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 +0 -5
- data/spec/http/http_spec/plugin_b/static/emptygit +0 -0
- data/spec/http/spec_helper.rb +0 -5
- data/spec/integration/spec_helper.rb +0 -5
- data/spec/mail/spec_helper.rb +0 -7
- data/spec/remote/spec_helper.rb +0 -17
- data/spec/router/spec_helper.rb +0 -20
- data/spec/template/spec_helper.rb +0 -6
- data/spec/template/template_spec/views/nested/format/b.erb +0 -1
@@ -0,0 +1,20 @@
|
|
1
|
+
class Micon::Core
|
2
|
+
def register_extension name, &block
|
3
|
+
name.must_be.a Symbol
|
4
|
+
block.must_be.defined
|
5
|
+
|
6
|
+
raise "extension :#{name} already registered!" if extensions.include? name
|
7
|
+
|
8
|
+
extensions[name] = block
|
9
|
+
end
|
10
|
+
|
11
|
+
def extension name, target = nil, *args, &default_extension
|
12
|
+
name.must_be.a Symbol
|
13
|
+
|
14
|
+
if block = extensions[name] || default_extension
|
15
|
+
target ? target.instance_exec(*args, &block) : block.call(*args)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def extensions; @extensions ||= {} end
|
20
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Rad::Filters
|
2
|
+
inherit Rad::Callbacks
|
3
|
+
|
4
|
+
module ClassMethods
|
5
|
+
def before *args, &block
|
6
|
+
opt = args.extract_options!
|
7
|
+
if block
|
8
|
+
set_callback :action, :before, opt, &block
|
9
|
+
else
|
10
|
+
args.each{|executor| set_callback :action, :before, executor, opt}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def around *args, &block
|
15
|
+
opt = args.extract_options!
|
16
|
+
if block
|
17
|
+
set_callback :action, :around, opt, &block
|
18
|
+
else
|
19
|
+
args.each{|executor| set_callback :action, :around, executor, opt}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def after *args, &block
|
24
|
+
opt = args.extract_options!
|
25
|
+
if block
|
26
|
+
set_callback :action, :after, opt, &block
|
27
|
+
else
|
28
|
+
args.each{|executor| set_callback :action, :after, executor, opt}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
File without changes
|
@@ -9,5 +9,11 @@ module Mime
|
|
9
9
|
type = ".#{type}" unless type =~ /^\./
|
10
10
|
Rack::Mime.mime_type(type) || raise("Unknown MIME type: #{type}")
|
11
11
|
end
|
12
|
+
|
13
|
+
def image? file_name
|
14
|
+
return false if file_name.blank?
|
15
|
+
extension = File.extname(file_name)
|
16
|
+
Rack::Mime.mime_type(extension) =~ /image/
|
17
|
+
end
|
12
18
|
end
|
13
19
|
end
|
@@ -5,8 +5,9 @@ class Module
|
|
5
5
|
# If no environment given uses non-cached version.
|
6
6
|
#
|
7
7
|
def cache_method_with_params_in_production method
|
8
|
-
|
9
|
-
|
8
|
+
escaped_method = escape_method(method)
|
9
|
+
method_with_cache, method_without_cache = "#{escaped_method}_with_cache", "#{escaped_method}_without_cache"
|
10
|
+
iv = "@#{escaped_method}_cache"
|
10
11
|
|
11
12
|
# raise "Method '#{method}' already defined!" if instance_methods.include?(method)
|
12
13
|
if instance_methods.include?(method_with_cache) or instance_methods.include?(method_without_cache)
|
@@ -31,13 +32,10 @@ class Module
|
|
31
32
|
result
|
32
33
|
end
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
else
|
39
|
-
alias_method method, method_without_cache
|
40
|
-
end
|
35
|
+
if rad.mode == :production
|
36
|
+
alias_method method, method_with_cache
|
37
|
+
else
|
38
|
+
alias_method method, method_without_cache
|
41
39
|
end
|
42
40
|
|
43
41
|
# by default uses non-cached version
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#
|
2
|
+
# ruby
|
3
|
+
#
|
4
|
+
raise 'ruby 1.9.2 or higher required!' unless RUBY_VERSION >= '1.9.2'
|
5
|
+
require 'rad/_support/encoding'
|
6
|
+
|
7
|
+
|
8
|
+
#
|
9
|
+
# gems
|
10
|
+
#
|
11
|
+
require 'rad/gems'
|
12
|
+
|
13
|
+
|
14
|
+
#
|
15
|
+
# dependencies
|
16
|
+
#
|
17
|
+
require 'rad/_support/active_support'
|
18
|
+
|
19
|
+
require 'ruby_ext'
|
20
|
+
|
21
|
+
require 'vfs'
|
22
|
+
|
23
|
+
require 'ruby_ext/more/open_constructor'
|
24
|
+
require 'rad/_support/ruby_ext_with_active_support'
|
25
|
+
|
26
|
+
require 'class_loader'
|
27
|
+
|
28
|
+
require 'micon'
|
29
|
+
require 'micon/rad'
|
30
|
+
# require 'rad/_support/micon'
|
31
|
+
|
32
|
+
require 'rad/_support/class_loader'
|
33
|
+
|
34
|
+
require 'dictionary'
|
35
|
+
|
36
|
+
require 'thread'
|
37
|
+
require 'time'
|
38
|
+
require 'uri'
|
39
|
+
require 'json'
|
40
|
+
|
41
|
+
|
42
|
+
require 'addressable/uri'
|
43
|
+
require 'rad/_support/addressable'
|
44
|
+
::Uri = Addressable::URI
|
45
|
+
|
46
|
+
#
|
47
|
+
# libraries
|
48
|
+
#
|
49
|
+
require 'rad/_support/hacks_and_fixes'
|
50
|
+
|
51
|
+
autoload :Nokogiri, 'nokogiri'
|
52
|
+
|
53
|
+
[
|
54
|
+
'module',
|
55
|
+
'callbacks',
|
56
|
+
'filters',
|
57
|
+
'mime',
|
58
|
+
'string',
|
59
|
+
'rson',
|
60
|
+
'exception',
|
61
|
+
'extensions'
|
62
|
+
].each{|f| require "rad/_support/#{f}"}
|
File without changes
|
File without changes
|
@@ -3,9 +3,17 @@ class String
|
|
3
3
|
ERB::Util.json_escape self
|
4
4
|
end
|
5
5
|
|
6
|
+
HTML_ESCAPE_MAP = { '&' => '&', '>' => '>', '<' => '<', '"' => '"' }
|
6
7
|
def html_escape
|
8
|
+
# ERB and Rack both are replacing '/' character, and it's wrong because it destroys links (like '/default/my_item')
|
7
9
|
# ERB::Util.html_escape self
|
8
|
-
Rack::Utils.escape_html self
|
10
|
+
# Rack::Utils.escape_html self
|
11
|
+
|
12
|
+
gsub(/[&"><]/){|special| HTML_ESCAPE_MAP[special]}
|
13
|
+
end
|
14
|
+
|
15
|
+
def url_escape
|
16
|
+
CGI.escape self
|
9
17
|
end
|
10
18
|
|
11
19
|
JS_ESCAPE_MAP = {
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Rad::Controller::Abstract::Micelaneous
|
2
|
+
#
|
3
|
+
# respond_to
|
4
|
+
#
|
5
|
+
def respond_to &block
|
6
|
+
@_responder.must_be.nil
|
7
|
+
@_responder = Rad::Controller::Abstract::Responder.new
|
8
|
+
block.call @_responder
|
9
|
+
handler = @_responder.handlers[params.format]
|
10
|
+
raise "can't respond to '#{params.format}' format!" unless handler
|
11
|
+
handler.call
|
12
|
+
end
|
13
|
+
|
14
|
+
module ClassMethods
|
15
|
+
#
|
16
|
+
# filter_parameter_logging
|
17
|
+
#
|
18
|
+
inheritable_accessor :filter_parameter_logging, []
|
19
|
+
def filter_parameter_logging_with_sugar *parameters
|
20
|
+
if parameters.empty?
|
21
|
+
filter_parameter_logging_without_sugar
|
22
|
+
else
|
23
|
+
filter_parameter_logging_without_sugar.push *parameters.collect(&:to_s)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
module Rad::Controller::Abstract::Render
|
2
|
+
SPECIAL_FORMAT_HANDLERS = {
|
3
|
+
json: lambda{|o| o.to_json},
|
4
|
+
xml: lambda{|o| o.to_xml},
|
5
|
+
js: lambda{|o| o},
|
6
|
+
}
|
7
|
+
|
8
|
+
def _layout *args
|
9
|
+
@_layout = *args unless args.empty?
|
10
|
+
@_layout
|
11
|
+
end
|
12
|
+
def _layout= layout
|
13
|
+
@_layout = layout
|
14
|
+
end
|
15
|
+
|
16
|
+
def render *args
|
17
|
+
options = rad.template.parse_arguments *args
|
18
|
+
content = render_with_parsed_arguments options, args
|
19
|
+
throw :halt, content
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
def render_action options
|
24
|
+
instance_variables = {
|
25
|
+
action_name: (options[:action] || workspace.action).to_sym,
|
26
|
+
controller_name: self.class.controller_name
|
27
|
+
}
|
28
|
+
instance_variable_names.each do |name|
|
29
|
+
instance_variables[name[1..-1]] = instance_variable_get name unless name =~ /^@_/
|
30
|
+
end
|
31
|
+
context = self.class.context_class.new(instance_variables, self)
|
32
|
+
|
33
|
+
options[:template] ||= options.delete(:action)
|
34
|
+
options[:template].must_be.present
|
35
|
+
options[:template] = options[:template].to_s
|
36
|
+
|
37
|
+
options.reverse_merge!(
|
38
|
+
context: context,
|
39
|
+
format: params.format,
|
40
|
+
exact_format: true,
|
41
|
+
prefixes: ['']
|
42
|
+
)
|
43
|
+
|
44
|
+
# rendering content
|
45
|
+
content, context = render_content options
|
46
|
+
|
47
|
+
# rendering layout
|
48
|
+
options[:content] = context
|
49
|
+
render_layout options, content
|
50
|
+
end
|
51
|
+
|
52
|
+
def render_layout options, content
|
53
|
+
layout = options.include?(:layout) ? options[:layout] : self._layout
|
54
|
+
if layout # and rad.template.exist? layout, options
|
55
|
+
rad.template.render layout, options do |*args|
|
56
|
+
if args.empty?
|
57
|
+
content
|
58
|
+
else
|
59
|
+
args.size.must_be == 1
|
60
|
+
variable_name = args.first.to_s
|
61
|
+
options[:context].content_variables[variable_name]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
else
|
65
|
+
content
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def render_content options
|
70
|
+
rad.template.basic_render options.merge(relative_path_resolver: self.class, if_not_exist: '/rad_default_templates/blank_template')
|
71
|
+
end
|
72
|
+
|
73
|
+
def render_with_parsed_arguments options, original_args
|
74
|
+
if special_format = SPECIAL_FORMAT_HANDLERS.keys.find{|f| options.include? f}
|
75
|
+
handler = SPECIAL_FORMAT_HANDLERS[special_format]
|
76
|
+
if special_format.to_s != params.format
|
77
|
+
raise "You trying responing with '#{special_format}' to the '#{params.format}' requested format!"
|
78
|
+
end
|
79
|
+
handler.call options[special_format]
|
80
|
+
elsif options.include? :inline
|
81
|
+
options[:inline]
|
82
|
+
elsif options[:template] == :nothing
|
83
|
+
''
|
84
|
+
else
|
85
|
+
render_action options
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
module ClassMethods
|
90
|
+
def layout layout, options = {}
|
91
|
+
before options do |controller|
|
92
|
+
controller._layout = layout
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def context_class
|
97
|
+
unless @context_class
|
98
|
+
parent_context_class = nil
|
99
|
+
ancestors[1..-1].each do |anc|
|
100
|
+
break if parent_context_class = anc.respond_to(:context_class)
|
101
|
+
end
|
102
|
+
parent_context_class ||= Rad::Controller::Context
|
103
|
+
|
104
|
+
class_name = "#{self.name}::#{self.name.split('::').last}Context"
|
105
|
+
|
106
|
+
# raise "Tempate context #{class_name} already defined!" if Object.const_defined? class_name
|
107
|
+
eval "class #{class_name} < #{parent_context_class}; end", TOPLEVEL_BINDING, __FILE__, __LINE__
|
108
|
+
@context_class = class_name.constantize
|
109
|
+
end
|
110
|
+
@context_class
|
111
|
+
end
|
112
|
+
|
113
|
+
def find_relative_template *args
|
114
|
+
return _find_relative_template *args unless rad.production?
|
115
|
+
|
116
|
+
# use cache
|
117
|
+
@relative_template ||= {}
|
118
|
+
unless @relative_template.include? args
|
119
|
+
@relative_template[args] = _find_relative_template *args
|
120
|
+
end
|
121
|
+
@relative_template[args]
|
122
|
+
end
|
123
|
+
|
124
|
+
def _find_relative_template tname, prefixes, format, exact_format, current_dir
|
125
|
+
tname.must_be.present
|
126
|
+
|
127
|
+
path = nil
|
128
|
+
|
129
|
+
# own templates
|
130
|
+
["/#{controller_name.underscore}/#{tname}", "/#{controller_name.gsub('::', '/')}/#{tname}"].each do |name|
|
131
|
+
path ||= rad.template.find_file(name, prefixes, format, exact_format, rad.template.paths)
|
132
|
+
end
|
133
|
+
|
134
|
+
# own :actions templates
|
135
|
+
["/#{controller_name.underscore}/actions", "/#{controller_name.gsub('::', '/')}/actions"].each do |name|
|
136
|
+
unless path
|
137
|
+
path = rad.template.find_file(name, prefixes, format, exact_format, rad.template.paths)
|
138
|
+
path = nil if path and (File.read(path) !~ /^.*when.+[^_a-zA-Z0-9]#{tname}[^_a-zA-Z0-9].*$/)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
# superclasses templates
|
143
|
+
unless path
|
144
|
+
parent = ancestors[1..-1].find{|a| a.respond_to?(:find_relative_template)} # and a.instance_methods.include?(action)
|
145
|
+
if parent and parent != Rad::Controller::Abstract
|
146
|
+
path = parent.find_relative_template(tname, prefixes, format, exact_format, current_dir)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
# relative template
|
151
|
+
if !path and current_dir
|
152
|
+
path = rad.template.relative_path_resolver.find_relative_template(tname, prefixes, format, exact_format, current_dir)
|
153
|
+
end
|
154
|
+
|
155
|
+
return path
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class Rad::Controller::Abstract::Responder < BasicObject
|
2
|
+
attr_reader :handlers
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@handlers = {}
|
6
|
+
end
|
7
|
+
|
8
|
+
protected
|
9
|
+
def method_missing m, *args, &block
|
10
|
+
args.must_be.empty
|
11
|
+
handlers[m.to_s] = block || lambda{} #.must_be.defined
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Rad::Controller::Abstract
|
2
|
+
inherit Rad::Filters
|
3
|
+
inherit Rad::Controller::Abstract::Render, Rad::Controller::Abstract::Micelaneous
|
4
|
+
|
5
|
+
inject workspace: :workspace, logger: :logger
|
6
|
+
|
7
|
+
def params
|
8
|
+
workspace.params
|
9
|
+
end
|
10
|
+
|
11
|
+
# def response
|
12
|
+
# workspace.response
|
13
|
+
# end
|
14
|
+
|
15
|
+
module ClassMethods
|
16
|
+
inject workspace: :workspace, logger: :logger
|
17
|
+
|
18
|
+
def controller_name
|
19
|
+
self.namespace ? "#{self.namespace.name}::#{self.alias}" : self.alias
|
20
|
+
end
|
21
|
+
|
22
|
+
def helper *args
|
23
|
+
args.to_a.each do |mod|
|
24
|
+
mod.must_be.a Module
|
25
|
+
context_class.inherit mod
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def helper_method *args
|
30
|
+
args = args.first if args.size == 1 and args.first.is_a?(Array)
|
31
|
+
# args.each{|m| m.to_s.must_be.in self.instance_methods}
|
32
|
+
args.each do |m|
|
33
|
+
context_class.delegate m, to: :controller
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Rad::Controller::Context < Rad::Template::Context
|
2
|
+
attr_reader :controller
|
3
|
+
def initialize instance_variables, controller
|
4
|
+
super instance_variables
|
5
|
+
@controller = controller
|
6
|
+
end
|
7
|
+
|
8
|
+
def controller_name
|
9
|
+
@controller_name #workspace.controller.class.controller_name
|
10
|
+
end
|
11
|
+
|
12
|
+
def action_name
|
13
|
+
@action_name #workspace.action.to_sym
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Rad::Controller::Http
|
2
|
+
inherit Rad::Controller::Abstract
|
3
|
+
|
4
|
+
# def response
|
5
|
+
# workspace.response
|
6
|
+
# end
|
7
|
+
|
8
|
+
protected
|
9
|
+
def render_with_parsed_arguments options, original_args
|
10
|
+
response = workspace.response
|
11
|
+
response.set!(
|
12
|
+
status: options[:status] || :ok,
|
13
|
+
content_type: options[:content_type] || Mime[params.format]
|
14
|
+
)
|
15
|
+
|
16
|
+
if original_args.size == 1 and (status = Rad::Http::Response.decode_status_message(original_args.first))
|
17
|
+
response.set! status: status
|
18
|
+
throw :halt, ""
|
19
|
+
elsif options[:location]
|
20
|
+
redirect_to options[:location]
|
21
|
+
else
|
22
|
+
super
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
module ClassMethods
|
27
|
+
inheritable_accessor :actions_allowed_for_get_request, []
|
28
|
+
|
29
|
+
def allow_get_for *methods
|
30
|
+
methods = methods.first if methods.first.is_a? Array
|
31
|
+
|
32
|
+
enable_protection_from_get_requests!
|
33
|
+
actions_allowed_for_get_request.push *(methods.collect(&:to_sym))
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
def enable_protection_from_get_requests!
|
38
|
+
unless respond_to? :protect_from_get_request
|
39
|
+
define_method :protect_from_get_request do
|
40
|
+
request = workspace.request
|
41
|
+
get = !(request.post? or request.put? or request.delete?)
|
42
|
+
if get and !self.class.actions_allowed_for_get_request.include?(workspace.action)
|
43
|
+
raise "GET request not allowed for :#{workspace.action} action!"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
before :protect_from_get_request
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#
|
2
|
+
# Libraries
|
3
|
+
#
|
4
|
+
class Rad::Controller
|
5
|
+
attr_accessor :development_error_template, :production_error_template, :test_error_template
|
6
|
+
|
7
|
+
module Abstract
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
%w(
|
12
|
+
_abstract/render
|
13
|
+
_abstract/responder
|
14
|
+
_abstract/micelaneous
|
15
|
+
_abstract
|
16
|
+
_context
|
17
|
+
|
18
|
+
_http
|
19
|
+
).each{|f| require "rad/controller/#{f}"}
|
@@ -0,0 +1 @@
|
|
1
|
+
rad.controller
|
@@ -0,0 +1 @@
|
|
1
|
+
rad.controller
|
@@ -0,0 +1 @@
|
|
1
|
+
rad.controller
|
@@ -1,28 +1,26 @@
|
|
1
|
-
|
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
|
1
|
+
rad.controller
|
12
2
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
3
|
+
class ControllerCaller < Rad::Conveyors::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::Controller::Abstract!" unless klass.is? Rad::Controller::Abstract
|
9
|
+
controller = workspace.controller = klass.new
|
10
|
+
action = workspace.action = workspace.method_name
|
11
|
+
format = workspace.params.format
|
19
12
|
|
20
|
-
|
21
|
-
controller.render action: action
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
13
|
+
# call
|
25
14
|
|
26
|
-
|
27
|
-
|
15
|
+
workspace.content = catch :halt 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
|
+
|
28
26
|
end
|
@@ -1,51 +1,49 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
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
|
1
|
+
rad.controller
|
2
|
+
|
3
|
+
class ControllerErrorHandling < Rad::Conveyors::Processor
|
4
|
+
def call
|
5
|
+
workspace.response.must_be.defined
|
30
6
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
7
|
+
begin
|
8
|
+
next_processor.call
|
9
|
+
rescue StandardError => e
|
10
|
+
if rad.test?
|
11
|
+
e.set_backtrace e.backtrace.sfilter(Exception.filters)
|
12
|
+
raise e
|
13
|
+
elsif rad.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
|
36
19
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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.controller.send("#{rad.mode}_error_template")
|
39
|
+
|
40
|
+
if tname and rad.template.exist?(tname, format: format, exact_format: true)
|
41
|
+
data = rad.template.render(tname,
|
42
|
+
format: format,
|
43
|
+
locals: {error: e}
|
44
|
+
)
|
45
|
+
else
|
46
|
+
e.message
|
47
|
+
end
|
48
|
+
}
|
51
49
|
end
|