Sha256: cba26d34674310a3d8df0e74d238be26c1c6f1748ecd55016cc479f7fe4ccaf0

Contents?: true

Size: 1.82 KB

Versions: 1

Compression:

Stored size: 1.82 KB

Contents

def sys cmd
  STDOUT.puts str.color(:black).background(:white)
  system cmd
end

def err msg
  STDOUT.puts msg.color(:yellow).background(:red)
  exit!
end

namespace :assets do
  task :clear_assets do
    p '== Clear old assets'
    js_path = File.join(Rails.root, 'app', 'assets', 'javascripts', 'zff')
    css_path = File.join(Rails.root, 'app', 'assets', 'stylesheets', 'zff')
    img_path = File.join(Rails.root, 'app', 'assets', 'images', 'zff')
    sys('rm -r ' + js_path) if File.exists?(js_path)
    sys('rm -r ' + css_path) if File.exists?(css_path)
    sys('rm -r ' + img_path) if File.exists?(img_path)
  end
  
  desc 'add assets files to app/assets'
  task :add_assets => :clear_assets do
    p '== Add assets'
    sys 'cp -Ruf ' << File.join(ZfbenRailsAssetsPath, 'assets') << ' ' << File.join(Rails.root, 'app')
  end
  
  task :clear_gem do
    gem_path = File.join(Rails.root, 'Gemfile')
    unless File.exists? gem_path
      err 'Gemfile is not exists'
    else
      p '== Clear old gems'
      file = File.open(gem_path).readlines.join('')
      regexp = /(\n)?# Added by zfben_rails_assets.*# End zfben_rails_assets/im
      File.open(gem_path, 'w'){ |f| f.write(file.gsub(regexp, '')) } if file =~ regexp
    end
  end
  
  desc 'add Gemfile'
  task :add_gem => :clear_gem do
    p '== Add gems'
    gem_path = File.join(Rails.root, 'Gemfile')
    file = File.open(gem_path).readlines
    file.push "\n# Added by zfben_rails_assets\n\n" << File.open(File.join(ZfbenRailsAssetsPath, 'Gemfile')).readlines.join('') << "\n# End zfben_rails_assets"
    File.open(gem_path, 'w'){ |f| f.write(file.join('')) }
  end
  
  desc 'install zfben_rails_assets'
  task :install => [:add_gem, :add_assets] do
    p ''
    p '!! Please run `bundle install`'
  end
  
  desc 'uninstall zfben_rails_assets'
  task :uninstall => [:clear_gem, :clear_assets]
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
zfben_rails_assets-0.0.4 lib/zfben_rails_assets/tasks.rb