Class: Jekyll::Importmap::Map
- Inherits:
-
Object
- Object
- Jekyll::Importmap::Map
- Defined in:
- lib/jekyll-importmap/map.rb
Defined Under Namespace
Classes: InvalidFile
Instance Attribute Summary collapse
-
#directories ⇒ Object
readonly
Returns the value of attribute directories.
-
#packages ⇒ Object
readonly
Returns the value of attribute packages.
Instance Method Summary collapse
- #draw(path = nil, &block) ⇒ Object
-
#initialize ⇒ Map
constructor
A new instance of Map.
- #pin(name, to: nil, preload: true) ⇒ Object
- #pin_all_from(dir, under: nil, to: nil, preload: true) ⇒ Object
- #preloaded_module_paths ⇒ Object
- #to_json ⇒ Object
Constructor Details
Instance Attribute Details
#directories ⇒ Object (readonly)
Returns the value of attribute directories.
6 7 8 |
# File 'lib/jekyll-importmap/map.rb', line 6 def directories @directories end |
#packages ⇒ Object (readonly)
Returns the value of attribute packages.
6 7 8 |
# File 'lib/jekyll-importmap/map.rb', line 6 def packages @packages end |
Instance Method Details
#draw(path = nil, &block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/jekyll-importmap/map.rb', line 15 def draw(path = nil, &block) if path && File.exist?(path) begin instance_eval(File.read(path), path.to_s) rescue StandardError => e raise InvalidFile, "Unable to parse importmap file from #{path}: #{e.}" end elsif block_given? instance_eval(&block) else raise InvalidFile, "You must provide a file path or a block to draw the importmap, given: #{path}" end self end |
#pin(name, to: nil, preload: true) ⇒ Object
31 32 33 |
# File 'lib/jekyll-importmap/map.rb', line 31 def pin(name, to: nil, preload: true) @packages[name] = Jekyll::Importmap::MappedFile.new(name: name, path: to || "#{name}.js", preload: preload) end |
#pin_all_from(dir, under: nil, to: nil, preload: true) ⇒ Object
34 35 36 |
# File 'lib/jekyll-importmap/map.rb', line 34 def pin_all_from(dir, under: nil, to: nil, preload: true) @directories[dir] = Jekyll::Importmap::MappedDir.new(dir: dir, under: under, path: to, preload: preload) end |
#preloaded_module_paths ⇒ Object
38 39 40 41 42 43 |
# File 'lib/jekyll-importmap/map.rb', line 38 def preloaded_module_paths resolve_asset_paths( , resolver: @resolver ).values end |
#to_json ⇒ Object
45 46 47 48 49 |
# File 'lib/jekyll-importmap/map.rb', line 45 def to_json JSON.pretty_generate({ "imports" => resolved_asset_paths }) end |