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) 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) if partial self.page.partials << partial unless self.page.partials.include?(partial) partial.pages << self.page unless partial.pages.include?(self.page) partial.render(locals) else nil end end end end