sinatra-seo 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +53 -4
- data/spec/seo_spec.rb +5 -3
- metadata +1 -1
data/README.markdown
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Sinatra SEO
|
2
|
-
This is a [Sinatra Extension][1] that integrates basic SEO functionality
|
2
|
+
This is a [Sinatra Extension][1] that integrates basic SEO functionality within your [Sinatra][2] application.
|
3
3
|
|
4
4
|
### Installation
|
5
5
|
In order to install this gem, you just need to install the gem from your command line like this:
|
@@ -11,9 +11,48 @@ You should take into account that this library have the following dependencies:
|
|
11
11
|
* [sinatra][2]
|
12
12
|
|
13
13
|
### Usage
|
14
|
-
This library requires you to define the basic SEO information such as the title, the description and the keywords for every page of your site on a separate file.
|
14
|
+
This library requires you to define the basic SEO information such as the title, the description and the keywords for every page of your site on a YAML-style separate file. Imagine that you created the file, let's say, *site.seo* then you should populate it as follow:
|
15
15
|
|
16
|
-
|
16
|
+
home:
|
17
|
+
title: Home | Site
|
18
|
+
description: my Home description goes here.
|
19
|
+
keywords: keyword1, keyword2, keyword3
|
20
|
+
about:
|
21
|
+
title: About | Site
|
22
|
+
description: my About description goes here.
|
23
|
+
keywords: keyword4, keyword5, keyword6
|
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.
|
26
|
+
|
27
|
+
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
|
+
|
29
|
+
require 'sinatra'
|
30
|
+
require 'sinatra/seo'
|
31
|
+
|
32
|
+
set :seo_file, File.join(File.dirname(__FILE__), 'site.seo')
|
33
|
+
|
34
|
+
# ... the rest of your code ...
|
35
|
+
|
36
|
+
In case you would prefer to follow the **Modular** approach on your application design, then you just need to declare your application as a class that inherit from the *Sinatra:Base* class in the *app.rb* file, then you should register the extension inside this class and finally you should set the SEO file this extension should parse.
|
37
|
+
|
38
|
+
require 'sinatra/base'
|
39
|
+
require 'sinatra/seo'
|
40
|
+
|
41
|
+
class App < Sinatra:Base
|
42
|
+
register Sinatra::Seo
|
43
|
+
|
44
|
+
set :seo_file, File.join(File.dirname(__FILE__), 'site.seo')
|
45
|
+
|
46
|
+
# ... the rest of your code ...
|
47
|
+
end
|
48
|
+
|
49
|
+
By now you should be able to use the **seo** helper method in your views. This method basically returns nested *OpenStruct* instances with read-only attributes that represents the content you wrote on the *site.seo* file.
|
50
|
+
|
51
|
+
seo.home.title # => 'Home | Site'
|
52
|
+
seo.about.description # => 'my About description goes here.'
|
53
|
+
seo.home.keywords # => 'keyword4, keyword5, keyword6'
|
54
|
+
|
55
|
+
Finally, you are able to implement SEO in your application with this extension!
|
17
56
|
|
18
57
|
### Contributions
|
19
58
|
Everybody is welcome to contribute to this project by commenting the source code, suggesting modifications or new ideas, reporting bugs, writing some documentation and, of course, you're also welcome to contribute with patches as well!
|
@@ -27,6 +66,14 @@ In case you would like to contribute on this library, here's the list of extra d
|
|
27
66
|
### Contributors
|
28
67
|
* [Julio Javier Cicchelli][6]
|
29
68
|
|
69
|
+
### Sites
|
70
|
+
The following sites are proudly using this extension:
|
71
|
+
|
72
|
+
* [Rock & Code][9]
|
73
|
+
* [Izcheznali][10]
|
74
|
+
|
75
|
+
If your site is also using this extension, please let us know!
|
76
|
+
|
30
77
|
### Notes
|
31
78
|
This extension have been tested on the versions 1.8.6, 1.8.7 and 1.9.1 of the [Ruby interpreter][7].
|
32
79
|
|
@@ -40,4 +87,6 @@ This extension is licensed under the [MIT License][8].
|
|
40
87
|
[5]: http://gitrdoc.com/brynary/rack-test/tree/master
|
41
88
|
[6]: http://github.com/mr-rock
|
42
89
|
[7]: http://www.ruby-lang.org/en/
|
43
|
-
[8]: http://creativecommons.org/licenses/MIT/
|
90
|
+
[8]: http://creativecommons.org/licenses/MIT/
|
91
|
+
[9]: http://rock-n-code.com
|
92
|
+
[10]: http://izcheznali.net
|
data/spec/seo_spec.rb
CHANGED
@@ -30,14 +30,16 @@ describe Sinatra::Seo do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
it "then the :seo_file option should contain the path to the SEO file." do
|
33
|
-
File.exist?('./test.seo').should be_true
|
34
|
-
File.extname(app.seo_file).should == '.seo'
|
35
|
-
|
36
33
|
app.seo_file.should_not be_nil
|
37
34
|
app.seo_file.should be_an_instance_of(String)
|
38
35
|
app.seo_file.should == './test.seo'
|
39
36
|
end
|
40
37
|
|
38
|
+
it "then the defined :seo_file should exist and have the '.seo' extension." do
|
39
|
+
File.exist?('./test.seo').should be_true
|
40
|
+
File.extname(app.seo_file).should == '.seo'
|
41
|
+
end
|
42
|
+
|
41
43
|
it "then the seo helper method should include every page (with :title, :description and :keywords as sub-attributes) as a read-only attribute." do
|
42
44
|
YAML.load_file('./test.seo').keys.each do |page|
|
43
45
|
seo.methods.include?(page).should be_true
|