Class: Backbone::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Helpers
Defined in:
lib/generators/backbone/install/install_generator.rb

Instance Method Summary collapse

Methods included from Helpers

#app_filename, #app_name, #asset_path, #collection_namespace, #js_path, #model_namespace, #namespaced_path, #namespaces, #rails_app_name, #router_namespace, #template_namespace, #template_path, #view_namespace

Instance Method Details

#create_app_fileObject



51
52
53
54
55
# File 'lib/generators/backbone/install/install_generator.rb', line 51

def create_app_file
  js = options[:javascript]
  ext = js ? ".js" : ".js.coffee"
  template "app#{ext}", "#{js_path}/#{app_filename}#{ext}"
end

#create_dir_layoutObject



41
42
43
44
45
46
47
48
49
# File 'lib/generators/backbone/install/install_generator.rb', line 41

def create_dir_layout
  %W{collections models routers views}.each do |dir|
    empty_directory "#{js_path}#{namespaced_path}/#{dir}"
  end

  %W{templates}.each do |dir|
    empty_directory "#{asset_path}/#{dir}#{namespaced_path}"
  end
end

#inject_backboneObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/generators/backbone/install/install_generator.rb', line 22

def inject_backbone
  libs = ['underscore', 'backbone']
  manifest = options[:manifest]
  paths = [ "../templates#{namespaced_path}", ".#{namespaced_path}/models",
            ".#{namespaced_path}/collections", ".#{namespaced_path}/views", ".#{namespaced_path}/routers"]

  create_file("#{js_path}/#{manifest}") unless File.exists?("#{js_path}/#{manifest}")

  append_to_file "#{js_path}/#{manifest}" do
    out = ""
    out << libs.map{ |lib| "//= require #{lib}" }.join("\n")
    out << "\n//\n"
    out << "//= require .#{app_filename}"
    out << "\n//\n"
    out << paths.map{ |path| "//= require_tree #{path}" }.join("\n")
    out << "\n"
  end
end