Sha256: 372bfd9d991adce05f2b8fcf401171361899566649f0c5849a9ae175d0d2410d

Contents?: true

Size: 790 Bytes

Versions: 10

Compression:

Stored size: 790 Bytes

Contents

require "erb"
 
module JqueryPluginGen
  class QuickTemplate
    attr_reader :args, :text, :file
    
    details = {:version => 'xxx'}
    
    def initialize(file, path="")
      @path = path.empty? ? File.join(File.dirname(__FILE__), '..', 'templates') : path
      @file = File.join(@path, file) + '.erb'
      @text = File.read(@file)
    end
    
    def exec(b)
      begin
        details = b
        # b = binding
        template = ERB.new(@text, 0, "%<>")
        result = template.result(binding)
        # Chomp the trailing newline
        #result.gsub(/\n$/,'')
        result
      rescue NameError
        puts "Error found for #{@file}"
        raise $!
      end
    end

    def self.erb(file, b, path="")
       QuickTemplate.new(file, path).exec(b)
    end
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
jqueryplugingen-0.2.6 lib/jquery_plugin_gen/quick_template.rb
jqueryplugingen-0.2.0 lib/jquery_plugin_gen/quick_template.rb
jqueryplugingen-0.2.5 lib/jquery_plugin_gen/quick_template.rb
jqueryplugingen-0.1.2 lib/jquery_plugin_gen/quick_template.rb
jqueryplugingen-0.1.4 lib/jquery_plugin_gen/quick_template.rb
jqueryplugingen-0.2.1 lib/jquery_plugin_gen/quick_template.rb
jqueryplugingen-0.2.2 lib/jquery_plugin_gen/quick_template.rb
jqueryplugingen-0.2.3 lib/jquery_plugin_gen/quick_template.rb
jqueryplugingen-0.1.3 lib/jquery_plugin_gen/quick_template.rb
jqueryplugingen-0.2.4 lib/jquery_plugin_gen/quick_template.rb