Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement importmaps #1188

Merged
merged 12 commits into from
Nov 2, 2023
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ gem 'time', '>= 0.2.2'

gem 'font-awesome-sass', '~> 6.4.0'

gem 'importmap-rails', '~> 1.2'

gem 'sprockets-rails', '>= 3.0.0'

# ------------------------------------------------------ With native extensions
# These require native extensions.
# Ensure Traveling Ruby provides an appropriate version before bumping.
Expand Down
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ GEM
i18n (1.14.1)
concurrent-ruby (~> 1.0)
image_size (1.3.1)
importmap-rails (1.2.1)
actionpack (>= 6.0.0)
railties (>= 6.0.0)
jbuilder (2.10.0)
activesupport (>= 5.0.0)
jquery-fileupload-rails (0.3.5)
Expand Down Expand Up @@ -564,6 +567,7 @@ DEPENDENCIES
guard-rspec
html-pipeline
image_size (~> 1.3.0)
importmap-rails (~> 1.2)
jbuilder (~> 2.7)
jquery-fileupload-rails (~> 0.3.4)
jquery-hotkeys-rails
Expand Down Expand Up @@ -604,6 +608,7 @@ DEPENDENCIES
simple_form
sinatra (~> 2.2.3)
spring
sprockets-rails (>= 3.0.0)
sqlite3
terser (~> 1.1)
thor (~> 1.2.1)
Expand Down
14 changes: 12 additions & 2 deletions app/assets/config/manifest.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
//= link application.css
//= link setup/setup.css
//= link tylium.css

//= link legacy.application.js
//= link tylium.js

//= link_tree ../../javascript .js
//= link_tree ../../../vendor/javascript .js

//= link_tree ../images
//= link_directory ../javascripts .js
//= link_directory ../stylesheets .css

//= link_tree ../../../vendor/assets
3 changes: 0 additions & 3 deletions app/assets/javascripts/tylium.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
//= require popper
//= require bootstrap

//= require vendor/datatables.min
//= require vendor/stupidtable

//= require cable

//= require shared/auto_save/local
Expand Down
3 changes: 3 additions & 0 deletions app/javascript/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
import 'datatables'
import 'stupidtable'
3 changes: 2 additions & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
<head>
<title><%= [content_for(:title), 'Dradis Community Edition'].compact.join(' | ') %></title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'legacy.application', 'data-turbolinks-track' => true %>
<%= favicon_link_tag %>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= javascript_importmap_tags %>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
Expand Down
1 change: 1 addition & 0 deletions app/views/layouts/tylium.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<%= javascript_include_tag 'tylium', 'data-turbolinks-track' => true %>
<%= csrf_meta_tag %>
<%= csp_meta_tag %>
<%= javascript_importmap_tags %>
</head>

<body class="<%= controller_name %> <%= action_name %>">
Expand Down
4 changes: 4 additions & 0 deletions bin/importmap
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env ruby

require_relative '../config/application'
require 'importmap/commands'
8 changes: 8 additions & 0 deletions config/importmap.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Pin npm packages by running ./bin/importmap

pin 'application', preload: true

pin 'datatables'
pin 'stupidtable'

pin_all_from 'app/javascript/tylium', under: 'tylium'
aapomm marked this conversation as resolved.
Show resolved Hide resolved
12 changes: 0 additions & 12 deletions config/initializers/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,6 @@
# Add additional assets to the asset load path.
# Rails.application.config.assets.paths << Emoji.images_path

# Add Yarn node_modules folder to the asset load path.
Rails.application.config.assets.paths << Rails.root.join('node_modules')

# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in the app/assets
# folder are already added.

# Setup
Rails.application.config.assets.precompile += %w( setup/setup.css )

# Tylium
Rails.application.config.assets.precompile += %w( tylium.js tylium.css )

# Include font files
Rails.application.config.assets.precompile << ["*.svg", "*.eot", "*.woff", "*.ttf"]