Class: Rye::Tpl

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(src, basename = 'rye-template') ⇒ Tpl



287
288
289
290
291
# File 'lib/rye.rb', line 287

def initialize(src, basename='rye-template')
  @basename = basename
  src = src.to_s
  @src, @template = src, ERB.new(src)
end

Instance Attribute Details

#basenameObject (readonly)

Returns the value of attribute basename.



286
287
288
# File 'lib/rye.rb', line 286

def basename
  @basename
end

#result(binding) ⇒ Object (readonly)

Returns the value of attribute result.



286
287
288
# File 'lib/rye.rb', line 286

def result
  @result
end

#srcObject (readonly)

Returns the value of attribute src.



286
287
288
# File 'lib/rye.rb', line 286

def src
  @src
end

Instance Method Details

#deleteObject



300
301
302
# File 'lib/rye.rb', line 300

def delete
  File.delete(@tf.path) if File.exists?(@tf.path)
end

#pathObject



292
293
294
295
296
297
298
299
# File 'lib/rye.rb', line 292

def path
  if @tf.nil?
    @tf = Tempfile.new basename
    @tf.write @result
    @tf.close
  end
  @tf.path
end

#result!(binding) ⇒ Object



303
304
305
# File 'lib/rye.rb', line 303

def result!(binding)
  @result = result(binding)
end

#to_sObject



309
# File 'lib/rye.rb', line 309

def to_s() src end