a bunch more to do with rewrites and headers and such

This commit is contained in:
John Bintz 2010-05-05 14:39:36 -04:00
parent 2c933b7837
commit 45b7062cc3
2 changed files with 40 additions and 2 deletions

View File

@ -127,10 +127,27 @@ module Apache
self << "Include #{opts * " "}"
end
def apache_alias(*opts)
self << "Alias #{quoteize(*opts) * " "}"
end
def rotatelogs(path, time)
"|#{@rotate_logs_path} #{path} #{time}"
end
def set_header(hash)
hash.each do |key, value|
output = "Header set #{quoteize(key)}"
case value
when String
output += " #{quoteize(value)}"
when Array
output += " #{quoteize(value.first)} #{value.last}"
end
self << output
end
end
private
def writable?(path)
if !File.directory? File.split(path).first

View File

@ -13,6 +13,10 @@ module Apache
def rewrites(&block)
self + indent(RewriteManager.build(&block))
end
def r301(*opt)
self << "Redirect permanent #{quoteize(*opt) * " "}"
end
end
class RewriteManager
@ -34,6 +38,13 @@ module Apache
@rewrites << @rewrite
end
def r301(*opts)
redirect = RedirectMatchPermanent.new
redirect.rule(*opts)
@rewrites << redirect
end
def rewrite_test(from, to, opts = {})
orig_from = from.dup
@rewrites.each do |r|
@ -48,7 +59,9 @@ module Apache
end
end
class RewriteRule
class MatchableThing
def tag; raise 'Override this method'; end
def initialize
@from = nil
@to = nil
@ -77,9 +90,17 @@ module Apache
end
output << "RewriteRule #{[@from.source, @to, @options].flatten * " "}"
output << "#{tag} #{[@from.source, @to, @options].flatten * " "}"
output * "\n"
end
end
class RewriteRule < MatchableThing
def tag; 'RewriteRule'; end
end
class RedirectMatchPermanent < MatchableThing
def tag; 'RedirectMatch permanent'; end
end
end