From 7c864f85c892fe21feeead09933f751e6773bdf6 Mon Sep 17 00:00:00 2001 From: Adam Saletnik Date: Fri, 11 Mar 2016 11:37:10 +0100 Subject: [PATCH 1/2] add separate helpers for cells, with proper render method call --- lib/cocoon.rb | 1 + lib/cocoon/cells_helpers.rb | 11 +++++++++++ lib/cocoon/view_helpers.rb | 7 ++++++- 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 lib/cocoon/cells_helpers.rb diff --git a/lib/cocoon.rb b/lib/cocoon.rb index 3118fb7c..8c9cc66c 100644 --- a/lib/cocoon.rb +++ b/lib/cocoon.rb @@ -1,4 +1,5 @@ require 'cocoon/view_helpers' +require 'cocoon/cells_helpers' module Cocoon class Engine < ::Rails::Engine diff --git a/lib/cocoon/cells_helpers.rb b/lib/cocoon/cells_helpers.rb new file mode 100644 index 00000000..1724bd3b --- /dev/null +++ b/lib/cocoon/cells_helpers.rb @@ -0,0 +1,11 @@ +module Cocoon + module CellsHelpers + include ViewHelpers + + # :nodoc: + def render_partial(partial, partial_options) + render(view: partial, locals: partial_options) + end + + end +end diff --git a/lib/cocoon/view_helpers.rb b/lib/cocoon/view_helpers.rb index 91f7153a..1591044b 100644 --- a/lib/cocoon/view_helpers.rb +++ b/lib/cocoon/view_helpers.rb @@ -49,10 +49,15 @@ def render_association(association, f, new_object, form_name, render_options={}, method_name = ancestors.include?('SimpleForm::FormBuilder') ? :simple_fields_for : (ancestors.include?('Formtastic::FormBuilder') ? :semantic_fields_for : :fields_for) f.send(method_name, association, new_object, {:child_index => "new_#{association}"}.merge(render_options)) do |builder| partial_options = {form_name.to_sym => builder, :dynamic => true}.merge(locals) - render(partial, partial_options) + render_partial(partial, partial_options) end end + # :nodoc: + def render_partial(partial, partial_options) + render(partial, partial_options) + end + # shows a link that will allow to dynamically add a new associated object. # # - *name* : the text to show in the link From 9476fdf16eddfd8dede7f94edbd646427085c6f2 Mon Sep 17 00:00:00 2001 From: Yury Snegirev Date: Thu, 20 Oct 2016 00:01:11 +0300 Subject: [PATCH 2/2] Fix rendering of template of cells --- lib/cocoon/cells_helpers.rb | 5 +++++ lib/cocoon/view_helpers.rb | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/cocoon/cells_helpers.rb b/lib/cocoon/cells_helpers.rb index 1724bd3b..c516c16b 100644 --- a/lib/cocoon/cells_helpers.rb +++ b/lib/cocoon/cells_helpers.rb @@ -7,5 +7,10 @@ def render_partial(partial, partial_options) render(view: partial, locals: partial_options) end + # :nodoc: + def insertion_template(association, f, new_object, form_parameter_name, render_options, override_partial) + CGI.unescapeHTML(render_association(association, f, new_object, form_parameter_name, render_options, override_partial).to_str).html_safe + end + end end diff --git a/lib/cocoon/view_helpers.rb b/lib/cocoon/view_helpers.rb index 1591044b..07fec6fe 100644 --- a/lib/cocoon/view_helpers.rb +++ b/lib/cocoon/view_helpers.rb @@ -58,6 +58,11 @@ def render_partial(partial, partial_options) render(partial, partial_options) end + # :nodoc: + def insertion_template(association, f, new_object, form_parameter_name, render_options, override_partial) + CGI.escapeHTML(render_association(association, f, new_object, form_parameter_name, render_options, override_partial).to_str).html_safe + end + # shows a link that will allow to dynamically add a new associated object. # # - *name* : the text to show in the link @@ -100,7 +105,7 @@ def link_to_add_association(*args, &block) new_object = create_object(f, association, force_non_association_create) new_object = wrap_object.call(new_object) if wrap_object.respond_to?(:call) - html_options[:'data-association-insertion-template'] = CGI.escapeHTML(render_association(association, f, new_object, form_parameter_name, render_options, override_partial).to_str).html_safe + html_options[:'data-association-insertion-template'] = insertion_template(association, f, new_object, form_parameter_name, render_options, override_partial) html_options[:'data-count'] = count if count > 0