module ATD module Compilation module Precompiler extend self def filetypes instance_methods(true) - [:filetypes] end end module Compiler extend self def filetypes instance_methods(true) - [:filetypes] end end def self.compile(name, contents) return contents if name.nil? name = name.split(".") extensions = name - [name.first] extensions.each do |extension| contents = Compiler.send(extension, contents) if Compiler.filetypes.include? extension.to_sym end contents end def self.pre_parse(route) output = route.output name = output return nil if output.nil? if output.include?(".") || output.is_a?(File) file = read_file(output) return nil if file.nil? name = (output.is_a?(File) ? File.basename(output) : output) file = precompile(name, file) route.output = file end name end class << self private def read_file(output) return File.read(File.join("assets/#{output}")) if output.is_a?(String) && File.exist?("assets/#{output}") return File.read(output) if output.is_a? File end def precompile(name, contents) name = name.split(".") extensions = name - [name.first] extensions.each do |extension| if Precompiler.filetypes.include? extension.to_sym contents = Precompiler.send(extension, contents) extensions -= [extension] end end contents end end end end