Sha256: 05f170cd41171231ac2dd804337db78590c2e98640eccc0ddc9c26d1e7ee8a6f
Contents?: true
Size: 1.01 KB
Versions: 3
Compression:
Stored size: 1.01 KB
Contents
require 'erubis' require 'digest/md5' module Sprinkle::Package module Rendering extend ActiveSupport::Concern included do self.send :include, Helpers end def template(src, context=binding) eruby = Erubis::Eruby.new(src) output = eruby.result(context) rescue Object => e raise Sprinkle::Errors::TemplateError.new(e, src, context) end def render(filename, context=binding) contents=File.read(expand_filename(filename)) template(contents, context) end # Helper methods can be called from inside your package and # verification code module Helpers # return the md5 of a string (as a hex string) def md5(s) Digest::MD5.hexdigest(s) end end private def expand_filename(n) #:nodoc: return n.to_s if n.to_s.starts_with? "/" ["./templates/#{n}","./templates/#{n}.erb"].each do |f| return f if File.exist?(f) end raise "template file not found" end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
sprinkle-0.7.4 | lib/sprinkle/package/rendering.rb |
sprinkle-0.7.3 | lib/sprinkle/package/rendering.rb |
sprinkle-0.7.2 | lib/sprinkle/package/rendering.rb |