module BladeRunner::Assets
Public Instance Methods
adapter_load_paths()
click to toggle source
# File lib/blade_runner/assets.rb, line 37 def adapter_load_paths gem_name = "blade_runner-#{BR.config.framework}_adapter" [ gem_pathname(gem_name).join("assets") ] end
blade_runner_load_paths()
click to toggle source
# File lib/blade_runner/assets.rb, line 29 def blade_runner_load_paths [ BR.root_path.join("assets"), gem_pathname("faye").join("lib") ] end
environment(name = :blade_runner)
click to toggle source
# File lib/blade_runner/assets.rb, line 8 def environment(name = :blade_runner) @environments[name] ||= Sprockets::Environment.new do |env| env.cache = Sprockets::Cache::FileStore.new(BR.tmp_path.join(name.to_s)) send("#{name}_load_paths").each do |path| env.append_path(path) end env.context_class.class_eval do extend Forwardable def_delegators "BladeRunner::Assets", :environment, :logical_paths end end end
logical_paths(type = nil)
click to toggle source
# File lib/blade_runner/assets.rb, line 23 def logical_paths(type = nil) paths = BR.config.logical_paths paths.select! { |path| File.extname(path) == ".#{type}" } if type paths end
user_load_paths()
click to toggle source
# File lib/blade_runner/assets.rb, line 33 def user_load_paths BR.config.load_paths.map { |a| Pathname.new(a) } end
watch_logical_paths()
click to toggle source
# File lib/blade_runner/assets.rb, line 42 def watch_logical_paths @mtimes = get_mtimes EM.add_periodic_timer(1) do mtimes = get_mtimes unless mtimes == @mtimes @mtimes = mtimes BR.publish("/assets", changed: @mtimes) end end end
Private Instance Methods
gem_pathname(gem_name)
click to toggle source
# File lib/blade_runner/assets.rb, line 69 def gem_pathname(gem_name) gemspec = Gem::Specification.find_by_name(gem_name) Pathname.new(gemspec.gem_dir) end
get_mtime(logical_path)
click to toggle source
# File lib/blade_runner/assets.rb, line 63 def get_mtime(logical_path) environment_for(:user)[logical_path].mtime rescue Exception => e e.to_s end
get_mtimes()
click to toggle source
# File lib/blade_runner/assets.rb, line 55 def get_mtimes {}.tap do |mtimes| BR.config.logical_paths.each do |path| mtimes[path] = get_mtime(path) end end end