Skip to content

Commit

Permalink
Bundle javascript with importmap
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Feb 22, 2023
1 parent a065359 commit 43b378f
Show file tree
Hide file tree
Showing 12 changed files with 175 additions and 99 deletions.
6 changes: 4 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ group :development, :test do
end

group :development do
gem 'guard-rspec', require: false
# gem 'guard-rspec', require: false
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 4.1.0'
# Display performance information such as SQL time and flame graphs for each request in your browser.
Expand All @@ -75,7 +75,7 @@ group :deployment do
end

gem 'blacklight', '~> 7.14'
gem 'blacklight-spotlight', '~> 3.1', github: 'projectblacklight/spotlight', branch: 'declare-var'
gem 'blacklight-spotlight', '~> 3.1', github: 'projectblacklight/spotlight', branch: 'nestable'
gem 'twitter-typeahead-rails', '0.11.1.pre.corejavascript'

gem 'friendly_id'
Expand Down Expand Up @@ -112,3 +112,5 @@ gem 'cache_with_locale'

gem 'i18n-js', '< 4' # v4 was a complete rewrite; will take some work to update
gem 'i18n-tasks'

gem "importmap-rails", "~> 1.1"
70 changes: 9 additions & 61 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GIT
remote: https://github.com/projectblacklight/spotlight.git
revision: 616e3e02b3be25f8a4f39bec90a81788e1daef14
branch: declare-var
revision: 3175f09046db7da5217c316e1e9644bf5e3353fc
branch: nestable
specs:
blacklight-spotlight (3.5.0.2)
activejob-status
Expand Down Expand Up @@ -231,7 +231,6 @@ GEM
aws-sdk-s3 (~> 1.0)
carrierwave (~> 2.0)
clipboard-rails (1.7.1)
coderay (1.1.3)
concurrent-ruby (1.2.0)
config (4.1.0)
deep_merge (~> 1.2, >= 1.2.1)
Expand Down Expand Up @@ -306,57 +305,23 @@ GEM
factory_bot_rails (6.2.0)
factory_bot (~> 6.2.0)
railties (>= 5.0.0)
faraday (1.10.3)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
faraday-excon (~> 1.1)
faraday-httpclient (~> 1.0)
faraday-multipart (~> 1.0)
faraday-net_http (~> 1.0)
faraday-net_http_persistent (~> 1.0)
faraday-patron (~> 1.0)
faraday-rack (~> 1.0)
faraday-retry (~> 1.0)
faraday (2.7.4)
faraday-net_http (>= 2.0, < 3.1)
ruby2_keywords (>= 0.0.4)
faraday-em_http (1.0.0)
faraday-em_synchrony (1.0.0)
faraday-excon (1.1.0)
faraday-follow_redirects (0.3.0)
faraday (>= 1, < 3)
faraday-httpclient (1.0.1)
faraday-multipart (1.0.4)
multipart-post (~> 2)
faraday-net_http (1.0.1)
faraday-net_http_persistent (1.2.0)
faraday-patron (1.0.0)
faraday-rack (1.0.0)
faraday-retry (1.0.3)
faraday-net_http (3.0.2)
ffi (1.15.5)
ffi-compiler (1.0.1)
ffi (>= 1.0.0)
rake
font-awesome-rails (4.7.0.8)
railties (>= 3.2, < 8.0)
formatador (1.1.0)
friendly_id (5.5.0)
activerecord (>= 4.0.0)
github-markup (4.0.1)
globalid (1.1.0)
activesupport (>= 5.0)
guard (2.18.0)
formatador (>= 0.2.4)
listen (>= 2.7, < 4.0)
lumberjack (>= 1.0.12, < 2.0)
nenv (~> 0.1)
notiffany (~> 0.0)
pry (>= 0.13.0)
shellany (~> 0.0)
thor (>= 0.18.1)
guard-compat (1.2.1)
guard-rspec (4.7.3)
guard (~> 2.1)
guard-compat (~> 1.1)
rspec (>= 2.99.0, < 4.0)
handlebars_assets (0.23.9)
execjs (~> 2.0)
sprockets (>= 2.0.0)
Expand Down Expand Up @@ -401,6 +366,9 @@ GEM
image_processing (1.12.2)
mini_magick (>= 4.9.5, < 5)
ruby-vips (>= 2.0.17, < 3)
importmap-rails (1.1.5)
actionpack (>= 6.0.0)
railties (>= 6.0.0)
io-console (0.6.0)
irb (1.6.2)
reline (>= 0.3.0)
Expand Down Expand Up @@ -430,9 +398,6 @@ GEM
rails (>= 4.2.0)
legato (0.7.0)
multi_json
listen (3.8.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
llhttp-ffi (0.4.0)
ffi-compiler (~> 1.0)
rake (~> 13.0)
Expand All @@ -444,7 +409,6 @@ GEM
loofah (2.19.1)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
lumberjack (1.2.8)
mail (2.8.1)
mini_mime (>= 0.1.1)
net-imap
Expand All @@ -460,8 +424,6 @@ GEM
msgpack (1.6.0)
multi_json (1.15.0)
multi_xml (0.6.0)
multipart-post (2.3.0)
nenv (0.3.0)
net-imap (0.3.4)
date
net-protocol
Expand All @@ -479,9 +441,6 @@ GEM
racc (~> 1.4)
nokogiri (1.14.2-x86_64-linux)
racc (~> 1.4)
notiffany (0.1.3)
nenv (~> 0.1)
shellany (~> 0.0)
oauth2 (2.0.9)
faraday (>= 0.17.3, < 3.0)
jwt (>= 1.0, < 3.0)
Expand All @@ -502,9 +461,6 @@ GEM
ast (~> 2.4.1)
pg (1.4.5)
popper_js (1.16.1)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
public_suffix (5.0.1)
puma (5.6.5)
nio4r (~> 2.0)
Expand Down Expand Up @@ -558,9 +514,6 @@ GEM
zeitwerk (~> 2.5)
rainbow (3.1.1)
rake (13.0.6)
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
redcarpet (3.6.0)
redis (5.0.6)
redis-client (>= 0.9.0)
Expand Down Expand Up @@ -596,10 +549,6 @@ GEM
rsolr (2.5.0)
builder (>= 2.1.2)
faraday (>= 0.9, < 3, != 2.0.0)
rspec (3.12.0)
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-core (3.12.1)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.2)
Expand Down Expand Up @@ -667,7 +616,6 @@ GEM
rack-proxy (>= 0.6.1)
railties (>= 5.2)
semantic_range (>= 2.3.0)
shellany (0.0.1)
sidekiq (7.0.5)
concurrent-ruby (< 2)
connection_pool (>= 2.3.0)
Expand Down Expand Up @@ -792,12 +740,12 @@ DEPENDENCIES
factory_bot_rails (~> 6.0)
font-awesome-rails
friendly_id
guard-rspec
honeybadger
http
i18n-js (< 4)
i18n-tasks
iiif-presentation (~> 1.0)
importmap-rails (~> 1.1)
jbuilder (~> 2.7)
jquery-rails
lograge
Expand Down
10 changes: 8 additions & 2 deletions app/assets/config/manifest.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
//= link_tree ../images
//= link_directory ../javascripts .js
//= link application.css
//= link spotlight/manifest.js
//= link spotlight/manifest.js
//= link_tree ../../javascript .js
//= link_tree ../../../vendor/javascript .js

