Sha256: 94add59311d13c41d54257e6f1eabbfdcd1fa592dec5bc54c4931ee2df1b44f7

Contents?: true

Size: 900 Bytes

Versions: 2

Compression:

Stored size: 900 Bytes

Contents

module RenderExecJS
  class Renderer
    class << self
      def environment
        @environment
      end

      def environment= new_environment
        @context = nil
        @environment = new_environment
      end

      def coffeescript_environment= new_environment
        if defined? CoffeeScript
          @context = nil
          @environment = CoffeeScript.compile new_environment, :bare => true
        elsif !new_environment.blank?
          puts "Can't find CoffeeScript. Did you forget to add it to your Gemfile?"
        end
      end

      def exec js, options = {}
        if options[:coffee_script]
          js = CoffeeScript.compile js, :bare => true
        end

        context.exec js
      end

      def call func, *args
        context.call func, *args
      end

      private
      def context
        @context ||= ExecJS.compile environment
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
render_execjs-0.0.3 lib/render_execjs/renderer.rb
render_execjs-0.0.2 lib/render_execjs/renderer.rb