sinatra-seo 0.0.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -1,5 +1,5 @@
1
1
  # Sinatra SEO
2
- This is a [Sinatra Extension][1] that renders for browser and AJAX calls any page or sub-pages located under the directory defined as *:views* and the layout file defined as *:layout* (if there is any) inside your [Sinatra][2] application.
2
+ This is a [Sinatra Extension][1] that integrates basic SEO functionality into 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,8 +11,10 @@ You should take into account that this library have the following dependencies:
11
11
  * [sinatra][2]
12
12
 
13
13
  ### Usage
14
- ... description goes here...
15
-
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.
15
+
16
+ ...some more description out here...
17
+
16
18
  ### Contributions
17
19
  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!
18
20
 
data/Rakefile CHANGED
@@ -34,7 +34,7 @@ namespace :deployment do
34
34
 
35
35
  desc "Deployment on Gemcutter."
36
36
  task :gemcutter => [:clean, :package] do
37
- sh "#{GEM_COMMAND} push pkg/*.gem"
37
+ sh 'gem push pkg/*.gem'
38
38
  end
39
39
  end
40
40
 
data/lib/sinatra/seo.rb CHANGED
@@ -1,7 +1,33 @@
1
1
  require 'sinatra/base'
2
+ require 'yaml'
3
+ require 'ostruct'
4
+
5
+ class OpenStruct
6
+ def new_ostruct_member(name)
7
+ name = name.to_sym
8
+
9
+ unless self.respond_to?(name)
10
+ class << self; self; end.class_eval do
11
+ define_method(name) {@table[name].is_a?(Hash) ? OpenStruct.new(@table[name]) : @table[name]}
12
+ end
13
+ end
14
+ end
15
+ end
2
16
 
3
17
  module Sinatra
4
18
  module Seo
5
- # ...
19
+ module Helpers
20
+ def seo
21
+ @seo ||= OpenStruct.new(YAML.load_file(app.seo_file))
22
+ end
23
+ end
24
+
25
+ def self.registered(app)
26
+ app.helpers Seo::Helpers
27
+
28
+ app.set :seo_file, nil
29
+ end
6
30
  end
31
+
32
+ register Seo
7
33
  end
data/spec/seo_spec.rb CHANGED
@@ -2,8 +2,60 @@ require 'spec_helper'
2
2
 
3
3
  describe Sinatra::Seo do
4
4
  include Rack::Test::Methods
5
+ include Sinatra::Seo::Helpers
5
6
 
6
7
  def app
7
8
  Sinatra::Application
8
9
  end
10
+
11
+ context "when initialized" do
12
+ before :all do
13
+ set :seo_file, nil
14
+ end
15
+
16
+ it "then the :seo_file option should be null." do
17
+ app.seo_file.should be_nil
18
+ end
19
+
20
+ it "then the seo helper method should release an error." do
21
+ lambda{seo}.should raise_error(TypeError)
22
+ end
23
+ end
24
+
25
+ context "when defined an existent SEO file" do
26
+ before :all do
27
+ File.open('./test.seo', 'w'){|file| file.write(YAML::dump(DATA))}
28
+
29
+ set :seo_file, './test.seo'
30
+ end
31
+
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
+ app.seo_file.should_not be_nil
37
+ app.seo_file.should be_an_instance_of(String)
38
+ app.seo_file.should == './test.seo'
39
+ end
40
+
41
+ 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
+ YAML.load_file('./test.seo').keys.each do |page|
43
+ seo.methods.include?(page).should be_true
44
+ seo.methods.include?(:"#{page}=").should be_false
45
+
46
+ eval("seo.#{page}").should be_an_instance_of(OpenStruct)
47
+
48
+ [:title, :description, :keywords].each do |attribute|
49
+ eval("seo.#{page}.methods").include?(attribute).should be_true
50
+ eval("seo.#{page}.methods").include?(:"#{attribute}=").should be_false
51
+ eval("seo.#{page}.#{attribute}").should be_an_instance_of(String)
52
+ eval("seo.#{page}.#{attribute}").should == DATA[page][attribute]
53
+ end
54
+ end
55
+ end
56
+
57
+ after :all do
58
+ File.delete './test.seo'
59
+ end
60
+ end
9
61
  end
data/spec/spec_helper.rb CHANGED
@@ -2,4 +2,9 @@ require 'sinatra'
2
2
  require 'rack/test'
3
3
  require File.join(Dir.pwd, %w{lib sinatra seo})
4
4
 
5
- set :environment, :test
5
+ set :environment, :test
6
+ enable :raise_errors
7
+
8
+ DATA = {:test1 => {:title => 'Title1', :description => 'Description1', :keywords => 'Keywords1'},
9
+ :test2 => {:title => 'Title2', :description => 'Description2', :keywords => 'Keywords2'},
10
+ :test3 => {:title => 'Title3', :description => 'Description3', :keywords => 'Keywords3'}}
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.0.1
4
+ version: 0.2.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-10 00:00:00 +01:00
12
+ date: 2010-03-12 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency