Class: Volt::OpalFiles
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
Instance Method Summary collapse
- #add_asset_folders(environment) ⇒ Object
-
#initialize(builder, app_path, component_paths) ⇒ OpalFiles
constructor
A new instance of OpalFiles.
Constructor Details
#initialize(builder, app_path, component_paths) ⇒ OpalFiles
Returns a new instance of OpalFiles.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/volt/server/rack/opal_files.rb', line 15 def initialize(builder, app_path, component_paths) Opal::Processor.source_map_enabled = Volt.source_maps? Opal::Processor.const_missing_enabled = true # Setup Opal paths # Add the lib directory to the load path Opal.append_path(Volt.root + '/app') Opal.append_path(Volt.root + '/lib') Gem.loaded_specs.values.each do |gem| path = gem.full_gem_path + '/app' if Dir.exists?(path) Opal.append_path(path) end end # Don't run arity checks in production # Opal::Processor.arity_check_enabled = !Volt.env.production? # Opal::Processor.dynamic_require_severity = :raise server = Opal::Server.new(prefix: '/') @component_paths = component_paths # @environment = Opal::Environment.new @environment = server.sprockets # Since the scope changes in builder blocks, we need to capture # environment in closure environment = @environment environment.cache = Sprockets::Cache::FileStore.new('./tmp') # Compress in production if Volt.config.compress_javascript require 'uglifier' environment.js_compressor = Sprockets::UglifierCompressor end if Volt.config.compress_css require 'ruby-clean-css' require 'ruby-clean-css/sprockets' RubyCleanCSS::Sprockets.register(environment) end server.append_path(app_path) volt_gem_lib_path = File.(File.join(File.dirname(__FILE__), '../../..')) server.append_path(volt_gem_lib_path) add_asset_folders(server) # Add the opal load paths Opal.paths.each do |path| server.append_path(path) end builder.map '/assets' do run server end # map server.source_maps.prefix do # run server.source_maps # end # if Volt.source_maps? # source_maps = SourceMapServer.new(environment) # # builder.map(source_maps.prefix) do # run source_maps # end # end end |
Instance Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
13 14 15 |
# File 'lib/volt/server/rack/opal_files.rb', line 13 def environment @environment end |
Instance Method Details
#add_asset_folders(environment) ⇒ Object
90 91 92 93 94 |
# File 'lib/volt/server/rack/opal_files.rb', line 90 def add_asset_folders(environment) @component_paths.asset_folders do |asset_folder| environment.append_path(asset_folder) end end |