Sha256: 8de54ba40cb88129f6bf6003a0feb89d0d21cf508ac2ddbbaff24c6c34d6745a

Contents?: true

Size: 1.31 KB

Versions: 2

Compression:

Stored size: 1.31 KB

Contents

module Amber
  module Render
    class Apache

      def self.write_htaccess(site, src_dir, dst_dir)
        src_htaccess_file = File.join(src_dir, '.htaccess')
        dst_htaccess_file = File.join(dst_dir, '.htaccess')
        template = Tilt::ERBTemplate.new(template_path("htaccess.erb"))

        tail_content = nil
        if File.exist?(src_htaccess_file)
          tail_content = File.read(src_htaccess_file)
        end
        File.open(dst_htaccess_file, 'w', :encoding => 'UTF-8') do |f|
          f.write template.render(context_object(:site => site))
          if tail_content
            f.write "\n\n"
            f.write tail_content
          end
        end
      end

      def self.echo_config(site, directory)
        template = Tilt::ERBTemplate.new(
          site.path_prefix ? template_path('apache_config_with_prefix.erb') : template_path('apache_config.erb')
        )
        puts template.render(context_object(:site => site, :directory => directory))
      end

      def self.context_object(variables)
        object = Object.new
        variables.each do |name, value|
          object.instance_variable_set("@#{name}", value)
        end
        object
      end

      def self.template_path(filename)
        File.expand_path("../templates/#{filename}", File.dirname(__FILE__))
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
amber-0.3.12 lib/amber/render/apache.rb
amber-0.3.11 lib/amber/render/apache.rb