Sha256: cb93cea43cf087c59e281f1c332e608e20e630c706c19770059fca773eb61eb8

Contents?: true

Size: 691 Bytes

Versions: 1

Compression:

Stored size: 691 Bytes

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
impartial-0.0.1 lib/impartial/helper.rb