Sha256: bd24d51a035d1374ee3d92685ca0f587b09e1209937aa064ad2f8cff7f959260

Contents?: true

Size: 1.5 KB

Versions: 4

Compression:

Stored size: 1.5 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|alpha/ }.
             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

  require './lib/jquery-cdn/version'
  if tag.to_s == JqueryCdn::VERSION
    puts "No releases, since #{ JqueryCdn::VERSION }"
  else
    puts "Load jQuery #{tag}"
    fetch(tag)

    puts "Update gem version"
    update_version(tag)

    puts "Done"
  end
end

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jquery-cdn-1.12.4 Rakefile
jquery-cdn-1.12.3 Rakefile
jquery-cdn-1.12.2 Rakefile
jquery-cdn-1.12.0 Rakefile