Skip to content

Commit

Permalink
Allow setting a title for the page
Browse files Browse the repository at this point in the history
  • Loading branch information
davidalejandroaguilar committed Nov 26, 2024
1 parent 5bac1ef commit e422e67
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
6 changes: 5 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
class ApplicationController < ActionController::Base
layout -> { ApplicationLayout }
layout -> { ApplicationLayout.new(title:) }

protect_from_forgery with: :exception

def title
nil
end
end
6 changes: 6 additions & 0 deletions app/controllers/docs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ def view_class
def doc_name
params[:doc_name]
end

def title
"PhlexyUI - #{doc_name.humanize}"
rescue
nil
end
end
6 changes: 6 additions & 0 deletions app/controllers/examples_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@ def component_name
def component
Component.from_name(component_name.to_s.camelize)
end

def title
"PhlexyUI - #{component.name}"
rescue
nil
end
end
14 changes: 9 additions & 5 deletions app/views/layouts/application_layout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ class ApplicationLayout < ApplicationView
include Phlex::Rails::Helpers::TurboFrameTag
include Phlex::Rails::Helpers::ImagePath

def initialize(title: nil)
@title = title
end

def view_template(&block)
doctype

html class: "overscroll-auto sm:overscroll-y-none", data: {theme: helpers.session[:theme] || :light} do
head do
title { "PhlexyUI Docs" }
title { @title || "PhlexyUI Docs" }
meta name: "viewport", content: "width=device-width,initial-scale=1"
csp_meta_tag
csrf_meta_tags
Expand Down Expand Up @@ -63,12 +67,12 @@ def view_template(&block)

meta(
name: "apple-mobile-web-app-title",
content: "PhlexyUI Docs"
content: @title || "PhlexyUI Docs"
)

meta(
name: "application-name",
content: "PhlexyUI Docs"
content: @title || "PhlexyUI Docs"
)

meta(
Expand All @@ -92,15 +96,15 @@ def view_template(&block)
# Facebook meta tags
meta property: "og:url", content: "https://phlexyui.com/"
meta property: "og:type", content: "website"
meta property: "og:title", content: "PhlexyUI Docs"
meta property: "og:title", content: @title || "PhlexyUI Docs"
meta property: "og:description", content: "PhlexyUI is a component library built with Phlex, a Ruby gem for building fast object-oriented HTML components. On top of DaisyUI, the most popular component library for Tailwind CSS."
meta property: "og:image", content: image_path("phlexy_ui_og.png")

# X meta tags
meta name: "twitter:card", content: "summary_large_image"
meta property: "twitter:domain", content: "phlexyui.com"
meta property: "twitter:url", content: "https://phlexyui.com/"
meta name: "twitter:title", content: "PhlexyUI Docs"
meta name: "twitter:title", content: @title || "PhlexyUI Docs"
meta name: "twitter:description", content: "PhlexyUI is a component library built with Phlex, a Ruby gem for building fast object-oriented HTML components. On top of DaisyUI, the most popular component library for Tailwind CSS."
meta name: "twitter:image", content: image_path("phlexy_ui_og.png")

Expand Down

0 comments on commit e422e67

Please sign in to comment.