From e6c5476176f63c2b4f2fa7c0aab3e429b4aaa8ae Mon Sep 17 00:00:00 2001 From: ratnikov Date: Wed, 18 Feb 2009 15:15:46 -0600 Subject: [PATCH] Added a gemspec and tasks for installation. Added gemspec that loads installation rake tasks via require 'tasks/ajax_resource' --- Rakefile | 39 +-------------------------------------- ajax_resource.gemspec | 15 ++++++++++++--- tasks/ajax_resource.rb | 13 +++++++++++++ tasks/build.rb | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 41 deletions(-) create mode 100644 tasks/ajax_resource.rb create mode 100644 tasks/build.rb diff --git a/Rakefile b/Rakefile index f090514..2db29b5 100644 --- a/Rakefile +++ b/Rakefile @@ -1,38 +1 @@ -require 'rake' - -desc "Cleans up the javascript build." -task :clean do - FileUtils.rm_r(File.dirname(__FILE__) + '/build') -end - -desc "Runs jslint on all files in the src directory" -task :jslint do - puts "Running jslint..." - with_errors = [] - Dir.glob("src/**/*js").each do |file| - unless (report = `cat #{file} | jslint`) =~ /No problems found/ - with_errors << file - puts <<-REPORT_END ----------------- -#{file} problems: - -#{report} - REPORT_END - end - end - - unless with_errors.size == 0 - puts "Following files had problems:" - with_errors.each { |file| puts " - #{file}" } - else - puts "All good." - end -end - -desc "Builds the javascript library." -task :build do - puts `jake --force` - puts "Done building." -end - -task :default => [ :jslint, :build ] +require 'tasks/ajax_resource' diff --git a/ajax_resource.gemspec b/ajax_resource.gemspec index 9aa226c..34ddfd7 100644 --- a/ajax_resource.gemspec +++ b/ajax_resource.gemspec @@ -1,10 +1,19 @@ +require 'tasks/build' + +AJAX_RESOURCE_VERSION = '0.01' + +# first build the library +Rake::Task["ajax_resource:build"].execute Gem::Specification.new do |s| s.name = "ajax_resource" - s.version = "0.01" + s.version = AJAX_RESOURCE_VERSION s.authors = [ "Dmitry Ratnikov" ] - s.date = Time.now.to_s - s.email = 'ratnikov@gmail.com' + s.date = Time.now + s.email = 'dmitryr@webitects.com' s.has_rdoc = false s.summary = "Javascript implementation of REST interface" + + s.files = [ 'build/ajax_resource-min.js', 'build/ajax_resource-src.js', 'tasks/ajax_resource.rb' ] + s.require_path = '.' end diff --git a/tasks/ajax_resource.rb b/tasks/ajax_resource.rb new file mode 100644 index 0000000..899b154 --- /dev/null +++ b/tasks/ajax_resource.rb @@ -0,0 +1,13 @@ + +namespace :ajax_resource do + namespace :rails do + desc "Installs ajax_resource javascript in the public/javascripts directory. Set COMPRESS=true to install the compressed version." + task :install do + extension = ENV["COMPRESS"] == "true" ? "min" : "src" + from = File.join File.dirname(__FILE__), '..', 'build', "ajax_resource-#{extension}.js" + to = File.join Rails.root, 'public', 'javascripts', 'ajax_resource.js' + FileUtils.cp(from, to, :verbose => true); + puts "Done installing." + end + end +end diff --git a/tasks/build.rb b/tasks/build.rb new file mode 100644 index 0000000..3c8c173 --- /dev/null +++ b/tasks/build.rb @@ -0,0 +1,40 @@ +require 'rake' + +namespace :ajax_resource do + desc "Cleans up the javascript build." + task :clean do + FileUtils.rm_r(File.dirname(__FILE__) + '/build') + end + + desc "Runs jslint on all files in the src directory" + task :jslint do + puts "Running jslint..." + with_errors = [] + Dir.glob("src/**/*js").each do |file| + unless (report = `cat #{file} | jslint`) =~ /No problems found/ + with_errors << file + puts <<-REPORT_END +---------------- +#{file} problems: + +#{report} +REPORT_END + end + end + + unless with_errors.size == 0 + puts "Following files had problems:" + with_errors.each { |file| puts " - #{file}" } + else + puts "All good." + end + end + + desc "Builds the javascript library." + task :build do + puts `jake --force` + puts "Done building." + end + + task :default => [ :jslint, :build ] +end