rewritten 0.15.2 → 0.16.0

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: b7a6bb53aa68bfdf91a14ddb75bc1c84626d4722
4
- data.tar.gz: f0b6c9dc59ae890105a08d8e718da649903949f4
3
+ metadata.gz: 1c46c2783b6c6c0b7513137ee064d35204d248a8
4
+ data.tar.gz: e30fe5d81af0086b38aca82dbd03e0a38b9833ef
5
5
  SHA512:
6
- metadata.gz: 943f60c79e3c96113f0fb4cd6556cdbb079c1cd34caa476ca46065c2529096c3661c8a7d1a0cc5bc31d6be293694bffa3da898b5bc4b689eb2e05b7e4a9ac933
7
- data.tar.gz: 135a2c929eaaedd54cd8558797885632eb42a22d806732c0dc221f8d984f20f31a870bc20bdadacbd42e023be8645267f7d7f7be51614b0f8d7faaffc21905f3
6
+ metadata.gz: d04627b4246a02ffb960087a07e54ac2a9d5f33196ef32d78b65e3b2ccaabe3515384a88f7536ed8305c9f5ceeb800bcf4c1fac8e9a1f109203839466727d113
7
+ data.tar.gz: 92736611e92c52327f5faa2754668c9cc97578f806c5aa145b2a7963c3616c0c137fb5c0333679b5312c1e61ecf2f30289494554b014b9599afa7cb92f878eb2
@@ -0,0 +1,12 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ #AllCops:
4
+ # Include:
5
+ # - '**/Rakefile'
6
+ # - '**/config.ru'
7
+ # Exclude:
8
+ # - 'test/fixtures/**/*'
9
+ # - 'db/**/*'
10
+ # - 'config/**/*'
11
+ # - 'vendor/**/*'
12
+ # - '/app/helpers/application_helper.rb'
@@ -0,0 +1,116 @@
1
+ # This configuration was generated by `rubocop --auto-gen-config`
2
+ # on 2015-07-31 12:23:42 +0200 using RuboCop version 0.32.0.
3
+ # The point is for the user to remove these configuration records
4
+ # one by one as the offenses are removed from the code base.
5
+ # Note that changes in the inspected code, or installation of new
6
+ # versions of RuboCop, may require this file to be generated again.
7
+
8
+ # Offense count: 1
9
+ # Configuration parameters: AllowSafeAssignment.
10
+ Lint/AssignmentInCondition:
11
+ Enabled: false
12
+
13
+ # Offense count: 1
14
+ # Cop supports --auto-correct.
15
+ # Configuration parameters: AlignWith, SupportedStyles, AutoCorrect.
16
+ Lint/DefEndAlignment:
17
+ Enabled: false
18
+
19
+ # Offense count: 1
20
+ # Cop supports --auto-correct.
21
+ # Configuration parameters: AlignWith, SupportedStyles, AutoCorrect.
22
+ Lint/EndAlignment:
23
+ Enabled: false
24
+
25
+ # Offense count: 2
26
+ Lint/UselessAssignment:
27
+ Enabled: false
28
+
29
+ # Offense count: 9
30
+ Metrics/AbcSize:
31
+ Max: 71
32
+
33
+ # Offense count: 1
34
+ # Configuration parameters: CountComments.
35
+ Metrics/ClassLength:
36
+ Max: 209
37
+
38
+ # Offense count: 4
39
+ Metrics/CyclomaticComplexity:
40
+ Max: 16
41
+
42
+ # Offense count: 40
43
+ # Configuration parameters: AllowURI, URISchemes.
44
+ Metrics/LineLength:
45
+ Max: 268
46
+
47
+ # Offense count: 10
48
+ # Configuration parameters: CountComments.
49
+ Metrics/MethodLength:
50
+ Max: 35
51
+
52
+ # Offense count: 1
53
+ # Configuration parameters: CountComments.
54
+ Metrics/ModuleLength:
55
+ Max: 231
56
+
57
+ # Offense count: 4
58
+ Metrics/PerceivedComplexity:
59
+ Max: 18
60
+
61
+ # Offense count: 1
62
+ # Cop supports --auto-correct.
63
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
64
+ Style/AndOr:
65
+ Enabled: false
66
+
67
+ # Offense count: 2
68
+ # Cop supports --auto-correct.
69
+ # Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
70
+ Style/BlockDelimiters:
71
+ Enabled: false
72
+
73
+ # Offense count: 1
74
+ # Cop supports --auto-correct.
75
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
76
+ Style/BracesAroundHashParameters:
77
+ Enabled: false
78
+
79
+ # Offense count: 2
80
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
81
+ Style/ClassAndModuleChildren:
82
+ Enabled: false
83
+
84
+ # Offense count: 14
85
+ Style/Documentation:
86
+ Enabled: false
87
+
88
+ # Offense count: 3
89
+ # Configuration parameters: Exclude.
90
+ Style/FileName:
91
+ Enabled: false
92
+
93
+ # Offense count: 1
94
+ # Configuration parameters: MinBodyLength.
95
+ Style/GuardClause:
96
+ Enabled: false
97
+
98
+ # Offense count: 1
99
+ Style/ModuleFunction:
100
+ Enabled: false
101
+
102
+ # Offense count: 2
103
+ # Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles.
104
+ Style/Next:
105
+ Enabled: false
106
+
107
+ # Offense count: 3
108
+ # Cop supports --auto-correct.
109
+ # Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
110
+ Style/RegexpLiteral:
111
+ Enabled: false
112
+
113
+ # Offense count: 1
114
+ # Configuration parameters: Methods.
115
+ Style/SingleLineBlockParams:
116
+ Enabled: false
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "http://rubygems.org"
1
+ source 'http://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in rewritten.gemspec
4
4
  gemspec
