Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cells support #391

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/cocoon.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'cocoon/view_helpers'
require 'cocoon/cells_helpers'

module Cocoon
class Engine < ::Rails::Engine
Expand Down
16 changes: 16 additions & 0 deletions lib/cocoon/cells_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Cocoon
module CellsHelpers
include ViewHelpers

# :nodoc:
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
14 changes: 12 additions & 2 deletions lib/cocoon/view_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,20 @@ 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

# :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
Expand Down Expand Up @@ -95,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

Expand Down