require 'fileutils' require 'coffee-script' module Pyro module Assets def self.included(base) base.extend(ClassMethods) end module ClassMethods def script *args args = args.first scripts = [] scripts << "./lib/#{args[:src]}" if args[:src] if args[:dir] Dir.glob("./lib/#{args[:dir]}/**/*.{js,coffee}").each do |f| scripts << f end end tags = '' scripts.each do |s| file_name = s.split('/').last extension = s.split('.').last name = file_name.sub(".#{extension}", '') path = s.sub(file_name, '') build_path = path.sub('./', "#{$build_dir}/") FileUtils.mkdir_p(build_path) contents = File.read(s) contents = CoffeeScript.compile(contents) if extension == 'coffee' File.open("#{build_path}/#{name}.js", 'w+') do |f| f.write(contents) end tags << "" end tags end end end end