middleman-robots 1.0.0 → 1.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d4f01f8d0fdf3304844fdb713988704f4f423358
4
- data.tar.gz: 001ecdfa3873a65ad43e8efb9e62372622dba93b
3
+ metadata.gz: ed8435b671910bf6bef582f73d1daaf2697ffc5c
4
+ data.tar.gz: f6a673e16af25cb55af1cf1fc5c33654e25140be
5
5
  SHA512:
6
- metadata.gz: 0be81551938bbf181122120adb2bb52b3e8c87580fd93bb8b1651809ec838744eac22171aec43ed0962f2d44e518fd325d0899f54ee47f201cbaff0cea5a5d1c
7
- data.tar.gz: 029da2753b999fcd612fec08d7ab68386a5541a63cc5f5d0ec057fdf471dea09d3f0712016932ce722604bb044c26d55613448c4a7e8e71a1924b6bc3c6ebd4d
6
+ metadata.gz: 2138d6831db51ec5465c199546ffd42823748f2101f50427178d7fa88f810c97f547b29b6eb3f1b6217e7c71c72d860a4691c197f8bfea4703c49e5976eb84ed
7
+ data.tar.gz: 198d3e0a6d7ab5f8a792877b3e33544cdbd53e5059b1d5108cfde0628c39fcfd16c462a37fcfcaea5f55b975ebe67e78d09db317672a6b1b08097d9fb0ed749a
data/.travis.yml CHANGED
@@ -1,14 +1,19 @@
1
1
  language: ruby
2
- script: "bundle exec cucumber"
2
+ script: bundle exec cucumber
3
3
  rvm:
4
- - 1.9.3
5
- - 2.0.0
6
- - 2.1.2
7
- - jruby-19mode
4
+ - ruby-head
5
+ - jruby-head
6
+ - jruby-19mode
7
+ - 2.2
8
+ - 2.1
9
+ - 2.0
10
+ - 1.9.3
11
+ os:
12
+ - linux
13
+ - osx
8
14
  env: TEST=true TRAVIS=true
9
15
  gemfile:
10
- - Gemfile
16
+ - Gemfile
11
17
  notifications:
12
- webhooks:
13
- - https://idobata.io/hook/travis_ci/80f5bf2c-144d-48e4-9283-3a5d4d5f53e2
14
-
18
+ slack:
19
+ secure: C8xb94J4fstzAI7t9GcvKQieKc1k+ECA96ydcxDwBI1fAbupQjz4jafMwnOnD1g9QMe8hlykSNUlCXNCbcA9DZG7COjPZHCY3Icv1+0Dp44bBTDQldR8DPACPMU5Qe+pWoTZViPgJQ7tq2V9TXrGdOnOtkPTwZ9KtZrmNhxW7tM=
@@ -11,7 +11,45 @@ Feature: Middleman-Robots
11
11
  And a successfully built app at "basic-app"
12
12
  When I cd to "build"
13
13
  Then a file named "robots.txt" should exist
14
- And the output should contain "middleman-robots: robots.txt created"
14
+ And the output should contain "== middleman-robots: robots.txt created =="
15
+
16
+ Scenario: Rules option with user_agent
17
+ Given a fixture app "basic-app"
18
+ And a file named "config.rb" with:
19
+ """
20
+ configure :build do
21
+ activate :robots, :rules => [
22
+ {:user_agent => '*'}
23
+ ]
24
+ end
25
+ """
26
+ And a successfully built app at "basic-app"
27
+ When I cd to "build"
28
+ Then the file "robots.txt" should contain exactly:
29
+ """
30
+ User-Agent: *
31
+
32
+ """
33
+
34
+ Scenario: Rules option with user_agent using block
35
+ Given a fixture app "basic-app"
36
+ And a file named "config.rb" with:
37
+ """
38
+ configure :build do
39
+ activate :robots do |r|
40
+ r.rules = [
41
+ {:user_agent => '*'}
42
+ ]
43
+ end
44
+ end
45
+ """
46
+ And a successfully built app at "basic-app"
47
+ When I cd to "build"
48
+ Then the file "robots.txt" should contain exactly:
49
+ """
50
+ User-Agent: *
51
+
52
+ """
15
53
 
