Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 70 lines (55 sloc) 1.912 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
require 'pathname'

require 'packr'
require 'yui/compressor'

desc "Create a zip file of the lastest release"
task :build do
  src_dir = Pathname.new(File.dirname(__FILE__)).expand_path
  build_dir = src_dir + "tarski"
  build_files = [".git", ".gitignore", ".DS_Store", "Rakefile", "tarski"]
  zip_name = "tarski_#{theme_version(src_dir + "style.dev.css")}.zip"
  
  # Create build directory
  FileUtils.rm_rf build_dir if Dir.exist? build_dir
  FileUtils.mkdir build_dir
  
  # Copy files
  (Dir.entries(src_dir) - build_files - [".", ".."]).
  reject {|path| path =~ /\.zip$/ }.each do |path|
    FileUtils.cp_r path, build_dir + path
  end
  
  # Zip build directory
  `cd #{src_dir}; zip -rmq #{zip_name} tarski`
end

desc "Compress JavaScript and CSS files"
task :minify => [:"minify:js", :"minify:css"]

namespace :minify do
  
  desc "Compress JavaScript files"
  task :js do
    Dir.glob("app/js/*.dev.js").each do |file|
      options = {:shrink_vars => true, :private => true}
      code = File.read(file)
      compressed = Packr.pack(code, options)
      File.open(file.sub(/\.dev.js$/, ".js"), "w") { |f| f.write(compressed) }
    end
  end
  
  desc "Compress CSS files"
  task :css do
    main = "style.dev.css"
    files = Dir.glob("library/css/*.dev.css") << main
    compressor = YUI::CssCompressor.new
    
    files.each do |file|
      code = File.read(file)
      compressed = compressor.compress(code)
      
      if file == main
        header = code.match(/\/\*.+?\*\//m)[0]
        output = header + "\n" + compressed
      else
        output = compressed
      end
      
      File.open(file.sub(/\.dev\.css/, ".css"), "w") { |f| f.write(output) }
    end
  end
  
end

def theme_version(stylesheet)
  lines = File.read(stylesheet).split("\n")
  prefix = "Version: "
  lines.select {|line| line =~ /^#{prefix}/ }.first.sub(prefix, "").strip
end
Something went wrong with that request. Please try again.