module Plate # Allow for partials within views module PartialsHelper def render(options = {}, locals = {}) path = options # If a hash is passed as the first option, use it for locals if Hash === options path = options.delete(:partial) locals = options.clone end locals.symbolize_keys! render_partial(path.to_s, locals) rescue site.log("Oops. There was a problem rendering the partial: #{path}") "" end protected # Create a new partial with the given options, and return its content def render_partial(path, locals) partial_name = Partial.name(self.site, path, self.file) partial = Partial.find(self.site, partial_name) self.page.partials << partial_name unless self.page.partials.include?(partial_name) if partial partial.pages << self.page unless partial.pages.include?(self.page) partial.render(locals) else nil end end end end