Class: Backbone::Generators::RouterGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
Helpers
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 Helpers

#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



27
28
29
# File 'lib/generators/backbone/router/router_generator.rb', line 27

def create_router_files 
  template 'router.coffee', File.join(backbone_path, "routers", class_path, "#{file_name}_router.js.coffee")
end

#create_view_filesObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/generators/backbone/router/router_generator.rb', line 31

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



18
19
20
21
22
23
24
25
# File 'lib/generators/backbone/router/router_generator.rb', line 18

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