From d6f2cd62525f2d2aac0ed6c58d2face6864c4dd5 Mon Sep 17 00:00:00 2001 From: Bryan Larsen Date: Mon, 4 Jul 2011 21:21:57 -0400 Subject: [PATCH] [#957] marshal context when other mechanisms fail --- dryml/lib/dryml/part_context.rb | 21 ++++++++++++++------- dryml/lib/dryml/template_environment.rb | 4 ++++ hobo/lib/hobo/helper.rb | 4 ++-- hobo/lib/hobo/rapid/taglibs/rapid_forms.dryml | 2 +- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/dryml/lib/dryml/part_context.rb b/dryml/lib/dryml/part_context.rb index f429ffe..59525e2 100644 --- a/dryml/lib/dryml/part_context.rb +++ b/dryml/lib/dryml/part_context.rb @@ -101,18 +101,25 @@ def parse_this_id(page_this) if this_id == "this" self.this = page_this - elsif this_id =~ /^this:(.*)/ - self.this = page_this - self.this_field = $1 elsif this_id == "nil" nil else parts = this_id.split(':') - if parts.length == 3 - self.this = Hobo::Model.find_by_typed_id("#{parts[0]}:#{parts[1]}") - self.this_field = parts[2] + if parts[0]=='this' + self.this = page_this + self.this_field = $1 + elsif parts[0]=='marshalled' + if parts.length == 3 + self.this_field = parts[2] + end + self.this = Marshal.load(Base64.decode64(parts[1])) else - self.this = Hobo::Model.find_by_typed_id(this_id) + if parts.length == 3 + self.this = Hobo::Model.find_by_typed_id("#{parts[0]}:#{parts[1]}") + self.this_field = parts[2] + else + self.this = Hobo::Model.find_by_typed_id(this_id) + end end end end diff --git a/dryml/lib/dryml/template_environment.rb b/dryml/lib/dryml/template_environment.rb index 4f3b013..e62dd51 100644 --- a/dryml/lib/dryml/template_environment.rb +++ b/dryml/lib/dryml/template_environment.rb @@ -146,6 +146,10 @@ module Dryml typed_id elsif object == @this "this" + elsif object.nil? + "nil" + else + "marshalled:#{Base64.encode64(Marshal.dump(object)).strip}" end attribute ? "#{id}:#{attribute}" : id end diff --git a/hobo/lib/hobo/helper.rb b/hobo/lib/hobo/helper.rb index cadcba4..bc2b6d6 100644 --- a/hobo/lib/hobo/helper.rb +++ b/hobo/lib/hobo/helper.rb @@ -171,12 +171,12 @@ module Hobo def type_and_field(*args) type, field = args.empty? ? [this_parent.class, this_field] : args - "#{type.typed_id}_#{field}" if type.respond_to?(:typed_id) + "#{type.typed_id.split.first}_#{field}" if type.respond_to?(:typed_id) end def model_id_class(object=this, attribute=nil) - object.respond_to?(:typed_id) ? "model::#{typed_id(object, attribute).to_s.dasherize}" : "" + object.respond_to?(:typed_id) ? "model::#{typed_id(object, attribute).to_s.split.first.dasherize}" : "" end def can_create?(object=this) diff --git a/hobo/lib/hobo/rapid/taglibs/rapid_forms.dryml b/hobo/lib/hobo/rapid/taglibs/rapid_forms.dryml index 4440fc0..e1b4dda 100644 --- a/hobo/lib/hobo/rapid/taglibs/rapid_forms.dryml +++ b/hobo/lib/hobo/rapid/taglibs/rapid_forms.dryml @@ -767,7 +767,7 @@ If you wish to set `min-chars` to 0, you will require this [patch to controls.js value = name(:no_wrapper => true, :if_present => true) -%> -- 1.7.4.1