require 'active_support/inflector' require 'handlebars' require 'impartial/error' module Impartial module Helper module_function def impartial(name, *args) cls = Impartial::Helper.find_class name puts cls.inspect puts cls.class.name view = cls.new *args path = cls.name.underscore shortname = cls.name.demodulize.underscore t = Rails.root.join("app", "impartials", path, "#{shortname}.html.hbs") Handlebars.compile(t.read).call(view).to_s.html_safe end def self.find_class(name) name.to_s.camelize.constantize rescue NameError => e raise Impartial::Exceptions::ClassNotFound.new e.to_s end end end