- This requires Hamlbars 2.0
- Use at your own risk
- Writes an .hbs file for every .hamlbars file
- Does not handle exceptions / invalid files
- Blindly deletes existing files
Usage:
Hamlbars::Converter.process_directory(pathName)| class File | |
| def to_str | |
| path | |
| end | |
| end | |
| class Hamlbars::Converter | |
| def self.process_directory(directory) | |
| dir = Dir.open(directory) | |
| entries = dir.entries | |
| # Shift off . and .. | |
| entries.delete(".") | |
| entries.delete("..") | |
| # For each file in this directory that ends in hbs, convert it to .hbs | |
| # if it's a directory, call the same method | |
| entries.each do |entry| | |
| fullPath = "#{directory}/#{entry}" | |
| if File.directory?(fullPath) | |
| process_directory(fullPath) | |
| elsif File.file?(fullPath) | |
| process_file(fullPath) | |
| end | |
| end | |
| end | |
| def self.process_file(filePath) | |
| if filePath.match(/(.+).hamlbars/) | |
| fileName = $1 | |
| readFile = File.open(filePath, "r") | |
| compiledHbs = Hamlbars::Template.new(readFile, :format => :xhtml).render | |
| writeFile = File.open("#{fileName}.hbs", 'w') | |
| writeFile.write(compiledHbs) | |
| writeFile.close | |
| readFile.close | |
| end | |
| end | |
| end |