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

Move towards import maps #1094

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions app/assets/javascripts/ace_config.js

This file was deleted.

12 changes: 1 addition & 11 deletions app/assets/javascripts/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@
//= require cookies_eu

//= require angular/angular
//= require ace-builds/src-min-noconflict/ace
//= require ace-builds/src-min-noconflict/ext-language_tools
//= require ace-builds/src-min-noconflict/mode-json
//= require ace-builds/src-min-noconflict/mode-javascript
//= require ace-builds/src-min-noconflict/mode-lucene


//= require vega
//= require vega-lite
Expand Down Expand Up @@ -75,12 +71,6 @@
//= require_tree ./factories
//= require_tree ./filters
//= require_tree ./interceptors
//= require_tree ./services
//= require_tree ./values
//= require_tree ../templates
//= require_tree ./components
//= require footer
//= require tether-shepherd/dist/js/tether
//= require tether-shepherd/dist/js/shepherd
//= require tour
//= require ace_config
2 changes: 1 addition & 1 deletion app/assets/stylesheets/core.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
@import "admin2";

// Tour/Guides
@import "tether-shepherd/dist/css/shepherd-theme-arrows";
@import "shepherd.js/dist/css/shepherd";
@import "tour";

// Screens
Expand Down
22 changes: 10 additions & 12 deletions app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,27 @@

class PagesController < ApplicationController
skip_before_action :require_login
skip_before_action :verify_authenticity_token, only: [ :theme_textmate, :mode_json ]
skip_before_action :verify_authenticity_token, only: [:worker_javascript, :worker_json ]
skip_before_action :check_for_announcement
# before_action :check_page, only: [:show]

# def show
# render template: "pages/#{params[:page]}"
# end

# this is how we deal with the ACE editor wanting this specific file.

def theme_textmate
path = 'node_modules/ace-builds/src-min-noconflict/theme-textmate.js'
# ace wants to always load the workers from the root "/" end point. So /worker-javascript.js and /worker-json.s
# It defines it's own full path, so we can't override it with one from importmaps
def worker_javascript
path = 'node_modules/ace-builds/src-min-noconflict/worker-javascript.js'
file_contents = File.read(path)
render js: file_contents, content_type: Mime::Type.lookup('application/javascript')
end

# In production this route kicks in, and in dev we load /assets/mode-json.js from
# the /app/assets/javascripts/mode-json.js location..
def mode_json
path = 'node_modules/ace-builds/src-min-noconflict/mode-json.js'

def worker_json
path = 'node_modules/ace-builds/src-min-noconflict/worker-json.js'
file_contents = File.read(path)
render js: file_contents, content_type: Mime::Type.lookup('application/javascript')
end
end

private

Expand Down
47 changes: 43 additions & 4 deletions app/javascript/application2.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,47 @@
// Note: the file in vendor/javascript/vendored-local-time.js is the one that was downloaded via
// importmap pin. See https://github.com/basecamp/local_time/issues/113 for others who suggested
// remaining it
import "@hotwired/turbo-rails"
import LocalTime from "local-time"
LocalTime.start()
//import "@hotwired/turbo-rails"
//import LocalTime from "local-time"
//LocalTime.start()

window.Turbo.setProgressBarDelay(1);
//window.Turbo.setProgressBarDelay(1);

import "ace"; // Import the Ace library
import "ext-language_tools"; // Import the JavaScript mode
import "mode-json"; // Import the Monokai theme
import "mode-javascript";
import "mode-lucene";
import "theme-chrome";
//import "worker-javascript"
//import "ace_config"

//import "tour" // Can't figure out how to get Shepherd.js to load
import "footer"

// Importing services
import "annotationsSvc";
import "bookSvc";
import "bootstrapSvc";
import "caseCSVSvc";
import "caseSvc";
import "caseTryNavSvc";
import "configurationSvc";
import "diffResultsSvc";
import "docCacheSvc";
import "importRatingsSvc";
import "paneSvc";
import "queriesSvc";
import "querySnapshotSvc";
import "queryViewSvc";
import "rateBulkSvc";
import "rateElementSvc";
import "ratingsStoreSvc";
import "scorerControllerActionsSvc";
import "scorerSvc";
import "searchEndpointSvc";
import "searchErrorTranslatorSvc";
import "settingsSvc";
import "teamSvc";
import "userSvc";
import "varExtractorSvc";
2 changes: 2 additions & 0 deletions app/views/layouts/core.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<%= stylesheet_link_tag 'ng-json-explorer/dist/angular-json-explorer', 'angular-wizard/dist/angular-wizard', 'ng-tags-input/build/ng-tags-input.min.css', 'ng-tags-input/build/ng-tags-input.bootstrap.min.css', media: 'all' %>
<%= csrf_meta_tags %>

