Sha256: 3fee8ec2158cd565ceca7ed8be632bc7f3997594c3e5fea07c0124c9a7ba54b0

Contents?: true

Size: 1.8 KB

Versions: 32

Compression:

Stored size: 1.8 KB

Contents

require 'volt/server/rack/source_map_server'
if Volt.env.production?
  # Compress assets in production
  require 'uglifier'
end

# Sets up the maps for the opal assets, and source maps if enabled.
class OpalFiles
  attr_reader :environment
  
  def initialize(builder, app_path, component_paths)
    Opal::Processor.source_map_enabled = Volt.source_maps?
    
    # Don't run arity checks in production
    # Opal::Processor.arity_check_enabled = !Volt.env.production?
    # Opal::Processor.dynamic_require_severity = :raise

    @component_paths = component_paths
    @environment = Opal::Environment.new
    
    # Since the scope changes in builder blocks, we need to capture 
    # environment in closure
    environment = @environment
    
    environment.cache = Sprockets::Cache::FileStore.new("./tmp")
    
    if Volt.env.production?
      # Compress in production
      environment.js_compressor = Sprockets::UglifierCompressor
      environment.css_compressor = Sprockets::YUICompressor
    end
  
    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 Volt.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

32 entries across 32 versions & 1 rubygems

Version Path
volt-0.6.5 lib/volt/server/rack/opal_files.rb
volt-0.6.4 lib/volt/server/rack/opal_files.rb
volt-0.6.3 lib/volt/server/rack/opal_files.rb
volt-0.6.2 lib/volt/server/rack/opal_files.rb
volt-0.6.1 lib/volt/server/rack/opal_files.rb
volt-0.6.0 lib/volt/server/rack/opal_files.rb
volt-0.5.18 lib/volt/server/rack/opal_files.rb
volt-0.5.17 lib/volt/server/rack/opal_files.rb
volt-0.5.16 lib/volt/server/rack/opal_files.rb
volt-0.5.15 lib/volt/server/rack/opal_files.rb
volt-0.5.14 lib/volt/server/rack/opal_files.rb
volt-0.5.13 lib/volt/server/rack/opal_files.rb
volt-0.5.12 lib/volt/server/rack/opal_files.rb
volt-0.5.11 lib/volt/server/rack/opal_files.rb
volt-0.5.10 lib/volt/server/rack/opal_files.rb
volt-0.5.9 lib/volt/server/rack/opal_files.rb
volt-0.5.8 lib/volt/server/rack/opal_files.rb
volt-0.5.7 lib/volt/server/rack/opal_files.rb
volt-0.5.6 lib/volt/server/rack/opal_files.rb
volt-0.5.4 lib/volt/server/rack/opal_files.rb