diff options
author | elijah <elijah@riseup.net> | 2013-02-12 21:33:39 -0800 |
---|---|---|
committer | elijah <elijah@riseup.net> | 2013-02-12 21:33:39 -0800 |
commit | 71ec0edea3f87fb69222dbb6fe025c2211402ca2 (patch) | |
tree | 5490323e8686df14165ccf5f37fa2d691fc99b88 /lib/site_mount_point.rb | |
parent | 00c785b728c5d97335b87e3eb7d10b9ad0c46d35 (diff) |
added capacity for pulling static pages from multiple directory source trees.
Diffstat (limited to 'lib/site_mount_point.rb')
-rw-r--r-- | lib/site_mount_point.rb | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/lib/site_mount_point.rb b/lib/site_mount_point.rb new file mode 100644 index 0000000..0b8224a --- /dev/null +++ b/lib/site_mount_point.rb @@ -0,0 +1,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
\ No newline at end of file |