Sha256: d394e449f29e153b4da918f79724bce1af7049bcb61186a19822e05e5404c3f4

Contents?: true

Size: 1.14 KB

Versions: 7

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true
require 'tilt'
require 'opal/builder'
require 'opal/config'
require 'opal/version'

$OPAL_SOURCE_MAPS = {}

module Opal
  class TiltTemplate < Tilt::Template
    self.default_mime_type = 'application/javascript'

    def self.inherited(subclass)
      subclass.default_mime_type = 'application/javascript'
    end

    def self.engine_initialized?
      true
    end

    def self.version
      ::Opal::VERSION
    end

    def self.compiler_options
      Opal::Config.compiler_options.merge(requirable: true)
    end

    def initialize_engine
      require_template_library 'opal'
    end

    def prepare
    end

    def evaluate(_, _, &block)
      if builder = @options[:builder]
        builder.dup.build(file).to_s
      elsif @options[:build]
        Opal::Builder.build(file).to_s
      else
        compiler_options = (compiler_options || {}).merge!(file: file)
        compiler = Compiler.new(data, compiler_options)
        compiler.compile.to_s
      end
    end

    def compiler_options
      self.class.compiler_options
    end
  end
end

Tilt.register 'rb',   Opal::TiltTemplate
Tilt.register 'opal', Opal::TiltTemplate

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
opal-0.11.4 lib/tilt/opal.rb
opal-0.11.3 lib/tilt/opal.rb
opal-0.11.2 lib/tilt/opal.rb
opal-0.11.1 lib/tilt/opal.rb
opal-0.11.1.pre lib/tilt/opal.rb
opal-0.11.0 lib/tilt/opal.rb
opal-0.11.0.rc1 lib/tilt/opal.rb