Class: BackboneGenerator::NamespaceGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/backbone_generator/namespace_generator.rb

Instance Method Summary collapse

Instance Method Details

#collection_name(classify = false) ⇒ Object



59
# File 'lib/generators/backbone_generator/namespace_generator.rb', line 59

def collection_name(classify=false); '__delte__' ;end

#model_name(classify = false) ⇒ Object



58
# File 'lib/generators/backbone_generator/namespace_generator.rb', line 58

def model_name(classify=false); '__delte__' ;end

#namespace(classify = false) ⇒ Object



53
54
55
56
# File 'lib/generators/backbone_generator/namespace_generator.rb', line 53

def namespace(classify=false)
  style = classify ?  :camelize : :underscore
  raw_namespace.send(style)
end


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/generators/backbone_generator/namespace_generator.rb', line 32

def print_tree
  tree = <<-TREE

  app/assets/javascripts/dashboard
  │   ├── collections
  │   ├── models
  │   ├── routes
  │   ├── templates
  │   └── views
  └── dashboard.coffee


  spec/javascripts/dashboard
  ├── collections
  ├── factories
  ├── models
  └── views
  TREE
  say tree.gsub(/dashboard/, namespace)
end

#setup_dir_structureObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/generators/backbone_generator/namespace_generator.rb', line 11

def setup_dir_structure
  Dir.glob(File.join(source_paths, "**/.gitkeep")) do |keep_path|
    template keep_path, keep_path.gsub(/^.*backbone_generator\/templates\//, "")
  end

  # build and require a namespace initializer
  template "app/assets/javascripts/%namespace%.coffee.tt", "app/assets/javascripts/%namespace%.coffee"
  path = File.join(destination_root, 'app/assets/javascripts/application.js')

  if behavior == :revoke  # destroy
    gsub_file path, /\/\/= require \.\/#{namespace}\n/, ''
  else
    regex_for_end_of_manifest_comments = /\/\/.*\n(\s|$)/
    gsub_file path, regex_for_end_of_manifest_comments do |match|
      match.sub /\n\s/, "\n//= require ./#{namespace}\n\n"
    end
  end
end