crystal_ext 0.0.7 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +70 -7
- data/lib/crystal/controller.rb +28 -0
- data/lib/crystal/controller/abstract_controller.rb +60 -0
- data/lib/crystal/controller/abstract_controller/micelaneous.rb +31 -0
- data/lib/crystal/controller/abstract_controller/render.rb +133 -0
- data/lib/crystal/controller/abstract_controller/responder.rb +17 -0
- data/lib/crystal/controller/controller_context.rb +7 -0
- data/lib/crystal/controller/http_controller.rb +43 -0
- data/lib/crystal/controller/processors/controller_caller.rb +40 -0
- data/lib/crystal/controller/processors/controller_error_handling.rb +53 -0
- data/lib/crystal/controller/processors/controller_logger.rb +13 -0
- data/lib/crystal/conveyor.rb +29 -0
- data/lib/crystal/conveyor/conveyor.rb +74 -0
- data/lib/crystal/conveyor/conveyors.rb +20 -0
- data/lib/crystal/conveyor/params.rb +22 -0
- data/lib/crystal/conveyor/processor.rb +68 -0
- data/lib/crystal/conveyor/processors/conveyor_logger.rb +24 -0
- data/lib/crystal/conveyor/workspace.rb +36 -0
- data/lib/crystal/environment.rb +52 -0
- data/lib/crystal/environment/config.rb +118 -0
- data/lib/crystal/environment/dependency_resolver.rb +107 -0
- data/lib/crystal/environment/environment.rb +5 -0
- data/lib/crystal/environment/files_helper.rb +42 -0
- data/lib/crystal/environment/logger.rb +21 -0
- data/lib/crystal/html.rb +28 -0
- data/lib/crystal/html/controller_helpers/controller_url_helper.rb +52 -0
- data/lib/crystal/html/controller_helpers/flash_helper.rb +5 -0
- data/lib/crystal/html/flash.rb +40 -0
- data/lib/crystal/html/include_into_controller.rb +24 -0
- data/lib/crystal/html/processors/prepare_flash.rb +26 -0
- data/lib/crystal/html/processors/scoped_params.rb +30 -0
- data/lib/crystal/html/view_helpers/basic_html_helper.rb +83 -0
- data/lib/crystal/html/view_helpers/form_helper.rb +104 -0
- data/lib/crystal/html/view_helpers/javascript_helper.rb +18 -0
- data/lib/crystal/html/view_helpers/model_helper.rb +119 -0
- data/lib/crystal/html/view_helpers/view_url_helper.rb +66 -0
- data/lib/crystal/http.rb +47 -0
- data/lib/crystal/http/http.rb +18 -0
- data/lib/crystal/http/http_adapter.rb +30 -0
- data/lib/crystal/http/middleware/static_files.rb +20 -0
- data/lib/crystal/http/processors/evaluate_format.rb +22 -0
- data/lib/crystal/http/processors/http_logger.rb +15 -0
- data/lib/crystal/http/processors/http_writer.rb +48 -0
- data/lib/crystal/http/processors/prepare_params.rb +24 -0
- data/lib/crystal/http/rack_config.rb +15 -0
- data/lib/crystal/http/support/rack/rack_adapter.rb +65 -0
- data/lib/crystal/http/support/rack/request.rb +12 -0
- data/lib/crystal/http/support/rack/response.rb +39 -0
- data/lib/crystal/mailer.rb +13 -0
- data/lib/crystal/mailer/mail.rb +7 -0
- data/lib/{crystal_ext/profiles/web_ext.rb → crystal/profiles/web.rb} +9 -15
- data/lib/crystal/profiles/web_require.rb +5 -0
- data/lib/crystal/remote.rb +9 -0
- data/lib/crystal/remote/processors/remote_caller.rb +54 -0
- data/lib/crystal/remote/processors/remote_logger.rb +13 -0
- data/lib/crystal/remote/remote.rb +15 -0
- data/lib/crystal/router.rb +19 -0
- data/lib/crystal/router/configurator.rb +23 -0
- data/lib/crystal/router/default_format_processor.rb +12 -0
- data/lib/crystal/router/default_router.rb +23 -0
- data/lib/crystal/router/named_router.rb +63 -0
- data/lib/crystal/router/processors/router.rb +22 -0
- data/lib/crystal/router/router.rb +218 -0
- data/lib/crystal/router/routing_helper.rb +17 -0
- data/lib/crystal/spec.rb +8 -0
- data/lib/crystal/spec/controller.rb +15 -0
- data/lib/crystal/spec/environment.rb +41 -0
- data/lib/crystal/spec/http.rb +67 -0
- data/lib/crystal/spec/mail.rb +20 -0
- data/lib/crystal/spec/remote.rb +9 -0
- data/lib/crystal/spec/view.rb +10 -0
- data/lib/crystal/spec/xhtml.rb +33 -0
- data/lib/crystal/support.rb +46 -0
- data/lib/crystal/support/active_support.rb +39 -0
- data/lib/crystal/support/active_support/micelaneous.rb +2 -0
- data/lib/crystal/support/addressable.rb +45 -0
- data/lib/crystal/support/buffered_logger.rb +38 -0
- data/lib/crystal/support/callbacks.rb +155 -0
- data/lib/crystal/support/exception.rb +20 -0
- data/lib/crystal/support/filters.rb +34 -0
- data/lib/crystal/support/format.rb +9 -0
- data/lib/crystal/support/gems.rb +8 -0
- data/lib/crystal/support/micon.rb +13 -0
- data/lib/crystal/support/mime.rb +11 -0
- data/lib/crystal/support/module.rb +44 -0
- data/lib/crystal/support/rson.rb +53 -0
- data/lib/crystal/support/ruby_ext_with_active_support.rb +4 -0
- data/lib/crystal/support/safe_hash.rb +135 -0
- data/lib/crystal/support/string.rb +26 -0
- data/lib/crystal/template.rb +21 -0
- data/lib/crystal/template/support/tilt.rb +68 -0
- data/lib/crystal/template/template.rb +244 -0
- data/lib/crystal/template/template_context.rb +57 -0
- data/lib/views/crystal_default_templates/development/error.html.erb +11 -0
- data/lib/views/crystal_default_templates/development/error.js.erb +1 -0
- data/readme.md +8 -11
- data/spec/_mailer/basic_spec.rb +110 -0
- data/spec/_mailer/helper.rb +7 -0
- data/spec/controller/abstract_controller_spec.rb +137 -0
- data/spec/controller/abstract_controller_spec/views/OperationsOrderSpec/action.erb +1 -0
- data/spec/controller/abstract_controller_spec/views/ViewVariablesSpec/action.erb +10 -0
- data/spec/controller/controller_context_spec.rb +122 -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_helper_spec.rb +57 -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_render_spec.rb +191 -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/ExplicitRenderSpec/action.erb +1 -0
- data/spec/controller/controller_render_spec/views/ExplicitRenderSpec/another_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/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/some_template.erb +1 -0
- data/spec/controller/controller_render_spec/views/standalone.html.erb +1 -0
- data/spec/controller/error_handling_spec.rb +96 -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/helper.rb +21 -0
- data/spec/controller/http_controller_spec.rb +89 -0
- data/spec/conveyor/conveyor_spec.rb +124 -0
- data/spec/conveyor/helper.rb +8 -0
- data/spec/environment/_dependency_resolver_spec.rb +50 -0
- data/spec/environment/environment_spec.rb +85 -0
- data/spec/environment/environment_spec/app/app_plugin/config/ec_layout +1 -0
- data/spec/environment/environment_spec/app/app_plugin/ec_some_file +1 -0
- data/spec/environment/environment_spec/app/config/config.test.yml +1 -0
- data/spec/environment/environment_spec/app/config/config.yml +2 -0
- data/spec/environment/environment_spec/gem_plugin/config/ec_layout +1 -0
- data/spec/environment/helper.rb +6 -0
- data/spec/environment/logger_spec.rb +18 -0
- data/spec/environment/minimal_app_spec.rb +27 -0
- data/spec/environment/minimal_app_spec/app.rb +3 -0
- data/spec/environment/standard_app_spec.rb +63 -0
- data/spec/environment/standard_app_spec_data/config/init.rb +18 -0
- data/spec/environment/standard_app_spec_data/plugin_a/plugin_a.rb +7 -0
- data/spec/html/basic_html_helper_spec.rb +28 -0
- data/spec/html/flash_spec.rb +184 -0
- data/spec/html/form_helper_spec.rb +56 -0
- data/spec/html/helper.rb +31 -0
- data/spec/html/javascript_helper_spec.rb +15 -0
- data/spec/html/model_helper_spec.rb +65 -0
- data/spec/html/scoped_params_spec.rb +17 -0
- data/spec/html/url_helper_spec.rb +151 -0
- data/spec/http/helper.rb +9 -0
- data/spec/http/http_spec.rb +56 -0
- data/spec/http/http_spec_data/config/init.rb +7 -0
- data/spec/http/http_spec_data/plugin_b/plugin_b.rb +6 -0
- data/spec/integration/basic_spec.rb +82 -0
- data/spec/integration/basic_spec/views/smoke_test_spec/action.erb +1 -0
- data/spec/integration/helper.rb +10 -0
- data/spec/remote/helper.rb +20 -0
- data/spec/remote/remote_spec.rb +75 -0
- data/spec/router/basic_spec.rb +130 -0
- data/spec/router/configurator_spec.rb +29 -0
- data/spec/router/helper.rb +24 -0
- data/spec/router/integration_spec.rb +42 -0
- data/spec/spec.opts +4 -0
- data/spec/support/callbacks_spec.rb +153 -0
- data/spec/support/filters_spec.rb +59 -0
- data/spec/support/helper.rb +7 -0
- data/spec/support/safe_hash_spec.rb +82 -0
- data/spec/template/helper.rb +8 -0
- data/spec/template/template_spec.rb +189 -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/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/_dialog.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/tilt_spec.rb +96 -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/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
- metadata +303 -33
- data/lib/crystal_ext/defer_js.rb +0 -75
- data/lib/crystal_ext/ensure_no_www.rb +0 -39
- data/lib/crystal_ext/gems.rb +0 -2
- data/lib/crystal_ext/i18n.rb +0 -25
- data/lib/crystal_ext/i18n/locales/ru/pluralization.rb +0 -62
- data/lib/crystal_ext/plugin.rb +0 -23
- data/lib/crystal_ext/plugin/app.rb +0 -19
- data/lib/crystal_ext/plugin/web.rb +0 -44
- data/lib/crystal_ext/prepare_model.rb +0 -20
- data/lib/crystal_ext/profiles/web_ext_require.rb +0 -13
- data/lib/crystal_ext/protect_from_forgery.rb +0 -66
- data/lib/crystal_ext/user_error.rb +0 -14
- data/spec/controller_spec_helper.rb +0 -19
- data/spec/defer_js_spec.rb +0 -33
- data/spec/i18n_spec.rb +0 -31
- data/spec/i18n_spec/locales/en/general.yml +0 -5
- data/spec/i18n_spec/locales/ru/general.yml +0 -7
- data/spec/prepare_model_spec.rb +0 -43
- data/spec/protect_from_forgery_spec.rb +0 -169
- data/spec/spec_helper.rb +0 -4
- data/spec/user_error_spec.rb +0 -41
data/Rakefile
CHANGED
@@ -1,10 +1,73 @@
|
|
1
|
-
require '
|
1
|
+
require 'rake'
|
2
|
+
require 'fileutils'
|
3
|
+
current_dir = File.expand_path(File.dirname(__FILE__))
|
4
|
+
Dir.chdir current_dir
|
2
5
|
|
3
|
-
|
6
|
+
|
7
|
+
#
|
8
|
+
# Specs
|
9
|
+
#
|
10
|
+
require 'spec/rake/spectask'
|
11
|
+
|
12
|
+
task :default => :spec
|
13
|
+
|
14
|
+
Spec::Rake::SpecTask.new('spec') do |t|
|
15
|
+
t.spec_files = FileList["spec/**/*_spec.rb"].select{|f| f !~ /\/_/}
|
16
|
+
t.libs = ["#{current_dir}/lib"]
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
#
|
21
|
+
# Gem
|
22
|
+
#
|
23
|
+
require 'rake/clean'
|
24
|
+
require 'rake/gempackagetask'
|
25
|
+
|
26
|
+
gem_options = {
|
4
27
|
:name => "crystal_ext",
|
5
|
-
:version => "0.0.
|
6
|
-
:summary => "
|
28
|
+
:version => "0.0.11",
|
29
|
+
:summary => "Ruby Web Framework",
|
30
|
+
:dependencies => %w(
|
31
|
+
activesupport
|
32
|
+
ruby_ext
|
33
|
+
rack
|
34
|
+
nokogiri
|
35
|
+
mail
|
36
|
+
addressable
|
37
|
+
)
|
38
|
+
}
|
39
|
+
|
40
|
+
gem_name = gem_options[:name]
|
41
|
+
spec = Gem::Specification.new do |s|
|
42
|
+
gem_options.delete(:dependencies).each{|d| s.add_dependency d}
|
43
|
+
gem_options.each{|k, v| s.send "#{k}=", v}
|
44
|
+
|
45
|
+
s.name = gem_name
|
46
|
+
s.author = "Alexey Petrushin"
|
47
|
+
s.homepage = "http://github.com/alexeypetrushin/#{gem_options[:name]}"
|
48
|
+
s.require_path = "lib"
|
49
|
+
s.files = (%w{Rakefile readme.md} + Dir.glob("{lib,spec}/**/*"))
|
50
|
+
|
51
|
+
s.platform = Gem::Platform::RUBY
|
52
|
+
s.has_rdoc = true
|
53
|
+
end
|
54
|
+
|
55
|
+
package_dir = "#{current_dir}/build"
|
56
|
+
Rake::GemPackageTask.new(spec) do |p|
|
57
|
+
p.need_tar = true if RUBY_PLATFORM !~ /mswin/
|
58
|
+
p.need_zip = true
|
59
|
+
p.package_dir = package_dir
|
60
|
+
end
|
61
|
+
|
62
|
+
task :push do
|
63
|
+
# dir = Dir.chdir package_dir do
|
64
|
+
gem_file = Dir.glob("#{package_dir}/#{gem_name}*.gem").first
|
65
|
+
system "gem push #{gem_file}"
|
66
|
+
# end
|
67
|
+
end
|
68
|
+
|
69
|
+
task :clean do
|
70
|
+
system "rm -r #{package_dir}"
|
71
|
+
end
|
7
72
|
|
8
|
-
|
9
|
-
:homepage => "http://github.com/alexeypetrushin/crystal_ext"
|
10
|
-
)
|
73
|
+
task :release => [:gem, :push, :clean]
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'crystal/conveyor'
|
2
|
+
require 'crystal/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 "crystal/controller/#{f}"}
|
15
|
+
|
16
|
+
module Crystal
|
17
|
+
autoload :HttpController, 'crystal/controller/http_controller'
|
18
|
+
end
|
19
|
+
|
20
|
+
#
|
21
|
+
# Initialization
|
22
|
+
#
|
23
|
+
Crystal::Config::DEFAULTS.merge!({
|
24
|
+
:development_error_template => "/crystal_default_templates/development/error",
|
25
|
+
:production_error_template => nil,
|
26
|
+
:test_error_template => "/crystal_default_templates/development/error",
|
27
|
+
}.stringify_keys)
|
28
|
+
Crystal::Config::DEFAULTS['default_method'] ||= 'call'
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Crystal
|
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
|
+
module ClassMethods
|
17
|
+
inject(
|
18
|
+
:workspace => :workspace,
|
19
|
+
:logger => :logger,
|
20
|
+
:config => :config
|
21
|
+
)
|
22
|
+
|
23
|
+
def controller_name
|
24
|
+
self.namespace ? "#{self.namespace.name}/#{self.alias}" : self.alias
|
25
|
+
end
|
26
|
+
|
27
|
+
def controller_context_class
|
28
|
+
unless @controller_context_class
|
29
|
+
parent_context_class = nil
|
30
|
+
ancestors[1..-1].each do |anc|
|
31
|
+
break if parent_context_class = anc.respond_to(:controller_context_class)
|
32
|
+
end
|
33
|
+
parent_context_class ||= Crystal::ControllerContext
|
34
|
+
|
35
|
+
class_name = "#{self.name}::#{self.name.split('::').last}ControllerContext"
|
36
|
+
|
37
|
+
# raise "Tempate context #{class_name} already defined!" if Object.const_defined? class_name
|
38
|
+
eval "class #{class_name} < #{parent_context_class}; end", TOPLEVEL_BINDING, __FILE__, __LINE__
|
39
|
+
@controller_context_class = class_name.constantize
|
40
|
+
end
|
41
|
+
@controller_context_class
|
42
|
+
end
|
43
|
+
|
44
|
+
def helper *args
|
45
|
+
args.to_a.each do |mod|
|
46
|
+
mod.must_be.a Module
|
47
|
+
controller_context_class.inherit mod
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def helper_method *args
|
52
|
+
args = args.first if args.size == 1 and args.first.is_a?(Array)
|
53
|
+
# args.each{|m| m.to_s.must_be.in self.instance_methods}
|
54
|
+
args.each do |m|
|
55
|
+
controller_context_class.delegate m, :to => :controller
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Crystal
|
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,133 @@
|
|
1
|
+
module Crystal
|
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
|
+
render_with_parsed_arguments options
|
28
|
+
end
|
29
|
+
|
30
|
+
def render_action options
|
31
|
+
options = options.to_openobject
|
32
|
+
|
33
|
+
template = self.class.template_name_for options.action
|
34
|
+
return "" unless Template.exist? template
|
35
|
+
|
36
|
+
instance_variables = {}
|
37
|
+
instance_variable_names.each do |name|
|
38
|
+
instance_variables[name[1..-1]] = instance_variable_get name unless name =~ /^@_/
|
39
|
+
end
|
40
|
+
|
41
|
+
render_options = {
|
42
|
+
:template => template,
|
43
|
+
:instance_variables => instance_variables,
|
44
|
+
:context_class => self.class.controller_context_class,
|
45
|
+
:format => params.format,
|
46
|
+
:action => true # this willn't allow to render partial starting with _
|
47
|
+
}.to_openobject
|
48
|
+
|
49
|
+
content, context = Template.basic_render render_options
|
50
|
+
|
51
|
+
layout = options.include?(:layout) ? options.layout : self.layout
|
52
|
+
if layout
|
53
|
+
content = Template.render_layout layout, :content => content, :context => context
|
54
|
+
end
|
55
|
+
|
56
|
+
content
|
57
|
+
end
|
58
|
+
|
59
|
+
protected
|
60
|
+
def render_with_parsed_arguments options
|
61
|
+
content = if options.action?
|
62
|
+
render_action options
|
63
|
+
elsif special_format_handler = SPECIAL_FORMAT_HANDLERS.find{|format, handler| options.include? format}
|
64
|
+
format, handler = special_format_handler
|
65
|
+
if format != params.format
|
66
|
+
raise "You trying responing with :#{format} to the :#{params.format} requested format!"
|
67
|
+
end
|
68
|
+
handler.call options[format]
|
69
|
+
elsif special_format_handler = SPECIAL_CASES_HANDLERS.find{|key, handler| options.include? key}
|
70
|
+
key, handler = special_format_handler
|
71
|
+
handler.call options[key]
|
72
|
+
else
|
73
|
+
Template.basic_render(options).first
|
74
|
+
end
|
75
|
+
|
76
|
+
throw :special_result, content
|
77
|
+
end
|
78
|
+
|
79
|
+
module ClassMethods
|
80
|
+
def layout layout, options = {}
|
81
|
+
before options do |controller|
|
82
|
+
controller.layout = layout
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def template_name_for action
|
87
|
+
action = action.to_s
|
88
|
+
|
89
|
+
return _template_name_for(action) if config.development?
|
90
|
+
|
91
|
+
@template_name_for ||= {}
|
92
|
+
|
93
|
+
unless tname = @template_name_for[action]
|
94
|
+
tname = _template_name_for(action)
|
95
|
+
@template_name_for[action] = tname
|
96
|
+
end
|
97
|
+
|
98
|
+
tname
|
99
|
+
end
|
100
|
+
|
101
|
+
protected
|
102
|
+
def _template_name_for action
|
103
|
+
instance_methods.must.include(action)
|
104
|
+
|
105
|
+
own_tnames = [
|
106
|
+
"/#{controller_name.gsub('::', '/')}/#{action}",
|
107
|
+
"/#{controller_name.underscore}/#{action}"
|
108
|
+
]
|
109
|
+
|
110
|
+
own_actions_tnames = [
|
111
|
+
"/#{controller_name.gsub('::', '/')}/actions",
|
112
|
+
"/#{controller_name.underscore}/actions"
|
113
|
+
]
|
114
|
+
|
115
|
+
action_template_exist = lambda do |tname|
|
116
|
+
Crystal::Template.exist?(tname) and
|
117
|
+
Crystal::Template.read(tname) =~ /^.+when.+:#{action}.+$/
|
118
|
+
end
|
119
|
+
|
120
|
+
if existing_template = own_tnames.find{|tname| Crystal::Template.exist? tname}
|
121
|
+
existing_template
|
122
|
+
elsif existing_action_template = own_actions_tnames.find(&action_template_exist)
|
123
|
+
existing_action_template
|
124
|
+
elsif parent = ancestors[1..-1].find{|a| a.respond_to?(:template_name_for) and a.instance_methods.include?(action)}
|
125
|
+
parent.template_name_for(action)
|
126
|
+
else
|
127
|
+
own_tnames.first
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Crystal
|
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,43 @@
|
|
1
|
+
module Crystal
|
2
|
+
module HttpController
|
3
|
+
inherit AbstractController
|
4
|
+
|
5
|
+
protected
|
6
|
+
def render_with_parsed_arguments options
|
7
|
+
if options.content_type?
|
8
|
+
workspace.response.content_type = options.content_type
|
9
|
+
super
|
10
|
+
elsif options.location?
|
11
|
+
response = workspace.response
|
12
|
+
response.location, response.status = options.location, (options.status || 301)
|
13
|
+
throw :special_result, %(<html><body>You are being <a href="#{options.location.html_escape}">redirected</a>.</body></html>)
|
14
|
+
elsif options.status?
|
15
|
+
workspace.response.status = options.status
|
16
|
+
super
|
17
|
+
else
|
18
|
+
super
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
module ClassMethods
|
23
|
+
inheritable_accessor :actions_allowed_for_get_request, []
|
24
|
+
|
25
|
+
def allow_get_for *methods
|
26
|
+
enable_protection_from_get_requests!
|
27
|
+
actions_allowed_for_get_request.push *methods.collect(&:to_s)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
def enable_protection_from_get_requests!
|
32
|
+
unless respond_to? :protect_from_get_request
|
33
|
+
define_method :protect_from_get_request do
|
34
|
+
if workspace.request.get? and !self.class.actions_allowed_for_get_request.include?(workspace.action)
|
35
|
+
raise "Get requests not allowed for :#{workspace.action} action!"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
before :protect_from_get_request
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Crystal
|
2
|
+
module Processors
|
3
|
+
class ControllerCaller < Processor
|
4
|
+
attr_accessor :result_variable
|
5
|
+
|
6
|
+
def initialize next_processor, result_variable = 'content'
|
7
|
+
result_variable.must_be.present
|
8
|
+
|
9
|
+
super(next_processor)
|
10
|
+
@result_variable = result_variable
|
11
|
+
end
|
12
|
+
|
13
|
+
def call
|
14
|
+
# prepare
|
15
|
+
klass = workspace.class.must_be.present
|
16
|
+
raise "The controller class #{klass} must be a Crystal::AbstractController!" unless klass.is? Crystal::AbstractController
|
17
|
+
controller = workspace.controller = klass.new
|
18
|
+
action = workspace.action = workspace.method_name
|
19
|
+
format = workspace.params.format
|
20
|
+
|
21
|
+
# call
|
22
|
+
special_result = catch :special_result do
|
23
|
+
controller.run_callbacks :action, :method => action do
|
24
|
+
# call controller
|
25
|
+
controller.send action
|
26
|
+
# render view
|
27
|
+
workspace[result_variable] = controller.render_action :action => action
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
if special_result
|
32
|
+
workspace[result_variable] = special_result
|
33
|
+
else
|
34
|
+
workspace[result_variable].must_be.defined
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|