module ActionView::AbstractRenderer::ObjectRendering
def initialize(lookup_context, options)
def initialize(lookup_context, options) super @context_prefix = lookup_context.prefixes.first end
def local_variable(path)
def local_variable(path) if as = @options[:as] raise_invalid_option_as(as) unless /\A[a-z_]\w*\z/.match?(as.to_s) as.to_sym else base = path.end_with?("/") ? "" : File.basename(path) raise_invalid_identifier(path) unless base =~ /\A_?(.*?)(?:\.\w+)*\z/ $1.to_sym end end
def merge_prefix_into_object_path(prefix, object_path)
def merge_prefix_into_object_path(prefix, object_path) if prefix.include?(?/) && object_path.include?(?/) prefixes = [] prefix_array = File.dirname(prefix).split("/") object_path_array = object_path.split("/")[0..-3] # skip model dir & partial prefix_array.each_with_index do |dir, index| break if dir == object_path_array[index] prefixes << dir end (prefixes << object_path).join("/") else object_path end end
def partial_path(object, view)
If +prefix_partial_path_with_controller_namespace+ is true, then this
then an +ArgumentError+ is raised.
will provide the path. If the object does not respond to +to_partial_path+,
responds to +to_partial_path+, then +to_partial_path+ will be called and
Obtains the path to where the object's partial is located. If the object
def partial_path(object, view) object = object.to_model if object.respond_to?(:to_model) path = if object.respond_to?(:to_partial_path) object.to_partial_path else raise ArgumentError.new("'#{object.inspect}' is not an ActiveModel-compatible object. It must implement :to_partial_path.") end if view.prefix_partial_path_with_controller_namespace PREFIXED_PARTIAL_NAMES[@context_prefix][path] ||= merge_prefix_into_object_path(@context_prefix, path.dup) else path end end
def raise_invalid_identifier(path)
def raise_invalid_identifier(path) raise ArgumentError, IDENTIFIER_ERROR_MESSAGE % path end
def raise_invalid_option_as(as)
def raise_invalid_option_as(as) raise ArgumentError, OPTION_AS_ERROR_MESSAGE % as end