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,59 @@
|
|
1
|
+
require "#{File.expand_path(File.dirname(__FILE__))}/helper"
|
2
|
+
require "crystal/support/callbacks"
|
3
|
+
require "crystal/support/filters"
|
4
|
+
|
5
|
+
describe "Filters" do
|
6
|
+
module ARemote
|
7
|
+
inherit Crystal::Filters
|
8
|
+
end
|
9
|
+
|
10
|
+
class FiltersBasic
|
11
|
+
inherit ARemote
|
12
|
+
|
13
|
+
before :set_user
|
14
|
+
|
15
|
+
def action
|
16
|
+
'result'
|
17
|
+
end
|
18
|
+
|
19
|
+
attr_reader :user
|
20
|
+
def set_user
|
21
|
+
@user = 'some user'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class FilterInheritance < FiltersBasic
|
26
|
+
before :set_model
|
27
|
+
|
28
|
+
attr_reader :model
|
29
|
+
def set_model
|
30
|
+
@model = 'some model'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class FilterOverrideAction < FiltersBasic
|
35
|
+
def action
|
36
|
+
'overriden result'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'basic' do
|
41
|
+
r = FiltersBasic.new
|
42
|
+
r.run_callbacks(:action){r.send :action}.should == 'result'
|
43
|
+
r.user.should == 'some user'
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'inheritance' do
|
47
|
+
r = FilterInheritance.new
|
48
|
+
r.run_callbacks(:action){r.send :action}.should == 'result'
|
49
|
+
r.user.should == 'some user'
|
50
|
+
r.model.should == 'some model'
|
51
|
+
end
|
52
|
+
|
53
|
+
it "overriding action" do
|
54
|
+
r = FilterOverrideAction.new
|
55
|
+
r.run_callbacks(:action){r.send :action}.should == 'overriden result'
|
56
|
+
r.user.should == 'some user'
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require "#{File.expand_path(File.dirname(__FILE__))}/helper"
|
2
|
+
require "crystal/support/safe_hash"
|
3
|
+
|
4
|
+
describe "SafeHash and SafeNil" do
|
5
|
+
it "should allow check for value presence" do
|
6
|
+
h = SafeHash.new :a => :b
|
7
|
+
h.a?.should be_true
|
8
|
+
h.b?.should be_false
|
9
|
+
|
10
|
+
h.should include(:a)
|
11
|
+
h.should_not include(:b)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "? should return boolean (from error)" do
|
15
|
+
h = SafeHash.new
|
16
|
+
lambda{raise "" unless h.a?.class.equal?(NilClass)}.should raise_error
|
17
|
+
lambda{raise "" unless h.a.a?.class.equal?(NilClass)}.should raise_error
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should treat assigned nil as value (from error)" do
|
21
|
+
h = SafeHash.new
|
22
|
+
h.v = nil
|
23
|
+
h.v?.should be_true
|
24
|
+
h.v!.should == nil
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should allow owerride values" do
|
28
|
+
h = SafeHash.new :a => :b
|
29
|
+
h.b = :c
|
30
|
+
h.b!.should == :c
|
31
|
+
end
|
32
|
+
|
33
|
+
it "general behaviour" do
|
34
|
+
h = SafeHash.new :key => :value
|
35
|
+
|
36
|
+
h.key.should == :value
|
37
|
+
h.key(:missing).should == :value
|
38
|
+
|
39
|
+
h[:key].should == :value
|
40
|
+
h[:key, :missing].should == :value
|
41
|
+
|
42
|
+
h['key'].should == :value
|
43
|
+
h['key', :missing].should == :value
|
44
|
+
|
45
|
+
h.a.b.c[:d].e('missing').should == 'missing'
|
46
|
+
h.a.b.c[:d][:e, 'missing'].should == 'missing'
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should build hierarchies of SafeHash" do
|
50
|
+
h = SafeHash.new :a => {:a => :b}
|
51
|
+
|
52
|
+
h.a.a.should == :b
|
53
|
+
h.a.missing.b.c('missing').should == 'missing'
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should require setting if ! used" do
|
57
|
+
h = SafeHash.new :a => :v, :b => {:c => :v}
|
58
|
+
|
59
|
+
h.a!.should == :v
|
60
|
+
h.b.c!.should == :v
|
61
|
+
h.b!.c!.should == :v
|
62
|
+
|
63
|
+
lambda{h.j!}.should raise_error(/No key j/)
|
64
|
+
lambda{h.j.b.c!}.should raise_error(/No key c/)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should be able to update itself" do
|
68
|
+
h = SafeHash.new
|
69
|
+
h.b?.should be_false
|
70
|
+
h.a = :a
|
71
|
+
h.a!.should == :a
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should implement include?" do
|
75
|
+
h = SafeHash.new :a => :b
|
76
|
+
h.include?(:a).should be_true
|
77
|
+
h.include?('a').should be_true
|
78
|
+
h.include?(:b).should be_false
|
79
|
+
|
80
|
+
h.b.include?(:a).should be_false
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,189 @@
|
|
1
|
+
require "#{File.expand_path(File.dirname(__FILE__))}/helper"
|
2
|
+
|
3
|
+
describe "Template" do
|
4
|
+
Template = Crystal::Template
|
5
|
+
|
6
|
+
delegate :render, :to => Template
|
7
|
+
|
8
|
+
with_environment :development
|
9
|
+
|
10
|
+
before :all do
|
11
|
+
@dir = "#{File.expand_path(File.dirname(__FILE__))}/template_spec"
|
12
|
+
$LOAD_PATH << @dir
|
13
|
+
|
14
|
+
::RenderResult = OpenObject.new
|
15
|
+
|
16
|
+
class ::SomeObject
|
17
|
+
attr_accessor :ivariable
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
after :all do
|
22
|
+
$LOAD_PATH.delete @dir
|
23
|
+
remove_constants %w(SomeObject RenderResult)
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'special' do
|
27
|
+
it "read" do
|
28
|
+
Template.read('/other/template').should == %{<% "ruby code" %> content}
|
29
|
+
end
|
30
|
+
|
31
|
+
it "exist?" do
|
32
|
+
Template.should exist('/other/template')
|
33
|
+
Template.should_not exist('/other/non-existing-template')
|
34
|
+
end
|
35
|
+
|
36
|
+
it "template prefixes" do
|
37
|
+
Template.exist?('/prefixes/underscored', :prefixes => ['']).should be_false
|
38
|
+
render('/prefixes/underscored', :prefixes => ['_', '']).should == "underscored"
|
39
|
+
render('/prefixes/underscored.erb', :prefixes => ['_', '']).should == "underscored"
|
40
|
+
|
41
|
+
Template.exist?('/prefixes/without_prefix', :prefixes => ['_']).should be_false
|
42
|
+
render('/prefixes/without_prefix', :prefixes => ['']).should == "whthout prefix"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should not use prefixes for :action" do
|
46
|
+
Template.exist?('/prefixes/underscored').should be_true
|
47
|
+
Template.exist?('/prefixes/underscored', :action => true).should be_false
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'basic' do
|
52
|
+
it "general" do
|
53
|
+
some_object = SomeObject.new
|
54
|
+
some_object.ivariable = "instance variable value"
|
55
|
+
options = {
|
56
|
+
:instance_variables => [some_object, {:ivariable2 => "instance variable value 2"}],
|
57
|
+
:object => OpenObject.new.update(:value => 'object value'),
|
58
|
+
:locals => {:lvariable => 'local value'},
|
59
|
+
:format => :html
|
60
|
+
}
|
61
|
+
|
62
|
+
result = render("/basic/general", options){|content_name| "content for :#{content_name}"}
|
63
|
+
|
64
|
+
check = %{\
|
65
|
+
Instance variable: instance variable value
|
66
|
+
Instance variable 2: instance variable value 2
|
67
|
+
Object value: object value
|
68
|
+
Locals value: local value
|
69
|
+
Yield: content for :content}
|
70
|
+
|
71
|
+
result.should == check
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should not render wrong format" do
|
75
|
+
Template.exist?('/basic/non_existing_format', :format => :html).should be_true
|
76
|
+
Template.exist?('/basic/non_existing_format', :format => :invalid).should be_false
|
77
|
+
|
78
|
+
# from error
|
79
|
+
Template.exist?('non_existing_format', :format => :invalid, :current_dir => "#{@dir}/views/basic").should be_false
|
80
|
+
end
|
81
|
+
|
82
|
+
it "extension" do
|
83
|
+
render('/basic/extension').should == "some content"
|
84
|
+
render('/basic/extension.erb').should == "some content"
|
85
|
+
end
|
86
|
+
|
87
|
+
it "must support custom context" do
|
88
|
+
class CustomTemplateContext < Crystal::TemplateContext
|
89
|
+
def custom_helper
|
90
|
+
'custom helper'
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
render('/basic/custom_context', :context_class => CustomTemplateContext).should == "content from custom helper"
|
95
|
+
end
|
96
|
+
|
97
|
+
it "no template" do
|
98
|
+
lambda{render('/non-existing-template')}.should raise_error(/No template/)
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should render arbitrary file" do
|
102
|
+
render(:file => "#{@dir}/file.erb").should == "file template"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe 'format' do
|
107
|
+
it "basic" do
|
108
|
+
render('/format/format', :format => :html).should == "html format"
|
109
|
+
render('/format/format', :format => :js).should == "js format"
|
110
|
+
render('/format/format', :format => :non_existing).should == "universal format"
|
111
|
+
render('/format/format.html', :format => :js).should == "html format"
|
112
|
+
render('/format/format.html.erb', :format => :js).should == "html format"
|
113
|
+
end
|
114
|
+
|
115
|
+
it "nesting different formats" do
|
116
|
+
render('/nesting_format/dialog', :format => :js).should == "$.showDialog(dialog, dialog form)"
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe 'nested' do
|
121
|
+
it "should render relative templates" do
|
122
|
+
render('/nested/relative/a').should == "template a, template b"
|
123
|
+
lambda{render('b')}.should raise_error(/You can't use relative template path/)
|
124
|
+
current_dir = "#{@dir}/views/nested/relative"
|
125
|
+
render('b', :current_dir => current_dir).should == "template b"
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should render relative templates with complex path (../../xxx)" do
|
129
|
+
render('/nested/relative/c').should == "template c, shared template"
|
130
|
+
end
|
131
|
+
|
132
|
+
it "nested templates should use the same format" do
|
133
|
+
render('/nested/format/a', :format => :js).should == "js format, js format"
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe "layout" do
|
138
|
+
def render_with_layout template, options, layout
|
139
|
+
content, context = Template.basic_render(Template.parse_arguments(template, options))
|
140
|
+
Template.render_layout(layout, :content => content, :context => context)
|
141
|
+
end
|
142
|
+
|
143
|
+
it "templates and layout must share the same context" do
|
144
|
+
render_with_layout(
|
145
|
+
'/layout/same_context/a', {:instance_variables => {:ivariable => "ivariable"}},
|
146
|
+
'/layout/same_context/layout'
|
147
|
+
).should == "layout ivariable content a ivariable content b ivariable"
|
148
|
+
end
|
149
|
+
|
150
|
+
it "content_for" do
|
151
|
+
render_with_layout(
|
152
|
+
'/layout/content_for/content', {},
|
153
|
+
'/layout/content_for/layout'
|
154
|
+
).should == %{\
|
155
|
+
head
|
156
|
+
|
157
|
+
content
|
158
|
+
|
159
|
+
bottom}
|
160
|
+
end
|
161
|
+
|
162
|
+
it "basic" do
|
163
|
+
render_with_layout(
|
164
|
+
'/layout/basic/content', {},
|
165
|
+
'/layout/basic/layout'
|
166
|
+
).should == "layotu begin content end"
|
167
|
+
end
|
168
|
+
|
169
|
+
it "layout with format" do
|
170
|
+
render_with_layout(
|
171
|
+
'/layout/format/content', {:format => :html},
|
172
|
+
'/layout/format/layout'
|
173
|
+
).should == "html layout begin html content end"
|
174
|
+
|
175
|
+
render_with_layout(
|
176
|
+
'/layout/format/content', {:format => :js},
|
177
|
+
'/layout/format/layout'
|
178
|
+
).should == "js layout begin js content end"
|
179
|
+
end
|
180
|
+
|
181
|
+
it "layout should support yield in partials (from error)" do
|
182
|
+
render_with_layout(
|
183
|
+
'/layout/nested_yield/a', {},
|
184
|
+
'/layout/nested_yield/layout'
|
185
|
+
).should == "some content"
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
file template
|
@@ -0,0 +1 @@
|
|
1
|
+
content from <%= custom_helper %>
|
@@ -0,0 +1 @@
|
|
1
|
+
some content
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
universal format
|
@@ -0,0 +1 @@
|
|
1
|
+
html format
|
@@ -0,0 +1 @@
|
|
1
|
+
js format
|
@@ -0,0 +1 @@
|
|
1
|
+
content
|
@@ -0,0 +1 @@
|
|
1
|
+
layotu begin <%= yield %> end
|
@@ -0,0 +1 @@
|
|
1
|
+
html content
|
@@ -0,0 +1 @@
|
|
1
|
+
js content
|
@@ -0,0 +1 @@
|
|
1
|
+
html layout begin <%= yield %> end
|
@@ -0,0 +1 @@
|
|
1
|
+
js layout begin <%= yield %> end
|
@@ -0,0 +1 @@
|
|
1
|
+
some content
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= render 'layout_b' %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= yield %>
|
@@ -0,0 +1 @@
|
|
1
|
+
content a <%= @ivariable %> <%= render('b') %>
|
@@ -0,0 +1 @@
|
|
1
|
+
content b <%= @ivariable %>
|
@@ -0,0 +1 @@
|
|
1
|
+
layout <%= @ivariable %> <%= yield %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= options.format %> format, <%= render 'b' %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= options.format %> format
|
@@ -0,0 +1 @@
|
|
1
|
+
template a, <%= render 'b' %>
|
@@ -0,0 +1 @@
|
|
1
|
+
template b
|
@@ -0,0 +1 @@
|
|
1
|
+
template c, <%= render '../shared/c' %>
|
@@ -0,0 +1 @@
|
|
1
|
+
shared template
|
@@ -0,0 +1 @@
|
|
1
|
+
dialog, <%= render 'form' %>
|
@@ -0,0 +1 @@
|
|
1
|
+
dialog form
|