Class: Edison::StaticFileHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/edison.rb

Class Method Summary collapse

Class Method Details

.filter_blacklisted(directory, files) ⇒ Object



113
114
115
116
117
118
119
120
# File 'lib/edison.rb', line 113

def self.filter_blacklisted(directory, files)
	blacklist = ["Gemfile", "Gemfile.lock", "config.rb", "Rakefile", "Procfile", "Makefile"]
	files.reject do |fname|
		name = fname.sub(/^#{directory}\//,'')
		dirname = File.dirname(fname)
		blacklist.include?(name) or name =~ /^_/ or File.directory?(fname)
	end
end

.load(directory) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/edison.rb', line 121

def self.load(directory)
	static = Dir[File.join(directory, "**/*")]
	static = self.filter_blacklisted(directory, static)

	possibly_dynamic = []
	just_copy = []

	static.each do |fname|
		name = fname.sub(/^#{directory}\//,'')
		if %w{.html .md}.include?(File.extname(fname))
			data = Hashie::Mash.new Edison::YAMLFrontMatter.read(fname)
			url = name.sub(/\.md$/,'')
			possibly_dynamic << [url, data]
		else
			just_copy << name
		end
	end

	OpenStruct.new(
		:possibly_dynamic => possibly_dynamic,
		:just_copy => just_copy
	)
end