@@ -1,3 +1,7 @@
1
+ == 0.16.0
2
+
3
+ * Makes rewritten work with fullpath. Example: Matching on '/some/url?q=1' will work now
4
+
1
5
  == 0.15.2
2
6
 
3
7
  * Fixes nested parameters
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require 'rake/testtask'
3
3
  require 'rdoc/task'
4
4
 
5
5
  desc 'Default: run all tests'
6
- task :default => :test
6
+ task default: :test
7
7
 
8
8
  Bundler::GemHelper.install_tasks
9
9
 
@@ -23,7 +23,3 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
23
23
  rdoc.rdoc_files.include('HISTORY.rdoc')
24
24
  rdoc.rdoc_files.include('lib/**/*.rb')
25
25
  end
26
-
27
-
28
-
29
-
@@ -6,40 +6,37 @@ require 'optparse'
6
6
  require 'rewritten'
7
7
 
8
8
  options = {
9
- :out => 'rewritten.csv',
10
- :verbose => false
9
+ out: 'rewritten.csv',
10
+ verbose: false
11
11
  }
12
12
 
13
13
  op = OptionParser.new do |opts|
14
- opts.banner = "Usage: rewriten-dump.rb [options]"
14
+ opts.banner = 'Usage: rewriten-dump.rb [options]'
15
15
 
16
- opts.on("-v", "--verbose", "be more verbose") do
16
+ opts.on('-v', '--verbose', 'be more verbose') do
17
17
  options[:verbose] = true
18
18
  end
19
19
 
20
- opts.on("-o", "--out FILE", 'output file or "-" for stdout') do |o|
20
+ opts.on('-o', '--out FILE', 'output file or "-" for stdout') do |o|
21
21
  options[:out] = o
22
22
  end
23
23
 
24
- opts.on("-u", "--uri URI", 'uri to the redis db') do |uri|
24
+ opts.on('-u', '--uri URI', 'uri to the redis db') do |uri|
25
25
  options[:uri] = uri
26
26
  end
27
27
 
28
- opts.on("-h", "--help", 'print help') do
28
+ opts.on('-h', '--help', 'print help') do
29
29
  puts opts
30
30
  exit 0
31
31
  end
32
-
33
32
  end
34
33
  op.parse!
35
34
 
36
- Rewritten.redis = options[:uri] if options[:uri]
35
+ Rewritten.redis = options[:uri] if options[:uri]
37
36
 
38
- file = options[:out] == "-" ? STDOUT : File.open(options[:out], "w")
37
+ file = options[:out] == '-' ? STDOUT : File.open(options[:out], 'w')
39
38
 
40
- file.puts "#from;to"
39
+ file.puts '#from;to'
41
40
  Rewritten.all_tos.each do |to|
42
- file.puts Rewritten.get_all_translations(to).map{|from| "#{Rewritten.full_line(from)};#{to}"}.join("\n")
41
+ file.puts Rewritten.get_all_translations(to).map { |from| "#{Rewritten.full_line(from)};#{to}" }.join("\n")
43
42
  end
44
-
45
-
@@ -7,28 +7,27 @@ require 'rewritten'
7
7
  require 'multi_json'
8
8
 
