Skip to content

Commit

Permalink
You can now set a templates directory with
Browse files Browse the repository at this point in the history
  • Loading branch information
its-danny committed Mar 9, 2010
1 parent 5a9001f commit b99d301
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions lib/sinatra/effigy.rb
Expand Up @@ -2,19 +2,27 @@
require 'effigy'

module Sinatra
module EffigyHelper
Dir['views/*'].each {|view| require view }
module Effigy
module Helpers
Dir['views/*'].each { |view| require view }

def effigy(name, *locals)
camel_name = "#{name}_view".
gsub(' ', '_').
gsub(/\/(.)/) { "::#{$1.upcase}" }.
gsub(/(?:^|_)(.)/) { $1.upcase }
view = Object.const_get(camel_name).new(*locals)
template = File.read("templates/#{name}.html")
view.render(template)
def effigy(name, *locals)
camel_name = "#{name}_view".
gsub(' ', '_').
gsub(/\/(.)/) { "::#{$1.upcase}" }.
gsub(/(?:^|_)(.)/) { $1.upcase }
view = Object.const_get(camel_name).new(*locals)
template = File.read("#{self.options.templates}/#{name}.html")
view.render(template)
end
end

def self.registered(app)
app.helpers Effigy::Helpers

app.set :templates, 'templates'
end
end

helpers EffigyHelper
register Effigy
end

0 comments on commit b99d301

Please sign in to comment.