Skip to content
This repository has been archived by the owner on Aug 18, 2018. It is now read-only.

Commit

Permalink
adding EJS rails plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Apr 29, 2008
1 parent fe953c4 commit cc83591
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions lib/rails/init.rb
@@ -0,0 +1,37 @@
require 'johnson'

class EJSHandler < ActionView::TemplateHandler
class EJSProxy # :nodoc:
def initialize(controller)
@controller = controller
end

def key?(pooperty)
@controller.instance_variables.include?("@#{pooperty}")
end

def [](pooperty)
@controller.instance_variable_get("@#{pooperty}")
end

def []=(pooperty, value)
@controller.instance_variable_set("@#{pooperty}", value)
end
end

def initialize(view)
@view = view
end

def render(template)
ctx = Johnson::Context.new
ctx.evaluate('Johnson.require("johnson/template");')
ctx['template'] = template.source
ctx['controller'] = @view.controller
ctx['at'] = EJSProxy.new(@view.controller)

ctx.evaluate('Johnson.templatize(template).call(at)')
end
end

ActionView::Template.register_template_handler("ejs", EJSHandler)

0 comments on commit cc83591

Please sign in to comment.