Class: Opal::Sprockets::PathReader

Inherits:
Object
  • Object
show all
Defined in:
/Users/elia/Code/opal-docs/opal/lib/opal/sprockets/path_reader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env, context) ⇒ PathReader

Returns a new instance of PathReader


5
6
7
8
# File '/Users/elia/Code/opal-docs/opal/lib/opal/sprockets/path_reader.rb', line 5

def initialize(env, context)
  @env ||= env
  @context ||= context
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context


32
33
34
# File '/Users/elia/Code/opal-docs/opal/lib/opal/sprockets/path_reader.rb', line 32

def context
  @context
end

#envObject (readonly)

Returns the value of attribute env


32
33
34
# File '/Users/elia/Code/opal-docs/opal/lib/opal/sprockets/path_reader.rb', line 32

def env
  @env
end

Instance Method Details

#expand(path) ⇒ Object


22
23
24
25
26
# File '/Users/elia/Code/opal-docs/opal/lib/opal/sprockets/path_reader.rb', line 22

def expand path
  env.resolve(path) or
    # Sprockets 3 just returns nil for unknown paths
    raise ::Sprockets::FileNotFound, path.inspect
end

#pathsObject


28
29
30
# File '/Users/elia/Code/opal-docs/opal/lib/opal/sprockets/path_reader.rb', line 28

def paths
  env.paths
end

#read(path) ⇒ Object


10
11
12
13
14
15
16
17
18
19
20
# File '/Users/elia/Code/opal-docs/opal/lib/opal/sprockets/path_reader.rb', line 10

def read path
  if path.end_with? '.js'
    context.depend_on_asset(path)
    env[path, bundle: true].to_s
  else
    context.depend_on(path)
    File.open(expand(path), 'rb:UTF-8'){|f| f.read}
  end
rescue ::Sprockets::FileNotFound
  nil
end