Skip to content

Commit

Permalink
Merge branch 'feature/match_with_params'
Browse files Browse the repository at this point in the history
  • Loading branch information
learnjin committed Jul 31, 2015
2 parents d88241f + 3bfee02 commit e6e4c9a
Show file tree
Hide file tree
Showing 30 changed files with 507 additions and 524 deletions.
12 changes: 12 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
inherit_from: .rubocop_todo.yml

#AllCops:
# Include:
# - '**/Rakefile'
# - '**/config.ru'
# Exclude:
# - 'test/fixtures/**/*'
# - 'db/**/*'
# - 'config/**/*'
# - 'vendor/**/*'
# - '/app/helpers/application_helper.rb'
116 changes: 116 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# This configuration was generated by `rubocop --auto-gen-config`
# on 2015-07-31 12:23:42 +0200 using RuboCop version 0.32.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# Configuration parameters: AllowSafeAssignment.
Lint/AssignmentInCondition:
Enabled: false

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AlignWith, SupportedStyles, AutoCorrect.
Lint/DefEndAlignment:
Enabled: false

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AlignWith, SupportedStyles, AutoCorrect.
Lint/EndAlignment:
Enabled: false

# Offense count: 2
Lint/UselessAssignment:
Enabled: false

# Offense count: 9
Metrics/AbcSize:
Max: 71

# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 209

# Offense count: 4
Metrics/CyclomaticComplexity:
Max: 16

# Offense count: 40
# Configuration parameters: AllowURI, URISchemes.
Metrics/LineLength:
Max: 268

# Offense count: 10
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 35

# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ModuleLength:
Max: 231

# Offense count: 4
Metrics/PerceivedComplexity:
Max: 18

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Style/AndOr:
Enabled: false

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
Style/BlockDelimiters:
Enabled: false

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Style/BracesAroundHashParameters:
Enabled: false

# Offense count: 2
# Configuration parameters: EnforcedStyle, SupportedStyles.
Style/ClassAndModuleChildren:
Enabled: false

# Offense count: 14
Style/Documentation:
Enabled: false

# Offense count: 3
# Configuration parameters: Exclude.
Style/FileName:
Enabled: false

# Offense count: 1
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Enabled: false

# Offense count: 1
Style/ModuleFunction:
Enabled: false

# Offense count: 2
# Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles.
Style/Next:
Enabled: false

# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
Style/RegexpLiteral:
Enabled: false

# Offense count: 1
# Configuration parameters: Methods.
Style/SingleLineBlockParams:
Enabled: false
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source "http://rubygems.org"
source 'http://rubygems.org'

# Specify your gem's dependencies in rewritten.gemspec
gemspec
4 changes: 4 additions & 0 deletions HISTORY.rdoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
== 0.16.0

* Makes rewritten work with fullpath. Example: Matching on '/some/url?q=1' will work now

== 0.15.2

* Fixes nested parameters
Expand Down
6 changes: 1 addition & 5 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require 'rake/testtask'
require 'rdoc/task'

desc 'Default: run all tests'
task :default => :test
task default: :test

Bundler::GemHelper.install_tasks

Expand All @@ -23,7 +23,3 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_files.include('HISTORY.rdoc')
rdoc.rdoc_files.include('lib/**/*.rb')
end




25 changes: 11 additions & 14 deletions bin/rewritten-dump.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,37 @@
require 'rewritten'

options = {
:out => 'rewritten.csv',
:verbose => false
out: 'rewritten.csv',
verbose: false
}

op = OptionParser.new do |opts|
opts.banner = "Usage: rewriten-dump.rb [options]"
opts.banner = 'Usage: rewriten-dump.rb [options]'

opts.on("-v", "--verbose", "be more verbose") do
opts.on('-v', '--verbose', 'be more verbose') do
options[:verbose] = true
end

opts.on("-o", "--out FILE", 'output file or "-" for stdout') do |o|
opts.on('-o', '--out FILE', 'output file or "-" for stdout') do |o|
options[:out] = o
end

opts.on("-u", "--uri URI", 'uri to the redis db') do |uri|
opts.on('-u', '--uri URI', 'uri to the redis db') do |uri|
options[:uri] = uri
end

opts.on("-h", "--help", 'print help') do
opts.on('-h', '--help', 'print help') do
puts opts
exit 0
end

end
op.parse!

Rewritten.redis = options[:uri] if options[:uri]
Rewritten.redis = options[:uri] if options[:uri]

file = options[:out] == "-" ? STDOUT : File.open(options[:out], "w")
file = options[:out] == '-' ? STDOUT : File.open(options[:out], 'w')

file.puts "#from;to"
file.puts '#from;to'
Rewritten.all_tos.each do |to|
file.puts Rewritten.get_all_translations(to).map{|from| "#{Rewritten.full_line(from)};#{to}"}.join("\n")
file.puts Rewritten.get_all_translations(to).map { |from| "#{Rewritten.full_line(from)};#{to}" }.join("\n")
end


