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
@@ -0,0 +1,15 @@
|
|
1
|
+
module Crystal
|
2
|
+
module Processors
|
3
|
+
class HTTPLogger < Processor
|
4
|
+
def call
|
5
|
+
if workspace.request? and workspace.params?
|
6
|
+
method, path, ip, time, format = workspace.request.request_method, workspace.path,
|
7
|
+
workspace.request.ip, (workspace.start_time || Time.now), workspace.params.format
|
8
|
+
logger.info "Started '#{path}' as '#{format}' (for #{ip} at #{time.to_s} with #{method})"
|
9
|
+
end
|
10
|
+
|
11
|
+
next_processor.call
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Crystal
|
2
|
+
module Processors
|
3
|
+
class HttpWriter < Processor
|
4
|
+
attr_accessor :result_variable
|
5
|
+
|
6
|
+
def initialize next_processor, result_variable = 'content'
|
7
|
+
super(next_processor)
|
8
|
+
@result_variable = result_variable
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
response = workspace.response.must_be.defined
|
13
|
+
|
14
|
+
begin
|
15
|
+
next_processor.call
|
16
|
+
|
17
|
+
result = workspace[result_variable]
|
18
|
+
response.body = result if response.body.blank? and result.present?
|
19
|
+
response.content_type ||= Mime[workspace.params.format]
|
20
|
+
rescue StandardError => e
|
21
|
+
raise e if config.test?
|
22
|
+
|
23
|
+
# if workspace.error_processed?
|
24
|
+
# result = workspace[@result_variable]
|
25
|
+
#
|
26
|
+
# response.body << result if result
|
27
|
+
# response.content_type = Mime[workspace.params.format]
|
28
|
+
# else
|
29
|
+
|
30
|
+
if workspace.params.format? and workspace.params.format.json?
|
31
|
+
response.body << {:error => (config.production? ? "Internal error!" : e.message)}.to_json
|
32
|
+
response.content_type = Mime.json
|
33
|
+
else
|
34
|
+
response.body << (config.production? ? "Internal error!" : e.message)
|
35
|
+
response.content_type = Mime.text
|
36
|
+
end
|
37
|
+
|
38
|
+
logger.error e
|
39
|
+
logger.info "\n"
|
40
|
+
|
41
|
+
# end
|
42
|
+
|
43
|
+
# response.error = e # for RSpec helpers
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Crystal
|
2
|
+
module Processors
|
3
|
+
class PrepareParams < Processor
|
4
|
+
def call
|
5
|
+
workspace.env.must_be.defined
|
6
|
+
|
7
|
+
workspace.request = Crystal::Request.new(workspace.env)
|
8
|
+
workspace.path = workspace.request.path
|
9
|
+
params = workspace.params = Crystal::Params.new(workspace.request.params)
|
10
|
+
|
11
|
+
if params.json?
|
12
|
+
json_params = JSON.load params['json']
|
13
|
+
json_params.must_be.a Hash
|
14
|
+
json_params.keys.each do |k|
|
15
|
+
logger.warn "Parameter :#{k} will be overwriden from JSON!" if params.include?(k)
|
16
|
+
end
|
17
|
+
params.merge! json_params
|
18
|
+
end
|
19
|
+
|
20
|
+
next_processor.call
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# module Crystal
|
2
|
+
# module RackConfig
|
3
|
+
# def run_common_app rack_config_file_path
|
4
|
+
# $APP_DIR = File.expand_path(File.dirname(rack_config_file_path))
|
5
|
+
#
|
6
|
+
# require "#{$APP_DIR}/config/init"
|
7
|
+
#
|
8
|
+
# Crystal::Config::DEFAULTS['environment'] = $CENV || 'production'
|
9
|
+
# Micon[:environment]
|
10
|
+
#
|
11
|
+
# Crystal.build_common_app self
|
12
|
+
# run Crystal
|
13
|
+
# end
|
14
|
+
# end
|
15
|
+
# end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Crystal
|
2
|
+
class RackAdapter
|
3
|
+
SERVERS = %w{mongrel thin webrick}
|
4
|
+
|
5
|
+
# class Callback
|
6
|
+
# def initialize app; end
|
7
|
+
# def self.call env; Crystal::Adapter.call env end
|
8
|
+
# end
|
9
|
+
|
10
|
+
class << self
|
11
|
+
inject(
|
12
|
+
:logger => :logger,
|
13
|
+
:config => :config
|
14
|
+
)
|
15
|
+
|
16
|
+
def build_common_app builder = nil, &block
|
17
|
+
if block
|
18
|
+
@build_common_app = block
|
19
|
+
else
|
20
|
+
unless @build_common_app
|
21
|
+
raise "Common App not defined! Use profiles (like crystal/profiles/web), define it by yourself or use your own configuration!"
|
22
|
+
end
|
23
|
+
@build_common_app.call builder
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def parse_config
|
28
|
+
app, options = Rack::Builder.parse_file 'config.ru'
|
29
|
+
app
|
30
|
+
end
|
31
|
+
|
32
|
+
def run app
|
33
|
+
handler = detect_rack_handler
|
34
|
+
handler_name = handler.name.gsub(/.*::/, '')
|
35
|
+
# unless handler_name =~/cgi/i
|
36
|
+
logger.info "Crystal #{Crystal::VERSION} started on #{config.port!} in :#{config.environment!} mode (at #{Time.now.to_s})\n\n"
|
37
|
+
handler.run app, :Host => config.host!, :Port => config.port! do |server|
|
38
|
+
[:INT, :TERM].each {|sig| trap(sig){quit!(server, handler_name)}}
|
39
|
+
end
|
40
|
+
rescue Errno::EADDRINUSE => e
|
41
|
+
logger.error "Port #{config.port!} taken!"
|
42
|
+
end
|
43
|
+
|
44
|
+
def quit!(server, handler_name)
|
45
|
+
## Use thins' hard #stop! if available, otherwise just #stop
|
46
|
+
server.respond_to?(:stop!) ? server.stop! : server.stop
|
47
|
+
puts "\nCrystal stopped" unless handler_name =~/cgi/i
|
48
|
+
end
|
49
|
+
|
50
|
+
protected
|
51
|
+
def detect_rack_handler
|
52
|
+
return Rack::Handler.get('mongrel')
|
53
|
+
SERVERS.each do |server_name|
|
54
|
+
begin
|
55
|
+
return Rack::Handler.get(server_name.downcase)
|
56
|
+
rescue LoadError
|
57
|
+
rescue NameError
|
58
|
+
end
|
59
|
+
end
|
60
|
+
fail " Server handler (#{SERVERS.join(', ')}) not found."
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Crystal
|
2
|
+
class Request < Rack::Request
|
3
|
+
# Returns an array of acceptable media types for the response
|
4
|
+
# def accept
|
5
|
+
# @env['HTTP_ACCEPT'].to_s.split(',').map { |a| a.split(';')[0].strip }
|
6
|
+
# end
|
7
|
+
#
|
8
|
+
# def secure?
|
9
|
+
# (@env['HTTP_X_FORWARDED_PROTO'] || @env['rack.url_scheme']) == 'https'
|
10
|
+
# end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Crystal
|
2
|
+
class Response
|
3
|
+
attr_accessor :status, :headers, :body
|
4
|
+
# attr_accessor :error # for specs
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@status, @headers, @body = 200, {}, ""
|
8
|
+
end
|
9
|
+
|
10
|
+
def write str
|
11
|
+
body << str
|
12
|
+
end
|
13
|
+
|
14
|
+
def content_type= type; headers["Content-Type"] = type end
|
15
|
+
def content_type; headers["Content-Type"] end
|
16
|
+
def content_type?; !!content_type end
|
17
|
+
|
18
|
+
def location; headers['Location'] end
|
19
|
+
def location= location; headers['Location'] = location end
|
20
|
+
|
21
|
+
def to_a
|
22
|
+
[status, headers, body]
|
23
|
+
end
|
24
|
+
|
25
|
+
def inspect
|
26
|
+
to_a.inspect
|
27
|
+
end
|
28
|
+
|
29
|
+
def == other
|
30
|
+
super(other) || to_a == other
|
31
|
+
end
|
32
|
+
|
33
|
+
def empty?
|
34
|
+
body.empty?
|
35
|
+
end
|
36
|
+
alias_method :blank?, :empty?
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
gem 'mail'
|
2
|
+
|
3
|
+
require 'crystal/template'
|
4
|
+
|
5
|
+
[
|
6
|
+
'mail',
|
7
|
+
].each{|f| require "crystal/remote/#{f}"}
|
8
|
+
|
9
|
+
crystal.register :mail, :depends_on => :environment do
|
10
|
+
Crystal::Mail.new #TODO2 add mail config here
|
11
|
+
end
|
12
|
+
|
13
|
+
Crystal.run :mail, :after => :render
|
@@ -1,16 +1,16 @@
|
|
1
|
-
require '
|
1
|
+
require 'crystal/profiles/web_require'
|
2
2
|
|
3
3
|
#
|
4
4
|
# Routes
|
5
5
|
#
|
6
|
-
Crystal::
|
6
|
+
Crystal::AbstractController.include Crystal::NamedRouter::Helper
|
7
7
|
Crystal::ControllerContext.include Crystal::NamedRouter::Helper
|
8
8
|
|
9
9
|
crystal.after :environment do
|
10
10
|
crystal.register(:router, :depends_on => :environment) do
|
11
11
|
Crystal::Router.new(:class, [
|
12
12
|
[:named_router, Crystal::NamedRouter.new],
|
13
|
-
[:default_router, Crystal::DefaultRouter.new]
|
13
|
+
[:default_router, Crystal::DefaultRouter.new]
|
14
14
|
])
|
15
15
|
end
|
16
16
|
end
|
@@ -19,9 +19,9 @@ end
|
|
19
19
|
#
|
20
20
|
# Conveyors
|
21
21
|
#
|
22
|
-
module Crystal::Processors
|
22
|
+
module Crystal::Processors
|
23
23
|
crystal.after :environment do
|
24
|
-
crystal.conveyors.web do |web|
|
24
|
+
crystal.conveyors.web do |web|
|
25
25
|
# conveyor
|
26
26
|
web.use ConveyorLogger
|
27
27
|
|
@@ -30,12 +30,6 @@ module Crystal::Processors
|
|
30
30
|
web.use PrepareParams
|
31
31
|
web.use EvaluateFormat
|
32
32
|
web.use HTTPLogger
|
33
|
-
|
34
|
-
# forgery protection
|
35
|
-
web.use PrepareAutenticityToken
|
36
|
-
|
37
|
-
# ensure no www
|
38
|
-
web.use EnsureNoWww
|
39
33
|
|
40
34
|
# html
|
41
35
|
web.use ScopedParams
|
@@ -49,15 +43,15 @@ module Crystal::Processors
|
|
49
43
|
# controller
|
50
44
|
web.use ControllerLogger
|
51
45
|
web.use ControllerCaller, :content
|
52
|
-
|
53
|
-
web.build!
|
46
|
+
|
47
|
+
web.build!
|
54
48
|
end
|
55
49
|
end
|
56
50
|
end
|
57
51
|
|
58
52
|
|
59
53
|
#
|
60
|
-
#
|
54
|
+
# Rack
|
61
55
|
#
|
62
56
|
Crystal::RackAdapter.build_common_app do |builder|
|
63
57
|
config = crystal.config
|
@@ -66,7 +60,7 @@ Crystal::RackAdapter.build_common_app do |builder|
|
|
66
60
|
builder.use Rack::Lint if config.development?
|
67
61
|
builder.use Crystal::StaticFiles, "#{config.root!}/public" if config.static? and config.root? and config.development?
|
68
62
|
|
69
|
-
# use Rack::Session::Cookie, :key => 'rack.session', :domain => 'foo.com', :path => '/', :expire_after => 2592000, :secret => 'change_me'
|
63
|
+
# use Rack::Session::Cookie, :key => 'rack.session', :domain => 'foo.com', :path => '/', :expire_after => 2592000, :secret => 'change_me'
|
70
64
|
builder.use Rack::Session::Cookie, config.session.to_hash if config.session?
|
71
65
|
|
72
66
|
# builder.use Rack::CommonLogger
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Crystal
|
2
|
+
module Processors
|
3
|
+
class RemoteCaller < Processor
|
4
|
+
# TODO2 :remote isn't registered with crystal[
|
5
|
+
inject :remote => :remote
|
6
|
+
|
7
|
+
def initialize next_processor, result_variable = 'content'
|
8
|
+
super(next_processor)
|
9
|
+
@result_variable = result_variable
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
return next_processor.call unless workspace.class?
|
14
|
+
|
15
|
+
# prepare
|
16
|
+
klass = workspace.class
|
17
|
+
raise "The remote class #{klass} must be a Crystal::Remote!" unless klass.is? Crystal::Remote
|
18
|
+
workspace.remote_object = klass.new
|
19
|
+
method = workspace.method_name
|
20
|
+
|
21
|
+
# call
|
22
|
+
begin
|
23
|
+
result = workspace.remote_object.run_callbacks :action, :method => method do
|
24
|
+
workspace.remote_object.send method
|
25
|
+
end
|
26
|
+
|
27
|
+
ensure_correct_result! result
|
28
|
+
workspace.remote_result = result
|
29
|
+
|
30
|
+
next_processor.call
|
31
|
+
|
32
|
+
# write JSON as a result if format is JSON and no one else filled it
|
33
|
+
if workspace[@result_variable].blank?
|
34
|
+
workspace[@result_variable] = workspace.remote_result.to_json
|
35
|
+
end
|
36
|
+
rescue StandardError => e
|
37
|
+
raise e if !workspace.params.format.json? or config.test?
|
38
|
+
|
39
|
+
workspace[@result_variable] = {:error => e.message}.to_json
|
40
|
+
|
41
|
+
logger.error e
|
42
|
+
logger.info "\n"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
def ensure_correct_result! result
|
48
|
+
unless result.rson?
|
49
|
+
raise "You can't use object of type '#{result.class}' as Remote's return value!"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Crystal
|
2
|
+
module Processors
|
3
|
+
class RemoteLogger < Processor
|
4
|
+
def call
|
5
|
+
next_processor.call
|
6
|
+
|
7
|
+
if (klass = workspace.class) and (method = workspace.method_name)
|
8
|
+
logger.info "Processing #{klass.name}.#{method} with #{workspace.params.inspect}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'crystal/conveyor'
|
2
|
+
|
3
|
+
%w(
|
4
|
+
configurator
|
5
|
+
router
|
6
|
+
routing_helper
|
7
|
+
default_router
|
8
|
+
named_router
|
9
|
+
default_format_processor
|
10
|
+
processors/router
|
11
|
+
).each{|f| require "crystal/router/#{f}"}
|
12
|
+
|
13
|
+
Crystal::Config::DEFAULTS.merge!({
|
14
|
+
:default_path => '/'
|
15
|
+
}.stringify_keys)
|
16
|
+
|
17
|
+
Crystal.metaclass do
|
18
|
+
delegate :routes, :to => Crystal::Routes::Configurator
|
19
|
+
end
|