// needed for import map pin_all_under
//= link spotlight/application.js
//= link spotlight/spotlight.esm.js
//= link spotlight/spotlight.js
32 changes: 0 additions & 32 deletions app/assets/javascripts/application.js

This file was deleted.

45 changes: 45 additions & 0 deletions app/javascript/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
import jQuery from 'jquery'
window.jQuery = jQuery
window.$ = jQuery

console.log("JQURY imported")
import 'bootstrap'
import "@hotwired/turbo-rails"
import L from 'leaflet'
window.L = L
import SirTrevor from 'sir-trevor'
window.SirTrevor = SirTrevor
import Clipboard from 'clipboard'
window.Clipboard = Clipboard

// We can probably ditch this dynamic import once we use Blacklight 8
import('blacklight/blacklight')
import('spotlight/spotlight.esm').then((Spotlight)=> {
console.log('spotlight defined')
window.Spotlight = Spotlight
})

import {I18n} from 'i18n-js'
window.I18n = I18n

//= require rails-ujs
//= require turbolinks
//
//
// Required by Blacklight
//= require jquery3
//= require popper
//= require twitter/typeahead
//= require bootstrap
//= require bootstrap/util
//= require blacklight/blacklight

//= require transform_result
//= require i18n/translations
// require_tree .


// For blacklight_range_limit built-in JS, if you don't want it you don't need
// this:
//= require 'blacklight_range_limit'
54 changes: 54 additions & 0 deletions app/views/layouts/spotlight/base.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!DOCTYPE html>
<%= content_tag :html, class: 'no-js', **(try(:html_tag_attributes) || {}) do %>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<%= render partial: 'shared/analytics' %>
<title><%= h(@page_title || application_name.to_s) %></title>
<link href="<%= current_exhibit ? spotlight.opensearch_exhibit_catalog_url(current_exhibit, format: 'xml') : main_app.opensearch_catalog_url(format: 'xml') %>" title="<%= h(@page_title || application_name.to_str) %>" type="application/opensearchdescription+xml" rel="search"/>
<%= favicon_link_tag 'favicon.ico' %>
<% if current_exhibit %>
<%= exhibit_stylesheet_link_tag "application" %>
<% else %>
<%= stylesheet_link_tag "application" %>
<% end %>

