Sha256: 54bf8c2809ee69b5d4573b4198bb40acf021fe33908fba3eda1ee5858ac8443f

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

#!/usr/bin/env rake

require 'bundler/gem_tasks'

desc 'Update assets from jQuery repo'
task :update do
  require 'json'
  require 'httpclient'

  def asset(file)
    Pathname(__FILE__).dirname.join('vendor/assets/javascripts').join(file)
  end

  def github_tags(repo)
    http = HTTPClient.new
    body = http.get("https://api.github.com/repos/#{repo}/tags").body
    response = JSON.parse(body)
    response.reject { |i| i['name'] =~ /rc|beta|\+/ }.
             map    { |i| Gem::Version.new(i['name']) }.
             sort
  end

  def fetch(tag)
    url  = "http://ajax.googleapis.com/ajax/libs/jquery/#{tag}/jquery.js"
    path = asset("jquery.js")

    path.dirname.rmtree if path.dirname.exist?
    path.dirname.mkpath

    path.open('w') do |io|
      http = HTTPClient.new
      http.transparent_gzip_decompression = true
      io << http.get(url).body
    end
  end

  def update_version(tag)
    version_file = Pathname(__FILE__).dirname.join('lib/jquery-cdn/version.rb')
    version_file.open('w') do |io|
      io << "module JqueryCdn\n  VERSION = \"#{tag}\"\nend\n"
    end
  end

  puts "Fetching tags"
  tag = github_tags('jquery/jquery').select { |i| i.to_s =~ /^1\./ }.last

  puts "Load jQuery #{tag}"
  fetch(tag)

  puts "Update gem version"
  update_version(tag)

  puts "Done"
end

desc 'Delete all generated files'
task :clobber do
  rm_r 'pkg' rescue nil
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jquery-cdn-1.10.2 Rakefile