16
54
  Scenario: Rules option with user_agent
17
55
  Given a fixture app "basic-app"
@@ -1,60 +1,70 @@
1
1
  module Middleman
2
2
  module Robots
3
+ # Robots Extension Class
4
+ #
5
+ # Create robots.txt when `$ middleman build`
3
6
  class Extension < ::Middleman::Extension
4
7
  option :rules, [], 'List of rules about sitemap.xml'
5
8
  option :sitemap, false, 'URI of sitemap.xml'
6
9
 
7
10
  def initialize(app, options_hash = {}, &block)
8
11
  super
12
+ build_dir = app.build_dir
9
13
 
10
14
  data = rules(options.rules) + sitemap(options.sitemap)
11
15
  data.gsub!(/\n+$/, "\n")
12
16
 
13
- build_dir = app.build_dir
14
17
  app.after_build do
15
- File.open(File.join(build_dir, "robots.txt"), "w") do |file|
18
+ File.open(File.join(build_dir, 'robots.txt'), 'w') do |file|
16
19
  file.puts(data)
17
20
  end
18
- puts " middleman-robots: robots.txt created"
21
+ logger.info '== middleman-robots: robots.txt created =='
19
22
  end
20
23
  end
21
24
 
22
25
  def rules(rules)
23
26
  return '' if rules.empty?
24
-
25
27
  data = []
26
28
  rules.each do |rule|
27
29
  row = []
30
+ row << user_agent(rule)
31
+ row << disallow(rule)
32
+ row << allow(rule)
33
+ row.compact!
34
+ data << row.join("\n") + "\n\n" if row.length > 0
35
+ end
36
+ data.join('')
37
+ end
28
38
 
29
- if (rule["user-agent"] || rule[:user_agent])
30
- user_agent = rule[:user_agent] || rule["user-agent"]
31
- row << "User-Agent: #{user_agent}"
32
- end
33
-
34
- if (rule[:disallow])
35
- rule[:disallow].each do |path|
36
- path = "/" + path unless /^\// =~ path
37
- row << "Disallow: #{path}"
38
- end
39
- end
40
-
41
- if (rule[:allow])
42
- rule[:allow].each do |path|
43
- path = "/" + path unless /^\// =~ path
44
- row << "Allow: #{path}"
45
- end
46
- end
39
+ def user_agent(rule)
40
+ return unless rule.key?('user-agent') || rule.key?(:user_agent)
41
+ user_agent = rule[:user_agent] || rule['user-agent']
42
+ "User-Agent: #{user_agent}"
43
+ end
47
44
 
48
- data << row.join("\n") + "\n\n" if row.length > 0
45
+ def disallow(rule)
46
+ return unless rule.key?(:disallow)
47
+ lines = []
48
+ rule[:disallow].each do |path|
49
+ path = File.join('/', path) unless /^\// =~ path
50
+ lines << "Disallow: #{path}"
49
51
  end
52
+ lines
53
+ end
50
54
 
51
- data.join('')
55
+ def allow(rule)
56
+ return unless rule.key?(:allow)
57
+ lines = []
58
+ rule[:allow].each do |path|
59
+ path = File.join('/' + path) unless /^\// =~ path
60
+ lines << "Allow: #{path}"
61
+ end
62
+ lines
52
63
  end
53
64
 
54
65
  def sitemap(path)
55
- path ? "Sitemap: #{path}" : ""
66
+ path ? "Sitemap: #{path}" : ''
56
67
  end
57
68
  end
58
69
  end
59
70
  end
60
-
@@ -1,5 +1,6 @@
1
1
  module Middleman
2
+ # Middleman robots module
2
3
  module Robots
3
- VERSION = "1.0.0"
4
+ VERSION = '1.0.1'
4
5
  end
5
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-robots
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - yterajima
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-11 00:00:00.000000000 Z
11
+ date: 2015-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: middleman
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  version: '0'
126
126
  requirements: []
127
127
  rubyforge_project:
128
- rubygems_version: 2.2.2
128
+ rubygems_version: 2.4.5
129
129
  signing_key:
130
130
  specification_version: 4
131
131
  summary: Create robots.txt when do 'build'.