Class: Amber::Render::Apache

Inherits:
Object
  • Object
show all
Defined in:
lib/amber/render/apache.rb

Class Method Summary collapse

Class Method Details

.context_object(variables) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/amber/render/apache.rb', line 30

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

.echo_config(site, directory) ⇒ Object



23
24
25
26
27
28
# File 'lib/amber/render/apache.rb', line 23

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

.template_path(filename) ⇒ Object



38
39
40
# File 'lib/amber/render/apache.rb', line 38

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

.write_htaccess(site, src_dir, dst_dir) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/amber/render/apache.rb', line 5

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.exists?(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