<%= javascript_importmap_tags 'application2' %>

<base href="<%= ENV['RAILS_RELATIVE_URL_ROOT'] %>/">
</head>
<body ng-app="QuepidApp">
Expand Down
20 changes: 18 additions & 2 deletions config/importmap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,21 @@
# Pin npm packages by running ./bin/importmap

pin 'application2', preload: true
pin 'local-time', to: 'vendored-local-time.js' # @3.0.2
pin '@hotwired/turbo-rails', to: 'turbo.min.js'
#pin 'local-time', to: 'vendored-local-time.js' # @3.0.2
#pin '@hotwired/turbo-rails', to: 'turbo.min.js'

pin "ace", to: "ace-builds/src-min-noconflict/ace.js"
pin "ext-language_tools", to: "ace-builds/src-min-noconflict/ext-language_tools.js"
pin "mode-json", to: "ace-builds/src-min-noconflict/mode-json.js"
pin "mode-javascript", to: "ace-builds/src-min-noconflict/mode-javascript.js"
pin "mode-lucene", to: "ace-builds/src-min-noconflict/mode-lucene.js"
pin "theme-chrome", to: "ace-builds/src-min-noconflict/theme-chrome.js"
pin 'footer', preload: true

#pin 'services/annotationsSvc.js'
# Pin each JavaScript file in the app/javascript/custom directory
Dir.glob(Rails.root.join('app', 'assets', 'javascripts','services', '*.js')).each do |file|
pin File.basename(file, '.js'), to: "services/#{File.basename(file)}"
end

# pin 'tour' // Can't figure out how to get Shepherd.js to load
27 changes: 27 additions & 0 deletions config/initializers/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,32 @@
analytics.js ]
Rails.application.config.assets.precompile += %w[ application_spec.js ]

# need to precompile stuff for importmaps
# In the past we made a giant single jS file, and then precompiled it
# but now we list each individaul file.
Rails.application.config.assets.precompile += %w[ footer.js ace_config.js ]

# JS from AngularJS app
Dir.glob(Rails.root.join('app', 'assets', 'javascripts', 'services', '*.js')).each do |file|
#relative_path = Pathname.new(file).relative_path_from(Pathname.new(Rails.root)).to_s
#puts "File.basename(file): #{relative_path}"
Rails.application.config.assets.precompile << "services/#{File.basename(file, '.js')}"
end
Rails.application.config.assets.precompile += %w[
services/annotationsSvc.js
]

# JS from node modules
Rails.application.config.assets.precompile += %w[
ace-builds/src-min-noconflict/ace.js
ace-builds/src-min-noconflict/ext-language_tools.js
ace-builds/src-min-noconflict/mode-json.js
ace-builds/src-min-noconflict/mode-javascript.js
ace-builds/src-min-noconflict/mode-lucene.js
ace-builds/src-min-noconflict/theme-chrome.js
ace-builds/src-min-noconflict/worker-javascript.js
]

# CSS from node modules
Rails.application.config.assets.precompile += %w[
ng-json-explorer/dist/angular-json-explorer.css
Expand All @@ -27,5 +53,6 @@
ng-tags-input/build/ng-tags-input.bootstrap.min.css
]


# For some reason the mapping in core.css.scss isn't working, so do this.'
Rails.application.config.assets.paths << Rails.root.join('node_modules/bootstrap-icons/font')
6 changes: 3 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@
# get '*page' => 'pages#show'
#

# Deal with ACE Editor really really wanting this file here
get '/javascripts/ace/theme-textmate.js' => 'pages#theme_textmate'
get '/assets/mode-json.js' => 'pages#mode_json'
# Deal with ACE Editor really really wanting workers to be in specific urls.
get '/worker-javascript.js' => 'pages#worker_javascript'
get '/worker-json.js' => 'pages#worker_json'
end
# rubocop:enable Metrics/BlockLength
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
"ngclipboard": "^2.0.0",
"party-js": "^2.2.0",
"popper.js": "^1.16.1",
"shepherd.js": "^14.1.0",
"splainer-search": "2.33.0",
"tether-shepherd": "latest",
"vega": "^5.27.0"
},
"devDependencies": {
Expand Down
51 changes: 39 additions & 12 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.