Class: Pbw::Generators::ScaffoldGenerator

Inherits:
ModelGenerator
  • Object
show all
Defined in:
lib/generators/pbw/scaffold_generator.rb

Instance Method Summary collapse

Methods inherited from ModelGenerator

#create_backbone_model, #create_model

Methods included from ResourceHelpers

#application_name, #backbone_path, #class_namespace, #collection_namespace, #home_view_namespace, #js_app_name, #js_model_namespace, #js_user_model_namespace, #jst, #plural_model_name, #router_name, #singular_model_name, #uncapitalize, #user_collection_namespace, #user_jst, #user_view_namespace, #view_namespace

Instance Method Details

#append_router_fileObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/generators/pbw/scaffold_generator.rb', line 7

def append_router_file
	routes = []
	route_methods = []
	if available_views.include?('index')
		routes << "#{route_entry(plural_model_name,"index#{model_namespace}#{plural_name.camelize}")}" 
		route_methods << "#{route_method("index#{model_namespace}#{plural_name.camelize}", "Index")}"
	end
	if available_views.include?('new')
		routes << "#{route_entry("#{plural_model_name}/new","new#{model_namespace}#{class_name}")}" 
		route_methods << "#{route_method("new#{model_namespace}#{class_name.camelize}", "New")}"
	end
	if available_views.include?('edit')
		routes << "#{route_entry("#{plural_model_name}/:id/edit","edit#{model_namespace}#{class_name}")}" 
		route_methods << "#{route_method("edit#{model_namespace}#{class_name.camelize}", "Edit")}"
	end
	if available_views.include?('show')
		routes << "#{route_entry("#{plural_model_name}/:id","show#{model_namespace}#{class_name}")}" 
		route_methods << "#{route_method("show#{model_namespace}#{class_name.camelize}", "Show")}"
	end
	if available_views.include?('index') # needs to be at the end
		routes << "#{route_entry("#{plural_model_name}/.*","index#{model_namespace}#{plural_name.camelize}")}" 
	end
	inject_into_file router_file, :after => 'initialize: (options) ->' do
		"\n    @#{plural_model_name} = new #{collection_namespace}Collection\n"
	end
	inject_into_file router_file, :after => 'routes:' do
		"\n#{routes.join('')}"
	end 
	inject_into_file router_file, :before => '  home: ->' do
		"#{route_methods.join("\n\n")}\n\n"
	end
end

#create_view_filesObject



40
41
42
43
44
45
46
47
# File 'lib/generators/pbw/scaffold_generator.rb', line 40

def create_view_files
	available_views.each do |view|
		template "views/#{view}_view.coffee", File.join(backbone_path, "views/#{model_namespace.downcase}", plural_name, "#{view}_view.js.coffee")
		template "templates/#{view}.jst", File.join(backbone_path, "templates/#{model_namespace.downcase}", plural_name, "#{view}.jst.ejs")  
	end
	template "views/model_view.coffee", File.join(backbone_path, "views/#{model_namespace.downcase}", plural_name, "#{singular_name}_view.js.coffee")
	template "templates/model.jst", File.join(backbone_path, "templates/#{model_namespace.downcase}", plural_name, "#{singular_name}.jst.ejs") 
end