somatics3 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +91 -0
- data/Rakefile +72 -0
- data/VERSION +1 -0
- data/bin/somatics +23 -0
- data/bin/somatify +21 -0
- data/lib/generators/somatics.rb +37 -0
- data/lib/generators/somatics/associated/associated_generator.rb +184 -0
- data/lib/generators/somatics/associated/templates/migration.rb +11 -0
- data/lib/generators/somatics/attributes/attributes_generator.rb +115 -0
- data/lib/generators/somatics/attributes/templates/migration.rb +11 -0
- data/lib/generators/somatics/authenticated/authenticated_generator.rb +65 -0
- data/lib/generators/somatics/authenticated/templates/partial_form.html.erb +23 -0
- data/lib/generators/somatics/authenticated_controller/authenticated_controller_generator.rb +38 -0
- data/lib/generators/somatics/authenticated_controller/templates/locales_en.yml +6 -0
- data/lib/generators/somatics/authenticated_controller/templates/locales_zh-TW.yml +6 -0
- data/lib/generators/somatics/authenticated_controller/templates/login.html.erb +31 -0
- data/lib/generators/somatics/authenticated_controller/templates/sessions_controller.rb +11 -0
- data/lib/generators/somatics/helper/helper_generator.rb +16 -0
- data/lib/generators/somatics/install/install_generator.rb +101 -0
- data/lib/generators/somatics/install/templates/config/locales/devise_zh-TW.yml +39 -0
- data/lib/generators/somatics/install/templates/config/locales/somatics_en.yml +35 -0
- data/lib/generators/somatics/install/templates/config/locales/somatics_zh-TW.yml +35 -0
- data/lib/generators/somatics/install/templates/controller_admin.rb +17 -0
- data/lib/generators/somatics/install/templates/controller_home.rb +4 -0
- data/lib/generators/somatics/install/templates/helper_admin.rb +99 -0
- data/lib/generators/somatics/install/templates/initializer_paper_trail.rb +2 -0
- data/lib/generators/somatics/install/templates/layout_admin.html.erb +87 -0
- data/lib/generators/somatics/install/templates/lib/active_record/diff.rb +61 -0
- data/lib/generators/somatics/install/templates/lib/somatic_link_renderer.rb +24 -0
- data/lib/generators/somatics/install/templates/lib/tasks/heroku.rake +30 -0
- data/lib/generators/somatics/install/templates/lib/tasks/svn.rake +47 -0
- data/lib/generators/somatics/install/templates/partial_menu.html.erb +1 -0
- data/lib/generators/somatics/install/templates/partial_versions.html.erb +56 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/add.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/arrow_collapsed.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/arrow_expanded.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/attachment.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/bullet_arrow_left.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/bullet_arrow_right.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/bullet_diamond.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/bullet_end.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/bullet_go.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/bullet_toggle_minus.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/bullet_toggle_plus.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/c.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/cancel.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/changeset.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/comment.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/comments.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/content-left.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/content-right.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/copy.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/csharp.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/database_key.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/default.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/delete.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/document.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/draft.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/duplicate.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/edit.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/exclamation.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/external.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/fav.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/fav_off.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/feed.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/folder.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/folder_open.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/footer-bg.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/footer-left.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/footer-right.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/group.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/help.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/history.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/image.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/lightning.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/link.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/loading.gif +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/locked.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/message.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/milestone.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/move.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/news.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/openid-bg.gif +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/package.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/pdf.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/php.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/plugin.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/projects.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/rails.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/reload.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/report.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/ruby.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/save.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/sort_asc.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/sort_desc.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/stats.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/table_multiple.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/task_done.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/task_late.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/task_parent_end.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/task_todo.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/text.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/text_list_bullets.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/textfield.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/ticket.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/ticket_checked.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/ticket_edit.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/ticket_go.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/ticket_note.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/time.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/time_add.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/toggle_check.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/true.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/unlock.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/user.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/warning.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/wiki_edit.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/xml.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/zip.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/zoom_in.png +0 -0
- data/lib/generators/somatics/install/templates/public/javascripts/somatics/base.js +237 -0
- data/lib/generators/somatics/install/templates/public/javascripts/somatics/context_menu.js +237 -0
- data/lib/generators/somatics/install/templates/public/javascripts/somatics/controls.js +965 -0
- data/lib/generators/somatics/install/templates/public/javascripts/somatics/dragdrop.js +974 -0
- data/lib/generators/somatics/install/templates/public/javascripts/somatics/effects.js +1123 -0
- data/lib/generators/somatics/install/templates/public/javascripts/somatics/prototype.js +6001 -0
- data/lib/generators/somatics/install/templates/public/javascripts/somatics/rails.js +175 -0
- data/lib/generators/somatics/install/templates/public/javascripts/somatics/select_list_move.js +82 -0
- data/lib/generators/somatics/install/templates/public/stylesheets/application.css +863 -0
- data/lib/generators/somatics/install/templates/public/stylesheets/somatics/base.css +951 -0
- data/lib/generators/somatics/install/templates/public/stylesheets/somatics/context_menu.css +52 -0
- data/lib/generators/somatics/install/templates/public/stylesheets/somatics/csshover.htc +122 -0
- data/lib/generators/somatics/install/templates/public/stylesheets/somatics/jstoolbar.css +95 -0
- data/lib/generators/somatics/install/templates/public/themes/default/stylesheets/application.css +951 -0
- data/lib/generators/somatics/install/templates/view_index.html.erb +46 -0
- data/lib/generators/somatics/relationship/relationship_generator.rb +173 -0
- data/lib/generators/somatics/relationship/templates/migration.rb +11 -0
- data/lib/generators/somatics/scaffold/scaffold_generator.rb +24 -0
- data/lib/generators/somatics/scaffold/templates/_form.html.erb +23 -0
- data/lib/generators/somatics/scaffold/templates/edit.html.erb +6 -0
- data/lib/generators/somatics/scaffold/templates/index.html.erb +27 -0
- data/lib/generators/somatics/scaffold/templates/new.html.erb +5 -0
- data/lib/generators/somatics/scaffold/templates/show.html.erb +12 -0
- data/lib/generators/somatics/scaffold_controller/USAGE +20 -0
- data/lib/generators/somatics/scaffold_controller/scaffold_controller_generator.rb +108 -0
- data/lib/generators/somatics/scaffold_controller/templates/builder_index.xls.builder +24 -0
- data/lib/generators/somatics/scaffold_controller/templates/builder_index.xml.builder +10 -0
- data/lib/generators/somatics/scaffold_controller/templates/controller.rb +123 -0
- data/lib/generators/somatics/scaffold_controller/templates/locales_en.yml +17 -0
- data/lib/generators/somatics/scaffold_controller/templates/locales_zh-TW.yml +20 -0
- data/lib/generators/somatics/scaffold_controller/templates/partial_bulk.html.erb +12 -0
- data/lib/generators/somatics/scaffold_controller/templates/partial_edit.html.erb +7 -0
- data/lib/generators/somatics/scaffold_controller/templates/partial_form.html.erb +13 -0
- data/lib/generators/somatics/scaffold_controller/templates/partial_list.html.erb +30 -0
- data/lib/generators/somatics/scaffold_controller/templates/partial_menu.html.erb +1 -0
- data/lib/generators/somatics/scaffold_controller/templates/partial_show.html.erb +31 -0
- data/lib/generators/somatics/scaffold_controller/templates/view_edit.html.erb +24 -0
- data/lib/generators/somatics/scaffold_controller/templates/view_index.html.erb +27 -0
- data/lib/generators/somatics/scaffold_controller/templates/view_new.html.erb +14 -0
- data/lib/generators/somatics/scaffold_controller/templates/view_show.html.erb +26 -0
- data/lib/generators/somatics/settings/settings_generator.rb +86 -0
- data/lib/generators/somatics/settings_controller/USAGE +20 -0
- data/lib/generators/somatics/settings_controller/settings_controller_generator.rb +11 -0
- data/lib/generators/somatics/settings_controller/templates/builder_index.xls.builder +24 -0
- data/lib/generators/somatics/settings_controller/templates/builder_index.xml.builder +10 -0
- data/lib/generators/somatics/settings_controller/templates/controller.rb +64 -0
- data/lib/generators/somatics/settings_controller/templates/helper.rb +2 -0
- data/lib/generators/somatics/settings_controller/templates/locales_en.yml +9 -0
- data/lib/generators/somatics/settings_controller/templates/locales_zh-TW.yml +28 -0
- data/lib/generators/somatics/settings_controller/templates/migration.rb +17 -0
- data/lib/generators/somatics/settings_controller/templates/partial_bulk.html.erb +12 -0
- data/lib/generators/somatics/settings_controller/templates/partial_edit.html.erb +7 -0
- data/lib/generators/somatics/settings_controller/templates/partial_form.html.erb +15 -0
- data/lib/generators/somatics/settings_controller/templates/partial_list.html.erb +28 -0
- data/lib/generators/somatics/settings_controller/templates/partial_menu.html.erb +1 -0
- data/lib/generators/somatics/settings_controller/templates/partial_show.html.erb +13 -0
- data/lib/generators/somatics/settings_controller/templates/view_edit.html.erb +23 -0
- data/lib/generators/somatics/settings_controller/templates/view_index.html.erb +22 -0
- data/lib/generators/somatics/settings_controller/templates/view_new.html.erb +14 -0
- data/lib/generators/somatics/settings_controller/templates/view_show.html.erb +23 -0
- data/lib/somatics.rb +9 -0
- data/somatics.gemspec +249 -0
- data/somatics3.gemspec +248 -0
- data/templates/somatics.rb +106 -0
- data/test/helper.rb +10 -0
- data/test/test_somatics3-generators.rb +7 -0
- metadata +398 -0
@@ -0,0 +1,46 @@
|
|
1
|
+
<h2><%%= t('Overview') %></h2>
|
2
|
+
<div id="activity">
|
3
|
+
<%% [Date.today, Date.yesterday, 2.days.ago.to_date].each do |day|%>
|
4
|
+
<h3><%%= date_to_words day %></h3>
|
5
|
+
<dl>
|
6
|
+
<%% (versions = Version.where(:created_at => day.beginning_of_day..day.end_of_day ).order('created_at desc')).each do |version|%>
|
7
|
+
<dt class="issue-closed me">
|
8
|
+
<img class="gravatar" alt="" width="24" height="24" src="http://www.gravatar.com/avatar/<%%=Digest::MD5::hexdigest((User.find(version.whodunnit.to_i).email rescue ''))%>?rating=PG&size=24">
|
9
|
+
<span class="time"><%%=version.created_at.to_s(:db)%></span>
|
10
|
+
<%% description = "" %>
|
11
|
+
<%% [:name,:title,:label].each do |d|
|
12
|
+
description = version.item.send(d) if version.item.respond_to? d
|
13
|
+
end
|
14
|
+
%>
|
15
|
+
<%%= link_to "#{version.item.class.model_name.human} ##{version.item.id} - #{description}", [:admin, version.item]%>
|
16
|
+
</dt>
|
17
|
+
<dd>
|
18
|
+
<span class="description">
|
19
|
+
<%% if version.event == 'create'%>
|
20
|
+
Initial Create
|
21
|
+
<%% else %>
|
22
|
+
<%% unless version.next.nil? %>
|
23
|
+
<%% version.reify.diff(version.next.reify).each do |t| %>
|
24
|
+
<%% unless t.first == :updated_at %>
|
25
|
+
<p>"<b><%%= t.first.to_s.humanize %></b>" was changed from "<b><%%= t.last.first.to_s rescue '' %></b>" to "<b><%%= t.last.last.to_s rescue '' %></b>"</p>
|
26
|
+
<%% end %>
|
27
|
+
<%% end rescue 'Undetermined Changes'%>
|
28
|
+
<%% else %>
|
29
|
+
<%% version.reify.diff(obj).each do |t| %>
|
30
|
+
<%% unless t.first == :updated_at %>
|
31
|
+
<p>"<b><%%= t.first.to_s.humanize %></b>" was changed from "<b><%%= t.last.first.to_s rescue '' %></b>" to "<b><%%= t.last.last.to_s rescue '' %></b>"</p>
|
32
|
+
<%% end %>
|
33
|
+
<%% end rescue 'Undetermined Changes'%>
|
34
|
+
<%% end %>
|
35
|
+
<%% end %></span>
|
36
|
+
<span class="author"><%%=User.find(version.whodunnit.to_i).name rescue 'Unknown'%></span>
|
37
|
+
</dd>
|
38
|
+
<%% end %>
|
39
|
+
<%% if versions.blank?%>
|
40
|
+
No Changes in <%%= day %>
|
41
|
+
<%% end %>
|
42
|
+
</dl>
|
43
|
+
<%% end %>
|
44
|
+
|
45
|
+
</div>
|
46
|
+
<div style="clear:both;"></div>
|
@@ -0,0 +1,173 @@
|
|
1
|
+
require 'generators/somatics'
|
2
|
+
require 'rails/generators/named_base'
|
3
|
+
require 'rails/generators/migration'
|
4
|
+
|
5
|
+
module Somatics
|
6
|
+
module Generators
|
7
|
+
class RelationshipGenerator < Rails::Generators::NamedBase
|
8
|
+
extend TemplatePath
|
9
|
+
include Rails::Generators::Migration
|
10
|
+
# include Rails::Generators::ResourceHelpers
|
11
|
+
class_option :skip_migration, :type => :boolean, :desc => "Don't generate a migration file for this model."
|
12
|
+
class_option :namespace, :banner => "NAME", :type => :string, :default => 'admin'
|
13
|
+
|
14
|
+
def dump_generator_attribute_names
|
15
|
+
generator_attribute_names = [
|
16
|
+
:name,
|
17
|
+
:singular_name,
|
18
|
+
:human_name,
|
19
|
+
:plural_name,
|
20
|
+
:relationship,
|
21
|
+
:model_name,
|
22
|
+
:class_name,
|
23
|
+
:reference_model_name,
|
24
|
+
:reference_class_name,
|
25
|
+
:reference_value,
|
26
|
+
:migration_model_name,
|
27
|
+
:migration_table_name,
|
28
|
+
:migration_attribute ,
|
29
|
+
:table_name
|
30
|
+
|
31
|
+
]
|
32
|
+
|
33
|
+
generator_attribute_names.each do |attr|
|
34
|
+
puts "%-40s %s" % ["#{attr}:", self.send(attr.to_s)] # instance_variable_get("@#{attr.to_s}"
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
def add_relationship_to_model
|
40
|
+
relation = " has_many :#{reference_value}\n"
|
41
|
+
# sentinel = "class #{class_name} < ActiveRecord::Base\n"
|
42
|
+
inject_into_class "app/models/#{model_name}.rb", class_name, relation
|
43
|
+
|
44
|
+
relation = " belongs_to :#{model_name}\n"
|
45
|
+
# sentinel = "class #{reference_class_name} < ActiveRecord::Base\n"
|
46
|
+
inject_into_class "app/models/#{reference_model_name}.rb",reference_class_name, relation
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
def add_show_view_to_model_show
|
51
|
+
sentinel = "<!-- More List View -->\n"
|
52
|
+
reference_list = <<-CODE
|
53
|
+
<% if @#{reference_model_name}.#{model_name} %>
|
54
|
+
<h3><%=link_to "\#{#{class_name}.model_name.human} #\#{@#{reference_model_name}.#{model_name}.id}", [:admin, @#{reference_model_name}.#{model_name}] %></h3>
|
55
|
+
<div class="issue detail">
|
56
|
+
<%= render :partial => 'admin/#{model_name.pluralize}/show' , :locals => {:#{model_name} => @#{reference_model_name}.#{model_name}} %>
|
57
|
+
</div>
|
58
|
+
<% end %>
|
59
|
+
CODE
|
60
|
+
inject_into_file File.join('app/views',options[:namespace], reference_model_name.pluralize, 'show.html.erb'), :after => sentinel do
|
61
|
+
"#{reference_list}"
|
62
|
+
end
|
63
|
+
|
64
|
+
inject_into_file File.join('app/views',options[:namespace], reference_model_name.pluralize, 'edit.html.erb'), :after => sentinel do
|
65
|
+
"#{reference_list}"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def add_list_view_to_model_show
|
70
|
+
sentinel = "<!-- More List View -->\n"
|
71
|
+
reference_list = <<-CODE
|
72
|
+
<div class="contextual">
|
73
|
+
<%= link_to "\#{t 'Add'} \#{#{reference_class_name}.model_name.human}", '#', :class => "icon icon-add", :onclick => "showAndScrollTo('add_#{reference_model_name}','focus_#{reference_model_name}'); return false;"%>
|
74
|
+
</div>
|
75
|
+
<h3><%=#{reference_class_name}.model_name.human%></h3>
|
76
|
+
<% @#{reference_value} = @#{model_name}.#{reference_value}.paginate(:page => params[:#{reference_model_name}_page], :order => (params[:#{reference_model_name}_sort].gsub('_reverse', ' DESC') unless params[:#{reference_model_name}_sort].blank?))%>
|
77
|
+
<div class="autoscroll">
|
78
|
+
<%= render :partial => 'admin/#{reference_value}/list', :locals => {:#{reference_value} => @#{reference_value}} %>
|
79
|
+
</div>
|
80
|
+
<%= will_paginate @#{reference_value}, :renderer => SomaticLinkRenderer %>
|
81
|
+
<div id="add_#{reference_model_name}" style="display:none">
|
82
|
+
<h3><%= "\#{t('New')} \#{#{reference_class_name}.model_name.human}" %></h3>
|
83
|
+
<div id="focus_#{reference_model_name}"></div>
|
84
|
+
<% form_for([:admin, @#{model_name}.#{reference_value}.build]) do |f| %>
|
85
|
+
<%= f.error_messages %>
|
86
|
+
<div class="issue">
|
87
|
+
<%= render :partial => 'admin/#{reference_value}/form' , :locals => {:f => f} %>
|
88
|
+
</div>
|
89
|
+
<%= hidden_field_tag :return_to, url_for%>
|
90
|
+
<%= f.submit t('Create') %>
|
91
|
+
<% end %>
|
92
|
+
<%= link_to_function t('Cancel'), "$('add_#{reference_model_name}').hide()"%>
|
93
|
+
</div>
|
94
|
+
CODE
|
95
|
+
inject_into_file File.join('app/views',options[:namespace], model_name.pluralize, 'show.html.erb'), :after => sentinel do
|
96
|
+
"#{reference_list}"
|
97
|
+
end
|
98
|
+
|
99
|
+
inject_into_file File.join('app/views',options[:namespace], model_name.pluralize, 'edit.html.erb'), :after => sentinel do
|
100
|
+
"#{reference_list}"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def add_hidden_field_to_edit_view
|
105
|
+
prepend_file File.join('app/views',options[:namespace], reference_model_name.pluralize, '_form.html.erb'), "<%= f.hidden_field :#{migration_attribute} %>"
|
106
|
+
end
|
107
|
+
|
108
|
+
def migrations
|
109
|
+
if relationship == 'has_many'
|
110
|
+
unless options[:skip_migration]
|
111
|
+
invoke "migration", [%(add_#{migration_attribute}_to_#{migration_table_name}), "#{migration_attribute}:integer"]
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
protected
|
118
|
+
|
119
|
+
def match_data
|
120
|
+
@match_data ||= name.match(/(.*)_(has_many|belongs_to)_(.*)/)
|
121
|
+
end
|
122
|
+
|
123
|
+
def relationship
|
124
|
+
match_data[2]
|
125
|
+
end
|
126
|
+
|
127
|
+
def model_name
|
128
|
+
match_data[1].singularize
|
129
|
+
end
|
130
|
+
|
131
|
+
def class_name
|
132
|
+
model_name.classify
|
133
|
+
end
|
134
|
+
|
135
|
+
def reference_model_name
|
136
|
+
match_data[3].singularize
|
137
|
+
end
|
138
|
+
|
139
|
+
def reference_class_name
|
140
|
+
reference_model_name.classify
|
141
|
+
end
|
142
|
+
|
143
|
+
def reference_value
|
144
|
+
reference_model_name.pluralize
|
145
|
+
end
|
146
|
+
|
147
|
+
def migration_table_name
|
148
|
+
reference_value
|
149
|
+
end
|
150
|
+
|
151
|
+
def migration_model_name
|
152
|
+
reference_model_name
|
153
|
+
end
|
154
|
+
|
155
|
+
def migration_attribute
|
156
|
+
"#{model_name}_id"
|
157
|
+
end
|
158
|
+
|
159
|
+
#
|
160
|
+
# Implement the required interface for Rails::Generators::Migration.
|
161
|
+
# taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
|
162
|
+
#
|
163
|
+
def self.next_migration_number(dirname) #:nodoc:
|
164
|
+
if ActiveRecord::Base.timestamped_migrations
|
165
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
166
|
+
else
|
167
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class <%= "add_#{migration_attribute}_to_#{migration_table_name}".camelize %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
add_column :<%= migration_table_name %>, :<%= migration_attribute %>, :integer
|
4
|
+
add_index :<%= migration_table_name %>, :<%= migration_attribute %>
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.down
|
8
|
+
remove_index :<%= migration_table_name %>, :<%= migration_attribute %>
|
9
|
+
remove_column :<%= migration_table_name %>, :<%= migration_attribute %>
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'generators/somatics'
|
2
|
+
require 'rails/generators/rails/resource/resource_generator'
|
3
|
+
require 'rails/generators/resource_helpers'
|
4
|
+
|
5
|
+
module Somatics
|
6
|
+
module Generators
|
7
|
+
class ScaffoldGenerator < Rails::Generators::ModelGenerator #metagenerator
|
8
|
+
include Rails::Generators::ResourceHelpers
|
9
|
+
|
10
|
+
hook_for :scaffold_controller, :required => true # do |controller|
|
11
|
+
# invoke controller, [ controller_name, attributes], {:namespace => 'admin' }
|
12
|
+
# end
|
13
|
+
|
14
|
+
#
|
15
|
+
# class_option :namespace, :banner => "NAME", :type => :string, :required => false, :default => "admin",
|
16
|
+
# :desc => "namespace to generate the controller for"
|
17
|
+
|
18
|
+
# include SomaticsHelpers
|
19
|
+
|
20
|
+
# remove_hook_for :resource_controller
|
21
|
+
# remove_class_option :actions
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<%%= form_for(@<%= singular_name %>) do |f| %>
|
2
|
+
<%% if @<%= singular_name %>.errors.any? %>
|
3
|
+
<div id="error_explanation">
|
4
|
+
<h2><%%= pluralize(@<%= singular_name %>.errors.count, "error") %> prohibited this <%= singular_name %> from being saved:</h2>
|
5
|
+
|
6
|
+
<ul>
|
7
|
+
<%% @<%= singular_name %>.errors.full_messages.each do |msg| %>
|
8
|
+
<li><%%= msg %></li>
|
9
|
+
<%% end %>
|
10
|
+
</ul>
|
11
|
+
</div>
|
12
|
+
<%% end %>
|
13
|
+
|
14
|
+
<% for attribute in attributes -%>
|
15
|
+
<div class="field">
|
16
|
+
<%%= f.label :<%= attribute.name %> %><br />
|
17
|
+
<%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
|
18
|
+
</div>
|
19
|
+
<% end -%>
|
20
|
+
<div class="actions">
|
21
|
+
<%%= f.submit %>
|
22
|
+
</div>
|
23
|
+
<%% end %>
|
@@ -0,0 +1,27 @@
|
|
1
|
+
<h1>Listing <%= plural_name %></h1>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<tr>
|
5
|
+
<% for attribute in attributes -%>
|
6
|
+
<th><%= attribute.human_name %></th>
|
7
|
+
<% end -%>
|
8
|
+
<th></th>
|
9
|
+
<th></th>
|
10
|
+
<th></th>
|
11
|
+
</tr>
|
12
|
+
|
13
|
+
<%% @<%= plural_name %>.each do |<%= singular_name %>| %>
|
14
|
+
<tr>
|
15
|
+
<% for attribute in attributes -%>
|
16
|
+
<td><%%= <%= singular_name %>.<%= attribute.name %> %></td>
|
17
|
+
<% end -%>
|
18
|
+
<td><%%= link_to 'Show', <%= singular_name %> %></td>
|
19
|
+
<td><%%= link_to 'Edit', edit_<%= singular_name %>_path(<%= singular_name %>) %></td>
|
20
|
+
<td><%%= link_to 'Destroy', <%= singular_name %>, :confirm => 'Are you sure?', :method => :delete %></td>
|
21
|
+
</tr>
|
22
|
+
<%% end %>
|
23
|
+
</table>
|
24
|
+
|
25
|
+
<br />
|
26
|
+
|
27
|
+
<%%= link_to 'New <%= human_name %>', new_<%= singular_name %>_path %>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<p id="notice"><%%= notice %></p>
|
2
|
+
|
3
|
+
<% for attribute in attributes -%>
|
4
|
+
<p>
|
5
|
+
<b><%= attribute.human_name %>:</b>
|
6
|
+
<%%= @<%= singular_name %>.<%= attribute.name %> %>
|
7
|
+
</p>
|
8
|
+
|
9
|
+
<% end -%>
|
10
|
+
|
11
|
+
<%%= link_to 'Edit', edit_<%= singular_name %>_path(@<%= singular_name %>) %> |
|
12
|
+
<%%= link_to 'Back', <%= plural_name %>_path %>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Description:
|
2
|
+
Stubs out a scaffolded controller and its views. Pass the model name,
|
3
|
+
either CamelCased or under_scored, and a list of views as arguments.
|
4
|
+
The controller name is retrieved as a pluralized version of the model
|
5
|
+
name.
|
6
|
+
|
7
|
+
To create a controller within a module, specify the model name as a
|
8
|
+
path like 'parent_module/controller_name'.
|
9
|
+
|
10
|
+
This generates a controller class in app/controllers and invokes helper,
|
11
|
+
template engine and test framework generators.
|
12
|
+
|
13
|
+
Example:
|
14
|
+
`rails generate scaffold_controller CreditCard`
|
15
|
+
|
16
|
+
Credit card controller with URLs like /credit_card/debit.
|
17
|
+
Controller: app/controllers/credit_cards_controller.rb
|
18
|
+
Functional Test: test/functional/credit_cards_controller_test.rb
|
19
|
+
Views: app/views/credit_cards/index.html.erb [...]
|
20
|
+
Helper: app/helpers/credit_cards_helper.rb
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'generators/somatics'
|
2
|
+
require 'rails/generators/resource_helpers'
|
3
|
+
|
4
|
+
module Somatics
|
5
|
+
module Generators
|
6
|
+
class ScaffoldControllerGenerator < Rails::Generators::NamedBase
|
7
|
+
extend TemplatePath
|
8
|
+
include Rails::Generators::ResourceHelpers
|
9
|
+
|
10
|
+
check_class_collision :suffix => "Controller"
|
11
|
+
# remove_hook_for :template_engine, :test_framework, :helper # TODO
|
12
|
+
|
13
|
+
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
14
|
+
|
15
|
+
class_option :orm, :banner => "NAME", :type => :string, :required => true,
|
16
|
+
:desc => "ORM to generate the controller for"
|
17
|
+
class_option :namespace, :banner => "NAME", :type => :string, :required => false, :default => "admin", :desc => "namespace to generate the controller for"
|
18
|
+
class_option :header, :type => :boolean, :default => true, :desc => "generate header menu tab"
|
19
|
+
class_option :locales, :type => :array, :banner => "LOCALE LOCALE", :default => %w( en zh-TW ),
|
20
|
+
:desc => "Supported Locales"
|
21
|
+
class_option :skip_auditing, :type => :boolean, :default => false, :desc => "Don't generate auditing information."
|
22
|
+
|
23
|
+
def create_controller_files
|
24
|
+
template 'controller.rb', File.join('app/controllers', options[:namespace], class_path, "#{controller_file_name}_controller.rb")
|
25
|
+
end
|
26
|
+
def create_view_files
|
27
|
+
template "partial_form.html.erb", File.join('app/views',options[:namespace], class_path, controller_file_name, "_form.html.erb" )
|
28
|
+
template "partial_list.html.erb", File.join('app/views',options[:namespace], class_path, controller_file_name, "_list.html.erb" )
|
29
|
+
template "partial_show.html.erb", File.join('app/views',options[:namespace], class_path, controller_file_name, "_show.html.erb" )
|
30
|
+
template "partial_edit.html.erb", File.join('app/views',options[:namespace], class_path, controller_file_name, "_edit.html.erb" )
|
31
|
+
template "partial_bulk.html.erb", File.join('app/views',options[:namespace], class_path, controller_file_name, "_bulk.html.erb" )
|
32
|
+
template "view_index.html.erb", File.join('app/views',options[:namespace], class_path, controller_file_name, "index.html.erb" )
|
33
|
+
template "view_new.html.erb", File.join('app/views',options[:namespace], class_path, controller_file_name, "new.html.erb" )
|
34
|
+
template "view_show.html.erb", File.join('app/views',options[:namespace], class_path, controller_file_name, "show.html.erb" )
|
35
|
+
template "view_edit.html.erb", File.join('app/views',options[:namespace], class_path, controller_file_name, "edit.html.erb" )
|
36
|
+
template "builder_index.xml.builder", File.join('app/views',options[:namespace], class_path, controller_file_name, "index.xml.builder")
|
37
|
+
template "builder_index.xls.builder", File.join('app/views',options[:namespace], class_path, controller_file_name, "index.xls.builder")
|
38
|
+
end
|
39
|
+
|
40
|
+
def add_header_menu_tab
|
41
|
+
if options[:header]
|
42
|
+
look_for = "<li><%= link_to '#{file_name.humanize}', '/admin/#{controller_file_name}', :class => (match_controller?('#{controller_file_name}')) ? 'selected' : ''%>\n\t<ul class='sub'></ul></li>\n"
|
43
|
+
gsub_file File.join('app/views/admin/shared', "_menu.html.erb"), look_for, ''
|
44
|
+
append_file File.join('app/views/admin/shared', "_menu.html.erb"), look_for
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def create_locales_files
|
49
|
+
# # Locales templates
|
50
|
+
options[:locales].each do |locale|
|
51
|
+
template "locales_#{locale}.yml", File.join('config/locales', "#{controller_file_name}_#{locale}.yml")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def add_resource_route
|
56
|
+
route_config = "namespace :#{namespace_name} do "
|
57
|
+
route_config << class_path.collect{|namespace| "namespace :#{namespace} do " }.join(" ")
|
58
|
+
route_config << "resources :#{file_name.pluralize}"
|
59
|
+
route_config << " end" * class_path.size
|
60
|
+
route_config << " end"
|
61
|
+
route route_config
|
62
|
+
end
|
63
|
+
|
64
|
+
def inject_somatics_filters
|
65
|
+
filters = [" has_filter :id, :integer, :default => true\n", " has_filter :created_at, :date\n"]
|
66
|
+
filters |= attributes.collect do |attribute|
|
67
|
+
" has_filter :#{attribute.name}, :#{attribute.type}\n"
|
68
|
+
end
|
69
|
+
# FIXME The model generator removes the model.rb already
|
70
|
+
if File.exists?("app/models/#{singular_name}.rb")
|
71
|
+
inject_into_class "app/models/#{singular_name}.rb", class_name, filters.join('')
|
72
|
+
inject_into_class "app/models/#{singular_name}.rb", class_name,
|
73
|
+
<<-RUBY
|
74
|
+
# Somatics Filter (Reference: http://github.com/inspiresynergy/somatics_filter)
|
75
|
+
RUBY
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def inject_paper_trail
|
80
|
+
unless options[:skip_auditing]
|
81
|
+
# FIXME The model generator removes the model.rb already
|
82
|
+
if File.exists?("app/models/#{singular_name}.rb")
|
83
|
+
inject_into_class "app/models/#{singular_name}.rb", class_name, " has_paper_trail :ignore => [:updated_at]\n"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# Test Cases
|
89
|
+
hook_for :test_framework, :as => :scaffold
|
90
|
+
|
91
|
+
protected
|
92
|
+
|
93
|
+
def namespace_class
|
94
|
+
options[:namespace].classify
|
95
|
+
end
|
96
|
+
|
97
|
+
def namespace_name
|
98
|
+
options[:namespace].underscore
|
99
|
+
end
|
100
|
+
|
101
|
+
# hook_for :template_engine, :test_framework, :as => :somatics_scaffold
|
102
|
+
# Invoke the helper using the controller name (pluralized)
|
103
|
+
# hook_for :helper, :as => :scaffold do |invoked|
|
104
|
+
# invoke invoked, [ controller_name ]
|
105
|
+
# end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|