Sha256: 403d5b0ca504fcaf137519f15294c9b71dd6ff22171069f7a9501acf8917de55

Contents?: true

Size: 871 Bytes

Versions: 16

Compression:

Stored size: 871 Bytes

Contents

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::Runtime.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)

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
jbarnette-johnson-1.0.0.200806240111 lib/rails/init.rb
jbarnette-johnson-1.0.0.200807291507 lib/rails/init.rb
jbarnette-johnson-1.0.0.200808062051 lib/rails/init.rb
jbarnette-johnson-1.0.0.200808062111 lib/rails/init.rb
jbarnette-johnson-1.0.0.200811251942 lib/rails/init.rb
jbarnette-johnson-1.0.0.20081126120511 lib/rails/init.rb
jbarnette-johnson-1.0.0.20090127202936 lib/rails/init.rb
jbarnette-johnson-1.0.0.20090225110820 lib/rails/init.rb
jbarnette-johnson-1.0.0.20090326122910 lib/rails/init.rb
jbarnette-johnson-1.0.0.20090326154650 lib/rails/init.rb
jbarnette-johnson-1.0.0.20090326161333 lib/rails/init.rb
jbarnette-johnson-1.0.0.20090402144841 lib/rails/init.rb
jbarnette-johnson-1.0.0.20090402155420 lib/rails/init.rb
johnson-1.1.1 lib/rails/init.rb
johnson-1.1.2 lib/rails/init.rb
johnson-1.1.0 lib/rails/init.rb