Sha256: 88aad4f54cb8bf3b44a1d22ffebfdb93564e59ede4d7e8a032570ab2e8736cbe

Contents?: true

Size: 1.34 KB

Versions: 3

Compression:

Stored size: 1.34 KB

Contents

require 'volt/server/rack/source_map_server'

SOURCE_MAPS = !!ENV['MAPS'] unless defined?(SOURCE_MAPS)

Opal::Processor.source_map_enabled = SOURCE_MAPS
# Opal::Processor.arity_check_enabled = true
# Opal::Processor.dynamic_require_severity = :raise

# Sets up the maps for the opal assets, and source maps if enabled.
class OpalFiles
  def initialize(builder, app_path, component_paths)
    @component_paths = component_paths
    environment = Opal::Environment.new
    environment.cache = Sprockets::Cache::FileStore.new("./tmp")
  
    environment.append_path(app_path)
  
    volt_gem_lib_path = File.expand_path(File.join(File.dirname(__FILE__), "../../.."))
    environment.append_path(volt_gem_lib_path)

    add_asset_folders(environment)

    # Add the opal load paths
    Opal.paths.each do |path|
      environment.append_path(path)
    end

    # opal-jquery gem
    spec = Gem::Specification.find_by_name("opal-jquery")
    environment.append_path(spec.gem_dir + "/opal")

    builder.map '/assets' do
      run environment
    end

    if SOURCE_MAPS
      source_maps = SourceMapServer.new(environment)

      builder.map(source_maps.prefix) do
        run source_maps
      end
    end    
  end
  
  def add_asset_folders(environment)
    @component_paths.asset_folders do |asset_folder|
      environment.append_path(asset_folder)
    end
  end
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
volt-0.2.7 lib/volt/server/rack/opal_files.rb
volt-0.2.5 lib/volt/server/rack/opal_files.rb
volt-0.2.4 lib/volt/server/rack/opal_files.rb