Module: Sprockets::Bower
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Defined in: | lib/sprockets/bower.rb |
Constant Summary
-
POSSIBLE_BOWER_JSONS =
Internal: All supported bower.json files.
['bower.json', 'component.json', '.bower.json']
Instance Method Summary
-
#read_bower_main(dirname, filename)
Internal: Read bower.json’s main directive.
-
#resolve_alternates(load_path, logical_path)
Internal: Override resolve_alternates to install bower.json behavior.
Instance Method Details
#read_bower_main(dirname, filename)
Internal: Read bower.json’s main directive.
dirname - String path to component directory. filename - String path to bower.json.
Returns nothing.
# File 'lib/sprockets/bower.rb', line 48
def read_bower_main(dirname, filename) bower = JSON.parse(File.read(filename), create_additions: false) case bower['main'] when String yield File. (bower['main'], dirname) when Array bower['main'].each do |name| yield File. (name, dirname) end end end
#resolve_alternates(load_path, logical_path)
Internal: Override resolve_alternates to install bower.json behavior.
load_path - String environment path logical_path - String path relative to base
Returns candidate filenames.
# File 'lib/sprockets/bower.rb', line 17
def resolve_alternates(load_path, logical_path) candidates, deps = super # bower.json can only be nested one level deep if !logical_path.index('/'.freeze) dirname = File.join(load_path, logical_path) if directory?(dirname) filenames = POSSIBLE_BOWER_JSONS.map { |basename| File.join(dirname, basename) } filename = filenames.detect { |fn| self.file?(fn) } if filename deps << build_file_digest_uri(filename) read_bower_main(dirname, filename) do |path| if file?(path) candidates << path end end end end end return candidates, deps end