Skip to content

Commit b899f20

Browse files
authored
Dynamic Logo/Background Image
* Navigation link ordering does not persist (#291) - orders link options by the navigation link order to ensure that order of selected options are preserved across saves - fixes flaky feature website/configuration_spec.rb to be more explicit about slug path [Navigation link ordering does not persist](https://miro.com/app/board/uXjVO6C1LxA=/?moveToWidget=3458764525170508650&cot=14) * Dynamic Logo/Background Image - Adds ability to embed the logo image or background image to a page - Updates templates to use custom dynamic tags - Updates website documentation about custom logo and background tags * Adds links with anchors to documentation
1 parent 8794cb5 commit b899f20

13 files changed

+90
-30
lines changed

app/decorators/website_decorator.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ def background_style
6161
{ style: "background-image: url('#{h.url_for(background)}');" }
6262
end
6363

64+
def background_style_html
65+
background_style.map {|key, value| "#{key} = \"#{value}\""}.join(' ').html_safe
66+
end
67+
6468
def session_format_configs
6569
event.session_formats.map.with_index do |session_format, index|
6670
SessionFormatConfig.find_or_initialize_by(session_format: session_format) do |config|
@@ -82,7 +86,7 @@ def link_options
8286
@link_options ||= pages.published.pluck(:name, :slug)
8387
.each_with_object(DEFAULT_LINKS.dup) do |(name, slug), memo|
8488
memo[name] = slug
85-
end
89+
end.sort_by { |_key, value| navigation_links.index(value) || 0 }.to_h
8690
end
8791

8892
def tracks

app/helpers/image_helper.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module ImageHelper
22
def resize_image_tag(image, width:, height: width)
3+
width ||= 100
34
return unless image.attached?
45
if image.content_type.match('svg')
56
image_tag(image, width: width)

app/helpers/page_helper.rb

+26-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,38 @@ module PageHelper
22
TAGS = {
33
"<sponsors-banner-adds></sponsors-banner-adds>" => "sponsors/banner_ads", #DEPRECATED spelling mistake
44
"<sponsors-banner-ads></sponsors-banner-ads>" => "sponsors/banner_ads",
5-
"<sponsors-footer></sponsors-footer>" => "sponsors/sponsors_footer"
5+
"<sponsors-footer></sponsors-footer>" => "sponsors/sponsors_footer",
6+
/(<logo-image.*><\/logo-image>)/ => :logo_image,
7+
"background-image-style-url" => :background_style,
68
}
79

810
def embed(body)
911
body.tap do |body|
1012
TAGS.each do |tag, template|
11-
body.gsub!(tag, render(template: template, layout: false))
13+
body.gsub!(tag) do
14+
args = tag.is_a?(Regexp) ? extract($1) : {}
15+
case template
16+
when String
17+
render(**args.merge(template: template, layout: false))
18+
when Symbol
19+
send(template, **args)
20+
end
21+
end
1222
end
1323
end.html_safe
1424
end
25+
26+
def extract(tag)
27+
fragment = Nokogiri::HTML.fragment(tag)
28+
tag_name = fragment.children.first.name
29+
fragment.at(tag_name).to_h.symbolize_keys
30+
end
31+
32+
def background_style
33+
current_website.background_style_html
34+
end
35+
36+
def logo_image(args)
37+
resize_image_tag(current_website.logo, **args)
38+
end
1539
end

app/helpers/website_helper.rb

+14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module WebsiteHelper
2+
DOCS_PAGE = "https://github.com/rubycentral/cfp-app/blob/main/docs/website_documentation.md".freeze
23
def website_event_slug
34
params[:slug] || (@older_domain_website && @older_domain_website.event.slug)
45
end
@@ -8,4 +9,17 @@ def font_file_label(font)
89
label.concat(" (Current File: #{font.file.filename.to_s})") if font.file.attached?
910
end
1011
end
12+
13+
def legend_with_docs(title)
14+
content_tag("legend", class: "fieldset-legend") do
15+
concat(title)
16+
concat(link_to_docs(title.parameterize))
17+
end
18+
end
19+
20+
def link_to_docs(anchor)
21+
link_to(DOCS_PAGE + "##{anchor}", target: "_blank") do
22+
content_tag("i", nil, class: "fa fa-fw fa-question-circle")
23+
end
24+
end
1125
end

app/views/staff/pages/_form.html.haml

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
%div{ data: { "editor-target": :html } }
2020
= f.input :unpublished_body,
2121
as: :text,
22+
label: "Unpublished Body #{link_to_docs("codemirror")}".html_safe,
2223
input_html: { data: { "editor-target": :htmlContent } }
2324
= link_to("WYSIWYG", '#', { data: { action: "click->editor#wysiwyg" } })
2425
.resize

app/views/staff/pages/index.html.haml

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
%th Slug
1616
%th Published
1717
%th Landing Page
18-
%th Actions
18+
%th
19+
Actions
20+
= link_to_docs("previewing")
1921
%tbody
2022
= render @pages
2123
%hr

app/views/staff/pages/new.html.haml

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
.row
22
.col-md-12
33
.page-header.clearfix
4-
%h1 New Website Page
4+
%h1
5+
New Website Page
6+
= link_to_docs("page-content-management")
57
= simple_form_for(:page, url: new_event_staff_page_path, method: :get) do |f|
68
= f.input(:template,
7-
label: "Start from scratch or choose a template below",
9+
label: "Start from scratch or choose a template below #{link_to_docs("page-templates")}".html_safe,
810
required: false,
911
collection: Page::TEMPLATES.keys,
1012
include_blank: true,

app/views/staff/pages/themes/default/home.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="pb-6 w-screen z-0 relative" style="background-image: url('<%= url_for(current_website.background) %>');" >
1+
<div class="pb-6 w-screen z-0 relative" background-image-style-url>
22
<div class="pt-8 w-full flex flex-col items-center lg:items-start lg:flex-row lg:justify-between h-full max-w-5xl mx-auto">
33
<div class="lg:w-1/2 pl-12 mb-6 lg:mb-0 lg:pt-8 z-10">
44
<h2 class="text-3xl font-semibold mb-3">Maecenas faucibus mollis interdum. Etiam porta sem malesuada magna mollis euismod. Nulla vitae elit libero, a pharetra augue.</h2>

app/views/staff/pages/themes/default/splash.html.erb

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
<%= content_tag(:div,
2-
**current_website.background_style,
3-
class: "flex relative h-screen") do %>
1+
<div class="flex relative h-screen" background-image-style-url>
42
<div class="flex flex-col justify-between z-10 bg-black bg-opacity-80 text-white p-8 w-full h-full">
53
<div class="flex justify-between flex-col sm:flex-row">
64
<div class="flex flex-col mb-2">
@@ -27,7 +25,7 @@
2725
</div>
2826
</div>
2927
<div class="flex flex-col items-start w-full my-4 sm:items-center">
30-
<%= resize_image_tag(current_website.logo, width: 175) %>
28+
<logo-image width=175></logo-image>
3129
<div class="text-2xl font-semibold mt-4"><%= current_website.name %></div>
3230
<div class="text-xl font-semibold"><%= current_website.city %></div>
3331
<div class="text-2xl font-semibold mt-4 mb-2"><%= current_website.date_range %></div>
@@ -49,4 +47,4 @@
4947
) %>
5048
</div>
5149
</div>
52-
<% end %>
50+
</div>

app/views/staff/websites/_form.html.haml

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.row
33
.col-md-6
44
%fieldset
5-
%legend.fieldset-legend General Content
5+
= legend_with_docs("General Content")
66
= image_input(f, :logo)
77
= image_input(f, :background)
88
= image_input(f, :favicon)
@@ -11,7 +11,7 @@
1111
= f.input :directions
1212
= f.input :prospectus_link
1313
%fieldset
14-
%legend.fieldset-legend Navigation and Footer
14+
= legend_with_docs("Navigation and Footer")
1515
= f.label :navigation_links
1616
= f.select :navigation_links,
1717
website.link_options,
@@ -29,7 +29,7 @@
2929
= f.input :instagram_url
3030
.col-md-6
3131
%fieldset
32-
%legend.fieldset-legend Configure Website Session Formats
32+
= legend_with_docs("Configure Website Session Formats")
3333
= f.simple_fields_for :session_format_configs do |ff|
3434
.session-format-name
3535
= "Configure #{ff.object.session_format.name}"
@@ -40,7 +40,7 @@
4040
= ff.hidden_field :session_format_id
4141

4242
%div{"data-controller": "nested-form", class: "nested-fonts"}
43-
%h4 Fonts
43+
=legend_with_docs("Fonts")
4444
%template{"data-nested-form-target": "template"}
4545
= f.simple_fields_for :fonts,
4646
Website::Font.new,
@@ -53,7 +53,7 @@
5353
data: { action: "click->nested-form#add_association" }
5454

5555
%div{"data-controller": "nested-form"}
56-
%legend.fieldset-legend Head and Footer Content
56+
= legend_with_docs("Head and Footer Content")
5757
%template{"data-nested-form-target": "template"}
5858
= f.simple_fields_for :contents,
5959
Website::Content.new,
@@ -65,14 +65,14 @@
6565
= link_to "Add Content", "#", class: 'btn btn-success',
6666
data: { action: "click->nested-form#add_association" }
6767

68-
%legend.fieldset-legend Meta Data
68+
= legend_with_docs("Meta Data")
6969
= f.simple_fields_for :meta_data, website.meta_data do |ff|
7070
= ff.input :title
7171
= ff.input :author
7272
= ff.input :description
7373
= image_input(ff, :image)
7474

75-
%legend.fieldset-legend Domains/Caching
75+
= legend_with_docs("Domains and Caching")
7676
= f.input :domains
7777
= f.input :caching, collection: Website.cachings, include_blank: false
7878
.row

docs/website_documentation.md

+20-6
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@ show up in static page content that is generated from [Page Templates](#page-tem
2929
Logo, background and favicon images can be uploaded and will be stored in s3 and
3030
resized as needed using Rails' builtin
3131
[ActiveStorage](https://edgeguides.rubyonrails.org/active_storage_overview.html)).
32-
The background image can be used by setting a url for a `background-image` style
33-
in appropriate html tags in static page content. Other general content fields
32+
The logo and background images are used in the header and footer and some page
33+
templates but can also be applied dynamically in any page using the [logo and
34+
background custom tags](#logo-and-background).
35+
36+
Other general content fields
3437
include:
3538

3639
- City: the city for the event (can include the state if desired).
@@ -182,7 +185,7 @@ website including title, description, open graph and twitter tags. Fields includ
182185
- image: a file field for uploading an image that will populate the url for
183186
`og:image` and `twitter:image`
184187

185-
### Domains/Caching
188+
### Domains and Caching
186189

187190
#### Domain Configuration
188191

@@ -316,15 +319,28 @@ the link below the editor block. Note that this editor has its own opionionated
316319
way of adding and editing the html and it is likely that someone more familiar
317320
with html will need to refine the content that has been added.
318321

319-
### Custom Sponsor Tags
322+
### Custom Tags
320323

324+
#### Sponsors
321325
Sponsor information can be embedded into any static page by adding some custom
322326
sponsor tags. Adding a `<sponsors-banner-ads></sponsors-banner-ads>` will add a
323327
rotating banner of the uploaded sponsors ads. Adding
324328
`<sponsors-footer></sponsors-footer>` will provide a complete list of the
325329
sponsors with their logos and description grouped by tiers typically added to
326330
the bottom of a page.
327331

332+
#### Logo and Background
333+
You can also embed the current logo image into the page by adding the
334+
`<logo-image width="150"></logo-image>` tag into the page with whatever width
335+
you want for the logo in pixels.
336+
337+
If you want to add the website background image as a background image style then
338+
add the `background-image-style-url` as an attribute to your tag like `<div
339+
background-image-style-url></div>`. If you need to further customize that tag
340+
you will not be able to add inline styles so we recommend using tailwind
341+
classes. For example to make the background image repeating this should work:
342+
`<div class="bg-repeat" background-image-style-url></div>`.
343+
328344
### Saving
329345

330346
Content is **not auto-saved** so be sure to save any wanted changes. As a bit of
@@ -361,8 +377,6 @@ url for the website. Clicking on the `Promote` button on the Pages index page
361377
will promote the selected page. You can see which page is currently promoted in
362378
the `Landing Page` column of the Page index page.
363379

364-
### Hiding the Header or Footer
365-
366380
### Other Buttons
367381

368382
It is probably obvious that you can edit a page by clicking the `Edit` button

spec/features/website/configuration_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
click_on(home_page.name, match: :first)
4646

47-
expect(current_path).to eq('/home')
47+
expect(current_path).to eq("/#{home_page.slug}")
4848
end
4949

5050
scenario "Organizer fails to add font file correctly", :js do

spec/features/website/page_management_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,14 @@
108108

109109
scenario "Organizer hides navigation to a page and hides a page entirely", :js do
110110
home_page = create(:page, published_body: 'Home Content')
111-
website.update(navigation_links: [home_page.slug])
111+
website.update(navigation_links: [home_page.slug, "schedule"])
112112
visit page_path(slug: event.slug, page: home_page.slug)
113-
expect(page).to have_content('Home Content')
114-
within('#main-nav') { expect(page).to have_link(home_page.name) }
113+
within('#main-nav') { expect(page).to have_content(home_page.name) }
115114

116115
login_as(organizer)
117116
visit edit_event_staff_website_path(event)
118-
find_field('Navigation links').send_keys(:backspace)
117+
expect(page).to have_content("Navigation links\nHomeSchedule")
118+
find_field('Navigation links').send_keys(:backspace).send_keys(:backspace)
119119
fill_in('Navigation links', with: "Schedule\n")
120120
click_on("Save")
121121

0 commit comments

Comments
 (0)