Module: BladeRunner::Assets

Extended by:
Assets
Included in:
Assets
Defined in:
lib/blade_runner/assets.rb

Instance Method Summary collapse

Instance Method Details

#adapter_load_pathsObject



37
38
39
40
# 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_pathsObject



29
30
31
# 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) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 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) ⇒ Object



23
24
25
26
27
# 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_pathsObject



33
34
35
# File 'lib/blade_runner/assets.rb', line 33

def user_load_paths
  BR.config.load_paths.map { |a| Pathname.new(a) }
end

#watch_logical_pathsObject



42
43
44
45
46
47
48
49
50
51
52
# 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