Class: EmberKonacha::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
EmberKonacha::GemHelper
Defined in:
lib/generators/ember_konacha/install_generator.rb

Instance Method Summary collapse

Methods included from EmberKonacha::GemHelper

#bundle_command, #bundle_gems!, #gemfile, #gemfile_content, #has_all_gems?, #has_any_gem?, #has_gem?, #ruby_gems

Instance Method Details

#add_gemsObject



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/generators/ember_konacha/install_generator.rb', line 25

def add_gems        
  unless has_gem? 'konacha'
    gem 'konacha', group: [:development, :test] 
  end

  has_gem?(js_driver) ? skip_driver : gem(js_driver, group: [:development, :test])

  unless has_gem?('coffee-rails') || !coffee?
    gem 'coffee-rails'
  end

  bundle_gems!
end

#add_preObject



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/generators/ember_konacha/install_generator.rb', line 81

def add_pre
  return unless has_file? Rails.root.join(coffee_manifest_file)

  # ensure App is prefixed with window namespace!
  gsub_file coffee_manifest_file, /[^\.]App =/ do |match|
    match << "window.App ="
  end        

  append_to_file coffee_manifest_file do
    'App.deferReadiness()'
  end
end

#create_infra_filesObject



39
40
41
42
43
44
45
46
47
# File 'lib/generators/ember_konacha/install_generator.rb', line 39

def create_infra_files
  infra_files.each do |name|
    begin
      coffee_template name
    rescue
      js_template name
    end            
  end        
end

#create_spec_filesObject



75
76
77
78
79
# File 'lib/generators/ember_konacha/install_generator.rb', line 75

def create_spec_files
  spec_files.each do |name|
    spec_template name
  end
end

#create_vendor_filesObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/generators/ember_konacha/install_generator.rb', line 49

def create_vendor_files
  return if has_sinon_file?

  require 'httparty'

  sinon_content = get_remote_file :sinon, sinon_version

  return if has_file? sinon_file_path

  if sinon_content.blank?
    fallback_sinon!
  end

  vendor(sinon_path, sinon_content)

rescue Exception => e
  say e.message, :red
  say %Q{Sinon URI access/download error: #{@uri}. 
Using sinon-1.6.js supplied by this gem ;)}
  fallback_sinon!
end

#create_view_filesObject



94
95
96
97
98
99
# File 'lib/generators/ember_konacha/install_generator.rb', line 94

def create_view_files
  return unless with_index?
  
  copy_file 'spec/views/layouts/application.html.slim', 'app/views/layouts/application.html.slim'
  copy_file 'spec/views/application/index.html.slim', 'app/views/application/index.html.slim'
end

#do_validationsObject



20
21
22
23
# File 'lib/generators/ember_konacha/install_generator.rb', line 20

def do_validations
  validate_driver!
  validate_sinon_version! 
end

#fallback_sinon!Object



71
72
73
# File 'lib/generators/ember_konacha/install_generator.rb', line 71

def fallback_sinon!
  template 'vendor/sinon.js', 'vendor/assets/javascripts/sinon.js'
end

#post_install_noticeObject



102
103
104
105
106
# File 'lib/generators/ember_konacha/install_generator.rb', line 102

def post_install_notice
  return if skipped_driver?

  say nice(js_driver_notice) , :green
end