Class: Jekyll::Importmap::Mappable

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll-importmap/mappable.rb

Direct Known Subclasses

MappedDir, MappedFile

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash, resolver = Jekyll::Importmap::Resolver) ⇒ Mappable

Returns a new instance of Mappable.



8
9
10
11
12
13
# File 'lib/jekyll-importmap/mappable.rb', line 8

def initialize(hash, resolver=Jekyll::Importmap::Resolver)
    @path = hash[:path]
    @preload = hash[:preload]
    @keyword_init = hash[:keyword_init] ||= true
    @resolver = resolver
end

Instance Attribute Details

#keyword_initObject (readonly)

Returns the value of attribute keyword_init.



6
7
8
# File 'lib/jekyll-importmap/mappable.rb', line 6

def keyword_init
  @keyword_init
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/jekyll-importmap/mappable.rb', line 6

def path
  @path
end

#preloadObject (readonly)

Returns the value of attribute preload.



6
7
8
# File 'lib/jekyll-importmap/mappable.rb', line 6

def preload
  @preload
end

Instance Method Details

#absolute_root_pathObject



18
19
20
# File 'lib/jekyll-importmap/mappable.rb', line 18

def absolute_root_path
    @pathname ||= calculate_absolute_root_path
end

#calculate_absolute_root_pathObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/jekyll-importmap/mappable.rb', line 21

def calculate_absolute_root_path
    pathname = Pathname.new(@dir || @path)
    if pathname.absolute?
        pathname
    else
        # this is where you can adjust whether we  allow adding js
        # files anywhere or just in the /assets/js directory

        Pathname.new(Dir.pwd).join(pathname)
    end
end

#resolved_pathObject



15
16
17
# File 'lib/jekyll-importmap/mappable.rb', line 15

def resolved_path
    @resolver.path_to_asset(@path)
end