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

File tree

13 files changed

+90
-30
lines changed

13 files changed

+90
-30
lines changed

app/decorators/website_decorator.rb

Lines changed: 5 additions & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 26 additions & 2 deletions
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

Lines changed: 14 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 4 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 5 deletions
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

Lines changed: 7 additions & 7 deletions
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

0 commit comments

Comments
 (0)