From 71ec0edea3f87fb69222dbb6fe025c2211402ca2 Mon Sep 17 00:00:00 2001 From: elijah Date: Tue, 12 Feb 2013 21:33:39 -0800 Subject: added capacity for pulling static pages from multiple directory source trees. --- lib/site_mount_point.rb | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 lib/site_mount_point.rb (limited to 'lib/site_mount_point.rb') 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 -- cgit v1.2.3