sinatra-seo 0.2.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +7 -1
- data/lib/sinatra/seo.rb +7 -0
- data/spec/seo_spec.rb +52 -22
- data/spec/spec_helper.rb +10 -3
- metadata +2 -2
data/README.markdown
CHANGED
@@ -22,7 +22,13 @@ This library requires you to define the basic SEO information such as the title,
|
|
22
22
|
description: my About description goes here.
|
23
23
|
keywords: keyword4, keyword5, keyword6
|
24
24
|
|
25
|
-
Please note that we are naming each page as named in your *views/* directory. The three attributes you're required to fill (**title**, **description** and **keywords**) should be strings
|
25
|
+
Please note that we are naming each page as named in your *views/* directory. The three attributes you're required to fill (**title**, **description** and **keywords**) should be strings and these attributes also should have a maximum of characters or words as detailed below:
|
26
|
+
|
27
|
+
* the attribute **Title** should have a maximum of 60 characters.
|
28
|
+
* the attribute **Description** should have a maximum of 160 characters.
|
29
|
+
* the attribute **Keywords** should contain a maximum of 15 words.
|
30
|
+
|
31
|
+
Even tough this limitation usually spark a discussion among SEO specialists, I've decided to use the minimum number in order to make sure all the data you define for your pages is parsed by the search engines.
|
26
32
|
|
27
33
|
Now, as any other existing extension, there are two possible use cases in order to hook up your *site.seo* file to your application. If you follow the **Classic** approach, then you just need to require this extension in your *app.rb* file and then set the SEO file this extension should parse.
|
28
34
|
|
data/lib/sinatra/seo.rb
CHANGED
@@ -6,6 +6,13 @@ class OpenStruct
|
|
6
6
|
def new_ostruct_member(name)
|
7
7
|
name = name.to_sym
|
8
8
|
|
9
|
+
@table[name] = case name
|
10
|
+
when :title then @table[name][0, 60]
|
11
|
+
when :description then @table[name][0, 160]
|
12
|
+
when :keywords then @table[name].split(" ")[0, 15].join(" ")
|
13
|
+
else @table[name]
|
14
|
+
end
|
15
|
+
|
9
16
|
unless self.respond_to?(name)
|
10
17
|
class << self; self; end.class_eval do
|
11
18
|
define_method(name) {@table[name].is_a?(Hash) ? OpenStruct.new(@table[name]) : @table[name]}
|
data/spec/seo_spec.rb
CHANGED
@@ -29,33 +29,63 @@ describe Sinatra::Seo do
|
|
29
29
|
set :seo_file, './test.seo'
|
30
30
|
end
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
32
|
+
context "then the :seo_file" do
|
33
|
+
it "should contain the path to the SEO file." do
|
34
|
+
app.seo_file.should_not be_nil
|
35
|
+
app.seo_file.should be_an_instance_of(String)
|
36
|
+
app.seo_file.should == './test.seo'
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should exist and have the '.seo' extension." do
|
40
|
+
File.exist?('./test.seo').should be_true
|
41
|
+
File.extname(app.seo_file).should == '.seo'
|
42
|
+
end
|
41
43
|
end
|
42
44
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
45
|
+
context "then the seo helper method" do
|
46
|
+
it "should include every page with its sub-attributes as a read-only attributes." do
|
47
|
+
YAML.load_file('./test.seo').keys.each do |page|
|
48
|
+
seo.methods.include?(page).should be_true
|
49
|
+
seo.methods.include?(:"#{page}=").should be_false
|
50
|
+
|
51
|
+
eval("seo.#{page}").should be_an_instance_of(OpenStruct)
|
52
|
+
|
53
|
+
[:title, :description, :keywords].each do |attribute|
|
54
|
+
eval("seo.#{page}.methods").include?(attribute).should be_true
|
55
|
+
eval("seo.#{page}.methods").include?(:"#{attribute}=").should be_false
|
56
|
+
eval("seo.#{page}.#{attribute}").should be_an_instance_of(String)
|
57
|
+
|
58
|
+
case attribute
|
59
|
+
when :title
|
60
|
+
eval("seo.#{page}.#{attribute}").should == DATA[page][attribute][0, 60]
|
61
|
+
when :description
|
62
|
+
eval("seo.#{page}.#{attribute}").should == DATA[page][attribute][0, 160]
|
63
|
+
else
|
64
|
+
eval("seo.#{page}.#{attribute}").should == DATA[page][attribute].split(" ")[0, 15].join(" ")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should allow a maximum of 60 characters for the Title sub-attribute." do
|
71
|
+
seo.instance_variable_get(:@table).keys.each do |page|
|
72
|
+
eval("seo.#{page}.title").size.should <= 60
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should allow a maximum of 160 characters for the Description aub-attribute." do
|
77
|
+
seo.instance_variable_get(:@table).keys.each do |page|
|
78
|
+
eval("seo.#{page}.description").size.should <= 160
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should allow a maximum of 15 words for the Keywords aub-attribute." do
|
83
|
+
seo.instance_variable_get(:@table).keys.each do |page|
|
84
|
+
eval("seo.#{page}.keywords").split(" ").size.should <= 15
|
55
85
|
end
|
56
86
|
end
|
57
87
|
end
|
58
|
-
|
88
|
+
|
59
89
|
after :all do
|
60
90
|
File.delete './test.seo'
|
61
91
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -5,6 +5,13 @@ require File.join(Dir.pwd, %w{lib sinatra seo})
|
|
5
5
|
set :environment, :test
|
6
6
|
enable :raise_errors
|
7
7
|
|
8
|
-
DATA = {:test1 => {:title =>
|
9
|
-
|
10
|
-
|
8
|
+
DATA = {:test1 => { :title => lambda{word = ""; 50.times{word += "t"}; word}.call,
|
9
|
+
:description => lambda{word = ""; 150.times{word += "d"}; word}.call,
|
10
|
+
:keywords => lambda{word = ""; 10.times{word += "k, "}; word}.call },
|
11
|
+
:test2 => { :title => lambda{word = ""; 60.times{word += "t"}; word}.call,
|
12
|
+
:description => lambda{word = ""; 160.times{word += "d"}; word}.call,
|
13
|
+
:keywords => lambda{word = ""; 15.times{word += "k, "}; word}.call },
|
14
|
+
:test3 => { :title => lambda{word = ""; 70.times{word += "t"}; word}.call,
|
15
|
+
:description => lambda{word = ""; 170.times{word += "d"}; word}.call,
|
16
|
+
:keywords => lambda{word = ""; 20.times{word += "k, "}; word}.call }}
|
17
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-seo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julio Javier Cicchelli
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-03-
|
12
|
+
date: 2010-03-16 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|