Sha256: 4fa8562d3409269ba40e406c26fd584749937ad27b005bf2d2ce3e052bb65a51

Contents?: true

Size: 1.47 KB

Versions: 6

Compression:

Stored size: 1.47 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').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

6 entries across 6 versions & 1 rubygems

Version Path
jquery-cdn-2.1.4.2 Rakefile
jquery-cdn-2.1.4.1 Rakefile
jquery-cdn-2.1.4 Rakefile
jquery-cdn-2.1.3 Rakefile
jquery-cdn-2.1.1 Rakefile
jquery-cdn-2.1.0 Rakefile