42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/generators/angularjs/scaffold/scaffold_generator.rb', line 42
def generate
remove_file "app/assets/stylesheets/scaffolds.css.scss"
if language_option == 'coffeescript'
insert_into_file "app/assets/javascripts/routes.coffee.erb",
", \'#{@plural_model_name}\'", :after => "'ngCookies'"
insert_into_file "app/assets/javascripts/routes.coffee.erb",
%{when("/#{@plural_model_name}",
controller: #{@controller}IndexCtrl
templateUrl: '<%= asset_path(\"#{@plural_model_name}/index.html\") %>'
).when("/#{@plural_model_name}/new",
controller: #{@controller}CreateCtrl
templateUrl: '<%= asset_path(\"#{@plural_model_name}/new.html\") %>'
).when("/#{@plural_model_name}/:id",
controller: #{@controller}ShowCtrl
templateUrl: '<%= asset_path(\"#{@plural_model_name}/show.html\") %>'
).when("/#{@plural_model_name}/:id/edit",
controller: #{@controller}EditCtrl
templateUrl: '<%= asset_path(\"#{@plural_model_name}/edit.html\") %>'
).}, :before => 'otherwise'
else
insert_into_file "app/assets/javascripts/routes.js.erb",
", '#{@plural_model_name}'", :after => "'ngCookies'"
insert_into_file "app/assets/javascripts/routes.js.erb",
%{\n when('/#{@plural_model_name}', {controller:#{@controller}IndexCtrl,
templateUrl:'<%= asset_path("#{@plural_model_name}/index.html") %>'}).
when('/#{@plural_model_name}/new', {controller:#{@controller}CreateCtrl,
templateUrl:'<%= asset_path("#{@plural_model_name}/new.html") %>'}).
when('/#{@plural_model_name}/:id', {controller:#{@controller}ShowCtrl,
templateUrl:'<%= asset_path("#{@plural_model_name}/show.html") %>'}).
when('/#{@plural_model_name}/:id/edit', {controller:#{@controller}EditCtrl,
templateUrl:'<%= asset_path("#{@plural_model_name}/edit.html") %>'}).}, :before => 'otherwise'
end
inject_into_class "app/controllers/#{@plural_model_name}_controller.rb",
"#{@controller}Controller".constantize, "respond_to :json\n"
template "new.html.erb",
"app/assets/templates/#{@plural_model_name}/new.html.erb"
template "edit.html.erb",
"app/assets/templates/#{@plural_model_name}/edit.html.erb"
template "show.html.erb",
"app/assets/templates/#{@plural_model_name}/show.html.erb"
template "index.html.erb",
"app/assets/templates/#{@plural_model_name}/index.html.erb"
model_index_link = "\n<li><%= link_to \'#{@controller_name}\', #{@plural_model_name}_path %></li>"
insert_into_file "app/views/layouts/application.html.erb", model_index_link,
after: "<!-- main menu models -->"
if language_option == 'coffeescript'
remove_file "app/assets/javascripts/#{@plural_model_name}.js"
remove_file "app/assets/javascripts/#{@plural_model_name}_controller.js"
template "plural_model_name.js.coffee", "app/assets/javascripts/#{@plural_model_name}.js.coffee"
template "plural_model_name_controller.js.coffee",
"app/assets/javascripts/#{@plural_model_name}_controller.js.coffee"
else
remove_file "app/assets/javascripts/#{@plural_model_name}.js.coffee"
remove_file "app/assets/javascripts/#{@plural_model_name}_controller.js.coffee"
template "plural_model_name.js", "app/assets/javascripts/#{@plural_model_name}.js"
template "plural_model_name_controller.js",
"app/assets/javascripts/#{@plural_model_name}_controller.js"
remove_file "app/assets/javascripts/#{@plural_model_name}.js.coffee"
end
end
|