Skip to content

Commit 3f4bd22

Browse files
authored
Merge pull request #2 from MITLibraries/support_additional_js
Adds support for adding arbitrary js libraries to HTML head
2 parents 3120bda + eecbad2 commit 3f4bd22

5 files changed

Lines changed: 52 additions & 27 deletions

File tree

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,29 @@ If you have local overrides for styles, import them _after_ the shared styles.
3434

3535
You'll want to set `<%= content_for(:title, "SOMETHING") %>` on your views.
3636

37-
You'll want to copy `app/views/layouts/_site_nav.html.erb` into your local repo and make appropriate changes.
37+
You'll want to copy `app/views/layouts/_site_nav.html.erb` into your local
38+
repo and make appropriate changes.
39+
40+
`app/views/layouts/_site_footer.html.erb` is also available if you really need
41+
a third footer above the other two (I'm looking at you bento!).
3842

3943
If you need to make changes to other templates, you can also copy those to your local repo but you should check with others as the main header / footer / etc are probably best left as they are in this gem.
4044

45+
## Adding Additional JavaScript to HTML Head
46+
47+
You can load additional js to individual pages using:
48+
49+
```
50+
<% content_for :additional_js do %>
51+
<script>alert("hi");</script>
52+
<% end %>
53+
```
54+
55+
This can appear as many times as you need on as many templates as you need. If
56+
called multiple times the results are concatenated. This is intended primarily
57+
for adding external support libraries. For JS you are writing, include via
58+
`application.scss` as normal.
59+
4160
## Development
4261

4362
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

app/views/layouts/_head.html.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
<%= render partial: "layouts/js_exception_handler" %>
2020
<%= javascript_include_tag "application" %>
21+
22+
<%= yield :additional_js %>
23+
2124
<% if (ENV['GOOGLE_ANALYTICS']) %>
2225
<script type="text/javascript">
2326
// Google Analytics
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<div class="wrap-outer-footer layout-band">
2+
<div class="wrap-footer footer-slim">
3+
<div class="footer-main" aria-label="MIT Libraries footer">
4+
<div class="identity">
5+
<div class="wrap-logo-lib">
6+
<a href="https://libraries.mit.edu" class="logo-mit-lib" alt="MIT Libraries Logo">
7+
<span class="sr">MIT Libraries home</span>
8+
<%= image_tag("mitlib-wordmark.svg", :alt => "MIT Libraries logo") %>
9+
</a>
10+
</div>
11+
</div><!-- end .identity -->
12+
<div class="wrap-sitemap">
13+
<nav class="sitemap-libraries-abbrev" aria-label="MIT Libraries site menu">
14+
<h2 class="sr">MIT Libraries navigation</h2>
15+
<a class="item" href="https://libraries.mit.edu/">Home</a>
16+
<a class="item" href="https://libraries.mit.edu/search">Search</a>
17+
<a class="item" href="https://libraries.mit.edu/hours">Hours &amp; locations</a>
18+
<a class="item" href="https://libraries.mit.edu/borrow">Borrow &amp; request</a>
19+
<a class="item" href="https://libraries.mit.edu/research-support">Research support</a>
20+
<a class="item" href="https://libraries.mit.edu/about">About the Libraries</a>
21+
</nav>
22+
</div><!-- end .links-all -->
23+
</div>
24+
</div>
25+
</div>
Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1 @@
1-
<div class="wrap-outer-footer layout-band">
2-
<div class="wrap-footer footer-slim">
3-
<div class="footer-main" aria-label="MIT Libraries footer">
4-
<div class="identity">
5-
<div class="wrap-logo-lib">
6-
<a href="https://libraries.mit.edu" class="logo-mit-lib" alt="MIT Libraries Logo">
7-
<span class="sr">MIT Libraries home</span>
8-
<%= image_tag("mitlib-wordmark.svg", :alt => "MIT Libraries logo") %>
9-
</a>
10-
</div>
11-
</div><!-- end .identity -->
12-
<div class="wrap-sitemap">
13-
<nav class="sitemap-libraries-abbrev" aria-label="MIT Libraries site menu">
14-
<h2 class="sr">MIT Libraries navigation</h2>
15-
<a class="item" href="https://libraries.mit.edu/">Home</a>
16-
<a class="item" href="https://libraries.mit.edu/search">Search</a>
17-
<a class="item" href="https://libraries.mit.edu/hours">Hours &amp; locations</a>
18-
<a class="item" href="https://libraries.mit.edu/borrow">Borrow &amp; request</a>
19-
<a class="item" href="https://libraries.mit.edu/research-support">Research support</a>
20-
<a class="item" href="https://libraries.mit.edu/about">About the Libraries</a>
21-
</nav>
22-
</div><!-- end .links-all -->
23-
</div>
24-
</div>
25-
</div>
1+
<%# This template can be used to place content at the bottom of each page above the libraries and institute footers %>

app/views/layouts/application.html.erb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<%= render partial: "layouts/global_alert" %>
1212

1313
<%= render partial: "layouts/site_header" %>
14+
1415
<%= render partial: "layouts/site_nav" %>
1516

1617
<div class="wrap-outer-content layout-band">
@@ -20,6 +21,7 @@
2021

2122
<%= yield %>
2223

24+
<%= render partial: "layouts/site_footer" %>
2325
</main>
2426
<!-- close content-main -->
2527
</div>
@@ -28,7 +30,7 @@
2830
<script src="https://use.fontawesome.com/38304317ff.js"></script>
2931

3032
<footer>
31-
<%= render partial: "layouts/site_footer" %>
33+
<%= render partial: "layouts/libraries_footer" %>
3234
<%= render partial: "layouts/institute_footer" %>
3335
</footer>
3436
</div>

0 commit comments

Comments
 (0)