Add classes to content wrapper for articles and pages (#20731)
* Add classes to content wrapper for articles and pages * Add class name check * Fix org check
This commit is contained in:
parent
be53be46f0
commit
83878e9c10
4 changed files with 32 additions and 10 deletions
|
|
@ -107,8 +107,7 @@
|
|||
z-index: var(--z-sticky);
|
||||
|
||||
@media (min-width: $breakpoint-m) {
|
||||
border-top-left-radius: 0;
|
||||
border-top-right-radius: 0;
|
||||
border-radius: var(--radius-large);
|
||||
padding: 0;
|
||||
padding-bottom: 0;
|
||||
background: var(--body-bg);
|
||||
|
|
|
|||
|
|
@ -67,14 +67,29 @@ module ApplicationHelper
|
|||
#
|
||||
# rubocop:disable Rails/HelperInstanceVariable
|
||||
def view_class
|
||||
if @podcast_episode_show # custom due to edge cases
|
||||
"stories stories-show podcast_episodes-show"
|
||||
elsif @story_show
|
||||
"stories stories-show"
|
||||
else
|
||||
"#{controller_name} #{current_page}"
|
||||
end
|
||||
base_classes = if @podcast_episode_show # custom due to edge cases
|
||||
"stories stories-show podcast_episodes-show"
|
||||
elsif @story_show
|
||||
"stories stories-show"
|
||||
else
|
||||
"#{controller_name} #{current_page}"
|
||||
end
|
||||
base_classes += article_view_classes if @article&.class&.name&.start_with?("Article") # Article or ArticleDecorator
|
||||
base_classes += page_view_classes if @page&.class&.name&.start_with?("Page")
|
||||
base_classes
|
||||
end
|
||||
|
||||
def article_view_classes
|
||||
base_classes = " #{@article.decorate.cached_tag_list_array.map { |tag| "articletag-#{tag}" }.join(' ')}"
|
||||
base_classes += " articleuser-#{@article.user_id}"
|
||||
base_classes += " articleorg-#{@article.organization_id}" if @article.organization_id
|
||||
base_classes
|
||||
end
|
||||
|
||||
def page_view_classes
|
||||
" pageslug-#{@page.slug.gsub('/', '__SLASH__')}"
|
||||
end
|
||||
|
||||
# rubocop:enable Rails/HelperInstanceVariable
|
||||
|
||||
# This function derives the appropriate "title" given the page_title. Further it assigns the
|
||||
|
|
|
|||
|
|
@ -9,12 +9,13 @@ RSpec.describe "Pages" do
|
|||
expect(response.body).to include("/page/#{page.slug}")
|
||||
end
|
||||
|
||||
it "has proper headline for top-level" do
|
||||
it "has proper headline and classes for top-level" do
|
||||
page = create(:page, title: "Edna O'Brien96", is_top_level_path: true)
|
||||
get "/#{page.slug}"
|
||||
expect(response.body).to include(CGI.escapeHTML(page.title))
|
||||
expect(response.body).not_to include("/page/#{page.slug}")
|
||||
expect(response.body).to include("stories-show")
|
||||
expect(response.body).to include(" pageslug-#{page.slug}")
|
||||
end
|
||||
|
||||
context "when json template" do
|
||||
|
|
|
|||
|
|
@ -100,6 +100,13 @@ RSpec.describe "StoriesShow" do
|
|||
expect(response.body).not_to include("<span class=\"fs-xl color-base-70 block\">Hey this is a test</span>")
|
||||
end
|
||||
|
||||
it "renders proper wrapper content clases" do
|
||||
get article.path
|
||||
expect(response.body)
|
||||
.to include(" #{article.decorate.cached_tag_list_array.map { |tag| "articletag-#{tag}" }.join(' ')}")
|
||||
expect(response.body).to include(" articleuser-#{article.user_id}")
|
||||
end
|
||||
|
||||
###
|
||||
|
||||
it "renders date-no-year if article published this year" do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue