GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: MetaOnRails: a Rails plugin that DRYs up your page meta tags.
Homepage: http://blog.ashchan.com/archive/2008/06/25/meta-on-rails-plugin-for-meta-tags/
Clone URL: git://github.com/ashchan/meta_on_rails.git
finished basic logic [#1 state:resolved]
ashchan (author)
Wed Jun 25 02:10:35 -0700 2008
commit  b96c9ba8e64df539e085d8b10982aee102f75af1
tree    13f9ec66b3f7729b6c1d5dd64c041db74cee26ae
parent  6b2e770862e07fc9c930ab718f9e541c416c1fa3
...
1
 
2
3
4
...
 
1
2
3
4
0
@@ -1,4 +1,4 @@
0
-Copyright (c) 2008 [name of plugin creator]
0
+Copyright (c) 2008 James Chan
0
 
0
 Permission is hereby granted, free of charge, to any person obtaining
0
 a copy of this software and associated documentation files (the
0
...
1
2
3
4
5
6
 
 
 
 
 
 
 
7
8
9
 
 
 
 
 
 
 
10
11
 
 
12
 
 
 
 
 
 
 
 
 
 
 
 
13
14
...
1
2
3
 
4
 
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
0
@@ -1,14 +1,39 @@
0
 MetaOnRails
0
 ===========
0
 
0
-
0
 MetaOnRails DRYs up your page meta tags.
0
-todo
0
+
0
+It is a very simple plugin to help you customize your pages' meta tags a little bit easier.
0
+
0
+How to Install
0
+======
0
+./script/plugin install git://github.com/ashchan/meta_on_rails.git
0
+
0
 
0
 Example
0
 =======
0
+Add the following code to the layout (e.g. app/views/layout/application.html.erb), be sure to put it in the head tag:
0
+
0
+<head>
0
+<%= display_meta(:keywords => "default,keywords", :description => "default description") %>
0
+</head>
0
+
0
+Default meta values can be set. In the above example, these two meta tags will be generated if they're not override on the views:
0
 
0
-todo
0
+<meta name="description" content="default description" />
0
+<meta name="keywords" content="default,keywords" />
0
 
0
+Then add this code to the view to set meta tags on that page:
0
+
0
+<% set_meta(:keywords => 'my,keyword', :generator => 'a bad <script /> generator') %>
0
+
0
+The output html will be like this:
0
+
0
+<meta name="generator" content="a bad generator" />
0
+<meta name="description" content="default description" />
0
+<meta name="keywords" content="my,keyword" />
0
+
0
+
0
+=======
0
 
0
 Copyright (c) 2008 James Chan (ashchan), released under the MIT license
...
1
 
...
 
1
0
@@ -1 +1 @@
0
-# Include hook code here
0
+ActionView::Base.send :include, MetaOnRails
...
1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
0
@@ -1 +1,21 @@
0
-# MetaOnRails
0
+module MetaOnRails
0
+
0
+ def set_meta(meta = {})
0
+ @meta = meta
0
+ end
0
+
0
+ def display_meta(default = {})
0
+ @meta ||= {}
0
+ #@meta.reverse_merge!(default)
0
+ @meta = default.merge(@meta)
0
+ @meta.map do |m|
0
+ "<meta name=\"#{m[0]}\" content=\"#{normalize(m[1])}\" />"
0
+ end.join("\n")
0
+ end
0
+
0
+ private
0
+ def normalize(s)
0
+ s.gsub(/<\/?[^>]*>/, '')
0
+ end
0
+
0
+end
...
1
 
2
3
4
5
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
8
...
1
2
3
4
 
 
 
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
0
@@ -1,8 +1,24 @@
0
 require 'test/unit'
0
+require File.dirname(__FILE__) + '/../lib/meta_on_rails'
0
 
0
 class MetaOnRailsTest < Test::Unit::TestCase
0
- # Replace this with your real tests.
0
- def test_this_plugin
0
- flunk
0
+ include MetaOnRails
0
+
0
+ def test_should_have_default_values
0
+ output = display_meta(:keywords => 'default')
0
+ assert output.include?("<meta name=\"keywords\" content=\"default\"")
0
+ end
0
+
0
+ def test_should_strip_html
0
+ set_meta(:keywords => '<bong>aword</bong>')
0
+ output = display_meta
0
+ assert !output.include?("<bong>")
0
+ assert output.include?("aword")
0
+ end
0
+
0
+ def test_should_override_default_values
0
+ set_meta(:keywords => 'override')
0
+ output = display_meta(:keywords => 'default')
0
+ assert output.include?('override')
0
   end
0
 end

Comments

    No one has commented yet.