rails_angular_seo 0.0.7 → 0.0.8
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.
- checksums.yaml +4 -4
 - data/README.txt +13 -6
 - data/VERSION +1 -1
 - data/lib/rails_angular_seo/middleware.rb +3 -1
 - data/lib/rails_angular_seo/renderer.rb +4 -2
 - data/rails_angular_seo.gemspec +1 -1
 - data/spec/middleware_spec.rb +10 -10
 - data/spec/renderer_spec.rb +1 -1
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 9dc8041502d1872ebe5c88a59f918f60f5e558a5
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: d25693f847227afd1281d02f284e80fd0ae010aa
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: d2aa7ff1534bb6f3990785140d9c3d2290377645f5e2075f86d5fb0efbbf82190c69db2ead5dbe93f56fd9ee096ffbdf670b6eaf8373ad4965fd5b3a84cc0b61
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: b72d584cea072fc59d36f8e58021f5d0573c858071997a2aebc23f111e5992c3a7b35dd369ed251cfc9aa6fd3bd38098ec80b0cce9db71aa21061bf8d09ce52c
         
     | 
    
        data/README.txt
    CHANGED
    
    | 
         @@ -4,14 +4,20 @@ 
     | 
|
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
            == DESCRIPTION:
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
      
 7 
     | 
    
         
            +
            rails_angular_seo assumes that phantomjs is installed. Please install it if not installed already.
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
       7 
9 
     | 
    
         
             
            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 
10 
     | 
    
         | 
| 
       9 
     | 
    
         
            -
            Googlebot
         
     | 
| 
       10 
     | 
    
         
            -
            Googlebot 
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
            Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)
         
     | 
| 
      
 11 
     | 
    
         
            +
                      "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)",
         
     | 
| 
      
 12 
     | 
    
         
            +
                      "Googlebot/2.1 (+http://www.google.com/bot.html)",
         
     | 
| 
      
 13 
     | 
    
         
            +
                      "compatible; Mediapartners-Google/2.1; +http://www.google.com/bot.html",
         
     | 
| 
      
 14 
     | 
    
         
            +
                      "AdsBot-Google (+http://www.google.com/adsbot.html)",
         
     | 
| 
      
 15 
     | 
    
         
            +
                      "Mediapartners-Google",
         
     | 
| 
      
 16 
     | 
    
         
            +
                      "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)",
         
     | 
| 
      
 17 
     | 
    
         
            +
                      "Mozilla/5.0 (compatible; bingbot/2.0 +http://www.bing.com/bingbot.htm)",
         
     | 
| 
      
 18 
     | 
    
         
            +
                      "Baiduspider+(+http://www.baidu.com/search/spider_jp.html)",
         
     | 
| 
      
 19 
     | 
    
         
            +
                      "Baiduspider+(+http://www.baidu.com/search/spider.htm)",
         
     | 
| 
      
 20 
     | 
    
         
            +
                      "BaiDuSpider"
         
     | 
| 
       15 
21 
     | 
    
         | 
| 
       16 
22 
     | 
    
         
             
            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 
23 
     | 
    
         | 
| 
         @@ -35,6 +41,7 @@ In order to serve a set of routes as a single-page app, your routes.rb usually c 
     | 
|
| 
       35 
41 
     | 
    
         
             
                RailsAngularSeo::Middleware.base_path = "/" # replace / for whichever path matches your app's index.html
         
     | 
| 
       36 
42 
     | 
    
         
             
                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 
43 
     | 
    
         
             
                RailsAngularSeo::Middleware.server_name    = "NAME OF YOUR SERVER"
         
     | 
| 
      
 44 
     | 
    
         
            +
                RailsAngularSeo::Middleware.phantomjs_path = "/usr/local/bin/phantomjs" # If phantomjs is not in the default PATH.
         
     | 
| 
       38 
45 
     | 
    
         | 
| 
       39 
46 
     | 
    
         
             
            And you're done! The middleware will only try to static-render requests made by bots AND that would render application/html content.
         
     | 
| 
       40 
47 
     | 
    
         | 
    
        data/VERSION
    CHANGED
    
    | 
         @@ -1 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            0.0. 
     | 
| 
      
 1 
     | 
    
         
            +
            0.0.8
         
     | 
| 
         @@ -11,6 +11,7 @@ module RailsAngularSeo 
     | 
|
| 
       11 
11 
     | 
    
         
             
                  attr_accessor :seo_id
         
     | 
| 
       12 
12 
     | 
    
         
             
                  attr_accessor :server_name
         
     | 
| 
       13 
13 
     | 
    
         
             
                  attr_accessor :phantomjs_path
         
     | 
| 
      
 14 
     | 
    
         
            +
                  attr_accessor :phantomjs_options
         
     | 
| 
       14 