9
9
  options = {
10
- :drop => false
10
+ drop: false
11
11
  }
12
12
 
13
13
  op = OptionParser.new do |opts|
14
- opts.banner = "Usage: rewriten-dump.rb [options]"
14
+ opts.banner = 'Usage: rewriten-dump.rb [options]'
15
15
 
16
- opts.on("-v", "--verbose", "be more verbose") do |v|
16
+ opts.on('-v', '--verbose', 'be more verbose') do |v|
17
17
  options[:verbose] = v
18
18
  end
19
19
 
20
- opts.on("-f", "--file FILE", 'input file') do |o|
20
+ opts.on('-f', '--file FILE', 'input file') do |o|
21
21
  options[:file] = o
22
22
  end
23
23
 
24
- opts.on("-u", "--uri URI", 'uri to the redis db') do |uri|
24
+ opts.on('-u', '--uri URI', 'uri to the redis db') do |uri|
25
25
  options[:uri] = uri
26
26
  end
27
27
 
28
- opts.on("-d", "--drop", 'drop translations first') do
28
+ opts.on('-d', '--drop', 'drop translations first') do
29
29
  options[:drop] = true
30
30
  end
31
-
32
31
  end
33
32
 
34
33
  op.parse!
@@ -38,15 +37,13 @@ unless options[:file]
38
37
  exit
39
38
  end
40
39
 
41
- Rewritten.redis = options[:uri] if options[:uri]
40
+ Rewritten.redis = options[:uri] if options[:uri]
42
41
 
43
42
  Rewritten.clear_translations if options[:drop]
44
43
 
45
44
  File.open(options[:file]).each do |line|
46
45
  next if line =~ /^#/
47
- from,to = line.split(";")
46
+ from, to = line.split(';')
48
47
  puts "adding #{from} -> #{to}" if options[:verbose]
49
- Rewritten.add_translation(from,to.chomp)
48
+ Rewritten.add_translation(from, to.chomp)
50
49
  end
51
-
52
-
@@ -6,20 +6,18 @@ begin
6
6
  rescue LoadError
7
7
  require 'rubygems'
8
8
  require 'vegas'
9
- end
9
+ end
10
10
 
11
11
  require 'rewritten/server'
12
12
 
13
13
  Vegas::Runner.new(Rewritten::Server, 'rewritten-web', {
14
- :before_run => lambda {|v|
15
- path = (ENV['RESQUECONFIG'] || v.args.first)
16
- load path.to_s.strip if path
17
- }
18
- }) do |runner, opts, app|
19
- opts.on('-N NAMESPACE', "--namespace NAMESPACE", "set the Redis namespace") {|namespace|
14
+ before_run: lambda {|v|
15
+ path = (ENV['RESQUECONFIG'] || v.args.first)
16
+ load path.to_s.strip if path
17
+ }
18
+ }) do |runner, opts, _app|
19
+ opts.on('-N NAMESPACE', '--namespace NAMESPACE', 'set the Redis namespace') {|namespace|
20
20
  runner.logger.info "Using Redis namespace '#{namespace}'"
21
21
  Rewritten.redis.namespace = namespace
22
22
  }
23
23
  end
24
-
25
-
data/config.ru CHANGED
@@ -1,4 +1,3 @@
1
1
  require 'rewritten'
2
2
 
3
3
  run Rewritten::Server
4
-
@@ -1,11 +1,8 @@
1
1
  require 'rack'
2
2
 
3
3
  module Rack
4
-
5
4
  module Rewritten
6
-
7
5
  class Canonical
8
-
9
6
  def initialize(app)
10
7
  @app = app
11
8
  end
@@ -15,30 +12,25 @@ module Rack
15
12
 
16
13
  status, headers, response = @app.call(req.env)
17
14
 
18
- if status == 200 && headers["Content-Type"] =~ /text\/html|application\/xhtml\+xml/
19
- body = ""
15
+ if status == 200 && headers['Content-Type'] =~ /text\/html|application\/xhtml\+xml/
16
+ body = ''
20
17
  response.each { |part| body << part }
21
- index = body.rindex("</head>")
18
+ index = body.rindex('</head>')
22
19
  if index
23
20
  # go with a request duplicate since infinitive works on translations
24
21
  target_req = req.dup
25
- target_req.path_info = ::Rewritten.infinitive( ::Rewritten.get_current_translation(req.path) )
22
+ target_req.path_info = ::Rewritten.infinitive(::Rewritten.get_current_translation(req.path))
26
23
  target_req.env['QUERY_STRING'] = ''
