Class: Opal::Sprockets::PathReader
- Inherits:
-
Object
- Object
- Opal::Sprockets::PathReader
- Defined in:
- opal/lib/opal/sprockets/path_reader.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
Instance Method Summary collapse
- #expand(path) ⇒ Object
-
#initialize(env, context) ⇒ PathReader
constructor
A new instance of PathReader.
- #paths ⇒ Object
- #read(path) ⇒ Object
Constructor Details
#initialize(env, context) ⇒ PathReader
Returns a new instance of PathReader
5 6 7 8
# File 'opal/lib/opal/sprockets/path_reader.rb', line 5 def initialize(env, context) @env ||= env @context ||= context end
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context
32 33 34
# File 'opal/lib/opal/sprockets/path_reader.rb', line 32 def context @context end
#env ⇒ Object (readonly)
Returns the value of attribute env
32 33 34
# File '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 '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
#paths ⇒ Object
28 29 30
# File '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 '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