Skip to content

Commit

Permalink
Move ESM code into app/javascript/alchemy_admin
Browse files Browse the repository at this point in the history
Follows Rails conventions and removes potential conflicts.
  • Loading branch information
tvdeyen committed Jun 28, 2023
1 parent ee892e5 commit da5252a
Show file tree
Hide file tree
Showing 25 changed files with 40 additions and 40 deletions.
2 changes: 1 addition & 1 deletion app/assets/config/alchemy_manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
//= link_tree ../images/alchemy/
//= link_tree ../../../vendor/assets/fonts/
//= link_tree ../../../vendor/assets/images/
//= link admin.js
//= link alchemy_admin.js
34 changes: 34 additions & 0 deletions app/javascript/alchemy_admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import translate from "./alchemy_admin/i18n"
import translationData from "./alchemy_admin/translations"
import NodeTree from "./alchemy_admin/node_tree"
import fileEditors from "./alchemy_admin/file_editors"
import IngredientAnchorLink from "./alchemy_admin/ingredient_anchor_link"
import pictureEditors from "./alchemy_admin/picture_editors"
import ImageLoader from "./alchemy_admin/image_loader"
import ImageCropper from "./alchemy_admin/image_cropper"
import Datepicker from "./alchemy_admin/datepicker"
import Sitemap from "./alchemy_admin/sitemap"
import Tinymce from "./alchemy_admin/tinymce"
import PagePublicationFields from "./alchemy_admin/page_publication_fields.js"

// Global Alchemy object
if (typeof window.Alchemy === "undefined") {
window.Alchemy = {}
}

// Enhance the global Alchemy object with imported features
Object.assign(Alchemy, {
// Global utility method for translating a given string
t: translate,
translations: Object.assign(Alchemy.translations || {}, translationData),
NodeTree,
fileEditors,
pictureEditors,
ImageLoader: ImageLoader.init,
ImageCropper,
IngredientAnchorLink,
Datepicker,
Sitemap,
Tinymce,
PagePublicationFields
})
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion app/views/layouts/alchemy/admin.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</script>
<%= render 'alchemy/admin/partials/routes' %>
<%= javascript_include_tag('alchemy/admin/all', 'data-turbolinks-track' => true) %>
<%= javascript_importmap_tags("@alchemy_cms/admin", importmap: Alchemy.importmap) %>
<%= javascript_importmap_tags("alchemy_admin", importmap: Alchemy.importmap) %>
<%= yield :javascript_includes %>
</head>
<%= content_tag :body, id: 'alchemy', class: alchemy_body_class do %>
Expand Down
2 changes: 1 addition & 1 deletion config/importmap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
pin "lodash-es/max", to: "https://ga.jspm.io/npm:lodash-es@4.17.21/max.js", preload: true
pin "sortablejs", to: "https://ga.jspm.io/npm:sortablejs@1.15.0/modular/sortable.esm.js", preload: true

pin "@alchemy_cms/admin", to: "admin.js", preload: true
pin "alchemy_admin", to: "alchemy_admin.js", preload: true
2 changes: 1 addition & 1 deletion lib/alchemy/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Engine < Rails::Engine
initializer "alchemy.importmap" do |app|
Alchemy.importmap.draw(Engine.root.join("config", "importmap.rb"))

package_path = Engine.root.join("package")
package_path = Engine.root.join("app/javascript")
app.config.assets.paths << package_path

if app.config.importmap.sweep_cache
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@alchemy_cms/admin",
"name": "alchemy_admin",
"scripts": {
"test": "jest"
},
Expand All @@ -22,7 +22,7 @@
"Alchemy": {}
},
"roots": [
"package"
"app/javascript/alchemy_admin"
]
}
}
34 changes: 0 additions & 34 deletions package/admin.js

This file was deleted.

0 comments on commit da5252a

Please sign in to comment.