Skip to content

Commit

Permalink
Added a gemspec and tasks for installation.
Browse files Browse the repository at this point in the history
Added gemspec that loads installation rake tasks via
require 'tasks/ajax_resource'
  • Loading branch information
ratnikov committed Feb 18, 2009
1 parent 7ad7271 commit e6c5476
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 41 deletions.
39 changes: 1 addition & 38 deletions 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'
15 changes: 12 additions & 3 deletions 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
13 changes: 13 additions & 0 deletions 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
40 changes: 40 additions & 0 deletions 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

0 comments on commit e6c5476

Please sign in to comment.