21 changes: 9 additions & 12 deletions bin/rewritten-import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,27 @@
require 'multi_json'

options = {
:drop => false
drop: false
}

op = OptionParser.new do |opts|
opts.banner = "Usage: rewriten-dump.rb [options]"
opts.banner = 'Usage: rewriten-dump.rb [options]'

opts.on("-v", "--verbose", "be more verbose") do |v|
opts.on('-v', '--verbose', 'be more verbose') do |v|
options[:verbose] = v
end

opts.on("-f", "--file FILE", 'input file') do |o|
opts.on('-f', '--file FILE', 'input file') do |o|
options[:file] = o
end

opts.on("-u", "--uri URI", 'uri to the redis db') do |uri|
opts.on('-u', '--uri URI', 'uri to the redis db') do |uri|
options[:uri] = uri
end

opts.on("-d", "--drop", 'drop translations first') do
opts.on('-d', '--drop', 'drop translations first') do
options[:drop] = true
end

end

op.parse!
Expand All @@ -38,15 +37,13 @@
exit
end

Rewritten.redis = options[:uri] if options[:uri]
Rewritten.redis = options[:uri] if options[:uri]

Rewritten.clear_translations if options[:drop]

File.open(options[:file]).each do |line|
next if line =~ /^#/
from,to = line.split(";")
from, to = line.split(';')
puts "adding #{from} -> #{to}" if options[:verbose]
Rewritten.add_translation(from,to.chomp)
Rewritten.add_translation(from, to.chomp)
end


16 changes: 7 additions & 9 deletions bin/rewritten-web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,18 @@
rescue LoadError
require 'rubygems'
require 'vegas'
end
end

require 'rewritten/server'

Vegas::Runner.new(Rewritten::Server, 'rewritten-web', {
:before_run => lambda {|v|
path = (ENV['RESQUECONFIG'] || v.args.first)
load path.to_s.strip if path
}
}) do |runner, opts, app|
opts.on('-N NAMESPACE', "--namespace NAMESPACE", "set the Redis namespace") {|namespace|
before_run: lambda {|v|
path = (ENV['RESQUECONFIG'] || v.args.first)
load path.to_s.strip if path
}
}) do |runner, opts, _app|
opts.on('-N NAMESPACE', '--namespace NAMESPACE', 'set the Redis namespace') {|namespace|
runner.logger.info "Using Redis namespace '#{namespace}'"
Rewritten.redis.namespace = namespace
}
end


1 change: 0 additions & 1 deletion config.ru
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'rewritten'

run Rewritten::Server

20 changes: 6 additions & 14 deletions lib/rack/canonical.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
require 'rack'

module Rack

module Rewritten

class Canonical

def initialize(app)
@app = app
end
Expand All @@ -15,30 +12,25 @@ def call(env)

status, headers, response = @app.call(req.env)

if status == 200 && headers["Content-Type"] =~ /text\/html|application\/xhtml\+xml/
body = ""
if status == 200 && headers['Content-Type'] =~ /text\/html|application\/xhtml\+xml/
body = ''
response.each { |part| body << part }
index = body.rindex("</head>")
index = body.rindex('</head>')
if index
# go with a request duplicate since infinitive works on translations
target_req = req.dup
target_req.path_info = ::Rewritten.infinitive( ::Rewritten.get_current_translation(req.path) )
target_req.path_info = ::Rewritten.infinitive(::Rewritten.get_current_translation(req.path))
target_req.env['QUERY_STRING'] = ''
target = target_req.url

body.insert(index, %Q|<link rel="canonical" href="#{target}"/>| )
headers["Content-Length"] = body.length.to_s
body.insert(index, %(<link rel="canonical" href="#{target}"/>))
headers['Content-Length'] = body.length.to_s
response = [body]
end

end
[status, headers, response]
end

end

end

end


21 changes: 7 additions & 14 deletions lib/rack/dummy.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
require 'rack'

module Rack

class Dummy

def call(env)
puts "-> Rack::Dummy"
puts '-> Rack::Dummy'
lines = []
req = Rack::Request.new(env)
lines << req.path
lines << req.params.inspect
lines << req.host
lines << req.env.inspect
lines << "SUBDOMAIN: #{env['SUBDOMAIN']}"
lines << req.path
lines << req.params.inspect
lines << req.host
lines << req.env.inspect
lines << "SUBDOMAIN: #{env['SUBDOMAIN']}"
lines << '<a href="/some/resource">'
[200, {"Content-Type" => "text/plain"}, lines.join("\n")]
[200, { 'Content-Type' => 'text/plain' }, lines.join("\n")]
end

end

end



Loading

0 comments on commit e6e4c9a

Please sign in to comment.