redmine-generators 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +112 -0
  3. data/Rakefile +38 -0
  4. data/lib/redmine-generators.rb +4 -0
  5. data/lib/redmine-generators/version.rb +3 -0
  6. data/lib/redmine/generators.rb +12 -0
  7. data/lib/redmine/generators/plugin_generator.rb +88 -0
  8. data/lib/redmine/generators/plugin_name_attribute.rb +42 -0
  9. data/lib/redmine/generators/plugin_support.rb +32 -0
  10. data/lib/redmine/generators/project_menu_generator.rb +21 -0
  11. data/lib/redmine/generators/project_module_generator.rb +25 -0
  12. data/lib/redmine/generators/remoteable_links.rb +18 -0
  13. data/lib/redmine/generators/resource_route_generator.rb +19 -0
  14. data/lib/redmine/generators/scaffold_controller_generator.rb +39 -0
  15. data/lib/redmine/generators/scaffold_generator.rb +51 -0
  16. data/lib/redmine/generators/sortable_headers.rb +18 -0
  17. data/lib/redmine/generators/templates/active_record/model/migration.rb +27 -0
  18. data/lib/redmine/generators/templates/active_record/model/model.rb +25 -0
  19. data/lib/redmine/generators/templates/erb/scaffold/_form.html.erb +13 -0
  20. data/lib/redmine/generators/templates/erb/scaffold/edit.html.erb +6 -0
  21. data/lib/redmine/generators/templates/erb/scaffold/index.html.erb +33 -0
  22. data/lib/redmine/generators/templates/erb/scaffold/new.html.erb +6 -0
  23. data/lib/redmine/generators/templates/erb/scaffold/show.html.erb +17 -0
  24. data/lib/redmine/generators/templates/rails/scaffold/_form.js.erb +14 -0
  25. data/lib/redmine/generators/templates/rails/scaffold/_model.html.erb +12 -0
  26. data/lib/redmine/generators/templates/rails/scaffold/create.js.erb +13 -0
  27. data/lib/redmine/generators/templates/rails/scaffold/destroy.js.erb +1 -0
  28. data/lib/redmine/generators/templates/rails/scaffold/edit.js.erb +7 -0
  29. data/lib/redmine/generators/templates/rails/scaffold/new.js.erb +7 -0
  30. data/lib/redmine/generators/templates/rails/scaffold/show.js.erb +19 -0
  31. data/lib/redmine/generators/templates/rails/scaffold/update.js.erb +12 -0
  32. data/lib/redmine/generators/templates/redmine/plugin/Gemfile +3 -0
  33. data/lib/redmine/generators/templates/redmine/plugin/en.yml +3 -0
  34. data/lib/redmine/generators/templates/redmine/plugin/init.rb +13 -0
  35. data/lib/redmine/generators/templates/redmine/plugin/plugin.rb +4 -0
  36. data/lib/redmine/generators/templates/redmine/plugin/routes.rb +5 -0
  37. data/lib/redmine/generators/templates/redmine/plugin/version.rb +3 -0
  38. data/lib/redmine/generators/templates/redmine/scaffold_controller/controller.rb +96 -0
  39. data/lib/redmine/generators/translation_generator.rb +41 -0
  40. data/test/dummy/README.rdoc +261 -0
  41. data/test/dummy/Rakefile +7 -0
  42. data/test/dummy/app/assets/javascripts/application.js +15 -0
  43. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  44. data/test/dummy/app/controllers/application_controller.rb +3 -0
  45. data/test/dummy/app/helpers/application_helper.rb +2 -0
  46. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  47. data/test/dummy/config.ru +4 -0
  48. data/test/dummy/config/application.rb +59 -0
  49. data/test/dummy/config/boot.rb +10 -0
  50. data/test/dummy/config/database.yml +25 -0
  51. data/test/dummy/config/environment.rb +5 -0
  52. data/test/dummy/config/environments/development.rb +37 -0
  53. data/test/dummy/config/environments/production.rb +67 -0
  54. data/test/dummy/config/environments/test.rb +37 -0
  55. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  56. data/test/dummy/config/initializers/inflections.rb +15 -0
  57. data/test/dummy/config/initializers/mime_types.rb +5 -0
  58. data/test/dummy/config/initializers/secret_token.rb +7 -0
  59. data/test/dummy/config/initializers/session_store.rb +8 -0
  60. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  61. data/test/dummy/config/locales/en.yml +5 -0
  62. data/test/dummy/config/routes.rb +58 -0
  63. data/test/dummy/db/test.sqlite3 +0 -0
  64. data/test/dummy/log/test.log +4 -0
  65. data/test/dummy/public/404.html +26 -0
  66. data/test/dummy/public/422.html +26 -0
  67. data/test/dummy/public/500.html +25 -0
  68. data/test/dummy/public/favicon.ico +0 -0
  69. data/test/dummy/script/rails +6 -0
  70. data/test/redmine-generators_test.rb +7 -0
  71. data/test/test_helper.rb +15 -0
  72. metadata +186 -0
