Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to import additional admin JS modules
Browse files Browse the repository at this point in the history
In order to be able to import additional JS modules
into the Alchemy admin UI you can use this.

Be sure to also pin the modules with `Alchemy.importmap`.

\## Example

    Alchemy.importmap.pin "flatpickr/de",
      to: "https://ga.jspm.io/npm:[email protected]/dist/l10n/de.js"

    Alchemy.admin_js_imports << "flatpickr/de"
tvdeyen committed Oct 3, 2023

Verified

This commit was signed with the committer’s verified signature. The key has expired.
tvdeyen Thomas von Deyen
1 parent 5ffc6c3 commit e44663d
Showing 2 changed files with 26 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/views/layouts/alchemy/admin.html.erb
Original file line number Diff line number Diff line change
@@ -35,6 +35,13 @@
<%= render 'alchemy/admin/partials/routes' %>
<%= javascript_include_tag('alchemy/admin/all', 'data-turbo-track' => true) %>
<%= javascript_importmap_tags("alchemy_admin", importmap: Alchemy.importmap) %>
<% if Alchemy.admin_js_imports.any? %>
<script type="module">
<% Alchemy.admin_js_imports.each do |path| %>
import "<%= path %>"
<% end %>
</script>
<% end %>
<%= yield :javascript_includes %>
</head>
<%= content_tag :body, id: 'alchemy', class: alchemy_body_class do %>
19 changes: 19 additions & 0 deletions lib/alchemy.rb
Original file line number Diff line number Diff line change
@@ -43,6 +43,25 @@ def self.preview_sources=(sources)
@_preview_sources = Array(sources)
end

# Additional JS modules to be imported in the Alchemy admin UI
#
# Be sure to also pin the modules with +Alchemy.importmap+.
#
# == Example
#
# Alchemy.importmap.pin "flatpickr/de",
# to: "https://ga.jspm.io/npm:[email protected]/dist/l10n/de.js"
#
# Alchemy.admin_js_imports << "flatpickr/de"
#
def self.admin_js_imports
@_admin_js_imports ||= Set.new
end

def self.admin_js_imports=(sources)
@_admin_js_imports = Set[sources]
end

# Define page publish targets
#
# A publish target is a ActiveJob that gets performed

0 comments on commit e44663d

Please sign in to comment.