Class: Spotlight::Assets::PropshaftGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Spotlight::Assets::PropshaftGenerator
show all
- Includes:
- GeneratorCommonUtilities
- Defined in:
- lib/generators/spotlight/assets/propshaft_generator.rb
Overview
Spotlight Propshaft Generator
Instance Method Summary
collapse
#blacklight_yarn_version, #bootstrap_version, #bootstrap_yarn_version, #package_yarn_version, #spotlight_yarn_version
Instance Method Details
#add_blacklight_frontend ⇒ Object
35
36
37
|
# File 'lib/generators/spotlight/assets/propshaft_generator.rb', line 35
def add_blacklight_frontend
run "yarn add blacklight-frontend@#{blacklight_yarn_version}"
end
|
#add_bootstrap ⇒ Object
39
40
41
42
|
# File 'lib/generators/spotlight/assets/propshaft_generator.rb', line 39
def add_bootstrap
run "yarn add bootstrap@\"^#{bootstrap_yarn_version}\""
run 'yarn add @popperjs/core'
end
|
#add_frontend ⇒ Object
Pick a version of the frontend asset package and install it.
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/generators/spotlight/assets/propshaft_generator.rb', line 45
def add_frontend
if ENV['CI']
run "yarn add file:#{Spotlight::Engine.root}"
elsif options[:test]
run 'yarn link spotlight-frontend'
elsif ENV['BRANCH']
run 'yarn add spotlight-frontend@latest'
else
run "yarn add spotlight-frontend@#{spotlight_yarn_version}"
end
end
|
#add_javascript ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/generators/spotlight/assets/propshaft_generator.rb', line 63
def add_javascript
copy_file 'javascript/jquery-shim.js', 'app/javascript/jquery-shim.js'
gsub_file 'app/javascript/application.js', 'import "controllers"', '// import "controllers"'
insert_into_file 'app/javascript/application.js', "import githubAutoCompleteElement from \"@github/auto-complete-element\";\n"
append_to_file 'app/javascript/application.js' do
<<~CONTENT
import Spotlight from "spotlight-frontend"
Blacklight.onLoad(function() {
Spotlight.activate();
});
CONTENT
end
end
|
#add_stylesheets ⇒ Object
81
82
83
84
|
# File 'lib/generators/spotlight/assets/propshaft_generator.rb', line 81
def add_stylesheets
copy_file 'assets/spotlight.scss', 'app/assets/stylesheets/spotlight.scss'
append_to_file 'app/assets/stylesheets/application.bootstrap.scss', "\n@import \"spotlight\";\n"
end
|
86
87
88
89
90
91
92
93
|
# File 'lib/generators/spotlight/assets/propshaft_generator.rb', line 86
def configure_esbuild
custom_options = '--main-fields=main,module --alias:jquery=./app/javascript/jquery-shim.js'
custom_options = "#{custom_options} --preserve-symlinks" if options[:test]
gsub_file 'package.json',
'esbuild app/javascript/*.* --bundle --sourcemap --format=esm --outdir=app/assets/builds --public-path=/assets',
"esbuild app/javascript/*.* --bundle --sourcemap --format=esm --outdir=app/assets/builds --public-path=/assets #{custom_options}"
end
|
#install_dependencies ⇒ Object
26
27
28
29
30
31
32
33
|
# File 'lib/generators/spotlight/assets/propshaft_generator.rb', line 26
def install_dependencies
run 'yarn add @github/auto-complete-element'
run 'yarn add @hotwired/turbo-rails'
run 'yarn add clipboard'
run 'yarn add leaflet'
run 'yarn add sir-trevor'
run 'yarn add sortablejs'
end
|