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,244 @@
|
|
1
|
+
module Crystal
|
2
|
+
module Template
|
3
|
+
DIRECTORY_NAME = "views"
|
4
|
+
|
5
|
+
class << self
|
6
|
+
inject(
|
7
|
+
:logger => :logger,
|
8
|
+
:config => :config,
|
9
|
+
:environment => :environment
|
10
|
+
)
|
11
|
+
|
12
|
+
def render *args, &block
|
13
|
+
result, context = basic_render(parse_arguments(*args), &block)
|
14
|
+
result
|
15
|
+
end
|
16
|
+
|
17
|
+
# def render_and_return_context *args, &block
|
18
|
+
# basic_render(*parse_arguments(*args), &block)
|
19
|
+
# end
|
20
|
+
|
21
|
+
def render_layout *args
|
22
|
+
options = parse_arguments(*args)
|
23
|
+
options = options.stringify_keys!
|
24
|
+
options.must.include :content
|
25
|
+
options.must.include :context
|
26
|
+
|
27
|
+
result, context = basic_render options do |*args|
|
28
|
+
if args.empty?
|
29
|
+
options.content
|
30
|
+
else
|
31
|
+
args.size.must_be == 1
|
32
|
+
variable_name = args.first.to_s
|
33
|
+
self.context.content_variables[variable_name]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
result
|
38
|
+
end
|
39
|
+
|
40
|
+
def exist? tname, options = {}
|
41
|
+
options = options.to_openobject
|
42
|
+
!!find_template(tname, calculate_prefixes(options), options.format, options.current_dir)
|
43
|
+
end
|
44
|
+
|
45
|
+
def read tname, options = {}
|
46
|
+
options = options.to_openobject
|
47
|
+
file = find_template tname, calculate_prefixes(options), options.format, options.current_dir
|
48
|
+
raise "No template '#{tname}'!" unless file
|
49
|
+
File.read file
|
50
|
+
end
|
51
|
+
|
52
|
+
def template_name_with_prefix tname, prefix
|
53
|
+
index = tname.rindex('/')
|
54
|
+
index = index ? index + 1 : 0
|
55
|
+
tname = tname.clone
|
56
|
+
tname.insert index, prefix
|
57
|
+
end
|
58
|
+
|
59
|
+
def parse_arguments *args
|
60
|
+
options = args.extract_options!.to_openobject
|
61
|
+
if args.size == 1
|
62
|
+
options.template = args.first
|
63
|
+
else
|
64
|
+
raise "Invalid input" if args.size != 0
|
65
|
+
end
|
66
|
+
|
67
|
+
options
|
68
|
+
end
|
69
|
+
|
70
|
+
def basic_render options, &block
|
71
|
+
options = options.clone.to_openobject
|
72
|
+
|
73
|
+
with_context options do |context|
|
74
|
+
context.content_block ||= block
|
75
|
+
|
76
|
+
with_scope options, context do |scope|
|
77
|
+
unless file = options.file
|
78
|
+
file = find_template options.template!, calculate_prefixes(options), scope.format, scope.current_dir
|
79
|
+
# p [tname, calculate_prefixes(options), scope.format, scope.current_dir]
|
80
|
+
raise "No template '#{options.template!}'!" unless file
|
81
|
+
end
|
82
|
+
|
83
|
+
scope.current_dir = dirname(file)
|
84
|
+
|
85
|
+
template = create_tilt_template file
|
86
|
+
|
87
|
+
result = with_template context, template do
|
88
|
+
render_template template, options, &context.content_block
|
89
|
+
end
|
90
|
+
|
91
|
+
return result, context
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
protected
|
97
|
+
def context
|
98
|
+
Thread.current[:render_context]
|
99
|
+
end
|
100
|
+
|
101
|
+
def calculate_prefixes options
|
102
|
+
options.action ? [''] : options.prefixes
|
103
|
+
end
|
104
|
+
|
105
|
+
def with_context options, &block
|
106
|
+
context = Thread.current[:render_context] || options.context || create_context(options)
|
107
|
+
|
108
|
+
old = Thread.current[:render_context]
|
109
|
+
begin
|
110
|
+
Thread.current[:render_context] = context
|
111
|
+
block.call context
|
112
|
+
ensure
|
113
|
+
Thread.current[:render_context] = old
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def with_scope options, context, &block
|
118
|
+
initial = context.scope_variables
|
119
|
+
|
120
|
+
old = context.scope_variables || OpenObject.new
|
121
|
+
begin
|
122
|
+
context.scope_variables = {
|
123
|
+
:current_dir => options.current_dir || old.current_dir,
|
124
|
+
:format => options.format || old.format
|
125
|
+
# :prefixes => options.prefixes || old.prefixes
|
126
|
+
}.to_openobject
|
127
|
+
|
128
|
+
block.call context.scope_variables
|
129
|
+
ensure
|
130
|
+
context.scope_variables = old if initial
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def with_template context, template, &block
|
135
|
+
old = context._tilt_template
|
136
|
+
begin
|
137
|
+
context._tilt_template = template
|
138
|
+
block.call context
|
139
|
+
ensure
|
140
|
+
context._tilt_template = old
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def create_context options
|
145
|
+
context_class = options.context_class || TemplateContext
|
146
|
+
raise "#{context_class} must inherit from TemplateContext!" unless context_class.is? TemplateContext
|
147
|
+
context = context_class.new
|
148
|
+
|
149
|
+
context.options = options
|
150
|
+
|
151
|
+
if ivs = options.instance_variables
|
152
|
+
(ivs.is_a?(Array) ? ivs : [ivs]).each do |container|
|
153
|
+
if container.is_a? Hash
|
154
|
+
container.each do |name, value|
|
155
|
+
context.instance_variable_set("@#{name}", value)
|
156
|
+
end
|
157
|
+
else
|
158
|
+
container.instance_variables.each do |ivname|
|
159
|
+
iv = container.instance_variable_get(ivname)
|
160
|
+
context.instance_variable_set(ivname, iv)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
context
|
167
|
+
end
|
168
|
+
|
169
|
+
def dirname_without_cache path;
|
170
|
+
File.dirname path
|
171
|
+
end
|
172
|
+
cache_method_with_params_in_production :dirname
|
173
|
+
|
174
|
+
def find_template tname, prefixes, format, current_dir
|
175
|
+
# splitted into two to optimize cache
|
176
|
+
if tname =~ /^\//
|
177
|
+
find_absolute_template tname, prefixes, format
|
178
|
+
else
|
179
|
+
find_relative_template tname, prefixes, format, current_dir
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
def find_absolute_template_without_cache tname, prefixes, format
|
184
|
+
prefixes = prefixes || config.default_template_prefixes!
|
185
|
+
prefixes.each do |prefix|
|
186
|
+
tname_with_prefix = template_name_with_prefix("/#{DIRECTORY_NAME}#{tname}", prefix)
|
187
|
+
file = find_file(tname_with_prefix, format, environment.directories)
|
188
|
+
return file if file
|
189
|
+
end
|
190
|
+
return nil
|
191
|
+
end
|
192
|
+
cache_method_with_params_in_production :find_absolute_template
|
193
|
+
|
194
|
+
def find_relative_template_without_cache tname, prefixes, format, current_dir
|
195
|
+
raise "You can't use relative template path '#{tname}' without :current_dir!" unless current_dir
|
196
|
+
prefixes = prefixes || config.default_template_prefixes!
|
197
|
+
prefixes.each do |prefix|
|
198
|
+
tname_with_prefix = template_name_with_prefix("/#{tname}", prefix)
|
199
|
+
file = find_file(tname_with_prefix, format, current_dir)
|
200
|
+
return file if file
|
201
|
+
end
|
202
|
+
return nil
|
203
|
+
end
|
204
|
+
cache_method_with_params_in_production :find_relative_template
|
205
|
+
|
206
|
+
def find_file tname, format, directories
|
207
|
+
if tname.include? '.'
|
208
|
+
_find_file(tname, directories) || _find_file("#{tname}.*", directories)
|
209
|
+
else
|
210
|
+
if format
|
211
|
+
_find_file("#{tname}.#{format}.*", directories) or
|
212
|
+
_find_file("#{tname}.*", directories, true)
|
213
|
+
else
|
214
|
+
_find_file("#{tname}.*", directories)
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
# with_one_extension - 'tname.*' matches not only 'tname.erb' but also 'tname.html.erb',
|
220
|
+
# with this option enabled it will not match 'tname.html.erb', only 'tname.erb'
|
221
|
+
def _find_file pattern, directories, with_one_extension = false
|
222
|
+
files = environment.find_files_by_pattern_without_cache pattern, directories
|
223
|
+
files = files.select{|f| f !~ /\.[^\.\/]+\.[^\.\/]+$/} if with_one_extension
|
224
|
+
logger.warn "Multiple templates for '#{pattern}'!" if files.size > 1
|
225
|
+
files.first
|
226
|
+
end
|
227
|
+
|
228
|
+
def create_tilt_template path
|
229
|
+
template_options = {
|
230
|
+
:ugly => true,
|
231
|
+
:outvar => "@output"
|
232
|
+
}
|
233
|
+
template = Tilt.new(path, nil, template_options)
|
234
|
+
end
|
235
|
+
|
236
|
+
def render_template template, options, &block
|
237
|
+
locals = options.locals || {}
|
238
|
+
locals[:object] = options.object if options.object?
|
239
|
+
|
240
|
+
template.render context, locals, &block
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Crystal
|
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 => ::Crystal::Template
|
25
|
+
delegate :url_for, :to => :router
|
26
|
+
|
27
|
+
|
28
|
+
#
|
29
|
+
# Content Variables
|
30
|
+
#
|
31
|
+
attr_accessor :content_block
|
32
|
+
def content_variables; @content_variables ||= {} end
|
33
|
+
def content_for name, content = nil, &block
|
34
|
+
content ||= capture(&block)
|
35
|
+
(content_variables[name.to_s] ||= "") << content
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
def prepend_to name, content = nil, &block
|
39
|
+
content ||= capture(&block)
|
40
|
+
(content_variables[name.to_s] ||= "").insert 0, content
|
41
|
+
nil
|
42
|
+
end
|
43
|
+
def wrap_content_for name, &block
|
44
|
+
block.must_be.defined
|
45
|
+
content = capture((content_variables[name.to_s] || ""), &block)
|
46
|
+
content_variables[name.to_s] ||= content
|
47
|
+
nil
|
48
|
+
end
|
49
|
+
def has_content_for? name
|
50
|
+
content_variables.include? name.to_s
|
51
|
+
end
|
52
|
+
|
53
|
+
def params
|
54
|
+
workspace.params
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
console.log("<%= error.message.js_escape %>");
|
data/readme.md
CHANGED
@@ -1,14 +1,11 @@
|
|
1
|
-
#
|
1
|
+
# Crystal - Ruby Web Framework inspired by Rails and Spring.
|
2
2
|
|
3
|
-
|
4
|
-
- common_interface - concrete interface built with abstract_interface tools.
|
5
|
-
- asset_packager - packages CSS and JS asset for your application.
|
6
|
-
- crystal_ext - additions and extensions of the Crystal.
|
7
|
-
- crystal_jquery - jQuery plugin for the Crystal.
|
8
|
-
- mongo_mapper_ext - additions and extensions of the MongoMapper.
|
9
|
-
- rad - Rapid Application Development tool built upon of the Crystal.
|
3
|
+
It kinda does the same thing as Rails but in different way. The idea is to provide you with an application framework as opened and extensible as the Ruby itself.
|
10
4
|
|
11
|
-
|
5
|
+
It's the constructor, built from set of low coupled components. You can start quickly using one of predefined 'opinionated' profiles, or tune and extend it as you wish.
|
6
|
+
The same apply for the architecture of your application - instead of to be a monolith it consists of cooperating plugins/gems.
|
12
7
|
|
13
|
-
|
14
|
-
|
8
|
+
Web tier looks almost like Rails and overall architecture is slightly borrowed from Java Spring framework.
|
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.
|
10
|
+
|
11
|
+
*It's under heavy development, and not ready to use.*
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# require "#{File.expand_path(File.dirname(__FILE__))}/helper"
|
2
|
+
#
|
3
|
+
# describe "Render" do
|
4
|
+
# inject :conveyors => :conveyors
|
5
|
+
#
|
6
|
+
# before :all do
|
7
|
+
# class ::AnItem
|
8
|
+
# inherit Crystal::Render
|
9
|
+
#
|
10
|
+
# def show
|
11
|
+
# {'result' => 'value'}
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# def partial
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# def format; end
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# class ::ALayout
|
21
|
+
# inherit Crystal::Render
|
22
|
+
# layout '/ALayout/layout'
|
23
|
+
#
|
24
|
+
# def show
|
25
|
+
# end
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# @dir = "#{File.expand_path(File.dirname(__FILE__))}/integration_spec"
|
29
|
+
#
|
30
|
+
# $LOAD_PATH << @dir
|
31
|
+
#
|
32
|
+
# Crystal.run nil, {:before => :environment}, :render_spec do
|
33
|
+
# crystal.config.environment = :test
|
34
|
+
# crystal.config.test_error_template = crystal.config.development_error_template
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# crystal[:config].environment = :test
|
38
|
+
# crystal[:environment] = Crystal::Environment.new
|
39
|
+
# crystal[:environment].load :render_spec
|
40
|
+
#
|
41
|
+
# conveyors.web << Crystal::Processors::RenderObject.new(:remote_object, :method_name, :remote_result)
|
42
|
+
# end
|
43
|
+
#
|
44
|
+
# after :all do
|
45
|
+
# $LOAD_PATH.delete @dir
|
46
|
+
# crystal.clear
|
47
|
+
# [:AnItem, :ALayout].each{|c| Object.send :remove_const, c if Object.const_defined? c}
|
48
|
+
# end
|
49
|
+
#
|
50
|
+
#
|
51
|
+
# it "should correctly display error messages (with correct format)" do
|
52
|
+
# error = StandardError.new('some error')
|
53
|
+
#
|
54
|
+
# workspace = wcall :error => error, :params => {:format => :html}
|
55
|
+
# workspace.response.body.should =~ /html.+some error/m
|
56
|
+
# workspace.response.content_type.should == Mime.html
|
57
|
+
#
|
58
|
+
# workspace = wcall :error => error, :params => {:format => :js}
|
59
|
+
# workspace.response.body.should =~ /some error/
|
60
|
+
# workspace.response.content_type.should == Mime.js
|
61
|
+
#
|
62
|
+
# workspace = wcall :error => error, :params => {:format => :non_existing_mime}
|
63
|
+
# workspace.response.body.should =~ /some error/
|
64
|
+
# workspace.response.content_type.should == Mime.text
|
65
|
+
# end
|
66
|
+
#
|
67
|
+
# it "layout" do
|
68
|
+
# workspace = wcall :remote_object => ALayout.new, :method_name => :show, :params => {:format => :html}
|
69
|
+
# workspace.response.body.should == "Layout html, content"
|
70
|
+
# workspace.response.content_type.should == Mime.html
|
71
|
+
#
|
72
|
+
# workspace = wcall :remote_object => ALayout.new, :method_name => :show, :params => {:format => :js}
|
73
|
+
# workspace.response.body.should == "Layout js, content"
|
74
|
+
# workspace.response.content_type.should == Mime.js
|
75
|
+
# end
|
76
|
+
#
|
77
|
+
# it "context, controller_name, method_name, object" do
|
78
|
+
# controller = AnItem.new
|
79
|
+
# workspace = wcall(
|
80
|
+
# :remote_object => controller,
|
81
|
+
# :method_name => :show,
|
82
|
+
# :remote_result => controller.show,
|
83
|
+
# :params => {:class_name => 'AnItem', :method_name => 'show'}
|
84
|
+
# )
|
85
|
+
#
|
86
|
+
# workspace.response.body.should == %{\
|
87
|
+
# Controller: AnItem
|
88
|
+
# Class Name: AnItem
|
89
|
+
# Mehtod Name: show
|
90
|
+
# Result object: value}
|
91
|
+
# workspace.response.content_type.should == Mime.html
|
92
|
+
# end
|
93
|
+
#
|
94
|
+
# it "format" do
|
95
|
+
# workspace = wcall :remote_object => AnItem.new, :method_name => :format, :params => {:format => :html}
|
96
|
+
# workspace.response.body.should == "html format"
|
97
|
+
# workspace.response.content_type.should == Mime.html
|
98
|
+
#
|
99
|
+
# workspace = wcall :remote_object => AnItem.new, :method_name => :format, :params => {:format => :js}
|
100
|
+
# workspace.response.body.should == "js format"
|
101
|
+
# workspace.response.content_type.should == Mime.js
|
102
|
+
# end
|
103
|
+
#
|
104
|
+
# it "should not allow to render partials as actions" do
|
105
|
+
# workspace = wcall :remote_object => AnItem.new, :method_name => :partial
|
106
|
+
# workspace.error.message.should =~ /No template/
|
107
|
+
# end
|
108
|
+
#
|
109
|
+
# it "should be able override layout inside of template"
|
110
|
+
# end
|