module Stimulus::ImportmapHelper

Public Instance Methods

importmap_list_from(*paths) click to toggle source
# File lib/stimulus/importmap_helper.rb, line 6
def importmap_list_from(*paths)
  Array(paths).flat_map do |path|
    absolute_path = Rails.root.join(path)
    dirname       = absolute_path.basename.to_s

    absolute_path.children.collect do |module_filename|
      module_name = importmap_module_name_from(module_filename)
      %("#{module_name}": "#{asset_path("#{dirname}/#{module_filename.basename}")}")
    end
  end.join(",\n")
end
importmap_list_with_stimulus_from(*paths) click to toggle source
# File lib/stimulus/importmap_helper.rb, line 2
def importmap_list_with_stimulus_from(*paths)
  [ %("stimulus": "#{asset_path("stimulus/libraries/stimulus")}"), importmap_list_from(*paths) ].join(",\n")
end

Private Instance Methods

importmap_module_name_from(filename) click to toggle source

Strip off the extension and any versioning data for an absolute module name.

# File lib/stimulus/importmap_helper.rb, line 20
def importmap_module_name_from(filename)
  filename.basename.to_s.remove(filename.extname).split("@").first
end