Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make it even faster by defining a method instead
  • Loading branch information
judofyr authored and defunkt committed Oct 5, 2009
1 parent 5b3b4c3 commit 0742298
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/mustache.rb
Expand Up @@ -11,17 +11,18 @@ def initialize(source, mustache)
end

def render(context)
(@compiled ||= compile_proc).call(context)
class << self; self; end.class_eval <<-EOF, __FILE__, __LINE__ - 1
def render(ctx)
#{compile}
end
EOF
render(context)
end

def compile(src = @source)
"\"#{compile_sections(src)}\""
end

def compile_proc(src = @source)
eval("proc{|ctx|#{compile(src)}}")
end

private

# {{#sections}}okay{{/sections}}
Expand Down

0 comments on commit 0742298

Please sign in to comment.