Created
February 23, 2011 18:09
-
-
Save joeyAghion/840848 to your computer and use it in GitHub Desktop.
Processes a directory of files and ERB templates into a destination directory (within the Rails app's environment).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# DirectoryGenerator.new.generate(Rails.root.join('src'), Rails.root.join('public', 'dest')) | |
class DirectoryGenerator | |
include Rails.application.routes.url_helpers | |
include ActionView::Helpers::TagHelper | |
default_url_options[:host] = 'www.example.com' | |
def generate(source, destination) | |
FileUtils.rmtree(destination) | |
FileUtils.mkdir_p(destination) | |
Dir.glob(File.join(source, '*')).each do |path| | |
pathname = Pathname.new(path) | |
if pathname.extname == '.erb' | |
File.open(destination.join(pathname.basename.sub(/\.erb$/, '')), 'w') do |file| | |
file.puts(ERB.new(File.read(path)).result(binding)) | |
end | |
else | |
FileUtils.cp(pathname, File.join(destination, pathname.basename)) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment