require 'fileutils' require 'less' require 'sass' module Pyro module Assets def self.included(base) base.extend(ClassMethods) end module ClassMethods def stylesheet *args args = args.first stylesheets = [] stylesheets << "./lib/#{args[:src]}" if args[:src] if args[:dir] Dir.glob("./lib/#{args[:dir]}/**/*.{css,scss,less}").each do |f| stylesheets << f end end tags = '' stylesheets.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) case extension when 'scss' contents = Sass::Engine.for_file(s, { style: :expanded }).render when 'less' contents = Less::Parser.new.parse(contents).to_css end File.open("#{build_path}/#{name}.css", 'w+') do |f| f.write(contents) end tags << "" end tags end end end end