15 
     | 
    
         
             
                end
         
     | 
| 
       15 
16 
     | 
    
         | 
| 
       16 
17 
     | 
    
         
             
                def initialize(app)
         
     | 
| 
         @@ -21,9 +22,10 @@ module RailsAngularSeo 
     | 
|
| 
       21 
22 
     | 
    
         
             
                  if will_render?(env)
         
     | 
| 
       22 
23 
     | 
    
         
             
                    self.class.server_name ||= env["HTTP_HOST"]
         
     | 
| 
       23 
24 
     | 
    
         
             
                    self.class.phantomjs_path ||= 'phantomjs'
         
     | 
| 
      
 25 
     | 
    
         
            +
                    self.class.phantomjs_options ||= ["--ssl-protocol=any"]
         
     | 
| 
       24 
26 
     | 
    
         
             
                    path = URI("#{env["rack.url_scheme"]}://#{self.class.server_name}#{env["REQUEST_URI"]}")
         
     | 
| 
       25 
27 
     | 
    
         
             
                    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)
         
     | 
| 
      
 28 
     | 
    
         
            +
                    RailsAngularSeo::Renderer.render(self.class.phantomjs_path, self.class.seo_id, path_without_port, {phantomjs_options: self.class.phantomjs_options})
         
     | 
| 
       27 
29 
     | 
    
         
             
                  else
         
     | 
| 
       28 
30 
     | 
    
         
             
                    @app.call(env)
         
     | 
| 
       29 
31 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -1,9 +1,11 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module RailsAngularSeo
         
     | 
| 
       2 
2 
     | 
    
         
             
              class Renderer
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
                def self.render(phantomjs_path, seo_id, path_without_port)
         
     | 
| 
      
 4 
     | 
    
         
            +
                def self.render(phantomjs_path, seo_id, path_without_port, options = {})
         
     | 
| 
       5 
5 
     | 
    
         
             
                  output = ""
         
     | 
| 
       6 
     | 
    
         
            -
                   
     | 
| 
      
 6 
     | 
    
         
            +
                  options = {phantomjs_options: []}.merge(options)
         
     | 
| 
      
 7 
     | 
    
         
            +
                  open_options = [phantomjs_path] + options[:phantomjs_options] + [File.expand_path("../../../phantomjs/phantomjs-runner.js", __FILE__), path_without_port, seo_id]
         
     | 
| 
      
 8 
     | 
    
         
            +
                  output = IO.popen(open_options){|phantom_output| output = phantom_output.read}
         
     | 
| 
       7 
9 
     | 
    
         
             
                  [200, { "Content-Type" => "text/html" }, [output]]
         
     | 
| 
       8 
10 
     | 
    
         
             
                end
         
     | 
| 
       9 
11 
     | 
    
         
             
              end
         
     | 
    
        data/rails_angular_seo.gemspec
    CHANGED
    
    
    
        data/spec/middleware_spec.rb
    CHANGED
    
    | 
         @@ -1,8 +1,8 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require " 
     | 
| 
      
 1 
     | 
    
         
            +
            require "rails_angular_seo/middleware"
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            describe  
     | 
| 
      
 3 
     | 
    
         
            +
            describe RailsAngularSeo::Middleware do
         
     | 
| 
       4 
4 
     | 
    
         
             
              let(:app) { stub }
         
     | 
