Class: Sprockets::FileReader

Inherits:
Object
  • Object
show all
Defined in:
lib/volt/server/template_handlers/sprockets_component_handler.rb

Overview

Internal: The first processor in the pipeline that reads the file into memory and passes it along as ‘input`.

Class Method Summary collapse

Class Method Details

.call(input) ⇒ Object



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
# File 'lib/volt/server/template_handlers/sprockets_component_handler.rb', line 36

def self.call(input)
  env = input[:environment]
  path = input[:filename]

  # Handle a /components path match.  /components will load up a component.
  if path =~ /\/components\/[^.]+[.]rb$/
    component_name = path.match(/\/components\/([^.]+)[.]rb$/)[1]

    cached = env.cached

    stats = cached.instance_variable_get('@stats')

    stats[path] = Volt::StatStub.new

    # Working with a component path
    volt_app = Thread.current['volt_app'] || $volt_app
    data = Volt::ComponentCode.new(volt_app, component_name, volt_app.component_paths, true).code
  else
    data = env.read_file(input[:filename], input[:content_type])
  end

  # dependencies = Set.new(input[:metadata][:dependencies])
  # dependencies += [env.build_file_digest_uri(input[:filename])]

  dependencies = input[:metadata][:dependencies]
  # dependencies.merge(env.build_file_digest_uri(input[:filename]))

  { data: data, dependencies: dependencies }
end