added capacity for pulling static pages from multiple directory source trees.
[leap_website.git] / lib / site_mount_point.rb
1 #
2 # A site can have many 'mount points' -- places in the site tree where different directories are inserted.
3 #
4 # At a minimum, every site needs a mount point for '/'
5 #
6 class SiteMountPoint
7
8   attr_accessor :directory
9   attr_accessor :relative_directory
10   attr_accessor :path
11   attr_accessor :options
12   attr_accessor :menu_file
13   attr_accessor :locales_dir
14   attr_accessor :timestamp
15
16   def initialize(site_config, directory_source, options={})
17     if directory_source.starts_with?('/')
18       @directory = directory_source
19     else
20       @directory = File.expand_path(directory_source, File.dirname(site_config.file_path))
21     end
22
23     @path               = options[:path]
24     @relative_directory = relative_dir_path(@directory)
25     @menu_file          = file_path('menu.txt')
26     @locales_dir        = file_path('locales')
27     @options            = options
28     reset_timestamp
29   end
30
31   def changed?
32     File.mtime(@directory) > @timestamp
33   end
34
35   def reset_timestamp
36     @timestamp = File.mtime(@directory)
37   end
38
39   private
40
41   def file_path(file)
42     path = File.join(@directory, file)
43     if File.exists?(path)
44       path
45     else
46       nil
47     end
48   end
49
50   #
51   # returns path relative to app/views
52   #
53   def relative_dir_path(directory)
54     if Rails.root
55       Pathname.new(directory).relative_path_from(Pathname.new(Rails.root + 'app/views')).to_s
56     end
57   end
58
59 end