require 'rack' module Adyen module SkinBuilder class SkeletonAdapter def initialize(skins_directory) @skins_directory = File.dirname(skins_directory) @order_data_file = @skin = File.basename(skins_directory) end def call(env) body = File.read(File.join(File.dirname(__FILE__), '../../adyen/skeleton.html')) body = body.gsub(/\$skinCode/, @skin) %w(cheader pmheader pmfooter customfields cfooter).each do |inc| body = body.gsub(%r{\" end end end class Server class << self def run(config) handler = Rack::Handler.default handler.run(self.app(config), :Port => config[:port], :AccessLog => []) end def app(config = {}) Rack::Builder.app do use Rack::CommonLogger if config[:log] use Rack::Head # TODO: process Adyen default files at "/hpp" map("/sf/#{File.basename(config[:skins_directory])}") do run Rack::Cascade.new([ Rack::File.new(config[:skins_directory]), Rack::File.new(File.join(File.dirname(config[:skins_directory]), 'base')) ]) end map('/') { run Adyen::SkinBuilder::SkeletonAdapter.new(config[:skins_directory]) } end end end end end end