@@ -0,0 +1,39 @@
1
+ require "redmine/generators/plugin_name_attribute"
2
+ require "redmine/generators/sortable_headers"
3
+ require "redmine/generators/remoteable_links"
4
+ require "rails/generators/erb/scaffold/scaffold_generator"
5
+ Rails::Generators.lookup %w(rails:scaffold_controller)
6
+
7
+ module Redmine
8
+ module Generators
9
+ class ScaffoldControllerGenerator < Rails::Generators::ScaffoldControllerGenerator
10
+ include PluginNameAttribute
11
+
12
+ argument :attributes, type: :array, default: [], banner: "field[:type][:index] field[:type][:index]"
13
+
14
+ class_option :author, type: :boolean, default: true, desc: "Add author User relation"
15
+ class_option :project, type: :boolean, default: true, desc: "Add project model relation"
16
+ class_option :authorize, type: :boolean, default: true, desc: "Add permissions"
17
+ class_option :pagination, type: :boolean, default: true, desc: "Add pagination"
18
+ class_option :sort, type: :boolean, default: true, desc: "Add sorting"
19
+ class_option :remote, type: :boolean, default: true, desc: "User javascript ajax views"
20
+
21
+ def initialize(*args)
22
+ super
23
+ Erb::Generators::ScaffoldGenerator.send :include, SortableHeaders
24
+ Erb::Generators::ScaffoldGenerator.send :include, RemoteableLinks
25
+ end
26
+
27
+ def self.base_name
28
+ "rails"
29
+ end
30
+
31
+ protected
32
+ def sort_initializer
33
+ unsortable = [:text, :references, :belongs_to]
34
+ sort_fields = attributes.map { |a| a.name unless unsortable.include? a.type }.compact
35
+ "sort_init \"updated_at\"\n sort_update %w(#{sort_fields.join " "} created_at updated_at)"
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,51 @@
1
+ require "redmine/generators/plugin_name_attribute"
2
+ require "redmine/generators/remoteable_links"
3
+ Rails::Generators.lookup %w(rails:scaffold)
4
+
5
+ module Redmine
6
+ module Generators
7
+ class ScaffoldGenerator < Rails::Generators::ScaffoldGenerator
8
+ include PluginNameAttribute
9
+ include RemoteableLinks
10
+
11
+ class_option :author, type: :boolean, default: true, desc: "Add author User relation"
12
+ class_option :project, type: :boolean, default: true, desc: "Add project model relation"
13
+ class_option :project_module, type: :boolean, default: true, desc: "Add a project module"
14
+ class_option :project_menu, type: :boolean, default: true, desc: "Add a project menu"
15
+ class_option :authorize, type: :boolean, default: true, desc: "Add permissions"
16
+ class_option :pagination, type: :boolean, default: true, desc: "Add pagination"
17
+ class_option :sort, type: :boolean, default: true, desc: "Add sorting"
18
+ class_option :translation, type: :boolean, default: true, desc: "Add translations"
19
+ class_option :remote, type: :boolean, default: true, desc: "User javascript ajax views"
20
+
21
+ remove_hook_for :assets
22
+ remove_hook_for :stylesheet_engine
23
+
24
+ hook_for :scaffold_controller, required: true
25
+
26
+ hook_for :resource_route, required: true
27
+ hook_for :translation, required: true
28
+
29
+ hook_for :project_module, required: true
30
+ hook_for :project_menu, required: true
31
+
32
+ def add_js_views
33
+ template "_model.html.erb", "app/views/#{plural_table_name}/_#{singular_table_name}.html.erb"
34
+ return false unless options[:remote]
35
+ %w(_form show new create edit update destroy).each do |view|
36
+ view_file = "#{view}.js.erb"
37
+ template view_file, "app/views/#{plural_table_name}/#{view_file}"
38
+ end
39
+ end
40
+
41
+ protected
42
+ def remote_option
43
+ options[:remote]
44
+ end
45
+
46
+ def created_by
47
+ options[:author] ? "#{singular_table_name}.author" : "User.anonymous"
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,18 @@
1
+ require "active_support/concern"
2
+
3
+ module Redmine
4
+ module Generators
5
+ module SortableHeaders
6
+ extend ActiveSupport::Concern
7
+
8
+ def sortable_header(name, caption = "field_#{name}", order = nil)
9
+ if parent_options[:sort]
10
+ order = ", " + key_value(:default_order, %("#{order}")) if order
11
+ %(<%= sort_header_tag "#{name}", caption: l(:#{caption})#{order} %>)
12
+ else
13
+ "<th><%= l(:#{caption}) %></th>"
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,27 @@
1
+ class <%= migration_class_name %> < ActiveRecord::Migration
2
+ def change
3
+ create_table :<%= table_name %> do |t|
4
+ <% attributes.each do |attribute| -%>
5
+ t.<%= attribute.type %> :<%= attribute.name %><%= attribute.inject_options %>
6
+ <% end -%>
7
+ <% if parent_options[:author] -%>
8
+ t.integer :author_id, <%= key_value :default, "0" %>, <%= key_value :null, "false" %>
9
+ <% end -%>
10
+ <% if parent_options[:project] -%>
11
+ t.integer :project_id, <%= key_value :default, "0" %>, <%= key_value :null, "false" %>
12
+ <% end -%>
13
+ <% if options[:timestamps] %>
14
+ t.timestamps
15
+ <% end -%>
16
+ end
17
+ <% attributes_with_index.each do |attribute| -%>
18
+ add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
19
+ <% end -%>
20
+ <% if parent_options[:author] -%>
21
+ add_index :<%= table_name %>, :author_id
22
+ <% end -%>
23
+ <% if parent_options[:project] -%>
24
+ add_index :<%= table_name %>, :project_id
25
+ <% end -%>
26
+ end
27
+ end
@@ -0,0 +1,25 @@
1
+ <% module_namespacing do -%>
2
+ class <%= class_name %> < <%= parent_class_name.classify %>
3
+ unloadable
4
+
5
+ <% attributes.select {|attr| attr.reference? }.each do |attribute| -%>
6
+ belongs_to :<%= attribute.name %>
7
+ <% end -%>
8
+ <% if parent_options[:author] -%>
9
+ belongs_to :author, <%= key_value :class_name, '"User"' %>, <%= key_value :foreign_key, '"author_id"' %>
10
+ <% end -%>
11
+ <% if parent_options[:project] -%>
12
+ belongs_to :project
13
+ <% end -%>
14
+ <% if !accessible_attributes.empty? -%>
15
+ attr_accessible <%= accessible_attributes.map {|a| ":#{a.name}" }.sort.join(', ') %>
16
+ <% else -%>
17
+ # attr_accessible :title, :body
18
+ <% end -%>
19
+ <% if parent_options[:project] || parent_options[:author] -%>
20
+
21
+ validates <%= [(":project" if parent_options[:project]), (":author" if parent_options[:author])].compact.join ", " %>, <%= key_value :presence, "true" %>
22
+
23
+ <% end -%>
24
+ end
25
+ <% end -%>
@@ -0,0 +1,13 @@
1
+ <%%= labelled_form_for(@<%= singular_table_name %>) do |f| %>
2
+ <%%= error_messages_for "<%= singular_table_name %>" %>
3
+
4
+ <div class="box tabular">
5
+ <% attributes.each do |attribute| -%>
6
+ <p><%%= f.<%= attribute.field_type %> :<%= attribute.name %> %></p>
7
+ <% end -%>
8
+ </div>
9
+
10
+ <p class="buttons">
11
+ <%%= f.submit %>
12
+ </p>
13
+ <%% end %>
@@ -0,0 +1,6 @@
1
+ <h2><%%= link_to l(:label_<%= singular_table_name %>_plural), <%= index_helper %>_path %>
2
+ &#187; <%%= l(:label_<%= singular_table_name %>_edit) %></h2>
3
+
4
+ <%%= render "form" %>
5
+
6
+ <%% html_title l(:label_<%= singular_table_name %>_edit) -%>
@@ -0,0 +1,33 @@
1
+ <div class="contextual">
2
+ <%%= link_to l(:label_<%= singular_table_name %>_new), new_<%= singular_table_name %>_path, <%= key_value :class, '"icon icon-add"' %><%= maybe_remote %> %>
3
+ </div>
4
+
5
+ <h2><%%= l(:label_<%= singular_table_name %>_plural) %></h2>
6
+
7
+ <%% if @<%= plural_table_name %>.empty? %>
8
+ <p class="nodata"><%%= l(:label_no_data) %></p>
9
+ <%% end %>
10
+
11
+ <div class="autoscroll">
12
+ <table class="list <%= plural_table_name %>" style="<%%= "display: none;" if @<%= plural_table_name %>.empty? %>">
13
+ <thead>
14
+ <tr>
15
+ <% attributes.each do |attribute| -%>
16
+ <%= sortable_header attribute.name %>
17
+ <% end -%>
18
+ <%= sortable_header "created_at", :field_created_on, "desc" %>
19
+ <%= sortable_header "updated_at", :field_updated_on, "desc" %>
20
+ <th></th>
21
+ </tr>
22
+ </thead>
23
+ <tbody>
24
+ <%%= render @<%= plural_table_name %> %>
25
+ </tbody>
26
+ </table>
27
+ </div>
28
+ <% if parent_options[:pagination] -%>
29
+
30
+ <p class="pagination"><%%= pagination_links_full @<%= singular_table_name %>_pages %></p>
31
+ <% end -%>
32
+
33
+ <%% html_title l(:label_<%= singular_table_name %>_plural) -%>
@@ -0,0 +1,6 @@
1
+ <h2><%%= link_to l(:label_<%= singular_table_name %>_plural), <%= index_helper %>_path %>
2
+ &#187; <%%= l(:label_<%= singular_table_name %>_new) %></h2>
3
+
4
+ <%%= render "form" %>
5
+
6
+ <%% html_title l(:label_<%= singular_table_name %>_new) -%>
@@ -0,0 +1,17 @@
1
+ <div class="contextual">
2
+ <%%= link_to l(:label_<%= singular_table_name %>_edit), edit_<%= singular_table_name %>_path(@<%= singular_table_name %>), <%= key_value :class, '"icon icon-edit"' %><%= maybe_remote %> %>
3
+ </div>
4
+
5
+ <h2><%%= link_to l(:label_<%= singular_table_name %>_plural), <%= index_helper %>_path %>
6
+ &#187; <%%= l(:label_<%= singular_table_name %>) %></h2>
7
+
8
+ <div class="box">
9
+ <% attributes.each do |attribute| -%>
10
+ <p>
11
+ <b><%= attribute.human_name %>:</b>
12
+ <%%= @<%= singular_table_name %>.<%= attribute.name %> %>
13
+ </p>
14
+ <% end -%>
15
+ </div>
16
+
17
+ <%% html_title l(:label_<%= singular_table_name %>) -%>
@@ -0,0 +1,14 @@
1
+ <%%= labelled_form_for(@<%= singular_table_name %><%= maybe_remote %>) do |f| %>
2
+ <%%= error_messages_for "<%= singular_table_name %>" %>
3
+
4
+ <div class="box tabular">
5
+ <% attributes.each do |attribute| -%>
6
+ <p><%%= f.<%= attribute.field_type %> :<%= attribute.name %> %></p>
7
+ <% end -%>
8
+ </div>
9
+
10
+ <p class="buttons">
11
+ <%%= f.submit %>
12
+ <%%= submit_tag l(:button_cancel), <%= key_value :onclick, '"hideModal(this);"' %>, <%= key_value :type, '"button"' %> %>
13
+ </p>
14
+ <%% end %>
@@ -0,0 +1,12 @@
1
+ <tr id="<%%= dom_id <%= singular_table_name %> %>" class="<%%= cycle "odd", "even" %>">
2
+ <% attributes.each do |attribute| -%>
3
+ <td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
4
+ <% end -%>
5
+ <td><%%= authoring <%= singular_table_name %>.created_at, <%= created_by %> %>.</td>
6
+ <td><%%= l(:label_updated_time, time_tag(<%= singular_table_name %>.updated_at)).html_safe %>.</td>
7
+ <td class="buttons">
8
+ <%%= link_to l(:button_show), <%= singular_table_name %><%= maybe_remote %> %>
9
+ <%%= link_to l(:button_edit), edit_<%= singular_table_name %>_path(<%= singular_table_name %>), <%= key_value :class, '"icon icon-edit"' %><%= maybe_remote %> %>
10
+ <%%= link_to l(:button_delete), <%= singular_table_name %>, <%= key_value :method, ":delete" %>, <%= key_value :data, "{ #{key_value :confirm, "l(:text_are_you_sure)"} }" %>, <%= key_value :class, '"icon icon-del"' %><%= maybe_remote %> %>
11
+ </td>
12
+ </tr>
@@ -0,0 +1,13 @@
1
+ <%% if @<%= singular_table_name %>.valid? %>
2
+ hideModal();
3
+ if ($(".<%= plural_table_name %>.list").length) {
4
+ $(".nodata").hide();
5
+ $(".<%= plural_table_name %>").show();
6
+ $("<%%= j render(@<%= singular_table_name %>, formats: [:html]) %>").prependTo(".<%= plural_table_name %> tbody").effect("highlight");
7
+ } else {
8
+ window.location.href = "<%%= url_for @<%= singular_table_name %> %>";
9
+ }
10
+ <%% else %>
11
+ $("#errorExplanation").remove();
12
+ $("<%%= j error_messages_for("<%= singular_table_name %>") %>").prependTo("#new_<%= singular_table_name %>");
13
+ <%% end %>
@@ -0,0 +1 @@
1
+ $("#<%%= dom_id @<%= singular_table_name %> %>").fadeOut();
@@ -0,0 +1,7 @@
1
+ <%% html = capture do %>
2
+ <h3 class="title"><%%= l(:label_<%= singular_table_name %>_edit) %></h3>
3
+ <%%= render partial: "form" %>
4
+ <%% end %>
5
+
6
+ $("#ajax-modal").html("<%%= j html %>").find(".box").css("z-index", "auto");
7
+ showModal("ajax-modal", "600px");
@@ -0,0 +1,7 @@
1
+ <%% html = capture do %>
2
+ <h3 class="title"><%%= l(:label_<%= singular_table_name %>_new) %></h3>
3
+ <%%= render partial: "form" %>
4
+ <%% end %>
5
+
6
+ $("#ajax-modal").html("<%%= j html %>").find(".box").css("z-index", "auto");
7
+ showModal("ajax-modal", "600px");
@@ -0,0 +1,19 @@
1
+ <%% html = capture do %>
2
+ <h3 class="title"><%%= l(:label_<%= singular_table_name %>) %></h3>
3
+
4
+ <div class="box">
5
+ <% attributes.each do |attribute| -%>
6
+ <p>
7
+ <b><%= attribute.human_name %>:</b>
8
+ <%%= @<%= singular_table_name %>.<%= attribute.name %> %>
9
+ </p>
10
+ <% end -%>
11
+ </div>
12
+
13
+ <p class="buttons">
14
+ <%%= submit_tag l(:button_cancel), <%= key_value :onclick, '"hideModal(this);"' %>, <%= key_value :type, '"button"' %> %>
15
+ </p>
16
+ <%% end %>
17
+
18
+ $("#ajax-modal").html("<%%= j html %>").find(".box").css("z-index", "auto");
19
+ showModal("ajax-modal", "600px");
@@ -0,0 +1,12 @@
1
+ <%% if @<%= singular_table_name %>.valid? %>
2
+ hideModal();
3
+ if ($(".<%= plural_table_name %>.list").length) {
4
+ $("#<%%= dom_id @<%= singular_table_name %> %>").replaceWith("<%%= j render(@<%= singular_table_name %>) %>");
5
+ $("#<%%= dom_id @<%= singular_table_name %> %>").effect("highlight");
6
+ } else {
7
+ window.location.href = "<%%= url_for @<%= singular_table_name %> %>";
8
+ }
9
+ <%% else %>
10
+ $("#errorExplanation").remove();
11
+ $("<%%= j error_messages_for("<%= singular_table_name %>") %>").prependTo("#edit_<%= singular_table_name %>_<%%= @<%= singular_table_name %>.id %>");
12
+ <%% end %>
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Plugin-specific gems
@@ -0,0 +1,3 @@
1
+ # English strings go here for Rails i18n
2
+ en:
3
+ # my_label: "My label"
@@ -0,0 +1,13 @@
1
+ require "<%= name %>"
2
+ require "<%= name %>/version"
3
+
4
+ Redmine::Plugin.register :<%= name %> do
5
+ name "<%= name.titleize %>"
6
+ author "<%= user_name %>"
7
+ description "<%= name.titleize %>"
8
+ version <%= class_name %>::VERSION
9
+ url ""
10
+ author_url ""
11
+ requires_redmine version_or_higher: "<%= redmine_version %>"
12
+ settings partial: "<%= name %>", default: {}
13
+ end
@@ -0,0 +1,4 @@
1
+ require "redmine"
2
+
3
+ module <%= class_name %>
4
+ end
@@ -0,0 +1,5 @@
1
+ # Plugin's routes
2
+ # See: http://guides.rubyonrails.org/routing.html
3
+ RedmineApp::Application.routes.draw do
4
+
5
+ end
@@ -0,0 +1,3 @@
1
+ module <%= class_name %>
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,96 @@
1
+ <% if namespaced? -%>
2
+ require_dependency "<%= namespaced_file_path %>/application_controller"
3
+
4
+ <% end -%>
5
+ <% module_namespacing do -%>
6
+ class <%= controller_class_name %>Controller < ApplicationController
7
+ unloadable
8
+
9
+ respond_to :html, :json
10
+ <% if options[:remote] -%>
11
+ respond_to :js, only: [:show, :new, :create, :edit, :update, :destroy]
12
+ <% end -%>
13
+
14
+ <% if options[:project] -%>
15
+ before_filter :find_project_by_project_id
16
+ <% end -%>
17
+ before_filter :find_<%= singular_table_name %>, only: [:show, :edit, :update, :destroy]
18
+ <% if options[:authorize] -%>
19
+ before_filter :authorize
20
+ <% end -%>
21
+ <% if options[:sort] -%>
22
+
23
+ include SortHelper
24
+ helper :sort
25
+ <% end -%>
26
+
27
+ def index
28
+ <% if options[:sort] -%>
29
+ <%= sort_initializer %>
30
+ <% end -%>
31
+ <% if options[:project] -%>
32
+ <%= "@#{singular_table_name}_pages, " if options[:pagination] %>@<%= plural_table_name %> = <%= "paginate " if options[:pagination] %><%= "#{class_name}.where(project_id: @project)" %><%= ".order(sort_clause)" if options[:sort] %>
33
+ <% else -%>
34
+ <%= "@#{singular_table_name}_pages, " if options[:pagination] %>@<%= plural_table_name %> = <%= "paginate " if options[:pagination] %><%= orm_class.all(class_name) %><%= ".order(sort_clause)" if options[:sort] %>
35
+ <% end -%>
36
+ respond_with @<%= plural_table_name %>
37
+ end
38
+
39
+ def show
40
+ respond_with @<%= singular_table_name %>
41
+ end
42
+
43
+ def new
44
+ @<%= singular_table_name %> = <%= orm_class.build(class_name) %>
45
+ respond_with @<%= singular_table_name %>
46
+ end
47
+
48
+ def edit
49
+ respond_with @<%= singular_table_name %>
50
+ end
51
+
52
+ def create
53
+ @<%= singular_table_name %> = <%= orm_class.build(class_name, "params[:#{singular_table_name}]") %>
54
+ <% if options[:project] -%>
55
+ @<%= singular_table_name %>.project = @project
56
+ <% end -%>
57
+ <% if options[:author] -%>
58
+ @<%= singular_table_name %>.author = User.current
59
+ <% end -%>
60
+ if @<%= singular_table_name %>.save && !request.xhr?
61
+ flash[:notice] = l(:label_<%= singular_table_name %>_created)
62
+ end
63
+ respond_with @<%= singular_table_name %>
64
+ end
65
+
66
+ def update
67
+ if @<%= orm_instance.update_attributes("params[:#{singular_table_name}]") %> && !request.xhr?
68
+ flash[:notice] = l(:label_<%= singular_table_name %>_updated)
69
+ end
70
+ respond_with @<%= singular_table_name %>
71
+ end
72
+
73
+ def destroy
74
+ @<%= orm_instance.destroy %>
75
+ flash[:notice] = l(:label_<%= singular_table_name %>_deleted) unless request.xhr?
76
+ respond_with @<%= singular_table_name %>, location: <%= index_helper %>_path
77
+ end
78
+
79
+ <% if options[:project] -%>
80
+ # Override url/path convenience methods options to include project
81
+ def url_options
82
+ super.reverse_merge project_id: @project
83
+ end
84
+ <% end -%>
85
+
86
+ private
87
+ def find_<%= singular_table_name %>
88
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
89
+ <% if options[:project] -%>
90
+ render_404 unless @<%= singular_table_name %>.project_id == @project.id
91
+ <% end -%>
92
+ rescue ActiveRecord::RecordNotFound
93
+ render_404
94
+ end
95
+ end
96
+ <% end -%>