a bunch of it works
This commit is contained in:
parent
e802ef4ed1
commit
c116f2f47f
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
.loadpath
|
||||
.project
|
12
Rakefile
Normal file
12
Rakefile
Normal file
@ -0,0 +1,12 @@
|
||||
$LOAD_PATH << 'lib'
|
||||
|
||||
require 'apache'
|
||||
|
||||
namespace :apache do
|
||||
desc "Generate the configs"
|
||||
task :generate, :path do |t, args|
|
||||
Dir[File.join(args[:path], '**', '*.rb')].each do |file|
|
||||
require file
|
||||
end
|
||||
end
|
||||
end
|
3
lib/apache.rb
Normal file
3
lib/apache.rb
Normal file
@ -0,0 +1,3 @@
|
||||
Dir[File.join(File.dirname(__FILE__), '**', '*.rb')].each do |file|
|
||||
require file
|
||||
end
|
23
lib/apache/config.rb
Normal file
23
lib/apache/config.rb
Normal file
@ -0,0 +1,23 @@
|
||||
require 'apache/master'
|
||||
|
||||
module Apache
|
||||
class Config
|
||||
class << self
|
||||
include Apache::Master
|
||||
include Apache::Quoteize
|
||||
|
||||
def build(target, &block)
|
||||
@config = []
|
||||
@indent = 0
|
||||
|
||||
self.instance_eval(&block)
|
||||
|
||||
puts @config * "\n"
|
||||
|
||||
#File.open(target, 'w') { |f| f.puts @config * "\n" }
|
||||
end
|
||||
end
|
||||
|
||||
block_methods :if_module, :directory, :virtual_host
|
||||
end
|
||||
end
|
86
lib/apache/master.rb
Normal file
86
lib/apache/master.rb
Normal file
@ -0,0 +1,86 @@
|
||||
module Apache
|
||||
module Quoteize
|
||||
def quoteize(*args)
|
||||
args.collect { |a| %{"#{a}"} }
|
||||
end
|
||||
end
|
||||
|
||||
module Master
|
||||
def modules(&block)
|
||||
@config << Modules.build(&block)
|
||||
end
|
||||
|
||||
def indent(string)
|
||||
" " * (@indent * 2) + string
|
||||
end
|
||||
|
||||
def block_methods(*methods)
|
||||
methods.each do |method|
|
||||
self.class.class_eval <<-EOT
|
||||
def #{method}(name = nil, &block)
|
||||
tag_name = apachify("#{method}")
|
||||
start = [ tag_name ]
|
||||
start << '"' + name + '"' if name
|
||||
start = start.uniq.join(' ')
|
||||
|
||||
@config << "" if (@indent == 0)
|
||||
@config << indent("<" + start + ">")
|
||||
@indent += 1
|
||||
self.instance_eval(&block)
|
||||
@indent -= 1
|
||||
@config << indent("</" + tag_name + ">")
|
||||
end
|
||||
EOT
|
||||
end
|
||||
end
|
||||
|
||||
def method_missing(method, *args)
|
||||
@config << indent([ apachify(method), *quoteize(*args) ] * ' ')
|
||||
end
|
||||
|
||||
def runner(user, group = nil)
|
||||
@config << indent("User #{user}")
|
||||
@config << indent("Group #{group}") if group
|
||||
end
|
||||
|
||||
def deny_from_all
|
||||
@config << indent("Order deny,allow")
|
||||
@config << indent("Deny from all")
|
||||
end
|
||||
|
||||
def allow_from_all
|
||||
@config << indent("Order allow,deny")
|
||||
@config << indent("Allow from all")
|
||||
end
|
||||
|
||||
private
|
||||
def apachify(name)
|
||||
name = name.to_s
|
||||
case name
|
||||
when true
|
||||
else
|
||||
name.split("_").collect(&:capitalize).join
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Modules
|
||||
class << self
|
||||
include Apache::Quoteize
|
||||
|
||||
def build(&block)
|
||||
@modules = []
|
||||
|
||||
self.instance_eval(&block)
|
||||
|
||||
@modules
|
||||
end
|
||||
|
||||
def method_missing(method, *args)
|
||||
module_name = "#{method}_module"
|
||||
module_path = args[0] || "modules/mod_#{method}.so"
|
||||
@modules << [ 'LoadModule', *quoteize(module_name, module_path) ] * " "
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
3
spec/master_spec.rb
Normal file
3
spec/master_spec.rb
Normal file
@ -0,0 +1,3 @@
|
||||
if __FILE__ == $0
|
||||
# TODO Generated stub
|
||||
end
|
27
test/config/httpd.rb
Normal file
27
test/config/httpd.rb
Normal file
@ -0,0 +1,27 @@
|
||||
Apache::Config.build('httpd.conf') do
|
||||
server_root '/var/html/apache'
|
||||
|
||||
modules do
|
||||
expires
|
||||
headers
|
||||
end
|
||||
|
||||
passenger_root '/var/html/ree/lib/ruby/gems/1.8/gems/passenger-2.2.11'
|
||||
passenger_ruby '/var/html/ree/bin/ruby'
|
||||
|
||||
if_module "!mpm_netware" do
|
||||
runner 'webby', 'opoadm'
|
||||
end
|
||||
|
||||
directory '/' do
|
||||
options 'FollowSymLinks'
|
||||
allow_override 'None'
|
||||
deny_from_all
|
||||
end
|
||||
|
||||
virtual_host '127.0.0.1:80' do
|
||||
directory '/' do
|
||||
allow_from_all
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user