nazca 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +88 -0
- data/MIT-LICENSE +20 -0
- data/README.markdown +65 -0
- data/Rakefile +11 -0
- data/lib/nazca.rb +3 -0
- data/lib/nazca/railtie.rb +16 -0
- data/lib/nazca/version.rb +3 -0
- data/lib/nazca/view_helpers.rb +67 -0
- data/nazca.gemspec +25 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/view_helpers_spec.rb +74 -0
- metadata +110 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
nazca (0.0.1)
|
5
|
+
rails (~> 3.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
abstract (1.0.0)
|
11
|
+
actionmailer (3.0.3)
|
12
|
+
actionpack (= 3.0.3)
|
13
|
+
mail (~> 2.2.9)
|
14
|
+
actionpack (3.0.3)
|
15
|
+
activemodel (= 3.0.3)
|
16
|
+
activesupport (= 3.0.3)
|
17
|
+
builder (~> 2.1.2)
|
18
|
+
erubis (~> 2.6.6)
|
19
|
+
i18n (~> 0.4)
|
20
|
+
rack (~> 1.2.1)
|
21
|
+
rack-mount (~> 0.6.13)
|
22
|
+
rack-test (~> 0.5.6)
|
23
|
+
tzinfo (~> 0.3.23)
|
24
|
+
activemodel (3.0.3)
|
25
|
+
activesupport (= 3.0.3)
|
26
|
+
builder (~> 2.1.2)
|
27
|
+
i18n (~> 0.4)
|
28
|
+
activerecord (3.0.3)
|
29
|
+
activemodel (= 3.0.3)
|
30
|
+
activesupport (= 3.0.3)
|
31
|
+
arel (~> 2.0.2)
|
32
|
+
tzinfo (~> 0.3.23)
|
33
|
+
activeresource (3.0.3)
|
34
|
+
activemodel (= 3.0.3)
|
35
|
+
activesupport (= 3.0.3)
|
36
|
+
activesupport (3.0.3)
|
37
|
+
arel (2.0.6)
|
38
|
+
builder (2.1.2)
|
39
|
+
diff-lcs (1.1.2)
|
40
|
+
erubis (2.6.6)
|
41
|
+
abstract (>= 1.0.0)
|
42
|
+
i18n (0.5.0)
|
43
|
+
mail (2.2.14)
|
44
|
+
activesupport (>= 2.3.6)
|
45
|
+
i18n (>= 0.4.0)
|
46
|
+
mime-types (~> 1.16)
|
47
|
+
treetop (~> 1.4.8)
|
48
|
+
mime-types (1.16)
|
49
|
+
polyglot (0.3.1)
|
50
|
+
rack (1.2.1)
|
51
|
+
rack-mount (0.6.13)
|
52
|
+
rack (>= 1.0.0)
|
53
|
+
rack-test (0.5.7)
|
54
|
+
rack (>= 1.0)
|
55
|
+
rails (3.0.3)
|
56
|
+
actionmailer (= 3.0.3)
|
57
|
+
actionpack (= 3.0.3)
|
58
|
+
activerecord (= 3.0.3)
|
59
|
+
activeresource (= 3.0.3)
|
60
|
+
activesupport (= 3.0.3)
|
61
|
+
bundler (~> 1.0)
|
62
|
+
railties (= 3.0.3)
|
63
|
+
railties (3.0.3)
|
64
|
+
actionpack (= 3.0.3)
|
65
|
+
activesupport (= 3.0.3)
|
66
|
+
rake (>= 0.8.7)
|
67
|
+
thor (~> 0.14.4)
|
68
|
+
rake (0.8.7)
|
69
|
+
rspec (2.4.0)
|
70
|
+
rspec-core (~> 2.4.0)
|
71
|
+
rspec-expectations (~> 2.4.0)
|
72
|
+
rspec-mocks (~> 2.4.0)
|
73
|
+
rspec-core (2.4.0)
|
74
|
+
rspec-expectations (2.4.0)
|
75
|
+
diff-lcs (~> 1.1.2)
|
76
|
+
rspec-mocks (2.4.0)
|
77
|
+
thor (0.14.6)
|
78
|
+
treetop (1.4.9)
|
79
|
+
polyglot (>= 0.3.1)
|
80
|
+
tzinfo (0.3.23)
|
81
|
+
|
82
|
+
PLATFORMS
|
83
|
+
ruby
|
84
|
+
|
85
|
+
DEPENDENCIES
|
86
|
+
nazca!
|
87
|
+
rails (~> 3.0)
|
88
|
+
rspec (~> 2.0)
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Jacek Galanciak
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# nazca
|
2
|
+
|
3
|
+
Nazca is a Rails 3 plugin to easily deal with all your `<title>` and `<meta>` tags, making your app more usable for people and more visible for search engines.
|
4
|
+
|
5
|
+
## Why?
|
6
|
+
|
7
|
+
Using instance variables for this purpose seemed so scruffy. Wrapping some code in this little plugin made my layout templates much smaller and cleaner as I could add all my meta tags in a single line of code.
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
<%= meta_tags "My awesome little site" %>
|
12
|
+
|
13
|
+
will yield `<title>My awesome little site</title>`.
|
14
|
+
|
15
|
+
|
16
|
+
# In views/posts/new.html.erb
|
17
|
+
<% title "Creating a post" %>
|
18
|
+
|
19
|
+
# In views/layouts/application.html.erb
|
20
|
+
<%= meta_tags "My awesome little site" %>
|
21
|
+
|
22
|
+
gives `<title>My awesome little site | Creating a new post</title>`.
|
23
|
+
|
24
|
+
You can specify the title inside a header tag as the `title` method returns the title itself:
|
25
|
+
|
26
|
+
<h1><%= title "Creating a post" %></h1>
|
27
|
+
|
28
|
+
You can reverse the order (ie. the subtitle first and the site name last):
|
29
|
+
|
30
|
+
<%= meta_tags "My awesome little site", :reverse => true %>
|
31
|
+
|
32
|
+
which yields `<title>Creating a new post | My awesome little site</title>`
|
33
|
+
|
34
|
+
It's possible to set custom separator
|
35
|
+
|
36
|
+
<%= meta_tags "My awesome little site", :reverse => true, :separator => "::" %>
|
37
|
+
<title>Creating a new post :: My awesome little site</title>
|
38
|
+
|
39
|
+
|
40
|
+
Setting description and keywords meta tag:
|
41
|
+
|
42
|
+
<% title "Creating a post" %>
|
43
|
+
<% keywords "omg,they,are,so,hot" %>
|
44
|
+
<% description "Cute girls programming Ruby." %>
|
45
|
+
<%= meta_tags "My awesome little site" %>
|
46
|
+
|
47
|
+
<title>My awesome little site | Creating a post</title>
|
48
|
+
<meta content="Cute girls programming Ruby." name="description" />
|
49
|
+
<meta content="omg,they,are,so,hot" name="keywords" />
|
50
|
+
|
51
|
+
## Why there are no controller methods to globally set up meta tags?
|
52
|
+
|
53
|
+
Because I respect MVC. Meta tags are views-specific.
|
54
|
+
|
55
|
+
## Ruby 1.9?
|
56
|
+
|
57
|
+
Yup. Do you still use 1.8?
|
58
|
+
|
59
|
+
## Rails 2?
|
60
|
+
|
61
|
+
Fork you.
|
62
|
+
|
63
|
+
## License
|
64
|
+
|
65
|
+
MIT.
|
data/Rakefile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'rspec/core'
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
task :default => :spec
|
7
|
+
desc "Run specs"
|
8
|
+
RSpec::Core::RakeTask.new do |t|
|
9
|
+
t.pattern = FileList['spec/**/*_spec.rb']
|
10
|
+
t.rspec_opts = %w(-fs --color)
|
11
|
+
end
|
data/lib/nazca.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'nazca'
|
2
|
+
require 'rails'
|
3
|
+
|
4
|
+
module Nazca
|
5
|
+
class Railtie < Rails::Railtie
|
6
|
+
def self.insert!
|
7
|
+
ActionView::Base.send(:include, Nazca::ViewHelpers)
|
8
|
+
end
|
9
|
+
|
10
|
+
initializer 'paperclip.insert_into_active_record' do
|
11
|
+
ActiveSupport.on_load :action_view do
|
12
|
+
Nazca::Railtie.insert!
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Nazca
|
2
|
+
module ViewHelpers
|
3
|
+
def tag!(tags = {})
|
4
|
+
@tags ||= {}
|
5
|
+
@tags.merge!(tags)
|
6
|
+
end
|
7
|
+
|
8
|
+
def title(t)
|
9
|
+
tag!(:title => normalize(t))
|
10
|
+
t
|
11
|
+
end
|
12
|
+
|
13
|
+
def keywords(k)
|
14
|
+
tag!(:keywords => normalize(k))
|
15
|
+
k
|
16
|
+
end
|
17
|
+
|
18
|
+
def description(d)
|
19
|
+
tag!(:description => normalize(d))
|
20
|
+
d
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def noindex
|
25
|
+
tag!(:noindex => true)
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
def nofollow(nofollow)
|
30
|
+
tag!(:nofollow => true)
|
31
|
+
end
|
32
|
+
|
33
|
+
def canonical(href)
|
34
|
+
tag!(:canonical => true)
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
def meta_tags(site_name, options = {})
|
39
|
+
result = ""
|
40
|
+
@tags ||= {}
|
41
|
+
|
42
|
+
options[:separator] ||= "|"
|
43
|
+
options[:reversed] ||= false
|
44
|
+
|
45
|
+
options.merge!(@tags)
|
46
|
+
|
47
|
+
if options[:title].to_s.length > 0 # maybe use ActiveSupport and .present? method
|
48
|
+
title = [site_name, options[:separator], options[:title]]
|
49
|
+
else
|
50
|
+
title = [site_name]
|
51
|
+
end
|
52
|
+
|
53
|
+
title.reverse! if options[:reverse]
|
54
|
+
result << content_tag(:title, title.join(' ').html_safe)
|
55
|
+
|
56
|
+
result << tag(:meta, :name => :description, :content => options[:description]) if options[:description]
|
57
|
+
result << tag(:meta, :name => :keywords, :content => options[:keywords]) if options[:keywords]
|
58
|
+
return result.html_safe
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
# Normalizes output string so that it's tags are stripped
|
63
|
+
def normalize(str)
|
64
|
+
str.gsub(/<\/?[^>]*>/, "")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/nazca.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "nazca/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "nazca"
|
7
|
+
s.version = Nazca::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Jacek Galanciak"]
|
10
|
+
s.email = ["jacek.galanciak@gmail.com"]
|
11
|
+
s.homepage = "http://razorjack.net"
|
12
|
+
s.summary = %q{Meta tags for Rails 3 views.}
|
13
|
+
s.description = %q{Rails 3 plugin that makes title and meta tags (keywords, description) easy and manageable.}
|
14
|
+
|
15
|
+
s.rubyforge_project = "nazca"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency("rails", ["~> 3.0"])
|
23
|
+
|
24
|
+
s.add_development_dependency "rspec", ["~> 2.0"]
|
25
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Nazca::ViewHelpers do
|
4
|
+
before :each do
|
5
|
+
@template = ActionView::Base.new
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should output base title only if there was no explicit title set earlier" do
|
9
|
+
@template.meta_tags("My site").should == "<title>My site</title>"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should return the title after setting it" do
|
13
|
+
@template.title("Test title").should == "Test title"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should display simple title" do
|
17
|
+
@template.title "Test title"
|
18
|
+
@template.meta_tags("My site").should == "<title>My site | Test title</title>"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should display simple title in reversed order with :reversed option" do
|
22
|
+
@template.title "Test title"
|
23
|
+
@template.meta_tags("My site", :reverse => true).should == "<title>Test title | My site</title>"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should strip tags from title" do
|
27
|
+
@template.title "OMG, just found 3 kg of <sup>235</sup>U in my attic"
|
28
|
+
@template.meta_tags("My site").should == "<title>My site | OMG, just found 3 kg of 235U in my attic</title>"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should deal with ampersand-escaped entities" do
|
32
|
+
@template.title "Uh, uh, time for some corporate ©!"
|
33
|
+
@template.meta_tags("My site").should == "<title>My site | Uh, uh, time for some corporate ©!</title>"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should change title separator with :separator option" do
|
37
|
+
@template.title "Test title"
|
38
|
+
@template.meta_tags("My site", :separator => "::").should == "<title>My site :: Test title</title>"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should display keywords meta tag (setting with meta_tags method)" do
|
42
|
+
@template.title "Test title"
|
43
|
+
@template.meta_tags("My site", :keywords => "my,key,word").should == "<title>My site | Test title</title><meta content=\"my,key,word\" name=\"keywords\" />"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should display keywords meta tag (setting with seperate method)" do
|
47
|
+
@template.title "Test title"
|
48
|
+
@template.keywords "my,key,word"
|
49
|
+
@template.meta_tags("My site").should == "<title>My site | Test title</title><meta content=\"my,key,word\" name=\"keywords\" />"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should add description meta tag (setting with meta_tags method)" do
|
53
|
+
@template.title "Test title"
|
54
|
+
@template.meta_tags("My site", :description => "Cute girls programming Ruby.").should == "<title>My site | Test title</title><meta content=\"Cute girls programming Ruby.\" name=\"description\" />"
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should add description meta tag (setting with seperate method)" do
|
58
|
+
@template.title "Test title"
|
59
|
+
@template.description "Cute girls programming Ruby."
|
60
|
+
@template.meta_tags("My site").should == "<title>My site | Test title</title><meta content=\"Cute girls programming Ruby.\" name=\"description\" />"
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should add both description and keywords meta tag" do
|
64
|
+
@template.title "Test title"
|
65
|
+
@template.description "Cute girls programming Ruby."
|
66
|
+
@template.keywords "my,key,word"
|
67
|
+
@template.meta_tags("My site").should == "<title>My site | Test title</title><meta content=\"Cute girls programming Ruby.\" name=\"description\" /><meta content=\"my,key,word\" name=\"keywords\" />"
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should be included in ActionView::Base" do
|
71
|
+
ActionView::Base.included_modules.should include Nazca::ViewHelpers
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nazca
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jacek Galanciak
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-01-08 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rails
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 7
|
30
|
+
segments:
|
31
|
+
- 3
|
32
|
+
- 0
|
33
|
+
version: "3.0"
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 2
|
47
|
+
- 0
|
48
|
+
version: "2.0"
|
49
|
+
type: :development
|
50
|
+
version_requirements: *id002
|
51
|
+
description: Rails 3 plugin that makes title and meta tags (keywords, description) easy and manageable.
|
52
|
+
email:
|
53
|
+
- jacek.galanciak@gmail.com
|
54
|
+
executables: []
|
55
|
+
|
56
|
+
extensions: []
|
57
|
+
|
58
|
+
extra_rdoc_files: []
|
59
|
+
|
60
|
+
files:
|
61
|
+
- .gitignore
|
62
|
+
- Gemfile
|
63
|
+
- Gemfile.lock
|
64
|
+
- MIT-LICENSE
|
65
|
+
- README.markdown
|
66
|
+
- Rakefile
|
67
|
+
- lib/nazca.rb
|
68
|
+
- lib/nazca/railtie.rb
|
69
|
+
- lib/nazca/version.rb
|
70
|
+
- lib/nazca/view_helpers.rb
|
71
|
+
- nazca.gemspec
|
72
|
+
- spec/spec_helper.rb
|
73
|
+
- spec/view_helpers_spec.rb
|
74
|
+
has_rdoc: true
|
75
|
+
homepage: http://razorjack.net
|
76
|
+
licenses: []
|
77
|
+
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
hash: 3
|
89
|
+
segments:
|
90
|
+
- 0
|
91
|
+
version: "0"
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
hash: 3
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
version: "0"
|
101
|
+
requirements: []
|
102
|
+
|
103
|
+
rubyforge_project: nazca
|
104
|
+
rubygems_version: 1.4.1
|
105
|
+
signing_key:
|
106
|
+
specification_version: 3
|
107
|
+
summary: Meta tags for Rails 3 views.
|
108
|
+
test_files:
|
109
|
+
- spec/spec_helper.rb
|
110
|
+
- spec/view_helpers_spec.rb
|