Sha256: 0851078bfc5915b140e6b0e3f91ba4303f8f4f046257cbbf2ca69dd64accad3a

Contents?: true

Size: 1.13 KB

Versions: 40

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

require 'tilt'
require 'opal/builder'
require 'opal/config'
require 'opal/version'

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
      # stub
    end

    def evaluate(_scope, _locals)
      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

40 entries across 40 versions & 1 rubygems

Version Path
opal-1.8.3.rc1 lib/tilt/opal.rb
opal-1.8.2 lib/tilt/opal.rb
opal-1.8.1 lib/tilt/opal.rb
opal-1.8.0 lib/tilt/opal.rb
opal-1.8.0.beta1 lib/tilt/opal.rb
opal-1.7.4 lib/tilt/opal.rb
opal-1.8.0.alpha1 lib/tilt/opal.rb
opal-1.7.3 lib/tilt/opal.rb
opal-1.7.2 lib/tilt/opal.rb
opal-1.7.1 lib/tilt/opal.rb
opal-1.7.0 lib/tilt/opal.rb
opal-1.7.0.rc1 lib/tilt/opal.rb
opal-1.6.1 lib/tilt/opal.rb
opal-1.6.0 lib/tilt/opal.rb
opal-1.6.0.rc1 lib/tilt/opal.rb
opal-1.6.0.alpha1 lib/tilt/opal.rb
opal-1.5.1 lib/tilt/opal.rb
opal-1.5.0 lib/tilt/opal.rb
opal-1.5.0.rc1 lib/tilt/opal.rb
opal-1.4.1 lib/tilt/opal.rb