Created
October 20, 2008 18:00
-
-
Save mig/18120 to your computer and use it in GitHub Desktop.
meta tag helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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