Sha256: e8842159c54b2d71c4721c427570d2963c681156ec2c2b5e78622824c3e43391
Contents?: true
Size: 947 Bytes
Versions: 1
Compression:
Stored size: 947 Bytes
Contents
module Stimulus::ImportmapHelper def importmap_list_with_stimulus_from(*paths) [ %("stimulus": "#{asset_path("stimulus/libraries/stimulus")}"), importmap_list_from(*paths) ].join(",\n") end def importmap_list_from(*paths) Array(paths).flat_map do |path| if (absolute_path = Rails.root.join(path)).exist? absolute_path.children.collect do |module_filename| next unless module_filename.extname =~ /js(m)?$/ module_name = importmap_module_name_from(module_filename) module_path = asset_path("#{absolute_path.basename.to_s}/#{module_filename.basename}") %("#{module_name}": "#{module_path}") end end end.compact.join(",\n") end private # Strip off the extension and any versioning data for an absolute module name. def importmap_module_name_from(filename) filename.basename.to_s.remove(filename.extname).split("@").first end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
stimulus-rails-0.1.4 | lib/stimulus/importmap_helper.rb |