Class: 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
30 31 32
# File 'opal/lib/opal/sprockets/path_reader.rb', line 30 def context @context end
#env ⇒ Object (readonly)
Returns the value of attribute env
30 31 32
# File 'opal/lib/opal/sprockets/path_reader.rb', line 30 def env @env end
Instance Method Details
#expand(path) ⇒ Object
22 23 24
# File 'opal/lib/opal/sprockets/path_reader.rb', line 22 def expand path env.resolve(path) end
#paths ⇒ Object
26 27 28
# File 'opal/lib/opal/sprockets/path_reader.rb', line 26 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.read(expand(path)) end rescue ::Sprockets ::FileNotFound nil end