rails_angular_seo 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +49 -0
- data/LICENSE.txt +22 -0
- data/README.txt +49 -0
- data/Rakefile +43 -0
- data/VERSION +1 -0
- data/lib/rails_angular_seo/middleware.rb +60 -0
- data/lib/rails_angular_seo/rails/railtie.rb +9 -0
- data/lib/rails_angular_seo/renderer.rb +10 -0
- data/lib/rails_angular_seo.rb +1 -0
- data/phantomjs/phantomjs-runner.js +46 -0
- data/rails_angular_seo.gemspec +65 -0
- data/spec/middleware_spec.rb +69 -0
- data/spec/renderer_spec.rb +19 -0
- metadata +134 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7e73eb69378b9cc7909a5fcbebe0acd2007ee332
|
4
|
+
data.tar.gz: 5164182c7c70d4428cbd6c76552fea53a9d4ea87
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9110d9537df5cb07ee4d22cd73d0bc08726d18dd58a500f4f51dfd67ad4b5f7d342f4503cb17f4881d3ebe333f135c82c17d986629044bc5e1f761fbf9dc992c
|
7
|
+
data.tar.gz: ed4746c179ad69cc9dc7e5c703f1c6fc7861474862e3ceea326f93651431076e3245771ede822a51327f23fd2ba2d4a8d5aedf5e93aa9da18425f49b60254041
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (3.2.13)
|
5
|
+
i18n (= 0.6.1)
|
6
|
+
multi_json (~> 1.0)
|
7
|
+
bourne (1.4.0)
|
8
|
+
mocha (~> 0.13.2)
|
9
|
+
diff-lcs (1.1.3)
|
10
|
+
git (1.2.5)
|
11
|
+
i18n (0.6.1)
|
12
|
+
jeweler (1.8.4)
|
13
|
+
bundler (~> 1.0)
|
14
|
+
git (>= 1.2.5)
|
15
|
+
rake
|
16
|
+
rdoc
|
17
|
+
json (1.7.7)
|
18
|
+
metaclass (0.0.1)
|
19
|
+
mocha (0.13.3)
|
20
|
+
metaclass (~> 0.0.1)
|
21
|
+
multi_json (1.7.2)
|
22
|
+
rake (10.0.4)
|
23
|
+
rdoc (3.12.2)
|
24
|
+
json (~> 1.4)
|
25
|
+
rspec (2.12.0)
|
26
|
+
rspec-core (~> 2.12.0)
|
27
|
+
rspec-expectations (~> 2.12.0)
|
28
|
+
rspec-mocks (~> 2.12.0)
|
29
|
+
rspec-core (2.12.2)
|
30
|
+
rspec-expectations (2.12.1)
|
31
|
+
diff-lcs (~> 1.1.3)
|
32
|
+
rspec-mocks (2.12.1)
|
33
|
+
shoulda (3.4.0)
|
34
|
+
shoulda-context (~> 1.0, >= 1.0.1)
|
35
|
+
shoulda-matchers (~> 1.0, >= 1.4.1)
|
36
|
+
shoulda-context (1.1.1)
|
37
|
+
shoulda-matchers (1.5.6)
|
38
|
+
activesupport (>= 3.0.0)
|
39
|
+
bourne (~> 1.3)
|
40
|
+
|
41
|
+
PLATFORMS
|
42
|
+
ruby
|
43
|
+
|
44
|
+
DEPENDENCIES
|
45
|
+
bundler
|
46
|
+
jeweler (~> 1.8.4)
|
47
|
+
rdoc (~> 3.12)
|
48
|
+
rspec
|
49
|
+
shoulda
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Herval Freire
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
'Software'), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.txt
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
= rails_angular_seo
|
2
|
+
|
3
|
+
* http://github.com/arunn/rails_angular_seo
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
rails_angular_seo allows you to make your single-page apps (Backbone, Angular, etc) built on Rails SEO-friendly. It works by injecting a small rack middleware that will render pages as plain html, when the requester has one of the following user-agent headers:
|
8
|
+
|
9
|
+
Googlebot
|
10
|
+
Googlebot-Mobile
|
11
|
+
AdsBot-Google
|
12
|
+
Mozilla/5.0 (compatible; Ask Jeeves/Teoma; +http://about.ask.com/en/docs/about/webmasters.shtml)
|
13
|
+
Baiduspider
|
14
|
+
Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)
|
15
|
+
|
16
|
+
Please note that, in order for this to work, you need more than one thread/process of your webserver running, as the middleware will effectively make a second call back to your own app and render the content, streaming it back to the requester (crawler/bot).
|
17
|
+
|
18
|
+
|
19
|
+
== TO DO/PROBLEMS:
|
20
|
+
|
21
|
+
* Caching support
|
22
|
+
* Support for other drivers
|
23
|
+
* Log what's going on
|
24
|
+
|
25
|
+
== INSTALL:
|
26
|
+
|
27
|
+
Add the following to your Gemfile:
|
28
|
+
|
29
|
+
gem 'rails_angular_seo'
|
30
|
+
|
31
|
+
In order to serve a set of routes as a single-page app, your routes.rb usually contains a catch-all route that will direct /* or /something/* to the same index.html file (the root of your js app). In order to allow the rails_angular_seo middleware to intercept the right routes, you need to add this to your app initialization:
|
32
|
+
|
33
|
+
config/initializers/rails_angular_seo.rb
|
34
|
+
|
35
|
+
RailsAngularSeo::Middleware.base_path = "/" # replace / for whichever path matches your app's index.html
|
36
|
+
RailsAngularSeo::Middleware.seo_id = "seo_id" # replace seo_id with whatever ID is used for the HTML DOM element which would be updated with status as "ready" once the ajax load is completed.
|
37
|
+
RailsAngularSeo::Middleware.server_name = "NAME OF YOUR SERVER"
|
38
|
+
|
39
|
+
And you're done! The middleware will only try to static-render requests made by bots AND that would render application/html content.
|
40
|
+
|
41
|
+
You can test that everything is working as expected by CURLing:
|
42
|
+
|
43
|
+
# this will render the usual blank slate client-side apps serve
|
44
|
+
curl http://localhost:3000/some/backbone/route
|
45
|
+
|
46
|
+
# this will render a static representation of your page (just like it would look like in a browser)
|
47
|
+
curl -A "Googlebot" http://localhost:3000/some/backbone/route
|
48
|
+
|
49
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "rails_angular_seo"
|
18
|
+
gem.homepage = "http://github.com/arunn/rails_angular_seo"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{ rails_angular_seo allows you to make your single-page apps (Backbone, Angular, etc) built on Rails SEO-friendly. }
|
21
|
+
gem.description = %Q{ rails_angular_seo allows you to make your single-page apps (Backbone, Angular, etc) built on Rails SEO-friendly. It works by injecting a small rack middleware that will render pages as plain html, when the requester is one of the most common crawlers/bots out there (Google, Yahoo Baidu and Bing }
|
22
|
+
gem.email = "arunkumar@chronus.com"
|
23
|
+
gem.authors = ["herval", "arunn"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core/rake_task'
|
29
|
+
|
30
|
+
RSpec::Core::RakeTask.new(:spec)
|
31
|
+
|
32
|
+
task :default => :spec
|
33
|
+
|
34
|
+
|
35
|
+
require 'rdoc/task'
|
36
|
+
Rake::RDocTask.new do |rdoc|
|
37
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
38
|
+
|
39
|
+
rdoc.rdoc_dir = 'rdoc'
|
40
|
+
rdoc.title = "rails_angular_seo #{version}"
|
41
|
+
rdoc.rdoc_files.include('README*')
|
42
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
43
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.7
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'rails_angular_seo/rails/railtie' if defined?(Rails)
|
2
|
+
require 'rails_angular_seo/renderer'
|
3
|
+
|
4
|
+
module RailsAngularSeo
|
5
|
+
class NotSeoFriendly < Exception
|
6
|
+
end
|
7
|
+
|
8
|
+
class Middleware
|
9
|
+
class << self
|
10
|
+
attr_accessor :base_path
|
11
|
+
attr_accessor :seo_id
|
12
|
+
attr_accessor :server_name
|
13
|
+
attr_accessor :phantomjs_path
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(app)
|
17
|
+
@app = app
|
18
|
+
end
|
19
|
+
|
20
|
+
def call(env)
|
21
|
+
if will_render?(env)
|
22
|
+
self.class.server_name ||= env["HTTP_HOST"]
|
23
|
+
self.class.phantomjs_path ||= 'phantomjs'
|
24
|
+
path = URI("#{env["rack.url_scheme"]}://#{self.class.server_name}#{env["REQUEST_URI"]}")
|
25
|
+
path_without_port = "#{env["rack.url_scheme"]}://#{path.host}#{env["REQUEST_URI"]}"
|
26
|
+
RailsAngularSeo::Renderer.render(self.class.phantomjs_path, self.class.seo_id, path_without_port)
|
27
|
+
else
|
28
|
+
@app.call(env)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def will_render?(env)
|
35
|
+
is_bot?(env) && is_renderable?(env)
|
36
|
+
end
|
37
|
+
|
38
|
+
def is_bot?(env)
|
39
|
+
[
|
40
|
+
"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)",
|
41
|
+
"Googlebot/2.1 (+http://www.google.com/bot.html)",
|
42
|
+
"compatible; Mediapartners-Google/2.1; +http://www.google.com/bot.html",
|
43
|
+
"AdsBot-Google (+http://www.google.com/adsbot.html)",
|
44
|
+
"Mediapartners-Google",
|
45
|
+
"Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)",
|
46
|
+
"Mozilla/5.0 (compatible; bingbot/2.0 +http://www.bing.com/bingbot.htm)",
|
47
|
+
"Baiduspider+(+http://www.baidu.com/search/spider_jp.html)",
|
48
|
+
"Baiduspider+(+http://www.baidu.com/search/spider.htm)",
|
49
|
+
"BaiDuSpider"
|
50
|
+
].include?(env["HTTP_USER_AGENT"])
|
51
|
+
end
|
52
|
+
|
53
|
+
def is_renderable?(env)
|
54
|
+
path = env["PATH_INFO"]
|
55
|
+
content_type = path.index(".") && path.split(".").last
|
56
|
+
|
57
|
+
path.start_with?(self.class.base_path) & [nil, "htm", "html"].include?(content_type) && env["REQUEST_METHOD"] == "GET"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module RailsAngularSeo
|
2
|
+
class Renderer
|
3
|
+
|
4
|
+
def self.render(phantomjs_path, seo_id, path_without_port)
|
5
|
+
output = ""
|
6
|
+
output = IO.popen([phantomjs_path, "--ssl-protocol=any", File.expand_path("../../../phantomjs/phantomjs-runner.js", __FILE__), path_without_port, seo_id]){|phantom_output| output = phantom_output.read}
|
7
|
+
[200, { "Content-Type" => "text/html" }, [output]]
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'rails_angular_seo/middleware'
|
@@ -0,0 +1,46 @@
|
|
1
|
+
var system = require('system');
|
2
|
+
var url = system.args[1] || '';
|
3
|
+
|
4
|
+
if(url.length > 0) {
|
5
|
+
var page = require('webpage').create();
|
6
|
+
page.viewportSize = {
|
7
|
+
width: 1280,
|
8
|
+
height: 960
|
9
|
+
};
|
10
|
+
page.onResourceError = function(resourceError) {
|
11
|
+
page.reason = resourceError.errorString;
|
12
|
+
page.reason_url = resourceError.url;
|
13
|
+
};
|
14
|
+
page.open(url, function (status) {
|
15
|
+
if (status == 'success') {
|
16
|
+
var try_count = 0;
|
17
|
+
var delay, checker = (function() {
|
18
|
+
var status_element_id = system.args[2] || '';
|
19
|
+
try_count += 1;
|
20
|
+
var html = page.evaluate(function (status_element_id) {
|
21
|
+
var body;
|
22
|
+
if(status_element_id == "")
|
23
|
+
{ body = document.getElementsByTagName('body')[0];}
|
24
|
+
else
|
25
|
+
{ body = document.getElementById(status_element_id);}
|
26
|
+
if(body == null || body.getAttribute('data-status') == null || body.getAttribute('data-status') == 'ready') {
|
27
|
+
return document.getElementsByTagName('html')[0].outerHTML;
|
28
|
+
}
|
29
|
+
}, status_element_id);
|
30
|
+
if(html) {
|
31
|
+
clearTimeout(delay);
|
32
|
+
console.log(html);
|
33
|
+
phantom.exit();
|
34
|
+
}
|
35
|
+
else if(try_count > 50){
|
36
|
+
phantom.exit(1);
|
37
|
+
}
|
38
|
+
});
|
39
|
+
delay = setInterval(checker, 100);
|
40
|
+
}
|
41
|
+
else {
|
42
|
+
console.log("Error opening url \"" + page.reason_url + "\": " + page.reason);
|
43
|
+
phantom.exit(1);
|
44
|
+
}
|
45
|
+
});
|
46
|
+
}
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "rails_angular_seo"
|
8
|
+
s.version = "0.0.7"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["herval", "arunn"]
|
12
|
+
s.date = "2014-10-01"
|
13
|
+
s.description = " rails_angular_seo allows you to make your single-page apps (Backbone, Angular, etc) built on Rails SEO-friendly. It works by injecting a small rack middleware that will render pages as plain html, when the requester is one of the most common crawlers/bots out there (Google, Yahoo Baidu and Bing) "
|
14
|
+
s.email = "arunkumar@chronus.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.txt"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
"Gemfile",
|
21
|
+
"Gemfile.lock",
|
22
|
+
"LICENSE.txt",
|
23
|
+
"README.txt",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/rails_angular_seo.rb",
|
27
|
+
"lib/rails_angular_seo/middleware.rb",
|
28
|
+
"lib/rails_angular_seo/rails/railtie.rb",
|
29
|
+
"lib/rails_angular_seo/renderer.rb",
|
30
|
+
"phantomjs/phantomjs-runner.js",
|
31
|
+
"rails_angular_seo.gemspec",
|
32
|
+
"spec/middleware_spec.rb",
|
33
|
+
"spec/renderer_spec.rb"
|
34
|
+
]
|
35
|
+
s.homepage = "http://github.com/arunn/rails_angular_seo"
|
36
|
+
s.licenses = ["MIT"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = "1.8.15"
|
39
|
+
s.summary = "rails_angular_seo allows you to make your single-page apps (Backbone, Angular, etc) built on Rails SEO-friendly."
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
s.specification_version = 3
|
43
|
+
|
44
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
45
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
46
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
47
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
48
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
49
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
50
|
+
else
|
51
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
52
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
53
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
54
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
55
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
56
|
+
end
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
59
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
60
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
61
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
62
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require "render_static/middleware"
|
2
|
+
|
3
|
+
describe RenderStatic::Middleware do
|
4
|
+
let(:app) { stub }
|
5
|
+
let(:middleware) { RenderStatic::Middleware.new(app) }
|
6
|
+
let(:request) {
|
7
|
+
{
|
8
|
+
"PATH_INFO" => "/somewhere/",
|
9
|
+
"REQUEST_METHOD" => "GET"
|
10
|
+
}
|
11
|
+
}
|
12
|
+
|
13
|
+
before do
|
14
|
+
RenderStatic::Middleware.base_path = "/somewhere/"
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "a non-bot user agent" do
|
18
|
+
it "passes-through" do
|
19
|
+
env = request.merge("HTTP_USER_AGENT" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.65 Safari/537.31")
|
20
|
+
|
21
|
+
app.should_receive(:call).with(env)
|
22
|
+
RenderStatic::Renderer.should_not_receive(:render)
|
23
|
+
|
24
|
+
middleware.call(env)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "a bot user agent" do
|
29
|
+
it "does not render if path doesn't match" do
|
30
|
+
env = request.merge("HTTP_USER_AGENT" => "Googlebot", "PATH_INFO" => "/somewhere_else/a.html")
|
31
|
+
|
32
|
+
app.should_receive(:call).with(env)
|
33
|
+
RenderStatic::Renderer.should_not_receive(:render)
|
34
|
+
middleware.call(env)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "requests the same url and renders it" do
|
38
|
+
env = request.merge("HTTP_USER_AGENT" => "Googlebot", "PATH_INFO" => "/somewhere/index.html")
|
39
|
+
|
40
|
+
app.should_not_receive(:call)
|
41
|
+
RenderStatic::Renderer.should_receive(:render).with(env)
|
42
|
+
middleware.call(env)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "renders content without an explicit type" do
|
46
|
+
env = request.merge("HTTP_USER_AGENT" => "Googlebot", "PATH_INFO" => "/somewhere/index")
|
47
|
+
|
48
|
+
app.should_not_receive(:call)
|
49
|
+
RenderStatic::Renderer.should_receive(:render).with(env)
|
50
|
+
middleware.call(env)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "only renders GETs" do
|
54
|
+
env = request.merge("REQUEST_METHOD" => "POST", "PATH_INFO" => "/somewhere/index")
|
55
|
+
|
56
|
+
app.should_receive(:call)
|
57
|
+
RenderStatic::Renderer.should_not_receive(:render)
|
58
|
+
middleware.call(env)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "does not render non-html content" do
|
62
|
+
env = request.merge("HTTP_USER_AGENT" => "Googlebot", "PATH_INFO" => "/somewhere/a.js")
|
63
|
+
|
64
|
+
app.should_receive(:call).with(env)
|
65
|
+
RenderStatic::Renderer.should_not_receive(:render)
|
66
|
+
middleware.call(env)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "RailsAngularSeo/renderer"
|
2
|
+
|
3
|
+
describe RailsAngularSeo::Renderer do
|
4
|
+
|
5
|
+
describe ".render" do
|
6
|
+
it "requests the content" do
|
7
|
+
env = { "HTTP_HOST" => "localhost:3000", "REQUEST_PATH" => "/abc", "rack.url_scheme" => "https" }
|
8
|
+
|
9
|
+
navigate = stub
|
10
|
+
browser = stub(navigate: navigate, page_source: "loaded page")
|
11
|
+
|
12
|
+
response = RailsAngularSeo::Renderer.render(env)
|
13
|
+
|
14
|
+
response[0].should == 200
|
15
|
+
response[1].should == {"Content-Type"=>"text/html"}
|
16
|
+
response[2].should == ["loaded page"]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_angular_seo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.7
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- herval
|
8
|
+
- arunn
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-10-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: shoulda
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rdoc
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ~>
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '3.12'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '3.12'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: bundler
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: jeweler
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 1.8.4
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ~>
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 1.8.4
|
84
|
+
description: ' rails_angular_seo allows you to make your single-page apps (Backbone,
|
85
|
+
Angular, etc) built on Rails SEO-friendly. It works by injecting a small rack middleware
|
86
|
+
that will render pages as plain html, when the requester is one of the most common
|
87
|
+
crawlers/bots out there (Google, Yahoo Baidu and Bing) '
|
88
|
+
email: arunkumar@chronus.com
|
89
|
+
executables: []
|
90
|
+
extensions: []
|
91
|
+
extra_rdoc_files:
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.txt
|
94
|
+
files:
|
95
|
+
- Gemfile
|
96
|
+
- Gemfile.lock
|
97
|
+
- LICENSE.txt
|
98
|
+
- README.txt
|
99
|
+
- Rakefile
|
100
|
+
- VERSION
|
101
|
+
- lib/rails_angular_seo.rb
|
102
|
+
- lib/rails_angular_seo/middleware.rb
|
103
|
+
- lib/rails_angular_seo/rails/railtie.rb
|
104
|
+
- lib/rails_angular_seo/renderer.rb
|
105
|
+
- phantomjs/phantomjs-runner.js
|
106
|
+
- rails_angular_seo.gemspec
|
107
|
+
- spec/middleware_spec.rb
|
108
|
+
- spec/renderer_spec.rb
|
109
|
+
homepage: http://github.com/arunn/rails_angular_seo
|
110
|
+
licenses:
|
111
|
+
- MIT
|
112
|
+
metadata: {}
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
requirements: []
|
128
|
+
rubyforge_project:
|
129
|
+
rubygems_version: 2.1.11
|
130
|
+
signing_key:
|
131
|
+
specification_version: 3
|
132
|
+
summary: rails_angular_seo allows you to make your single-page apps (Backbone, Angular,
|
133
|
+
etc) built on Rails SEO-friendly.
|
134
|
+
test_files: []
|