Class: Volt::OpalFiles
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Instance Method Summary collapse
- #add_asset_folders(environment) ⇒ Object
- #add_image_compression ⇒ Object
-
#initialize(builder, app_url, app_path, component_paths) ⇒ OpalFiles
constructor
A new instance of OpalFiles.
Constructor Details
#initialize(builder, app_url, 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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/volt/server/rack/opal_files.rb', line 15 def initialize(builder, app_url, 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') Gem.loaded_specs.values.select {|gem| gem.name =~ /^(volt|ejson_ext)/ } .each do |gem| ['app', 'lib'].each do |folder| path = gem.full_gem_path + "/#{folder}" Opal.append_path(path) if Dir.exist?(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: app_url, debug: Volt.source_maps?) @server.use_index = false @component_paths = component_paths # @environment = Opal::Environment.new @environment = @server.sprockets 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 # Use csso for css compression by default. require 'csso' require 'volt/utils/csso_patch' Csso.install(environment) end if Volt.config.compress_images add_image_compression 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) # Setup ViewProcessor to parse views Volt::ViewProcessor.setup(@environment) # Use the cached env in production so it doesn't have to stat the FS if Volt.env.production? @environment = @environment.cached @server.sprockets = @environment end # Since the scope changes in builder blocks, we need to capture # environment in closure environment = @environment builder.map(app_url) do run environment end # Remove dup paths Opal.paths.uniq! @environment.logger.level ||= Logger::DEBUG source_map_enabled = Volt.source_maps? if source_map_enabled maps_prefix = Opal::Server::SOURCE_MAPS_PREFIX_PATH maps_app = Opal::SourceMapServer.new(@environment, maps_prefix) ::Opal::Sprockets::SourceMapHeaderPatch.inject!(maps_prefix) end if source_map_enabled builder.map(maps_prefix) do require 'rack/conditionalget' require 'rack/etag' use Rack::ConditionalGet use Rack::ETag run maps_app 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 |
#server ⇒ Object (readonly)
Returns the value of attribute server.
13 14 15 |
# File 'lib/volt/server/rack/opal_files.rb', line 13 def server @server end |
Instance Method Details
#add_asset_folders(environment) ⇒ Object
126 127 128 129 130 131 |
# File 'lib/volt/server/rack/opal_files.rb', line 126 def add_asset_folders(environment) # @component_paths.asset_folders do |asset_folder| # puts "ADD ASSET FOLDER: #{asset_folder.inspect}" # environment.append_path(asset_folder) # end end |
#add_image_compression ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/volt/server/rack/opal_files.rb', line 110 def add_image_compression if defined?(ImageOptim) env = @environment image_optim = ImageOptim.new({pngout: false, svgo: false}) processor = proc do |_context, data| image_optim.optimize_image_data(data) || data end env.register_preprocessor 'image/gif', :image_optim, &processor env.register_preprocessor 'image/jpeg', :image_optim, &processor env.register_preprocessor 'image/png', :image_optim, &processor env.register_preprocessor 'image/svg+xml', :image_optim, &processor end end |