hobo 0.8.3 → 0.8.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.txt +330 -0
- data/Manifest +12 -4
- data/Rakefile +4 -6
- data/dryml_generators/rapid/cards.dryml.erb +5 -1
- data/dryml_generators/rapid/forms.dryml.erb +8 -10
- data/dryml_generators/rapid/pages.dryml.erb +65 -36
- data/hobo.gemspec +28 -15
- data/lib/active_record/association_collection.rb +3 -22
- data/lib/hobo.rb +25 -258
- data/lib/hobo/accessible_associations.rb +131 -0
- data/lib/hobo/authentication_support.rb +15 -9
- data/lib/hobo/composite_model.rb +1 -1
- data/lib/hobo/controller.rb +7 -8
- data/lib/hobo/dryml.rb +9 -10
- data/lib/hobo/dryml/dryml_builder.rb +7 -1
- data/lib/hobo/dryml/dryml_doc.rb +161 -0
- data/lib/hobo/dryml/dryml_generator.rb +18 -9
- data/lib/hobo/dryml/part_context.rb +76 -42
- data/lib/hobo/dryml/tag_parameters.rb +1 -0
- data/lib/hobo/dryml/taglib.rb +2 -1
- data/lib/hobo/dryml/template.rb +39 -29
- data/lib/hobo/dryml/template_environment.rb +79 -37
- data/lib/hobo/dryml/template_handler.rb +66 -21
- data/lib/hobo/guest.rb +2 -10
- data/lib/hobo/hobo_helper.rb +125 -53
- data/lib/hobo/include_in_save.rb +0 -1
- data/lib/hobo/lifecycles.rb +54 -24
- data/lib/hobo/lifecycles/actions.rb +95 -31
- data/lib/hobo/lifecycles/creator.rb +18 -23
- data/lib/hobo/lifecycles/lifecycle.rb +86 -62
- data/lib/hobo/lifecycles/state.rb +1 -2
- data/lib/hobo/lifecycles/transition.rb +22 -28
- data/lib/hobo/model.rb +64 -176
- data/lib/hobo/model_controller.rb +67 -54
- data/lib/hobo/model_router.rb +5 -2
- data/lib/hobo/permissions.rb +397 -0
- data/lib/hobo/permissions/associations.rb +167 -0
- data/lib/hobo/scopes.rb +15 -38
- data/lib/hobo/scopes/association_proxy_extensions.rb +15 -5
- data/lib/hobo/scopes/automatic_scopes.rb +43 -18
- data/lib/hobo/scopes/named_scope_extensions.rb +2 -2
- data/lib/hobo/user.rb +10 -4
- data/lib/hobo/user_controller.rb +6 -5
- data/lib/hobo/view_hints.rb +58 -0
- data/rails_generators/hobo/hobo_generator.rb +7 -3
- data/rails_generators/hobo/templates/guest.rb +1 -13
- data/rails_generators/hobo_front_controller/hobo_front_controller_generator.rb +1 -1
- data/rails_generators/hobo_model/hobo_model_generator.rb +4 -2
- data/rails_generators/hobo_model/templates/hints.rb +4 -0
- data/rails_generators/hobo_model/templates/model.rb +8 -8
- data/rails_generators/hobo_model_controller/hobo_model_controller_generator.rb +10 -0
- data/rails_generators/hobo_model_controller/templates/controller.rb +1 -1
- data/rails_generators/hobo_rapid/templates/hobo-rapid.js +91 -56
- data/rails_generators/hobo_rapid/templates/lowpro.js +15 -15
- data/rails_generators/hobo_rapid/templates/reset.css +36 -3
- data/rails_generators/hobo_rapid/templates/themes/clean/public/stylesheets/clean.css +13 -17
- data/rails_generators/hobo_user_controller/templates/controller.rb +1 -1
- data/rails_generators/hobo_user_model/templates/model.rb +18 -16
- data/taglibs/core.dryml +60 -18
- data/taglibs/rapid.dryml +8 -401
- data/taglibs/rapid_core.dryml +586 -0
- data/taglibs/rapid_document_tags.dryml +28 -10
- data/taglibs/rapid_editing.dryml +92 -55
- data/taglibs/rapid_forms.dryml +406 -87
- data/taglibs/rapid_generics.dryml +1 -1
- data/taglibs/rapid_navigation.dryml +2 -1
- data/taglibs/rapid_pages.dryml +7 -16
- data/taglibs/rapid_plus.dryml +39 -14
- data/taglibs/rapid_support.dryml +1 -1
- data/taglibs/rapid_user_pages.dryml +14 -4
- data/tasks/{generate_tag_reference.rb → generate_tag_reference.rake} +49 -18
- data/tasks/hobo_tasks.rake +16 -0
- data/test/permissions/models/models.rb +134 -0
- data/test/permissions/models/schema.rb +55 -0
- data/test/permissions/models/test.sqlite3 +0 -0
- data/test/permissions/test_permissions.rb +436 -0
- metadata +27 -14
- data/lib/hobo/mass_assignment.rb +0 -64
- data/rails_generators/hobo/templates/patch_routing.rb +0 -30
- data/uninstall.rb +0 -1
data/lib/hobo/dryml/taglib.rb
CHANGED
@@ -46,7 +46,8 @@ module Hobo
|
|
46
46
|
"#{RAILS_ROOT}/#{options[:template_dir].gsub(/^\//, '')}" # remove leading / if there is one
|
47
47
|
end
|
48
48
|
|
49
|
-
|
49
|
+
src = options[:src] || plugin
|
50
|
+
filename = "#{base}/#{src}.dryml"
|
50
51
|
raise DrymlException, "No such taglib: #{base} #{options.inspect} #{filename}" unless File.exists?(filename)
|
51
52
|
filename
|
52
53
|
end
|
data/lib/hobo/dryml/template.rb
CHANGED
@@ -102,7 +102,7 @@ module Hobo::Dryml
|
|
102
102
|
|
103
103
|
|
104
104
|
def children_to_erb(nodes)
|
105
|
-
nodes.map{|x| node_to_erb(x)}.join
|
105
|
+
nodes.map { |x| node_to_erb(x) }.join
|
106
106
|
end
|
107
107
|
|
108
108
|
|
@@ -443,7 +443,7 @@ module Hobo::Dryml
|
|
443
443
|
@builder.add_part(part_name, restore_erb_scriptlets(part_src), element_line_num(el))
|
444
444
|
|
445
445
|
newlines = "\n" * part_src.count("\n")
|
446
|
-
args = [attribute_to_ruby(dom_id), ":#{part_name}",
|
446
|
+
args = [attribute_to_ruby(dom_id), ":#{part_name}", part_locals].compact
|
447
447
|
"<%= call_part(#{args * ', '}) #{newlines} %>"
|
448
448
|
end
|
449
449
|
|
@@ -523,7 +523,8 @@ module Hobo::Dryml
|
|
523
523
|
elsif t =~ /^[A-Z]/
|
524
524
|
t
|
525
525
|
elsif t =~ /^[a-z]/ && defined? HoboFields.to_class
|
526
|
-
|
526
|
+
klass = HoboFields.to_class(t)
|
527
|
+
klass.name
|
527
528
|
elsif is_code_attribute?(t)
|
528
529
|
t[1..-1]
|
529
530
|
else
|
@@ -610,9 +611,9 @@ module Hobo::Dryml
|
|
610
611
|
when nil
|
611
612
|
call_type = is_parameter_tag ? :named_params : :default_param_only
|
612
613
|
when :named_params
|
613
|
-
dryml_exception("mixed parameter tags and non-parameter tags", el) unless is_parameter_tag
|
614
|
+
dryml_exception("mixed parameter tags and non-parameter tags (did you forget a ':'?)", el) unless is_parameter_tag
|
614
615
|
when :default_param_only
|
615
|
-
dryml_exception("mixed parameter tags and non-parameter tags", el) if is_parameter_tag
|
616
|
+
dryml_exception("mixed parameter tags and non-parameter tags (did you forget a ':'?)", el) if is_parameter_tag
|
616
617
|
end
|
617
618
|
|
618
619
|
if is_parameter_tag
|
@@ -639,7 +640,7 @@ module Hobo::Dryml
|
|
639
640
|
merge_param_names = merge_params.split(/\s*,\s*/).*.gsub("-", "_")
|
640
641
|
"all_parameters & #{merge_param_names.inspect}"
|
641
642
|
end
|
642
|
-
"{#{param_items}}
|
643
|
+
"merge_parameter_hashes({#{param_items}}, (#{extra_params}) || {})"
|
643
644
|
else
|
644
645
|
"{#{param_items}}"
|
645
646
|
end
|
@@ -763,8 +764,8 @@ module Hobo::Dryml
|
|
763
764
|
def maybe_make_part_call(el, call)
|
764
765
|
part_name = el.attributes['part']
|
765
766
|
if part_name
|
766
|
-
part_id =
|
767
|
-
"<div class='part-wrapper' id='#{part_id}'
|
767
|
+
part_id = el.attributes['id'] || part_name
|
768
|
+
"<div class='part-wrapper' id='<%= #{attribute_to_ruby part_id} %>'>#{part_element(el, call)}</div>"
|
768
769
|
else
|
769
770
|
call
|
770
771
|
end
|
@@ -781,30 +782,40 @@ module Hobo::Dryml
|
|
781
782
|
items = attributes.map do |n,v|
|
782
783
|
dryml_exception("invalid attribute name '#{n}'", el) unless n =~ DRYML_NAME_RX
|
783
784
|
|
784
|
-
|
785
|
-
|
786
|
-
|
785
|
+
next if n.in?(SPECIAL_ATTRIBUTES) || n =~ /^without-/
|
786
|
+
next if el.attributes['part'] && n == 'id' # The id is rendered on the <div class="part-wrapper"> instead
|
787
|
+
|
788
|
+
":#{ruby_name n} => #{attribute_to_ruby(v)}"
|
787
789
|
end.compact
|
788
790
|
|
789
791
|
# if there's a ':' el.name is just the part after the ':'
|
790
792
|
items << ":field => \"#{ruby_name el.name}\"" if field_shorthand_element?(el)
|
791
793
|
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
794
|
+
hash = "{#{items.join(", ")}}"
|
795
|
+
|
796
|
+
if merge_attribute(el)
|
797
|
+
"merge_attrs(#{hash}, attributes)"
|
798
|
+
elsif el.attributes['merge-attrs']
|
799
|
+
merge_attrs = compile_merge_attrs(el)
|
800
|
+
"merge_attrs(#{hash}, #{merge_attrs} || {})"
|
801
|
+
else
|
802
|
+
hash
|
803
|
+
end
|
804
|
+
end
|
805
|
+
|
806
|
+
|
807
|
+
def compile_merge_attrs(el)
|
808
|
+
merge_attrs = el.attributes['merge-attrs']
|
809
|
+
if merge_attrs == "&true"
|
810
|
+
"attributes"
|
811
|
+
elsif is_code_attribute?(merge_attrs)
|
812
|
+
"(#{merge_attrs[1..-1]})"
|
804
813
|
else
|
805
|
-
"
|
814
|
+
merge_attr_names = merge_attrs.split(/\s*,\s*/).*.gsub("-", "_").*.to_sym
|
815
|
+
"(all_attributes & #{merge_attr_names.inspect})"
|
806
816
|
end
|
807
817
|
end
|
818
|
+
|
808
819
|
|
809
820
|
def static_tag_to_method_call(el)
|
810
821
|
part = el.attributes["part"]
|
@@ -821,11 +832,9 @@ module Hobo::Dryml
|
|
821
832
|
|
822
833
|
# Convert the attributes hash to a call to merge_attrs if
|
823
834
|
# there's a merge-attrs attribute
|
824
|
-
attrs = if
|
825
|
-
|
826
|
-
|
827
|
-
"merge_attrs({#{attrs * ', '}}, " +
|
828
|
-
"((__merge_attrs__ = (#{merge_attrs[1..-1]})) == true ? attributes : __merge_attrs__))"
|
835
|
+
attrs = if el.attributes['merge-attrs']
|
836
|
+
merge_attrs = compile_merge_attrs(el)
|
837
|
+
"merge_attrs({#{attrs * ', '}}, #{merge_attrs} || {})"
|
829
838
|
else
|
830
839
|
"{" + attrs.join(', ') + "}"
|
831
840
|
end
|
@@ -888,6 +897,7 @@ module Hobo::Dryml
|
|
888
897
|
elsif is_code_attribute?(val)
|
889
898
|
"#{val[1..-1]}"
|
890
899
|
else
|
900
|
+
val.gsub!('-', '_')
|
891
901
|
attr == "repeat" ? %("#{val}") : "this.#{val}"
|
892
902
|
end
|
893
903
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Hobo::Dryml
|
2
2
|
|
3
3
|
class TemplateEnvironment
|
4
|
-
|
4
|
+
|
5
5
|
class << self
|
6
6
|
def inherited(subclass)
|
7
7
|
subclass.compiled_local_names = []
|
@@ -22,10 +22,9 @@ module Hobo::Dryml
|
|
22
22
|
alias_method :delayed_alias_method_chain, :alias_method_chain
|
23
23
|
|
24
24
|
end
|
25
|
+
|
26
|
+
include ActionView::Helpers
|
25
27
|
|
26
|
-
for mod in ActionView::Helpers.constants.grep(/Helper$/).map {|m| ActionView::Helpers.const_get(m)}
|
27
|
-
include mod
|
28
|
-
end
|
29
28
|
|
30
29
|
def initialize(view_name=nil, view=nil)
|
31
30
|
unless view_name.nil? && view.nil?
|
@@ -34,6 +33,7 @@ module Hobo::Dryml
|
|
34
33
|
@_erb_binding = binding
|
35
34
|
@_part_contexts = {}
|
36
35
|
@_scoped_variables = ScopedVariables.new
|
36
|
+
@_polymorphic_tag_cache = {}
|
37
37
|
|
38
38
|
# Make sure the "assigns" from the controller are available (instance variables)
|
39
39
|
if view
|
@@ -51,11 +51,11 @@ module Hobo::Dryml
|
|
51
51
|
|
52
52
|
for attr in [:erb_binding, :part_contexts, :view_name,
|
53
53
|
:this, :this_parent, :this_field, :this_key,
|
54
|
-
:form_this, :form_field_names]
|
54
|
+
:form_this, :form_field_path, :form_field_names]
|
55
55
|
class_eval "def #{attr}; @_#{attr}; end"
|
56
56
|
end
|
57
57
|
|
58
|
-
def
|
58
|
+
def path_for_form_field
|
59
59
|
@_form_field_path.nil? and raise Hobo::Dryml::DrymlException,
|
60
60
|
"DRYML cannot provide the correct form-field name here (this_field = #{this_field.inspect}, this = #{this.inspect})"
|
61
61
|
@_form_field_path
|
@@ -133,7 +133,7 @@ module Hobo::Dryml
|
|
133
133
|
end
|
134
134
|
|
135
135
|
|
136
|
-
def
|
136
|
+
def typed_id(object=nil, attribute=nil)
|
137
137
|
if object.nil?
|
138
138
|
# nothing passed -- use context
|
139
139
|
if this_parent && this_field && !this_parent.respond_to?(:member_class)
|
@@ -143,29 +143,51 @@ module Hobo::Dryml
|
|
143
143
|
end
|
144
144
|
end
|
145
145
|
|
146
|
-
if (
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
146
|
+
id = if (typed_id = object.try.typed_id)
|
147
|
+
typed_id
|
148
|
+
elsif object == @this
|
149
|
+
"this"
|
150
|
+
end
|
151
|
+
attribute ? "#{id}:#{attribute}" : id
|
152
|
+
end
|
152
153
|
|
153
154
|
|
154
|
-
def call_part(part_node_id, part_name,
|
155
|
+
def call_part(part_node_id, part_name, *locals)
|
155
156
|
res = ''
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
res = send("#{part_name}_part", *locals)
|
160
|
-
end
|
161
|
-
else
|
162
|
-
new_context do
|
163
|
-
@_part_contexts[part_node_id] = PartContext.new(part_name, dom_id, locals)
|
164
|
-
res = send("#{part_name}_part", *locals)
|
165
|
-
end
|
157
|
+
new_context do
|
158
|
+
@_part_contexts[part_node_id] = PartContext.for_call(part_name, self, locals)
|
159
|
+
res = send("#{part_name}_part", *locals)
|
166
160
|
end
|
167
161
|
res
|
168
162
|
end
|
163
|
+
|
164
|
+
|
165
|
+
def refresh_part(encoded_context, session, dom_id)
|
166
|
+
context = Hobo::Dryml::PartContext.for_refresh(encoded_context, @this, session)
|
167
|
+
|
168
|
+
with_part_context(context) do
|
169
|
+
send("#{context.part_name}_part", *context.locals)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
|
174
|
+
def with_part_context(context, &block)
|
175
|
+
this, this_field = context.this, context.this_field
|
176
|
+
|
177
|
+
b = if context.form_field_path
|
178
|
+
proc { with_form_context(:unknown, context.form_field_path, &block) }
|
179
|
+
else
|
180
|
+
block
|
181
|
+
end
|
182
|
+
|
183
|
+
if this && this_field
|
184
|
+
new_object_context(this) { new_field_context(this_field, &b) }
|
185
|
+
elsif this
|
186
|
+
new_object_context(this, &b)
|
187
|
+
else
|
188
|
+
new_context(&b)
|
189
|
+
end
|
190
|
+
end
|
169
191
|
|
170
192
|
|
171
193
|
def call_polymorphic_tag(name, *args)
|
@@ -185,16 +207,22 @@ module Hobo::Dryml
|
|
185
207
|
def find_polymorphic_tag(name, call_type=nil)
|
186
208
|
call_type ||= (this.respond_to?(:member_class) && this.member_class) || this_type
|
187
209
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
210
|
+
begin
|
211
|
+
found = nil
|
212
|
+
while true
|
213
|
+
if respond_to?(poly_name = "#{name}__for_#{call_type.name.to_s.underscore.gsub('/', '__')}")
|
214
|
+
found = poly_name
|
215
|
+
break
|
194
216
|
else
|
195
|
-
call_type
|
217
|
+
if call_type == ActiveRecord::Base || call_type == Object
|
218
|
+
found = name
|
219
|
+
break
|
220
|
+
else
|
221
|
+
call_type = call_type.superclass
|
222
|
+
end
|
196
223
|
end
|
197
224
|
end
|
225
|
+
found
|
198
226
|
end
|
199
227
|
end
|
200
228
|
|
@@ -313,10 +341,10 @@ module Hobo::Dryml
|
|
313
341
|
end
|
314
342
|
|
315
343
|
|
316
|
-
def with_form_context
|
317
|
-
@_form_this =
|
318
|
-
@_form_field_path =
|
319
|
-
@_form_field_paths_by_object = {
|
344
|
+
def with_form_context(form_this=this, form_field_path=[form_this.class.name.underscore])
|
345
|
+
@_form_this = form_this
|
346
|
+
@_form_field_path = form_field_path
|
347
|
+
@_form_field_paths_by_object = { form_this => form_field_path }
|
320
348
|
res = scope.new_scope :in_form => true, :form_field_names => [] do
|
321
349
|
yield
|
322
350
|
end
|
@@ -453,7 +481,7 @@ module Hobo::Dryml
|
|
453
481
|
end
|
454
482
|
|
455
483
|
|
456
|
-
# This
|
484
|
+
# This method is used where 'param' is declared on a tag that is
|
457
485
|
# itself a parameter tag. Takes two procs that each return a pair
|
458
486
|
# of hashes (attributes and parameters). Returns a single proc
|
459
487
|
# that also returns a pair of hashes - the merged atributes and
|
@@ -472,7 +500,7 @@ module Hobo::Dryml
|
|
472
500
|
|
473
501
|
attrs = merge_attrs(general_attrs, overriding_attrs)
|
474
502
|
overriding_default = overriding_parameters.delete(:default)
|
475
|
-
params = general_parameters
|
503
|
+
params = merge_parameter_hashes(general_parameters, overriding_parameters)
|
476
504
|
|
477
505
|
# The overrider should provide its :default as the new
|
478
506
|
# 'default_content'
|
@@ -494,6 +522,20 @@ module Hobo::Dryml
|
|
494
522
|
end
|
495
523
|
end
|
496
524
|
end
|
525
|
+
|
526
|
+
|
527
|
+
def merge_parameter_hashes(given_parameters, overriding_parameters)
|
528
|
+
to_merge = given_parameters.keys & overriding_parameters.keys
|
529
|
+
no_merge = overriding_parameters.keys - to_merge
|
530
|
+
result = given_parameters.dup
|
531
|
+
|
532
|
+
no_merge.each { |k| result[k] = overriding_parameters[k] }
|
533
|
+
to_merge.each { |k| result[k] = merge_tag_parameter(given_parameters[k], overriding_parameters[k])}
|
534
|
+
|
535
|
+
result
|
536
|
+
end
|
537
|
+
|
538
|
+
|
497
539
|
|
498
540
|
|
499
541
|
def part_contexts_javascripts
|
@@ -1,21 +1,27 @@
|
|
1
1
|
module Hobo::Dryml
|
2
2
|
|
3
3
|
class TemplateHandler < ActionView::TemplateHandler
|
4
|
-
|
4
|
+
|
5
|
+
def compile(*args)
|
6
|
+
# Ignore - we handle compilation ourselves
|
7
|
+
end
|
8
|
+
|
9
|
+
# Pre Rails 2.2
|
5
10
|
def render(template)
|
6
|
-
renderer = Hobo::Dryml.page_renderer_for_template(@view, template)
|
11
|
+
renderer = Hobo::Dryml.page_renderer_for_template(@view, template.locals.keys, template)
|
7
12
|
this = @view.instance_variable_set("@this", @view.controller.send(:dryml_context) || template.locals[:this])
|
8
13
|
s = renderer.render_page(this, template.locals)
|
9
|
-
|
10
14
|
# Important to strip whitespace, or the browser hangs around for ages (FF2)
|
11
|
-
s
|
15
|
+
s.strip
|
16
|
+
end
|
17
|
+
|
18
|
+
def render_for_rails22(template, view, local_assigns)
|
19
|
+
renderer = Hobo::Dryml.page_renderer_for_template(view, local_assigns.keys, template)
|
20
|
+
this = @view.instance_variable_set("@this", view.controller.send(:dryml_context) || local_assigns[:this])
|
21
|
+
s = renderer.render_page(this, local_assigns)
|
12
22
|
|
13
|
-
#
|
14
|
-
|
15
|
-
s.gsub(/^(.*?)(<!DOCTYPE.*?>).*?(<html.*?>)/m, "\\2\\3\\1")
|
16
|
-
else
|
17
|
-
s
|
18
|
-
end
|
23
|
+
# Important to strip whitespace, or the browser hangs around for ages (FF2)
|
24
|
+
s.strip
|
19
25
|
end
|
20
26
|
|
21
27
|
end
|
@@ -36,7 +42,7 @@ module ActionController
|
|
36
42
|
|
37
43
|
|
38
44
|
def call_dryml_tag(tag, options={})
|
39
|
-
|
45
|
+
@template.send(:_evaluate_assigns_and_ivars)
|
40
46
|
|
41
47
|
# TODO: Figure out what this bit is all about :-)
|
42
48
|
if options[:with]
|
@@ -50,23 +56,62 @@ module ActionController
|
|
50
56
|
|
51
57
|
|
52
58
|
# TODO: This is namespace polution, should be called render_dryml_tag
|
53
|
-
def render_tag(tag,
|
54
|
-
text = call_dryml_tag(tag,
|
55
|
-
text && render({:text => text, :layout => false }.merge(
|
59
|
+
def render_tag(tag, attributes={}, options={})
|
60
|
+
text = call_dryml_tag(tag, attributes)
|
61
|
+
text && render({:text => text, :layout => false }.merge(options))
|
56
62
|
end
|
57
63
|
|
58
|
-
def render_for_file_with_dryml(template_path, *args)
|
59
|
-
if template_path !~ /^([a-z]:)?\//i && # not an absolute path (e.g. an exception ERB template)
|
60
|
-
!template_exists?(template_path) && # no template available in app/views
|
61
|
-
tag_name = @dryml_fallback_tag || "#{File.basename(template_path).dasherize}-page"
|
62
64
|
|
63
|
-
|
64
|
-
|
65
|
+
# DRYML fallback tags -- monkey patch this method to attempt to render a tag if there's no template
|
66
|
+
def render_for_file_with_dryml(template_path, status = nil, layout = nil, locals = {})
|
67
|
+
render_for_file_without_dryml(template_path, status, layout, locals)
|
68
|
+
rescue ActionView::MissingTemplate => ex
|
69
|
+
# Try to use a DRYML <page> tag instead
|
70
|
+
tag_name = @dryml_fallback_tag || "#{File.basename(template_path).dasherize}-page"
|
71
|
+
|
72
|
+
text = call_dryml_tag(tag_name)
|
73
|
+
if text
|
74
|
+
render_for_text text, status
|
65
75
|
else
|
66
|
-
|
76
|
+
raise ex
|
67
77
|
end
|
68
78
|
end
|
69
79
|
alias_method_chain :render_for_file, :dryml
|
70
80
|
|
71
81
|
end
|
72
82
|
end
|
83
|
+
|
84
|
+
class ActionView::Template
|
85
|
+
|
86
|
+
def render_with_dryml(view, local_assigns = {})
|
87
|
+
if handler == Hobo::Dryml::TemplateHandler
|
88
|
+
render_dryml(view, local_assigns)
|
89
|
+
else
|
90
|
+
render_without_dryml(view, local_assigns)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
alias_method_chain :render, :dryml
|
94
|
+
|
95
|
+
# We've had to copy a bunch of logic from Renderable#render, because we need to prevent Rails
|
96
|
+
# from trying to compile our template. DRYML templates are each compiled as a class, not just a method,
|
97
|
+
# so the support for compiling templates that Rails provides is innadequate.
|
98
|
+
def render_dryml(view, local_assigns = {})
|
99
|
+
stack = view.instance_variable_get(:@_render_stack)
|
100
|
+
stack.push(self)
|
101
|
+
|
102
|
+
# This is only used for TestResponse to set rendered_template
|
103
|
+
unless is_a?(ActionView::InlineTemplate) || view.instance_variable_get(:@_first_render)
|
104
|
+
view.instance_variable_set(:@_first_render, self)
|
105
|
+
end
|
106
|
+
|
107
|
+
view.send(:_evaluate_assigns_and_ivars)
|
108
|
+
view.send(:_set_controller_content_type, mime_type) if respond_to?(:mime_type)
|
109
|
+
|
110
|
+
result = Hobo::Dryml::TemplateHandler.new.render_for_rails22(self, view, local_assigns)
|
111
|
+
|
112
|
+
stack.pop
|
113
|
+
result
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|