lib/nice_partials/partial.rb in nice_partials-0.1.2 vs lib/nice_partials/partial.rb in nice_partials-0.1.3
- old
+ new
@@ -1,7 +1,9 @@
module NicePartials
class Partial
+ delegate_missing_to :@view_context
+
def initialize(view_context)
@view_context = view_context
@key = SecureRandom.uuid
end
@@ -12,11 +14,23 @@
def helpers(&block)
class_eval &block
end
+ # See the `ActionView::PartialRenderer` monkey patch in `lib/nice_partials/monkey_patch.rb` for something similar.
def content_for(name, content = nil, options = {}, &block)
- @view_context.content_for("#{name}_#{@key}".to_sym, content, options, &block)
+ if block_given?
+ partial_prefix = nice_partials_locale_prefix_from_view_context_and_block(@view_context, block)
+ @view_context.nice_partials_push_t_prefix(partial_prefix)
+ end
+
+ result = @view_context.content_for("#{name}_#{@key}".to_sym, content, options, &block)
+
+ if block_given?
+ @view_context.nice_partials_pop_t_prefix
+ end
+
+ return result
end
def content_for?(name)
@view_context.content_for?("#{name}_#{@key}".to_sym)
end