Sha256: 45b4d3b104ad8e9464738443eda7aab57f76d0126815f164f6f1550a1469fdc5

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

# encoding: utf-8

require 'tilt'

module EmberScript

  class << self
    def engine
    end

    def engine=(engine)
    end

    def version
      `ember-script -v`
    end

    # Compile a EmberScript file to JavaScript
    # or generate the source maps.
    #
    # @param [String,#read] the source string or IO
    # @param [Hash] options the compiler options
    # @option options [Boolean] bare compile the JavaScript without the top-level function safety wrapper
    # @option options [String] format the output format, either `:map` or `:js`
    #
    def compile(script, options = {})
      script = script.read if script.respond_to?(:read)

      Open3.capture3("ember-script --js", :stdin_data=>script)[0]
    end
  end

  class EmberScriptTemplate < ::Tilt::Template
    self.default_mime_type = 'application/javascript'

    def self.engine_initialized?
      true
    end

    def evaluate(scope, locals, &block)
      @output ||= EmberScript.compile(data, options)
    end

    def allows_script?
      false
    end

    def prepare
    end
  end

  ::Tilt.register EmberScriptTemplate, 'em'

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ember_script-0.0.2 lib/ember_script.rb
ember_script-0.0.1 lib/ember_script.rb