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