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,175 @@
|
|
1
|
+
class Rad::Template
|
2
|
+
inject logger: :logger, environment: :environment
|
3
|
+
|
4
|
+
attr_accessor :relative_path_resolver, :prefixes
|
5
|
+
require_attr :prefixes
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@relative_path_resolver = RelativePathResolver.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def render *args, &block
|
12
|
+
result, context = basic_render(parse_arguments(*args), &block)
|
13
|
+
result
|
14
|
+
end
|
15
|
+
|
16
|
+
def exist? tname, options = {}
|
17
|
+
!!find_template(tname, options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def read tname, options = {}
|
21
|
+
file = find_template(tname, options) || raise("no template '#{tname}'!")
|
22
|
+
File.read file
|
23
|
+
end
|
24
|
+
|
25
|
+
def basic_render options, &block
|
26
|
+
with_context options do |context|
|
27
|
+
context.content_block ||= block
|
28
|
+
|
29
|
+
with_scope options, context do |scope|
|
30
|
+
file = (
|
31
|
+
options[:file] ||
|
32
|
+
find_template(options[:template], options.merge(scope)) ||
|
33
|
+
(options[:if_not_exist] && find_template(options[:if_not_exist], options.merge(scope))) ||
|
34
|
+
raise("no template '#{options[:template]}'!")
|
35
|
+
)
|
36
|
+
|
37
|
+
scope[:current_dir] = dirname(file)
|
38
|
+
|
39
|
+
template = create_tilt_template file
|
40
|
+
|
41
|
+
result = with_template context, template do
|
42
|
+
render_template template, context, options, &context.content_block
|
43
|
+
end
|
44
|
+
|
45
|
+
return result, context
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def parse_arguments *args
|
51
|
+
options = args.extract_options!
|
52
|
+
if args.size == 1
|
53
|
+
options[:template] = args.first
|
54
|
+
else
|
55
|
+
raise "Invalid input" if args.size != 0
|
56
|
+
end
|
57
|
+
|
58
|
+
options
|
59
|
+
end
|
60
|
+
|
61
|
+
def find_file tname, prefixes, format, exact_format, directories
|
62
|
+
prefixes = prefixes || self.prefixes
|
63
|
+
prefixes.each do |prefix|
|
64
|
+
tname = template_name_with_prefix("#{directory_name}#{tname}", prefix)
|
65
|
+
file = if tname.include? '.'
|
66
|
+
_find_file(tname, directories) || _find_file("#{tname}.*", directories)
|
67
|
+
else
|
68
|
+
if format
|
69
|
+
_find_file("#{tname}.#{format}.*", directories) or
|
70
|
+
_find_file("#{tname}.*", directories, exact_format)
|
71
|
+
else
|
72
|
+
_find_file("#{tname}.*", directories)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
return file if file
|
76
|
+
end
|
77
|
+
return nil
|
78
|
+
end
|
79
|
+
|
80
|
+
def directory_name; "" end
|
81
|
+
|
82
|
+
def paths; @paths ||= [] end
|
83
|
+
|
84
|
+
protected
|
85
|
+
# with_one_extension - 'tname.*' matches not only 'tname.erb' but also 'tname.html.erb',
|
86
|
+
# with this option enabled it will not match 'tname.html.erb', only 'tname.erb'
|
87
|
+
def _find_file pattern, directories, with_one_extension = false
|
88
|
+
files = rad.environment.find_files_by_pattern_without_cache pattern, directories
|
89
|
+
files = files.select{|f| f !~ /\.[^\.\/]+\.[^\.\/]+$/} if with_one_extension
|
90
|
+
raise "multiple templates for '#{pattern}'!" if files.size > 1
|
91
|
+
files.first
|
92
|
+
end
|
93
|
+
|
94
|
+
def template_name_with_prefix tname, prefix
|
95
|
+
index = tname.rindex('/')
|
96
|
+
index = index ? index + 1 : 0
|
97
|
+
tname = tname.clone
|
98
|
+
tname.insert index, prefix
|
99
|
+
end
|
100
|
+
|
101
|
+
def with_context options, &block
|
102
|
+
context = Thread.current[:render_context] || options[:context] || Context.new(options[:instance_variables])
|
103
|
+
|
104
|
+
old = Thread.current[:render_context]
|
105
|
+
begin
|
106
|
+
Thread.current[:render_context] = context
|
107
|
+
block.call context
|
108
|
+
ensure
|
109
|
+
Thread.current[:render_context] = old
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def with_scope options, context, &block
|
114
|
+
initial = context.scope_variables
|
115
|
+
|
116
|
+
old = context.scope_variables || OpenObject.new
|
117
|
+
begin
|
118
|
+
context.scope_variables = {
|
119
|
+
current_dir: (options[:current_dir] || old[:current_dir]),
|
120
|
+
format: (options[:format] || old[:format]),
|
121
|
+
relative_path_resolver: (options[:relative_path_resolver] || old[:relative_path_resolver])
|
122
|
+
}
|
123
|
+
|
124
|
+
block.call context.scope_variables
|
125
|
+
ensure
|
126
|
+
context.scope_variables = old if initial
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def with_template context, template, &block
|
131
|
+
old = context._tilt_template
|
132
|
+
begin
|
133
|
+
context._tilt_template = template
|
134
|
+
block.call context
|
135
|
+
ensure
|
136
|
+
context._tilt_template = old
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def dirname path;
|
141
|
+
File.dirname path
|
142
|
+
end
|
143
|
+
cache_method_with_params_in_production :dirname
|
144
|
+
|
145
|
+
def find_template tname, options
|
146
|
+
tname.must_be.a String
|
147
|
+
# splitted into two to optimize cache
|
148
|
+
if tname =~ /^\//
|
149
|
+
find_absolute_template tname, options[:prefixes], options[:format], options[:exact_format]
|
150
|
+
else
|
151
|
+
resolver = options[:relative_path_resolver] || relative_path_resolver
|
152
|
+
resolver.find_relative_template tname, options[:prefixes], options[:format], options[:exact_format], options[:current_dir]
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def find_absolute_template tname, prefixes, format, exact_format
|
157
|
+
prefixes = prefixes || self.prefixes
|
158
|
+
find_file(tname, prefixes, format, exact_format, paths)
|
159
|
+
end
|
160
|
+
cache_method_with_params_in_production :find_absolute_template
|
161
|
+
|
162
|
+
def create_tilt_template path
|
163
|
+
Tilt.new(path, nil, ugly: true, outvar: "@output"){|t| File.read(t.file)}
|
164
|
+
end
|
165
|
+
cache_method_with_params_in_production :create_tilt_template
|
166
|
+
|
167
|
+
def render_template template, context, options, &block
|
168
|
+
locals = options[:locals] || {}
|
169
|
+
if object = options[:object]
|
170
|
+
locals[:object] = object
|
171
|
+
end
|
172
|
+
|
173
|
+
template.render context, locals, &block
|
174
|
+
end
|
175
|
+
end
|
@@ -1,62 +1 @@
|
|
1
|
-
|
2
|
-
class TemplateContext
|
3
|
-
include Tilt::CompileSite, Tilt::ContextExt
|
4
|
-
|
5
|
-
#
|
6
|
-
# System
|
7
|
-
#
|
8
|
-
attr_accessor :options, :_tilt_template
|
9
|
-
|
10
|
-
# for saving :format, :current_dir and others
|
11
|
-
# def scope_variables; @scope_variables ||= OpenObject.new end
|
12
|
-
attr_accessor :scope_variables
|
13
|
-
|
14
|
-
|
15
|
-
#
|
16
|
-
# Helpers
|
17
|
-
#
|
18
|
-
inject(
|
19
|
-
workspace: :workspace,
|
20
|
-
router: :router,
|
21
|
-
config: :config
|
22
|
-
)
|
23
|
-
|
24
|
-
delegate :render, to: ::Rad::Template
|
25
|
-
delegate :url_for, to: :router
|
26
|
-
|
27
|
-
|
28
|
-
def j obj
|
29
|
-
obj.to_s.json_escape
|
30
|
-
end
|
31
|
-
|
32
|
-
|
33
|
-
#
|
34
|
-
# Content Variables
|
35
|
-
#
|
36
|
-
attr_accessor :content_block
|
37
|
-
def content_variables; @content_variables ||= {}.to_openobject end
|
38
|
-
def content_for name, content = nil, &block
|
39
|
-
content ||= capture(&block)
|
40
|
-
(content_variables[name.to_s] ||= "") << content
|
41
|
-
nil
|
42
|
-
end
|
43
|
-
def prepend_to name, content = nil, &block
|
44
|
-
content ||= capture(&block)
|
45
|
-
(content_variables[name.to_s] ||= "").insert 0, content
|
46
|
-
nil
|
47
|
-
end
|
48
|
-
def wrap_content_for name, &block
|
49
|
-
block.must_be.defined
|
50
|
-
content = capture((content_variables[name.to_s] || ""), &block)
|
51
|
-
content_variables[name.to_s] ||= content
|
52
|
-
nil
|
53
|
-
end
|
54
|
-
def has_content_for? name
|
55
|
-
content_variables.include? name.to_s
|
56
|
-
end
|
57
|
-
|
58
|
-
def params
|
59
|
-
workspace.params
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
1
|
+
rad.template
|
data/lib/rad/template.rb
CHANGED
@@ -1,25 +1 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'rad/environment'
|
4
|
-
|
5
|
-
require 'erb'
|
6
|
-
require 'haml'
|
7
|
-
require 'tilt'
|
8
|
-
require 'rad/template/support/tilt'
|
9
|
-
require 'rad/template/support/tilt_fixes'
|
10
|
-
|
11
|
-
[
|
12
|
-
'template',
|
13
|
-
'template_context'
|
14
|
-
].each{|f| require "rad/template/#{f}"}
|
15
|
-
|
16
|
-
rad_core_dir = "#{__FILE__}/../../../..".dirname
|
17
|
-
Rad::Template.paths << "#{rad_core_dir}/views"
|
18
|
-
|
19
|
-
|
20
|
-
#
|
21
|
-
# Initialization
|
22
|
-
#
|
23
|
-
Rad::Config::DEFAULTS.merge!(
|
24
|
-
default_template_prefixes: ['', '_']
|
25
|
-
)
|
1
|
+
rad.template
|
data/lib/rad.rb
ADDED
data/readme.md
CHANGED
@@ -1,14 +1,26 @@
|
|
1
|
-
# Rad - Ruby Web Framework
|
1
|
+
# Rad - Ruby Web Framework
|
2
2
|
|
3
|
-
|
3
|
+
Goals: **give You tools to fight complexity** and freedom to do it in a way You like.
|
4
4
|
|
5
|
-
|
6
|
-
The same apply for the architecture of your application - instead of to be a monolith it consists of cooperating plugins/gems.
|
5
|
+
You can start quickly using one of predefined *opinionated* profiles, or take a total control over all aspects of environment and completelly modify it according to Your goals.
|
7
6
|
|
8
|
-
|
9
|
-
Yes, I know that IoC aren't much popular in Ruby community, but it's not quite ordinary IoC, and it's really handy.
|
7
|
+
If You whould like **to see it working, please go to http://ruby-lang.info** - that site powered by Rad.
|
10
8
|
|
11
|
-
|
9
|
+
It's designed to:
|
10
|
+
|
11
|
+
- Divide and rule (build app as a set of cooperated components)
|
12
|
+
- True support for OOP (models, routes, controllers/resources + views)
|
13
|
+
- Simple things should be simple (simple API, instant start with minimal config)
|
14
|
+
- Complete control if You need it, it's designed to be open and customizable
|
15
|
+
- Agile/Extreme development should be easy (specs, iterative development, fast prototyping)
|
16
|
+
|
17
|
+
## Some thecnical thoughts and ideas
|
18
|
+
|
19
|
+
- I tried to keep codebase as small and simple as possible and delegate job do another libraries, so actually it's an integration layer on top of other libraries that focuses on providing nice and consistent interface.
|
20
|
+
- It uses "conveyors" for assembling all kind of responces, and it's very easy to set custom assembly chain or modify existing one. This way You have a strong controll over wide aspects of framework.
|
21
|
+
- So, it looks like **lots of config**? - **No** - there are predefined profiles and if You don't need special environment - just use one and start instantly. But if You ever would need a complete control - it is there.
|
22
|
+
- I also tried to comply to KISS principle - always fighting complex stuff, seeking for not needed API or code that can be eliminated or delegated to external library.
|
23
|
+
- I tried to reuse existing good stuff as much as possible, for example - web tier looks kinda like Rails (so, You don't have to learn much of new stuff and API) but the behaviour of it is slightly (or sometimes significally) different.
|
12
24
|
|
13
25
|
## Why did I make another Rails?
|
14
26
|
There are many things that I like in Rails:
|
@@ -19,15 +31,31 @@ There are many things that I like in Rails:
|
|
19
31
|
- nice and very handy API and naming conventions
|
20
32
|
- no config and fast start with leaning learning curve
|
21
33
|
|
22
|
-
But, there are some problems
|
34
|
+
But, there are some problems:
|
23
35
|
|
24
|
-
- there's only one way - The Rails Way, it's all simple and cool when
|
36
|
+
- there's only one way - The Rails Way, it's all simple and cool when You are on this way. But if You wanna to step aside and do it in Your way - You'll get big problems, so big that they are almost completely eliminates all the goodness.
|
25
37
|
- very hard to extend and customize
|
26
|
-
-
|
38
|
+
- You forced to build monolithic applications, it's hard to build application as set of modules (partially fixed in Rails 3).
|
27
39
|
- weak support of object oriented paradigm, there's really no true inheritance in Controller and Routing scheme.
|
28
40
|
- hard to build distributed applications.
|
29
41
|
|
30
42
|
With Rad I tried to save all the goodness and use API as closed to Rails as possible but also give the developer freedom to choose it's own way and also solve those important problems.
|
31
43
|
|
32
|
-
##
|
33
|
-
|
44
|
+
## Finished functional
|
45
|
+
|
46
|
+
- Controllers (80% of Rails + new stuff)
|
47
|
+
- Views (80% of Rails + new stuff)
|
48
|
+
- Router (Polymorphic, Restful, Simple)
|
49
|
+
- Migrations (MongoDB, multiple databases, versions, up/down)
|
50
|
+
- Deployment automation (90% of capistrano + new stuff)
|
51
|
+
- Mailers (80% of Rails)
|
52
|
+
- Code reloading in :development
|
53
|
+
- Asset packaging
|
54
|
+
- MooTools support
|
55
|
+
- Specs support (Controllers, Models + new stuff)
|
56
|
+
- Console (nothing special, just like rails console)
|
57
|
+
- and more ...
|
58
|
+
|
59
|
+
## License
|
60
|
+
|
61
|
+
Copyright (c) Alexey Petrushin http://4ire.net, released under the **MIT** license.
|
data/spec/controller/{abstract_controller_spec → abstract_spec}/views/OperationsOrderSpec/action.erb
RENAMED
File without changes
|
data/spec/controller/{abstract_controller_spec → abstract_spec}/views/ViewVariablesSpec/action.erb
RENAMED
File without changes
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Abstract" do
|
4
|
+
with_view_path "#{spec_dir}/views"
|
5
|
+
with_abstract_controller
|
6
|
+
|
7
|
+
after :all do
|
8
|
+
remove_constants %w(
|
9
|
+
WorkspaceVariablesSpec
|
10
|
+
SpecialResultSpec
|
11
|
+
RespondToSpec
|
12
|
+
ViewVariablesSpec
|
13
|
+
OperationsOrderSpec
|
14
|
+
NoTemplateSpec
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should set workspace variables" do
|
19
|
+
class ::WorkspaceVariablesSpec
|
20
|
+
inherit Rad::Controller::Abstract
|
21
|
+
|
22
|
+
def action; end
|
23
|
+
end
|
24
|
+
|
25
|
+
ccall WorkspaceVariablesSpec, :action
|
26
|
+
|
27
|
+
workspace.controller.should be_a(WorkspaceVariablesSpec)
|
28
|
+
workspace.response.should respond_to("body=")
|
29
|
+
|
30
|
+
expected_result = {
|
31
|
+
params: {},
|
32
|
+
|
33
|
+
class: WorkspaceVariablesSpec,
|
34
|
+
method_name: :action,
|
35
|
+
action: :action
|
36
|
+
}
|
37
|
+
workspace.to_h(true).subset(expected_result.keys).should == expected_result
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should be able to throw :halt in controller or view and that result must be assigned as result" do
|
41
|
+
class ::SpecialResultSpec
|
42
|
+
inherit Rad::Controller::Abstract
|
43
|
+
def action
|
44
|
+
throw :halt, 'some content'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
ccall(SpecialResultSpec, :action).should == "some content"
|
49
|
+
end
|
50
|
+
|
51
|
+
it "respond_to" do
|
52
|
+
class ::RespondToSpec
|
53
|
+
inherit Rad::Controller::Abstract
|
54
|
+
|
55
|
+
def action
|
56
|
+
respond_to do |format|
|
57
|
+
format.html{render inline: 'html'}
|
58
|
+
format.json{render json: {a: 'b'}}
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
ccall(RespondToSpec, :action, format: 'html').should == 'html'
|
64
|
+
ccall(RespondToSpec, :action, format: 'json').should == %({"a":"b"})
|
65
|
+
lambda{ccall(RespondToSpec, :action, format: 'js')}.should raise_error(/can't respond to 'js' format/)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "controller's instance variables must be available in view, and also other variables" do
|
69
|
+
class ::ViewVariablesSpec
|
70
|
+
inherit Rad::Controller::Abstract
|
71
|
+
|
72
|
+
def action
|
73
|
+
@instance_variable = "iv value"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
ccall(ViewVariablesSpec, :action, param: 'param value', format: 'html').should == %(\
|
78
|
+
controller: ViewVariablesSpec
|
79
|
+
controller_name: ViewVariablesSpec
|
80
|
+
|
81
|
+
class: ViewVariablesSpec
|
82
|
+
method_name: action
|
83
|
+
action: action
|
84
|
+
|
85
|
+
instance_variable: iv value
|
86
|
+
|
87
|
+
params: param value
|
88
|
+
format: html)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "operations order" do
|
92
|
+
class ::OperationsOrderSpec
|
93
|
+
inherit Rad::Controller::Abstract
|
94
|
+
|
95
|
+
def self.result
|
96
|
+
@result ||= []
|
97
|
+
end
|
98
|
+
|
99
|
+
around do |controller, block|
|
100
|
+
begin
|
101
|
+
OperationsOrderSpec.result << :before
|
102
|
+
block.call
|
103
|
+
ensure
|
104
|
+
OperationsOrderSpec.result << :after
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def action
|
109
|
+
OperationsOrderSpec.result << :action
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
ccall(OperationsOrderSpec, :action)
|
114
|
+
OperationsOrderSpec.result.should == [:before, :action, :template, :after]
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should render :nothing" do
|
118
|
+
class NoTemplateSpec
|
119
|
+
inherit Rad::Controller::Abstract
|
120
|
+
|
121
|
+
def action; end
|
122
|
+
end
|
123
|
+
|
124
|
+
ccall(NoTemplateSpec, :action).should == ""
|
125
|
+
end
|
126
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Controller Context" do
|
4
|
+
with_view_path "#{spec_dir}/views"
|
5
|
+
|
6
|
+
before :all do
|
7
|
+
class ItemSpec
|
8
|
+
inherit Rad::Controller::Abstract
|
9
|
+
|
10
|
+
def show; end
|
11
|
+
def update; end
|
12
|
+
def delete; end
|
13
|
+
def increase; end
|
14
|
+
def decrease; end
|
15
|
+
end
|
16
|
+
|
17
|
+
class PageSpec < ItemSpec
|
18
|
+
def show; end
|
19
|
+
def increase; end
|
20
|
+
end
|
21
|
+
|
22
|
+
module NamespaceSpec
|
23
|
+
class ClassSpec
|
24
|
+
inherit Rad::Controller::Abstract
|
25
|
+
|
26
|
+
def show; end
|
27
|
+
def update; end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
after :all do
|
33
|
+
remove_constants %w(
|
34
|
+
ItemSpec
|
35
|
+
PageSpec
|
36
|
+
NamespaceSpec
|
37
|
+
ItemSpecHelper
|
38
|
+
PageSpecHelper
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "basic" do
|
43
|
+
before{@args = [[''], nil, nil, nil]}
|
44
|
+
|
45
|
+
it "should return nil for non-existing template" do
|
46
|
+
ItemSpec.find_relative_template(:delete, *@args).should be_nil
|
47
|
+
PageSpec.find_relative_template(:delete, *@args).should be_nil
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should provide template name for existing template" do
|
51
|
+
ItemSpec.find_relative_template(:update, *@args).should == "#{spec_dir}/views/item_spec/update.erb"
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should inherit template name for template existing in parent" do
|
55
|
+
PageSpec.find_relative_template(:update, *@args).should == "#{spec_dir}/views/item_spec/update.erb"
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should override template name for template existing in both self and parent" do
|
59
|
+
ItemSpec.find_relative_template(:show, *@args).should == "#{spec_dir}/views/item_spec/show.erb"
|
60
|
+
PageSpec.find_relative_template(:show, *@args).should == "#{spec_dir}/views/page_spec/show.erb"
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should transfer namespaces into folders" do
|
64
|
+
NamespaceSpec::ClassSpec.find_relative_template(:show, *@args).should == "#{spec_dir}/views/NamespaceSpec/ClassSpec/show.erb"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "actions" do
|
69
|
+
before{@args = [[''], nil, nil, nil]}
|
70
|
+
|
71
|
+
it "should be able to check for action inside of actions.xxx files" do
|
72
|
+
ItemSpec.find_relative_template(:increase, *@args).should == "#{spec_dir}/views/item_spec/actions.erb"
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should be able to check for action inside of actions.xxx files" do
|
76
|
+
ItemSpec.find_relative_template(:increase, *@args).should == "#{spec_dir}/views/item_spec/actions.erb"
|
77
|
+
ItemSpec.find_relative_template(:decrease, *@args).should == "#{spec_dir}/views/item_spec/actions.erb"
|
78
|
+
ItemSpec.find_relative_template(:action_not_defined_inside_of_actions_file, *@args).should == nil
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should inherit actions.xxx" do
|
82
|
+
PageSpec.find_relative_template(:increase, *@args).should == "#{spec_dir}/views/item_spec/actions.erb"
|
83
|
+
PageSpec.find_relative_template(:decrease, *@args).should == "#{spec_dir}/views/page_spec/actions.erb"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "context_class, helper" do
|
88
|
+
before do
|
89
|
+
ItemSpec.instance_variable_set "@context_class", nil
|
90
|
+
ItemSpec.instance_variable_set "@context_class", nil
|
91
|
+
end
|
92
|
+
|
93
|
+
it "context_class" do
|
94
|
+
ItemSpec.context_class.should == ItemSpec::ItemSpecContext
|
95
|
+
PageSpec.context_class.should == PageSpec::PageSpecContext
|
96
|
+
PageSpec::PageSpecContext.is?(PageSpec::ItemSpecContext).should be_true
|
97
|
+
end
|
98
|
+
|
99
|
+
it "helper" do
|
100
|
+
module ::ItemSpecHelper
|
101
|
+
def controller_item; end
|
102
|
+
end
|
103
|
+
|
104
|
+
module ::PageSpecHelper
|
105
|
+
def controller_page; end
|
106
|
+
end
|
107
|
+
|
108
|
+
ItemSpec.helper ItemSpecHelper
|
109
|
+
PageSpec.helper PageSpecHelper
|
110
|
+
|
111
|
+
ItemSpec::ItemSpecContext.instance_methods.should include(:controller_item)
|
112
|
+
|
113
|
+
PageSpec::PageSpecContext.instance_methods.should include(:controller_item)
|
114
|
+
PageSpec::PageSpecContext.instance_methods.should include(:controller_page)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe "other" do
|
119
|
+
it "should understand underscored paths" do
|
120
|
+
NamespaceSpec::ClassSpec.find_relative_template(:update, [''], nil, nil, nil).should == "#{spec_dir}/views/namespace_spec/class_spec/update.erb"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|