# frozen_string_literal: true
def yarn(lib)
run("yarn add #{lib}")
end
run("yarn install")
generate(:controller, 'bootstrap', 'index')
yarn 'bootstrap@next'
yarn '@popperjs/core'
inject_into_file 'app/views/layouts/application.html.erb', after: "<%= csp_meta_tag %>\n" do <<~EOF
<%= stylesheet_pack_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
EOF
end
file 'app/javascript/stylesheets/application.scss' do <<~EOF
@import "bootstrap"
EOF
end
inject_into_file 'app/javascript/packs/application.js', after: "require(\"channels\")\n" do <<~EOF
import "bootstrap"
import "../stylesheets/application"
EOF
end
inject_into_file 'app/views/bootstrap/index.html.erb', after: "<p>Find me in app/views/bootstrap/index.html.erb</p>\n" do <<~EOF
<div class="spinner-border text-primary" role="status">
<span class="sr-only">Loading...</span>
</div>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
EOF
end
say "all done. start your server and navigate to http://localhost:3000/bootstrap/index to test that it's working"