| 
       5 
     | 
    
         
            -
              let(:middleware) {  
     | 
| 
      
 5 
     | 
    
         
            +
              let(:middleware) { RailsAngularSeo::Middleware.new(app) }
         
     | 
| 
       6 
6 
     | 
    
         
             
              let(:request) {
         
     | 
| 
       7 
7 
     | 
    
         
             
                {
         
     | 
| 
       8 
8 
     | 
    
         
             
                    "PATH_INFO" => "/somewhere/",
         
     | 
| 
         @@ -11,7 +11,7 @@ describe RenderStatic::Middleware do 
     | 
|
| 
       11 
11 
     | 
    
         
             
              }
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
13 
     | 
    
         
             
              before do
         
     | 
| 
       14 
     | 
    
         
            -
                 
     | 
| 
      
 14 
     | 
    
         
            +
                RailsAngularSeo::Middleware.base_path = "/somewhere/"
         
     | 
| 
       15 
15 
     | 
    
         
             
              end
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
       17 
17 
     | 
    
         
             
              describe "a non-bot user agent" do
         
     | 
| 
         @@ -19,7 +19,7 @@ describe RenderStatic::Middleware do 
     | 
|
| 
       19 
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 
20 
     | 
    
         | 
| 
       21 
21 
     | 
    
         
             
                  app.should_receive(:call).with(env)
         
     | 
| 
       22 
     | 
    
         
            -
                   
     | 
| 
      
 22 
     | 
    
         
            +
                  RailsAngularSeo::Renderer.should_not_receive(:render)
         
     | 
| 
       23 
23 
     | 
    
         | 
| 
       24 
24 
     | 
    
         
             
                  middleware.call(env)
         
     | 
| 
       25 
25 
     | 
    
         
             
                end
         
     | 
| 
         @@ -30,7 +30,7 @@ describe RenderStatic::Middleware do 
     | 
|
| 
       30 
30 
     | 
    
         
             
                  env = request.merge("HTTP_USER_AGENT" => "Googlebot", "PATH_INFO" => "/somewhere_else/a.html")
         
     | 
| 
       31 
31 
     | 
    
         | 
| 
       32 
32 
     | 
    
         
             
                  app.should_receive(:call).with(env)
         
     | 
| 
       33 
     | 
    
         
            -
                   
     | 
| 
      
 33 
     | 
    
         
            +
                  RailsAngularSeo::Renderer.should_not_receive(:render)
         
     | 
| 
       34 
34 
     | 
    
         
             
                  middleware.call(env)
         
     | 
| 
       35 
35 
     | 
    
         
             
                end
         
     | 
| 
       36 
36 
     | 
    
         | 
| 
         @@ -38,7 +38,7 @@ describe RenderStatic::Middleware do 
     | 
|
| 
       38 
38 
     | 
    
         
             
                  env = request.merge("HTTP_USER_AGENT" => "Googlebot", "PATH_INFO" => "/somewhere/index.html")
         
     | 
| 
       39 
39 
     | 
    
         | 
| 
       40 
40 
     | 
    
         
             
                  app.should_not_receive(:call)
         
     | 
| 
       41 
     | 
    
         
            -
                   
     | 
| 
      
 41 
     | 
    
         
            +
                  RailsAngularSeo::Renderer.should_receive(:render).with(env)
         
     | 
| 
       42 
42 
     | 
    
         
             
                  middleware.call(env)
         
     | 
| 
       43 
43 
     | 
    
         
             
                end
         
     | 
| 
       44 
44 
     | 
    
         | 
| 
         @@ -46,7 +46,7 @@ describe RenderStatic::Middleware do 
     | 
|
| 
       46 
46 
     | 
    
         
             
                  env = request.merge("HTTP_USER_AGENT" => "Googlebot", "PATH_INFO" => "/somewhere/index")
         
     | 
| 
       47 
47 
     | 
    
         | 
| 
       48 
48 
     | 
    
         
             
                  app.should_not_receive(:call)
         
     | 
| 
       49 
     | 
    
         
            -
                   
     | 
| 
      
 49 
     | 
    
         
            +
                  RailsAngularSeo::Renderer.should_receive(:render).with(env)
         
     | 
| 
       50 
50 
     | 
    
         
             
                  middleware.call(env)
         
     | 
| 
       51 
51 
     | 
    
         
             
                end
         
     | 
| 
       52 
52 
     | 
    
         | 
| 
         @@ -54,7 +54,7 @@ describe RenderStatic::Middleware do 
     | 
|
| 
       54 
54 
     | 
    
         
             
                  env = request.merge("REQUEST_METHOD" => "POST", "PATH_INFO" => "/somewhere/index")
         
     | 
| 
       55 
55 
     | 
    
         | 
| 
       56 
56 
     | 
    
         
             
                  app.should_receive(:call)
         
     | 
| 
       57 
     | 
    
         
            -
                   
     | 
| 
      
 57 
     | 
    
         
            +
                  RailsAngularSeo::Renderer.should_not_receive(:render)
         
     | 
| 
       58 
58 
     | 
    
         
             
                  middleware.call(env)
         
     | 
| 
       59 
59 
     | 
    
         
             
                end
         
     | 
| 
       60 
60 
     | 
    
         | 
| 
         @@ -62,7 +62,7 @@ describe RenderStatic::Middleware do 
     | 
|
| 
       62 
62 
     | 
    
         
             
                  env = request.merge("HTTP_USER_AGENT" => "Googlebot", "PATH_INFO" => "/somewhere/a.js")
         
     | 
| 
       63 
63 
     | 
    
         | 
| 
       64 
64 
     | 
    
         
             
                  app.should_receive(:call).with(env)
         
     | 
| 
       65 
     | 
    
         
            -
                   
     | 
| 
      
 65 
     | 
    
         
            +
                  RailsAngularSeo::Renderer.should_not_receive(:render)
         
     | 
| 
       66 
66 
     | 
    
         
             
                  middleware.call(env)
         
     | 
| 
       67 
67 
     | 
    
         
             
                end
         
     | 
| 
       68 
68 
     | 
    
         
             
              end
         
     | 
    
        data/spec/renderer_spec.rb
    CHANGED