Class: Impartial::Base
- Inherits:
-
Object
- Object
- Impartial::Base
- Defined in:
- lib/impartial/base.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Base
constructor
A new instance of Base.
- #render(name, *args) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Base
Returns a new instance of Base.
11 12 13 14 15 16 |
# File 'lib/impartial/base.rb', line 11 def initialize(={}) = Impartial..merge() Configuration::VALID_OPTIONS_KEYS.each do |key| send("#{key}=", [key]) end end |
Class Method Details
.find_class(name) ⇒ Object
32 33 34 35 36 |
# File 'lib/impartial/base.rb', line 32 def self.find_class(name) name.to_s.camelize.constantize rescue NameError => e raise Impartial::Exceptions::ClassNotFound.new e.to_s end |
Instance Method Details
#render(name, *args) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/impartial/base.rb', line 18 def render(name, *args) cls = Impartial::Base.find_class name view = cls.new *args path = cls.name.underscore shortname = cls.name.demodulize.underscore paths.each do |load_path| t = File.join(load_path, path, "#{shortname}.html.hbs") if File.exist? t return Handlebars.compile(File.open(t).read).call(view).to_s end end raise Impartial::Exceptions::TemplateMissing.new end |