27
24
  target = target_req.url
28
25
 
29
- body.insert(index, %Q|<link rel="canonical" href="#{target}"/>| )
30
- headers["Content-Length"] = body.length.to_s
26
+ body.insert(index, %(<link rel="canonical" href="#{target}"/>))
27
+ headers['Content-Length'] = body.length.to_s
31
28
  response = [body]
32
29
  end
33
30
 
34
31
  end
35
32
  [status, headers, response]
36
33
  end
37
-
38
34
  end
39
-
40
35
  end
41
-
42
36
  end
43
-
44
-
@@ -1,25 +1,18 @@
1
1
  require 'rack'
2
2
 
3
3
  module Rack
4
-
5
4
  class Dummy
6
-
7
5
  def call(env)
8
- puts "-> Rack::Dummy"
6
+ puts '-> Rack::Dummy'
9
7
  lines = []
10
8
  req = Rack::Request.new(env)
11
- lines << req.path
12
- lines << req.params.inspect
13
- lines << req.host
14
- lines << req.env.inspect
15
- lines << "SUBDOMAIN: #{env['SUBDOMAIN']}"
9
+ lines << req.path
10
+ lines << req.params.inspect
11
+ lines << req.host
12
+ lines << req.env.inspect
13
+ lines << "SUBDOMAIN: #{env['SUBDOMAIN']}"
16
14
  lines << '<a href="/some/resource">'
17
- [200, {"Content-Type" => "text/plain"}, lines.join("\n")]
15
+ [200, { 'Content-Type' => 'text/plain' }, lines.join("\n")]
18
16
  end
19
-
20
17
  end
21
-
22
18
  end
23
-
24
-
25
-
@@ -1,11 +1,8 @@
1
1
  require 'rack'
2
2
 
3
3
  module Rack
4
-
5
4
  module Rewritten
6
-
7
5
  class Html
8
-
9
6
  def initialize(app)
10
7
  @app = app
11
8
  end
@@ -20,15 +17,13 @@ module Rack
20
17
  links = line.scan(/href="([^"]+)"/).flatten.uniq
21
18
  res = line
22
19
  links.each do |link|
23
-
24
20
  if ::Rewritten.exist_translation_for?(link)
25
21
  t = ::Rewritten.get_current_translation(link)
26
- res.gsub!(%Q|href="#{link}"|, %Q|href="#{t}"|) if t
27
- res.gsub!(%Q|href='#{link}'|, %Q|href='#{t}'|) if t
28
- res.gsub!(%Q|href="#{link}?|, %Q|href="#{t}?|) if t
29
- res.gsub!(%Q|href='#{link}?|, %Q|href='#{t}?|) if t
22
+ res.gsub!(%(href="#{link}"), %(href="#{t}")) if t
23
+ res.gsub!(%(href='#{link}'), %(href='#{t}')) if t
24
+ res.gsub!(%(href="#{link}?), %(href="#{t}?)) if t
25
+ res.gsub!(%(href='#{link}?), %(href='#{t}?)) if t
30
26
  end
31
-
32
27
  end
33
28
  new_response << res
34
29
  end
@@ -38,10 +33,6 @@ module Rack
38
33
 
39
34
  [status, headers, new_response]
40
35
  end
41
-
42
36
  end
43
-
44
37
  end
45
38
  end
46
-
47
-
@@ -1,11 +1,8 @@
1
1
  require 'rack'
2
2
 
3
3
  module Rack
4
-
5
4
  module Rewritten
6
-
7
5
  class Record
8
-
9
6
  def initialize(app)
10
7
  @app = app
11
8
  end
@@ -13,18 +10,15 @@ module Rack
13
10
  def call(env)
14
11
  req = Rack::Request.new(env.clone)
15
12
  status, headers, response = @app.call(env)
16
- puts "-> Rack::Rewritten::Record"
13
+ puts '-> Rack::Rewritten::Record'
17
14
  puts headers.inspect
18
15
 
19
- if [200,301,302].include?(status)
20
- ::Rewritten.add_hit(req.path,status, headers["Content-Type"]) if headers["Content-Type"] =~ /text\/html/
16
+ if [200, 301, 302].include?(status)
17
+ ::Rewritten.add_hit(req.path, status, headers['Content-Type']) if headers['Content-Type'] =~ /text\/html/
21
18
  end
22
19
 
23
20
  [status, headers, response]
24
21
  end
25
-
26
22
  end
27
-
28
23
  end
29
-
30
24
  end