Class: Backbone::Generators::RouterGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
ResourceHelpers
Defined in:
lib/generators/backbone/router/router_generator.rb

Constant Summary collapse

RESERVED_JS_WORDS =
%W{
  break case catch continue debugger default delete do else finally for 
  function if in instanceof new return switch this throw try typeof var void while with 
}

Instance Method Summary collapse

Methods included from ResourceHelpers

#application_name, #backbone_path, #collection_namespace, #js_app_name, #jst, #model_namespace, #plural_model_name, #router_namespace, #singular_model_name, #uncapitalize, #view_namespace

Instance Method Details

#create_router_filesObject



30
31
32
33
34
35
36
# File 'lib/generators/backbone/router/router_generator.rb', line 30

def create_router_files
  if options[:single]
    template 'router-sp.coffee', File.join(backbone_path, "routers", class_path, "#{file_name}_router.js.coffee")
  else
    template 'router.coffee', File.join(backbone_path, "routers", class_path, "#{file_name}_router.js.coffee")
  end
end

#create_view_filesObject



38
39
40
41
42
43
44
45
46
47
# File 'lib/generators/backbone/router/router_generator.rb', line 38

def create_view_files
   actions.each do |action|
     @action = action
     @view_path = File.join(backbone_path, "views", plural_name, "#{action}_view.js.coffee")
     @jst_path = File.join(backbone_path,"templates", plural_name, "#{action}.jst.ejs")
     
     template "view.coffee", @view_path
     template "template.jst", @jst_path
   end
end

#validate_no_reserved_wordsObject



21
22
23
24
25
26
27
28
# File 'lib/generators/backbone/router/router_generator.rb', line 21

def validate_no_reserved_words
  actions.each do |action|
    if RESERVED_JS_WORDS.include? action
       raise Thor::Error, "The name '#{action}' is reserved by javascript " <<
                          "Please choose an alternative action name and run this generator again."
    end
  end
end