Class: JqueryPluginGen::QuickTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/jquery_plugin_gen/quick_template.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, path = "") ⇒ QuickTemplate

Returns a new instance of QuickTemplate.



9
10
11
12
13
# File 'lib/jquery_plugin_gen/quick_template.rb', line 9

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

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



5
6
7
# File 'lib/jquery_plugin_gen/quick_template.rb', line 5

def args
  @args
end

#fileObject (readonly)

Returns the value of attribute file.



5
6
7
# File 'lib/jquery_plugin_gen/quick_template.rb', line 5

def file
  @file
end

#textObject (readonly)

Returns the value of attribute text.



5
6
7
# File 'lib/jquery_plugin_gen/quick_template.rb', line 5

def text
  @text
end

Class Method Details

.erb(file, b, path = "") ⇒ Object



30
31
32
# File 'lib/jquery_plugin_gen/quick_template.rb', line 30

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

Instance Method Details

#exec(b) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/jquery_plugin_gen/quick_template.rb', line 15

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