Class: Spine::Generators::NewGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/spine/new/new_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_spine_app_to_applicationObject



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/generators/spine/new/new_generator.rb', line 35

def add_spine_app_to_application
  source  = "app/assets/javascripts/application.js"
  content = File.read(source)

  if content.include?("//= require_tree .")
    inject_into_file source, :before => "//= require_tree ." do
      "//= require #{app_name}\n"
    end
  else
    append_file source, "\n//= require #{app_name}"
  end
end

#app_classObject



16
17
18
# File 'lib/generators/spine/new/new_generator.rb', line 16

def app_class
  app_name.camelize
end

#app_nameObject



12
13
14
# File 'lib/generators/spine/new/new_generator.rb', line 12

def app_name
  options[:app]
end

#create_app_fileObject



27
28
29
# File 'lib/generators/spine/new/new_generator.rb', line 27

def create_app_file
  template "index.coffee.erb", "app/assets/javascripts/#{app_name}/index.js.coffee"
end

#create_dir_layoutObject



20
21
22
23
24
25
# File 'lib/generators/spine/new/new_generator.rb', line 20

def create_dir_layout
  %W{models views controllers lib}.each do |dir|
    empty_directory "app/assets/javascripts/#{app_name}/#{dir}"
    create_file "app/assets/javascripts/#{app_name}/#{dir}/.keep"
  end
end

#create_lib_fileObject



31
32
33
# File 'lib/generators/spine/new/new_generator.rb', line 31

def create_lib_file
  template "view.coffee.erb", "app/assets/javascripts/#{app_name}/lib/view.js.coffee"
end