<%#= javascript_include_tag "application" %>
<%= javascript_importmap_tags %>
<%= csrf_meta_tags %>
<%= content_for(:head) %>
<%= description %>
<%= twitter_card %>
<%= opengraph %>
<%= javascript_tag "window.addEventListener('load', () => Spotlight.sirTrevorIcon = '#{asset_path('spotlight/blocks/sir-trevor-icons.svg')}')" %>
<%= javascript_tag '$.fx.off = true;' if Rails.env.test? %>
</head>
<body class="<%= render_body_class %>">
<%= render partial: 'shared/body_preamble' %>
<div id="skip-link">
<% if should_render_spotlight_search_bar? %>
<%= link_to t('blacklight.skip_links.search_field'), '#search_field', class: 'element-invisible element-focusable rounded-bottom py-2 px-3', data: { turbolinks: 'false' } %>
<% end %>
<%= link_to t('blacklight.skip_links.main_content'), '#main-container', class: 'element-invisible element-focusable rounded-bottom py-2 px-3', data: { turbolinks: 'false' } %>
<%= content_for(:skip_links) %>
</div>

<%= render partial: 'shared/header_navbar' %>
<%= render partial: 'shared/masthead' %>
<%= content_for?(:header_content) ? yield(:header_content) : "" %>

<main id="main-container" class="<%= container_classes %>" role="main" aria-label="<%= t('blacklight.main.aria.main_container') %>">
<%= content_for(:container_header) %>

<%= render partial: 'shared/flash_msg', layout: 'shared/flash_messages' %>

<div class="row">
<%= content_for?(:content) ? yield(:content) : yield %>
</div>
</main>

<%= render partial: 'shared/footer' %>
<%= render partial: 'shared/modal' %>
</body>
<% end %>
7 changes: 5 additions & 2 deletions app/views/shared/_i18n_js.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<%= javascript_tag do %>
I18n.defaultLocale = "<%= I18n.default_locale %>";
I18n.locale = "<%= I18n.locale %>";
window.addEventListener('load', () => {
console.log("SPOT", window.Spotlight)
I18n.defaultLocale = "<%= I18n.default_locale %>";
I18n.locale = "<%= I18n.locale %>";
})
<% end %>
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"
19 changes: 19 additions & 0 deletions config/importmap.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Pin npm packages by running ./bin/importmap

pin "application", preload: true
pin "jquery", to: "https://ga.jspm.io/npm:[email protected]/dist/jquery.js", preload: true
pin "bootstrap", to: "https://ga.jspm.io/npm:[email protected]/dist/js/bootstrap.js"
pin "popper.js", to: "https://ga.jspm.io/npm:[email protected]/dist/umd/popper.js"
pin "@hotwired/turbo-rails", to: "https://ga.jspm.io/npm:@hotwired/[email protected]/app/javascript/turbo/index.js"
pin "@hotwired/turbo", to: "https://ga.jspm.io/npm:@hotwired/[email protected]/dist/turbo.es2017-esm.js"
pin "@rails/actioncable/src", to: "https://ga.jspm.io/npm:@rails/[email protected]/src/index.js"
pin "leaflet", to: "https://ga.jspm.io/npm:[email protected]/dist/leaflet-src.js"
pin_all_from Blacklight::Engine.root.join('app/assets/javascripts/blacklight/'), under: 'blacklight'
pin_all_from Spotlight::Engine.root.join('app/assets/javascripts/spotlight/'), under: 'spotlight'
pin "sir-trevor", to: "https://ga.jspm.io/npm:[email protected]/build/sir-trevor.js"
pin "clipboard", to: "https://ga.jspm.io/npm:[email protected]/lib/clipboard.js"
pin "delegate", to: "https://ga.jspm.io/npm:[email protected]/src/delegate.js"
pin "good-listener", to: "https://ga.jspm.io/npm:[email protected]/src/listen.js"
pin "select", to: "https://ga.jspm.io/npm:[email protected]/src/select.js"
pin "tiny-emitter", to: "https://ga.jspm.io/npm:[email protected]/index.js"
pin "i18n-js", to: "https://ga.jspm.io/npm:[email protected]/app/assets/javascripts/i18n.js"
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"@blueprintjs/core": "^4.13.0",
"@blueprintjs/icons": "^4.11.0",
"babel-loader": "8",
"blacklight-frontend": "^7",
"browser": "^0.2.6",
"compression-webpack-plugin": "9",
"mirador": "^3.3.0",
Expand Down
Empty file added vendor/javascript/.keep
Empty file.
Loading

0 comments on commit 43b378f

Please sign in to comment.