Class | Webgen::Source::FileSystem |
In: |
lib/webgen/source/filesystem.rb
|
Parent: | Object |
Create a new file system source for the root path root using the provided glob.
# File lib/webgen/source/filesystem.rb, line 39 39: def initialize(root, glob = '**/*') 40: if root =~ /^([a-zA-Z]:|\/)/ 41: @root = root 42: else 43: @root = File.join(WebsiteAccess.website.directory, root) 44: end 45: @glob = glob 46: end
Return all paths under root which match glob.
# File lib/webgen/source/filesystem.rb, line 49 49: def paths 50: @paths ||= Dir.glob(File.join(@root, @glob), File::FNM_DOTMATCH|File::FNM_CASEFOLD).to_set.collect do |f| 51: next unless File.exists?(f) # handle invalid links 52: temp = Pathname.new(f.sub(/^#{Regexp.escape(@root)}\/?/, '/')).cleanpath.to_s 53: temp += '/' if File.directory?(f) && temp[-1] != ?/ 54: path = Path.new(temp, f) 55: path 56: end.compact 57: end