Skip to content
This repository has been archived by the owner on Jan 16, 2023. It is now read-only.

Commit

Permalink
adding angularjs-rails-resource, making install code more explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuavial committed Aug 7, 2013
1 parent 991600f commit a322fdf
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 19 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ Update config/karma.conf.js to load the files you want to test and run `rake kar

## Changelog

### 0.1.3
- adding [angularjs-rails-resource](https://github.com/FineLinePrototyping/angularjs-rails-resource)
- adding test spec so rake karma works straight after install

### 0.1.2
- fixing error with shell command installing karma

Expand Down
11 changes: 5 additions & 6 deletions files/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ files = [
JASMINE,
JASMINE_ADAPTER,

//libs
//angular
'vendor/assets/javascripts/rails_karma/angular.js',
'vendor/assets/javascripts/rails_karma/angular-cookies.js',
'vendor/assets/javascripts/rails_karma/angular-loader.js',
'vendor/assets/javascripts/rails_karma/angular-resource.js',
'vendor/assets/javascripts/rails_karma/angular-sanitize.js',
'vendor/assets/javascripts/rails_karma/angular-mocks.js',
'vendor/assets/javascripts/rails_karma/*.js',

//angular rails resource
'vendor/assets/javascripts/rails_karma/angularjs-rails-resource/**',

//our app!
'app/assets/angular/**',
Expand Down
3 changes: 3 additions & 0 deletions files/karma_test.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
describe "Karma", ->
it "should pass", ->
expect(true).toBe(true)
63 changes: 51 additions & 12 deletions lib/rails_karma/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
desc 'Install karma files'
task :install do
puts 'Generating Karma files'
RailsKarma::Installer.karma
RailsKarma::Installer.angular_files
RailsKarma::Installer.karma_config
RailsKarma::Installer.install_karma_lib
RailsKarma::Installer.ignore_node_modules
RailsKarma::Installer.make_vendor_dir
RailsKarma::Installer.copy_angularjs_files
RailsKarma::Installer.copy_angularjs_resource_files
RailsKarma::Installer.copy_karma_config
RailsKarma::Installer.create_karma_dir
RailsKarma::Installer.copy_test_spec
end

desc 'Uninstall karma files'
Expand All @@ -20,7 +25,7 @@

files.each do |f|
if File.exists? f
puts f
puts "rm -rf #{f}"
FileUtils.rm_rf f
end
end
Expand All @@ -32,7 +37,7 @@

module RailsKarma
class Installer
def self.karma
def self.install_karma_lib
unless File.exists?('package.json')
puts './package.json'
File.open('package.json', 'w') {|f| f.write '{}'}
Expand All @@ -41,37 +46,71 @@ def self.karma
puts 'installing karma'
puts `npm install karma --save-dev`
end
end

def self.ignore_node_modules
unless File.open('.gitignore') {|f| f.read.include? 'node_modules'}
puts 'adding node_modules to .gitignore'
File.open('.gitignore', 'a') {|f| f.write "node_modules\n"}
end
end

def self.angular_files
vendor_dir = File.join('vendor', 'assets', 'javascripts', 'rails_karma')
def self.vendor_dir
File.join('vendor', 'assets', 'javascripts', 'rails_karma')
end

def self.rails_resource_dir
File.join(vendor_dir, 'angularjs-rails-resource')
end

def self.make_vendor_dir
unless Dir.exists?(vendor_dir)
puts vendor_dir
puts "mkdir #{vendor_dir}"
Dir.mkdir vendor_dir
end
unless Dir.exists?(rails_resource_dir)
puts "mkdir #{rails_resource_dir}"
Dir.mkdir rails_resource_dir
end
end

angular_glob = File.join(Gem.loaded_specs['angularjs-rails'].full_gem_path, 'vendor', 'assets', 'javascripts', '*.js')
Dir.glob(angular_glob).each do |file|
FileUtils.cp file, File.join(vendor_dir,File.basename(file))
def self.copy_angularjs_files
angular_files = ['angular.js', 'angular-cookies.js', 'angular-loader.js', 'angular-resource.js', 'angular-sanitize.js', 'angular-mocks.js']
angular_files.each do |file_name|
path = File.join(Gem.loaded_specs['angularjs-rails'].full_gem_path, 'vendor', 'assets', 'javascripts', file_name)
FileUtils.cp path, File.join(vendor_dir,File.basename(path))
end
end

def self.karma_config
def self.copy_angularjs_resource_files
rails_resource_lib = File.join(Gem.loaded_specs['angularjs-rails-resource'].full_gem_path, 'vendor', 'assets', 'javascripts', 'angularjs', 'rails', 'resource')
FileUtils.cp_r rails_resource_lib, rails_resource_dir
end

def self.copy_karma_config
config_source = File.join(Gem.loaded_specs['rails_karma'].full_gem_path, 'files', 'karma.conf.js')
config_target = File.join(Rails.root, 'config', 'karma.conf.js')
unless File.exists?(config_target)
puts './config/karma.conf.js'
FileUtils.cp_r config_source, config_target
end
end

def self.create_karma_dir
unless Dir.exists?('karma')
puts './karma'
Dir.mkdir 'karma'
end
end

def self.copy_test_spec
test_spec = File.join(Gem.loaded_specs['rails_karma'].full_gem_path, 'files', 'karma_test.coffee')
target = File.join(Rails.root, 'karma', 'karma_test.coffee')
unless File.exists?(target)
puts './karma/karma_test.coffee'
FileUtils.cp test_spec, target
end
end
end
end

2 changes: 1 addition & 1 deletion lib/rails_karma/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module RailsKarma
VERSION = "0.1.2"
VERSION = "0.1.3"
end
1 change: 1 addition & 0 deletions rails_karma.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'bundler', '~> 1.3'
spec.add_development_dependency 'rake'
spec.add_dependency 'angularjs-rails', '~>1.0.7'
spec.add_dependency 'angularjs-rails-resource', '~> 0.2.0'
end

0 comments on commit a322fdf

Please sign in to comment.