Skip to content

Commit c9acfed

Browse files
Change the typography of the site (#283)
* Change the typography of the site - creates Website::Font model with has_many association to website - adds ability to upload multiple fonts using nested-form stimulus controller - adds css styles in heads for including font-face for website fonts and setting root font variables - adds ability to group checkboxes in nested form so that only one is selected - fixes strftime format for schedule dates to skip padding appease Capybara [Change the typography of the site](https://miro.com/app/board/uXjVO6C1LxA=/?moveToWidget=3458764523893333023&cot=14) * Adpply secondary body font to website elements Co-authored-by: Cody Brooks <[email protected]>
1 parent f59b5d9 commit c9acfed

File tree

18 files changed

+207
-14
lines changed

18 files changed

+207
-14
lines changed

app/assets/stylesheets/modules/_forms.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,9 @@ span[title="required"] {
5858
input.boolean {
5959
margin: 4px;
6060
}
61+
62+
.inline-form {
63+
display: flex;
64+
gap: 10px;
65+
align-items: center;
66+
}

app/assets/stylesheets/themes/default/application.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
--nav_link_hover: white;
1414
--main_content_background: white;
1515
--sans-serif-font: 'Rubik';
16+
--secondary-body-font: 'Rubik'
1617
}
1718

1819
html {
@@ -43,6 +44,7 @@ header + #content {
4344
}
4445

4546
p {
47+
font-family: var(--secondary-body-font);
4648
font-size: 14px;
4749
line-height: 21px;
4850
margin-bottom: 20px;

app/assets/stylesheets/themes/default/program.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
}
116116

117117
.session-abstract {
118+
font-family: var(--secondary-body-font);
118119
height: 6.25rem;
119120
font-size: 16px;
120121
font-weight: 400;
@@ -130,6 +131,7 @@
130131
}
131132

132133
.session-format-tag {
134+
font-family: var(--secondary-body-font);
133135
padding: 8px 10px 8px 50px;
134136
border: 1px solid $divider-light;
135137
border-radius: 100px;
@@ -155,6 +157,7 @@
155157
}
156158

157159
.track-tag {
160+
font-family: var(--secondary-body-font);
158161
font-size: 12px;
159162
padding: 7px 10px;
160163
border-radius: 20px;

app/controllers/staff/websites_controller.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ def website_params
5151
navigation_links: [],
5252
session_format_configs_attributes: [
5353
:id, :name, :display, :position, :session_format_id
54-
])
54+
],
55+
fonts_attributes: [
56+
:id, :name, :file, :_destroy, :primary, :secondary
57+
],
58+
)
5559
end
5660
end

app/decorators/website_decorator.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,28 @@ def session_format_tag_class(session_format)
107107
def session_format_name(session_format)
108108
object.session_format_configs.find_by(session_format: session_format).name
109109
end
110+
111+
def font_faces_css
112+
fonts.map do |font|
113+
<<~CSS
114+
@font-face {
115+
font-family: "#{font.name}";
116+
src: url('#{h.url_for(font.file)}');
117+
}
118+
CSS
119+
end.join("\n").html_safe
120+
end
121+
122+
def font_root_css
123+
font_primary = fonts.primary.first
124+
font_secondary = fonts.secondary.first
125+
126+
return "" unless font_primary || font_secondary
127+
<<~CSS.html_safe
128+
:root {
129+
#{"--sans-serif-font: '#{font_primary.name}' !important;" if font_primary}
130+
#{"--secondary-body-font: '#{font_secondary.name}' !important;" if font_secondary}
131+
}
132+
CSS
133+
end
110134
end

app/helpers/website_helper.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,10 @@ module WebsiteHelper
22
def website_event_slug
33
params[:slug] || (@older_domain_website && @older_domain_website.event.slug)
44
end
5+
6+
def font_file_label(font)
7+
"File".tap do |label|
8+
label.concat(" (Current File: #{font.file.filename.to_s})") if font.file.attached?
9+
end
10+
end
511
end

app/javascript/controllers/editor_controller.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ export default class extends Controller {
115115
}
116116

117117
leavingPage(event) {
118-
console.log(this.changedValue);
119118
if (this.changedValue) {
120119
event.returnValue = "Are you sure you want to leave with unsaved changes?";
121120
return event.returnValue;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { Controller } from "stimulus"
2+
3+
export default class extends Controller {
4+
static targets = [ "links", "template", "grouped" ]
5+
6+
connect() {
7+
this.wrapperClass = this.data.get("wrapperClass") || "nested-fields"
8+
}
9+
10+
add_association(event) {
11+
event.preventDefault()
12+
13+
var content = this.templateTarget.innerHTML.replace(/NEW_RECORD/g, new Date().getTime())
14+
this.linksTarget.insertAdjacentHTML('beforebegin', content)
15+
}
16+
17+
remove_association(event) {
18+
event.preventDefault()
19+
20+
let wrapper = event.target.closest("." + this.wrapperClass)
21+
22+
// New records are simply removed from the page
23+
if (wrapper.dataset.newRecord == "true") {
24+
wrapper.remove()
25+
26+
// Existing records are hidden and flagged for deletion
27+
} else {
28+
wrapper.querySelector("input[name*='_destroy']").value = 1
29+
wrapper.style.display = 'none'
30+
}
31+
}
32+
33+
radio_chosen(event) {
34+
var els = this.element.getElementsByClassName(event.target.classList[0])
35+
Array.from(els).forEach( (e) => {
36+
e.checked = false;
37+
});
38+
event.target.checked = true;
39+
}
40+
}

app/models/session_format_config.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,27 @@ def slug
99
session_format.name.parameterize.pluralize
1010
end
1111
end
12+
13+
# == Schema Information
14+
#
15+
# Table name: session_format_configs
16+
#
17+
# id :bigint(8) not null, primary key
18+
# website_id :bigint(8)
19+
# session_format_id :bigint(8)
20+
# position :integer
21+
# name :string
22+
# display :boolean
23+
# created_at :datetime not null
24+
# updated_at :datetime not null
25+
#
26+
# Indexes
27+
#
28+
# index_session_format_configs_on_session_format_id (session_format_id)
29+
# index_session_format_configs_on_website_id (website_id)
30+
#
31+
# Foreign Keys
32+
#
33+
# fk_rails_... (session_format_id => session_formats.id)
34+
# fk_rails_... (website_id => websites.id)
35+
#

app/models/website.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
class Website < ApplicationRecord
22
belongs_to :event
33
has_many :pages, dependent: :destroy
4+
has_many :fonts, class_name: 'Website::Font', dependent: :destroy
45

56
has_many :session_formats, through: :event
67
has_many :session_format_configs
8+
9+
accepts_nested_attributes_for :fonts, reject_if: :all_blank, allow_destroy: true
710
accepts_nested_attributes_for :session_format_configs
811

912
has_one_attached :logo

0 commit comments

Comments
 (0)