Skip to content

Instantly share code, notes, and snippets.

@mig
Created October 20, 2008 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mig/18120 to your computer and use it in GitHub Desktop.
Save mig/18120 to your computer and use it in GitHub Desktop.
meta tag helper
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<%= yield_page_info %>
</head>
<body>
<%= yield %>
</body>
</html>
def yield_page_info(options = {})
controller = @controller.controller_name
action = @controller.action_name
data = YAML.load_file(RAILS_ROOT + "/config/page_info.yml")
default_title = options[:default_title] || data["default"]["title"]
if data[controller] && data[controller][action]
page = data[controller][action]
else
page = {
"title" => default_title,
"description" => "",
"keywords" => "",
"robots" => ""
}
end
returning output = "" do |out|
out << content_tag(:title, page["title"])
out << tag(:meta, :name => "description", :content => page["description"]) + "\n" if page["description"]
out << tag(:meta, :name => "keywords", :content => page["keywords"]) + "\n" if page["keywords"]
out << tag(:meta, :name => "robots", :content => page["robots"]) if page["robots"]
end
end
default:
title: Default Site Title
public:
index:
title: public_controller.rb title
description: description meta tag contents
keywords: public, awesome
robots: index, follow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment