somatics3 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (189) hide show
  1. data/.document +5 -0
  2. data/LICENSE +20 -0
  3. data/README.rdoc +91 -0
  4. data/Rakefile +72 -0
  5. data/VERSION +1 -0
  6. data/bin/somatics +23 -0
  7. data/bin/somatify +21 -0
  8. data/lib/generators/somatics.rb +37 -0
  9. data/lib/generators/somatics/associated/associated_generator.rb +184 -0
  10. data/lib/generators/somatics/associated/templates/migration.rb +11 -0
  11. data/lib/generators/somatics/attributes/attributes_generator.rb +115 -0
  12. data/lib/generators/somatics/attributes/templates/migration.rb +11 -0
  13. data/lib/generators/somatics/authenticated/authenticated_generator.rb +65 -0
  14. data/lib/generators/somatics/authenticated/templates/partial_form.html.erb +23 -0
  15. data/lib/generators/somatics/authenticated_controller/authenticated_controller_generator.rb +38 -0
  16. data/lib/generators/somatics/authenticated_controller/templates/locales_en.yml +6 -0
  17. data/lib/generators/somatics/authenticated_controller/templates/locales_zh-TW.yml +6 -0
  18. data/lib/generators/somatics/authenticated_controller/templates/login.html.erb +31 -0
  19. data/lib/generators/somatics/authenticated_controller/templates/sessions_controller.rb +11 -0
  20. data/lib/generators/somatics/helper/helper_generator.rb +16 -0
  21. data/lib/generators/somatics/install/install_generator.rb +101 -0
  22. data/lib/generators/somatics/install/templates/config/locales/devise_zh-TW.yml +39 -0
  23. data/lib/generators/somatics/install/templates/config/locales/somatics_en.yml +35 -0
  24. data/lib/generators/somatics/install/templates/config/locales/somatics_zh-TW.yml +35 -0
  25. data/lib/generators/somatics/install/templates/controller_admin.rb +17 -0
  26. data/lib/generators/somatics/install/templates/controller_home.rb +4 -0
  27. data/lib/generators/somatics/install/templates/helper_admin.rb +99 -0
  28. data/lib/generators/somatics/install/templates/initializer_paper_trail.rb +2 -0
  29. data/lib/generators/somatics/install/templates/layout_admin.html.erb +87 -0
  30. data/lib/generators/somatics/install/templates/lib/active_record/diff.rb +61 -0
  31. data/lib/generators/somatics/install/templates/lib/somatic_link_renderer.rb +24 -0
  32. data/lib/generators/somatics/install/templates/lib/tasks/heroku.rake +30 -0
  33. data/lib/generators/somatics/install/templates/lib/tasks/svn.rake +47 -0
  34. data/lib/generators/somatics/install/templates/partial_menu.html.erb +1 -0
  35. data/lib/generators/somatics/install/templates/partial_versions.html.erb +56 -0
  36. data/lib/generators/somatics/install/templates/public/images/somatics/add.png +0 -0
  37. data/lib/generators/somatics/install/templates/public/images/somatics/arrow_collapsed.png +0 -0
  38. data/lib/generators/somatics/install/templates/public/images/somatics/arrow_expanded.png +0 -0
  39. data/lib/generators/somatics/install/templates/public/images/somatics/attachment.png +0 -0
  40. data/lib/generators/somatics/install/templates/public/images/somatics/bullet_arrow_left.png +0 -0
  41. data/lib/generators/somatics/install/templates/public/images/somatics/bullet_arrow_right.png +0 -0
  42. data/lib/generators/somatics/install/templates/public/images/somatics/bullet_diamond.png +0 -0
  43. data/lib/generators/somatics/install/templates/public/images/somatics/bullet_end.png +0 -0
  44. data/lib/generators/somatics/install/templates/public/images/somatics/bullet_go.png +0 -0
  45. data/lib/generators/somatics/install/templates/public/images/somatics/bullet_toggle_minus.png +0 -0
  46. data/lib/generators/somatics/install/templates/public/images/somatics/bullet_toggle_plus.png +0 -0
  47. data/lib/generators/somatics/install/templates/public/images/somatics/c.png +0 -0
  48. data/lib/generators/somatics/install/templates/public/images/somatics/cancel.png +0 -0
  49. data/lib/generators/somatics/install/templates/public/images/somatics/changeset.png +0 -0
  50. data/lib/generators/somatics/install/templates/public/images/somatics/comment.png +0 -0
  51. data/lib/generators/somatics/install/templates/public/images/somatics/comments.png +0 -0
  52. data/lib/generators/somatics/install/templates/public/images/somatics/content-left.png +0 -0
  53. data/lib/generators/somatics/install/templates/public/images/somatics/content-right.png +0 -0
  54. data/lib/generators/somatics/install/templates/public/images/somatics/copy.png +0 -0
  55. data/lib/generators/somatics/install/templates/public/images/somatics/csharp.png +0 -0
  56. data/lib/generators/somatics/install/templates/public/images/somatics/database_key.png +0 -0
  57. data/lib/generators/somatics/install/templates/public/images/somatics/default.png +0 -0
  58. data/lib/generators/somatics/install/templates/public/images/somatics/delete.png +0 -0
  59. data/lib/generators/somatics/install/templates/public/images/somatics/document.png +0 -0
  60. data/lib/generators/somatics/install/templates/public/images/somatics/draft.png +0 -0
  61. data/lib/generators/somatics/install/templates/public/images/somatics/duplicate.png +0 -0
  62. data/lib/generators/somatics/install/templates/public/images/somatics/edit.png +0 -0
  63. data/lib/generators/somatics/install/templates/public/images/somatics/exclamation.png +0 -0
  64. data/lib/generators/somatics/install/templates/public/images/somatics/external.png +0 -0
  65. data/lib/generators/somatics/install/templates/public/images/somatics/fav.png +0 -0
  66. data/lib/generators/somatics/install/templates/public/images/somatics/fav_off.png +0 -0
  67. data/lib/generators/somatics/install/templates/public/images/somatics/feed.png +0 -0
  68. data/lib/generators/somatics/install/templates/public/images/somatics/folder.png +0 -0
  69. data/lib/generators/somatics/install/templates/public/images/somatics/folder_open.png +0 -0
  70. data/lib/generators/somatics/install/templates/public/images/somatics/footer-bg.png +0 -0
  71. data/lib/generators/somatics/install/templates/public/images/somatics/footer-left.png +0 -0
  72. data/lib/generators/somatics/install/templates/public/images/somatics/footer-right.png +0 -0
  73. data/lib/generators/somatics/install/templates/public/images/somatics/group.png +0 -0
  74. data/lib/generators/somatics/install/templates/public/images/somatics/help.png +0 -0
  75. data/lib/generators/somatics/install/templates/public/images/somatics/history.png +0 -0
  76. data/lib/generators/somatics/install/templates/public/images/somatics/image.png +0 -0
  77. data/lib/generators/somatics/install/templates/public/images/somatics/lightning.png +0 -0
  78. data/lib/generators/somatics/install/templates/public/images/somatics/link.png +0 -0
  79. data/lib/generators/somatics/install/templates/public/images/somatics/loading.gif +0 -0
  80. data/lib/generators/somatics/install/templates/public/images/somatics/locked.png +0 -0
  81. data/lib/generators/somatics/install/templates/public/images/somatics/message.png +0 -0
  82. data/lib/generators/somatics/install/templates/public/images/somatics/milestone.png +0 -0
  83. data/lib/generators/somatics/install/templates/public/images/somatics/move.png +0 -0
  84. data/lib/generators/somatics/install/templates/public/images/somatics/news.png +0 -0
  85. data/lib/generators/somatics/install/templates/public/images/somatics/openid-bg.gif +0 -0
  86. data/lib/generators/somatics/install/templates/public/images/somatics/package.png +0 -0
  87. data/lib/generators/somatics/install/templates/public/images/somatics/pdf.png +0 -0
  88. data/lib/generators/somatics/install/templates/public/images/somatics/php.png +0 -0
  89. data/lib/generators/somatics/install/templates/public/images/somatics/plugin.png +0 -0
  90. data/lib/generators/somatics/install/templates/public/images/somatics/projects.png +0 -0
  91. data/lib/generators/somatics/install/templates/public/images/somatics/rails.png +0 -0
  92. data/lib/generators/somatics/install/templates/public/images/somatics/reload.png +0 -0
  93. data/lib/generators/somatics/install/templates/public/images/somatics/report.png +0 -0
  94. data/lib/generators/somatics/install/templates/public/images/somatics/ruby.png +0 -0
  95. data/lib/generators/somatics/install/templates/public/images/somatics/save.png +0 -0
  96. data/lib/generators/somatics/install/templates/public/images/somatics/sort_asc.png +0 -0
  97. data/lib/generators/somatics/install/templates/public/images/somatics/sort_desc.png +0 -0
  98. data/lib/generators/somatics/install/templates/public/images/somatics/stats.png +0 -0
  99. data/lib/generators/somatics/install/templates/public/images/somatics/table_multiple.png +0 -0
  100. data/lib/generators/somatics/install/templates/public/images/somatics/task_done.png +0 -0
  101. data/lib/generators/somatics/install/templates/public/images/somatics/task_late.png +0 -0
  102. data/lib/generators/somatics/install/templates/public/images/somatics/task_parent_end.png +0 -0
  103. data/lib/generators/somatics/install/templates/public/images/somatics/task_todo.png +0 -0
  104. data/lib/generators/somatics/install/templates/public/images/somatics/text.png +0 -0
  105. data/lib/generators/somatics/install/templates/public/images/somatics/text_list_bullets.png +0 -0
  106. data/lib/generators/somatics/install/templates/public/images/somatics/textfield.png +0 -0
  107. data/lib/generators/somatics/install/templates/public/images/somatics/ticket.png +0 -0
  108. data/lib/generators/somatics/install/templates/public/images/somatics/ticket_checked.png +0 -0
  109. data/lib/generators/somatics/install/templates/public/images/somatics/ticket_edit.png +0 -0
  110. data/lib/generators/somatics/install/templates/public/images/somatics/ticket_go.png +0 -0
  111. data/lib/generators/somatics/install/templates/public/images/somatics/ticket_note.png +0 -0
  112. data/lib/generators/somatics/install/templates/public/images/somatics/time.png +0 -0
  113. data/lib/generators/somatics/install/templates/public/images/somatics/time_add.png +0 -0
  114. data/lib/generators/somatics/install/templates/public/images/somatics/toggle_check.png +0 -0
  115. data/lib/generators/somatics/install/templates/public/images/somatics/true.png +0 -0
  116. data/lib/generators/somatics/install/templates/public/images/somatics/unlock.png +0 -0
  117. data/lib/generators/somatics/install/templates/public/images/somatics/user.png +0 -0
  118. data/lib/generators/somatics/install/templates/public/images/somatics/warning.png +0 -0
  119. data/lib/generators/somatics/install/templates/public/images/somatics/wiki_edit.png +0 -0
  120. data/lib/generators/somatics/install/templates/public/images/somatics/xml.png +0 -0
  121. data/lib/generators/somatics/install/templates/public/images/somatics/zip.png +0 -0
  122. data/lib/generators/somatics/install/templates/public/images/somatics/zoom_in.png +0 -0
  123. data/lib/generators/somatics/install/templates/public/javascripts/somatics/base.js +237 -0
  124. data/lib/generators/somatics/install/templates/public/javascripts/somatics/context_menu.js +237 -0
  125. data/lib/generators/somatics/install/templates/public/javascripts/somatics/controls.js +965 -0
  126. data/lib/generators/somatics/install/templates/public/javascripts/somatics/dragdrop.js +974 -0
  127. data/lib/generators/somatics/install/templates/public/javascripts/somatics/effects.js +1123 -0
  128. data/lib/generators/somatics/install/templates/public/javascripts/somatics/prototype.js +6001 -0
  129. data/lib/generators/somatics/install/templates/public/javascripts/somatics/rails.js +175 -0
  130. data/lib/generators/somatics/install/templates/public/javascripts/somatics/select_list_move.js +82 -0
  131. data/lib/generators/somatics/install/templates/public/stylesheets/application.css +863 -0
  132. data/lib/generators/somatics/install/templates/public/stylesheets/somatics/base.css +951 -0
  133. data/lib/generators/somatics/install/templates/public/stylesheets/somatics/context_menu.css +52 -0
  134. data/lib/generators/somatics/install/templates/public/stylesheets/somatics/csshover.htc +122 -0
  135. data/lib/generators/somatics/install/templates/public/stylesheets/somatics/jstoolbar.css +95 -0
  136. data/lib/generators/somatics/install/templates/public/themes/default/stylesheets/application.css +951 -0
  137. data/lib/generators/somatics/install/templates/view_index.html.erb +46 -0
  138. data/lib/generators/somatics/relationship/relationship_generator.rb +173 -0
  139. data/lib/generators/somatics/relationship/templates/migration.rb +11 -0
  140. data/lib/generators/somatics/scaffold/scaffold_generator.rb +24 -0
  141. data/lib/generators/somatics/scaffold/templates/_form.html.erb +23 -0
  142. data/lib/generators/somatics/scaffold/templates/edit.html.erb +6 -0
  143. data/lib/generators/somatics/scaffold/templates/index.html.erb +27 -0
  144. data/lib/generators/somatics/scaffold/templates/new.html.erb +5 -0
  145. data/lib/generators/somatics/scaffold/templates/show.html.erb +12 -0
  146. data/lib/generators/somatics/scaffold_controller/USAGE +20 -0
  147. data/lib/generators/somatics/scaffold_controller/scaffold_controller_generator.rb +108 -0
  148. data/lib/generators/somatics/scaffold_controller/templates/builder_index.xls.builder +24 -0
  149. data/lib/generators/somatics/scaffold_controller/templates/builder_index.xml.builder +10 -0
  150. data/lib/generators/somatics/scaffold_controller/templates/controller.rb +123 -0
  151. data/lib/generators/somatics/scaffold_controller/templates/locales_en.yml +17 -0
  152. data/lib/generators/somatics/scaffold_controller/templates/locales_zh-TW.yml +20 -0
  153. data/lib/generators/somatics/scaffold_controller/templates/partial_bulk.html.erb +12 -0
  154. data/lib/generators/somatics/scaffold_controller/templates/partial_edit.html.erb +7 -0
  155. data/lib/generators/somatics/scaffold_controller/templates/partial_form.html.erb +13 -0
  156. data/lib/generators/somatics/scaffold_controller/templates/partial_list.html.erb +30 -0
  157. data/lib/generators/somatics/scaffold_controller/templates/partial_menu.html.erb +1 -0
  158. data/lib/generators/somatics/scaffold_controller/templates/partial_show.html.erb +31 -0
  159. data/lib/generators/somatics/scaffold_controller/templates/view_edit.html.erb +24 -0
  160. data/lib/generators/somatics/scaffold_controller/templates/view_index.html.erb +27 -0
  161. data/lib/generators/somatics/scaffold_controller/templates/view_new.html.erb +14 -0
  162. data/lib/generators/somatics/scaffold_controller/templates/view_show.html.erb +26 -0
  163. data/lib/generators/somatics/settings/settings_generator.rb +86 -0
  164. data/lib/generators/somatics/settings_controller/USAGE +20 -0
  165. data/lib/generators/somatics/settings_controller/settings_controller_generator.rb +11 -0
  166. data/lib/generators/somatics/settings_controller/templates/builder_index.xls.builder +24 -0
  167. data/lib/generators/somatics/settings_controller/templates/builder_index.xml.builder +10 -0
  168. data/lib/generators/somatics/settings_controller/templates/controller.rb +64 -0
  169. data/lib/generators/somatics/settings_controller/templates/helper.rb +2 -0
  170. data/lib/generators/somatics/settings_controller/templates/locales_en.yml +9 -0
  171. data/lib/generators/somatics/settings_controller/templates/locales_zh-TW.yml +28 -0
  172. data/lib/generators/somatics/settings_controller/templates/migration.rb +17 -0
  173. data/lib/generators/somatics/settings_controller/templates/partial_bulk.html.erb +12 -0
  174. data/lib/generators/somatics/settings_controller/templates/partial_edit.html.erb +7 -0
  175. data/lib/generators/somatics/settings_controller/templates/partial_form.html.erb +15 -0
  176. data/lib/generators/somatics/settings_controller/templates/partial_list.html.erb +28 -0
  177. data/lib/generators/somatics/settings_controller/templates/partial_menu.html.erb +1 -0
  178. data/lib/generators/somatics/settings_controller/templates/partial_show.html.erb +13 -0
  179. data/lib/generators/somatics/settings_controller/templates/view_edit.html.erb +23 -0
  180. data/lib/generators/somatics/settings_controller/templates/view_index.html.erb +22 -0
  181. data/lib/generators/somatics/settings_controller/templates/view_new.html.erb +14 -0
  182. data/lib/generators/somatics/settings_controller/templates/view_show.html.erb +23 -0
  183. data/lib/somatics.rb +9 -0
  184. data/somatics.gemspec +249 -0
  185. data/somatics3.gemspec +248 -0
  186. data/templates/somatics.rb +106 -0
  187. data/test/helper.rb +10 -0
  188. data/test/test_somatics3-generators.rb +7 -0
  189. metadata +398 -0
@@ -0,0 +1,24 @@
1
+ excel_document(xml) do
2
+ xml.Worksheet 'ss:Name' => '<%= plural_name.humanize %>' do
3
+ xml.Table do
4
+ # Header
5
+ xml.Row do
6
+ @headers.each do |header|
7
+ xml.Cell { xml.Data header, 'ss:Type' => 'String' }
8
+ end
9
+ end
10
+
11
+ # Rows
12
+ unless @<%= plural_name %>.blank?
13
+ for <%= singular_name %> in @<%= plural_name %>
14
+ xml.Row do
15
+ @fields.each do |f|
16
+ xml.Cell { xml.Data <%= singular_name %>.send(f), 'ss:Type' => 'String' }
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,10 @@
1
+ xml.instruct!
2
+ xml.<%= plural_name %> do
3
+ @<%= plural_name %>.each do |<%= singular_name %>|
4
+ xml.<%= singular_name %> do
5
+ @fields.each do |f|
6
+ xml.tag! f, <%= singular_name %>.send(f)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,123 @@
1
+ class <%=namespace_class%>::<%= controller_class_name %>Controller < <%=namespace_class%>::AdminController
2
+ # GET /<%= plural_table_name %>
3
+ # GET /<%= plural_table_name %>.xml
4
+ def index
5
+ @fields = <%= attributes.collect {|attribute| attribute.name}.inspect %>
6
+ @headers = <%= attributes.collect {|attribute| attribute.name.humanize}.inspect %>
7
+ respond_to do |format|
8
+ format.html {
9
+ @<%= plural_table_name %> = <%= class_name %>.apply_query(params).paginate(:page => params[:<%= plural_table_name %>_page], :order => (params[:<%= singular_name %>_sort].gsub('_reverse', ' DESC') unless params[:<%= singular_name %>_sort].blank?))
10
+ }
11
+ format.xml {
12
+ @<%= plural_table_name %> = <%= class_name %>.apply_query(params)
13
+ }
14
+ format.csv {
15
+ @<%= plural_table_name %> = <%= class_name %>.apply_query(params)
16
+ csv_string = FasterCSV.generate do |csv|
17
+ csv << @headers
18
+ @<%= plural_table_name %>.each do |<%= singular_name %>|
19
+ csv << @fields.collect { |f| <%= singular_name %>.send(f) }
20
+ end
21
+ end
22
+ send_data csv_string, :type => 'text/csv; charset=iso-8859-1; header=present',
23
+ :disposition => "attachment; filename=<%= plural_table_name %>.csv"
24
+ }
25
+ format.xls {
26
+ @<%= plural_table_name %> = <%= class_name %>.apply_query(params)
27
+ render :xls => @<%= plural_table_name %>
28
+ }
29
+ end
30
+ end
31
+
32
+ # GET /<%= plural_table_name %>/1
33
+ # GET /<%= plural_table_name %>/1.xml
34
+ def show
35
+ @<%= file_name %> = <%= class_name %>.find(params[:id])
36
+
37
+ respond_to do |format|
38
+ format.html # show.html.erb
39
+ format.xml { render :xml => @<%= file_name %> }
40
+ end
41
+ end
42
+
43
+ # GET /<%= plural_table_name %>/new
44
+ # GET /<%= plural_table_name %>/new.xml
45
+ def new
46
+ @<%= file_name %> = <%= class_name %>.new
47
+
48
+ respond_to do |format|
49
+ format.html # new.html.erb
50
+ format.xml { render :xml => @<%= file_name %> }
51
+ end
52
+ end
53
+
54
+ # GET /<%= plural_table_name %>/1/edit
55
+ def edit
56
+ @<%= file_name %> = <%= class_name %>.find(params[:id])
57
+ end
58
+
59
+ # POST /<%= plural_table_name %>
60
+ # POST /<%= plural_table_name %>.xml
61
+ def create
62
+ @<%= file_name %> = <%= class_name %>.new(params[:<%= file_name %>])
63
+
64
+ respond_to do |format|
65
+ if @<%= file_name %>.save
66
+ flash[:notice] = '<%= class_name %> was successfully created.'
67
+ format.html { redirect_to(params[:return_to] || [:admin,@<%= file_name %>]) }
68
+ format.xml { render :xml => @<%= file_name %>, :status => :created, :location => @<%= file_name %> }
69
+ else
70
+ format.html { render :action => "new" }
71
+ format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
72
+ end
73
+ end
74
+ end
75
+
76
+ # PUT /<%= plural_table_name %>/1
77
+ # PUT /<%= plural_table_name %>/1.xml
78
+ def update
79
+ @<%= file_name %> = <%= class_name %>.find(params[:id])
80
+
81
+ respond_to do |format|
82
+ if @<%= file_name %>.update_attributes(params[:<%= file_name %>])
83
+ flash[:notice] = '<%= class_name %> was successfully updated.'
84
+ format.html { redirect_to([:admin,@<%= file_name %>]) }
85
+ format.xml { head :ok }
86
+ else
87
+ format.html { render :action => "edit" }
88
+ format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
89
+ end
90
+ end
91
+ end
92
+
93
+ # DELETE /<%= plural_table_name %>/1
94
+ # DELETE /<%= plural_table_name %>/1.xml
95
+ def destroy
96
+ @<%= file_name %> = <%= class_name %>.find(params[:id])
97
+ @<%= file_name %>.destroy
98
+ flash[:notice] = '<%= class_name %> was successfully deleted.'
99
+ respond_to do |format|
100
+ format.html { redirect_to(admin_<%= plural_table_name %>_url) }
101
+ format.xml { head :ok }
102
+ end
103
+ end
104
+
105
+ # def bulk
106
+ # unless params[:ids].blank?
107
+ # <%= plural_table_name %> = <%= class_name %>.find(params[:ids])
108
+ # success = true
109
+ # params[:<%= file_name %>].delete_if {|k, v| v.blank?}
110
+ # <%= plural_table_name %>.each do |<%= file_name %>|
111
+ # success &&= <%= file_name %>.update_attributes(params[:<%= file_name %>])
112
+ # end
113
+ # success ? flash[:notice] = '<%= class_name.pluralize %> were successfully updated.' : flash[:error] = 'Bulk Update Failed.'
114
+ # else
115
+ # flash[:error] = 'No <%= class_name %> record is selected.'
116
+ # end
117
+ #
118
+ # respond_to do |format|
119
+ # format.html { redirect_to(admin_<%= plural_table_name %>_path) }
120
+ # format.xml { head :ok }
121
+ # end
122
+ # end
123
+ end
@@ -0,0 +1,17 @@
1
+ en:
2
+ activerecord:
3
+ models:
4
+ <%= singular_name %>: <%= singular_name.humanize %>
5
+ attributes:
6
+ <%= singular_name %>:
7
+ <% if options[:authenticated] -%>
8
+ login: Login
9
+ name: Name
10
+ email: Email
11
+ created_at: Created At
12
+ password: Password
13
+ password_confirmation: Password Confirmation
14
+ <% end -%>
15
+ <% attributes.each do |attribute| -%>
16
+ <%= attribute.name %>: <%= attribute.name.humanize %>
17
+ <% end -%>
@@ -0,0 +1,20 @@
1
+ <%-
2
+ require 'net/http'
3
+ require 'uri'
4
+ require 'json'
5
+ class GoogleTranslate
6
+ def self.t(text)
7
+ uri = URI.parse('http://ajax.googleapis.com/ajax/services/language/translate')
8
+ JSON.parse(Net::HTTP.post_form(uri, {"q" => text, "langpair" => "en|zh-TW", "v" => '1.0'}).body)['responseData']['translatedText'] rescue text.humanize
9
+ end
10
+ end
11
+ -%>
12
+ "zh-TW":
13
+ activerecord:
14
+ models:
15
+ <%= singular_name %>: <%= GoogleTranslate.t singular_name.humanize %>
16
+ attributes:
17
+ <%= singular_name %>:
18
+ <% attributes.each do |attribute| -%>
19
+ <%= attribute.name %>: <%= GoogleTranslate.t attribute.name.humanize %>
20
+ <% end -%>
@@ -0,0 +1,12 @@
1
+ <h3><%%= "#{t('Bulk')} #{t('Update')}" %></h3>
2
+ <div class="issue">
3
+ <table width="100%">
4
+ <tbody>
5
+ <!-- <tr>
6
+ <td><b>Field</b></td>
7
+ <td><%%#= text_field_tag '<%= singular_name %>[field]' %></td>
8
+ </tr> -->
9
+ </tbody>
10
+ </table>
11
+ </div>
12
+ <%%= submit_tag("#{t('Bulk')} #{t('Update')}") %>
@@ -0,0 +1,7 @@
1
+ <%% form_for([:admin, @<%= singular_name %>]) do |f| %>
2
+ <div class="box tabular settings">
3
+ <%%= f.error_messages %>
4
+ <%%= render :partial => 'form' , :locals => {:f => f} %>
5
+ </div>
6
+ <%%= f.submit t('Update') %>
7
+ <%% end %>
@@ -0,0 +1,13 @@
1
+ <table width="100%">
2
+ <tbody>
3
+ <tr>
4
+ <td colspan="2"><br/><h3><%%= <%=class_name %>.model_name.human %></h3></td>
5
+ </tr>
6
+ <% for attribute in attributes -%>
7
+ <tr>
8
+ <td><b><%%= <%= class_name %>.human_attribute_name(:<%=attribute.name%>) %></b></td>
9
+ <td><%%= f.<%= attribute.field_type %> :<%= attribute.name %> %></td>
10
+ </tr>
11
+ <% end -%>
12
+ </tbody>
13
+ </table>
@@ -0,0 +1,30 @@
1
+ <table class="list issues">
2
+ <thead>
3
+ <tr>
4
+ <!-- <th><%%#= link_to image_tag('toggle_check.png', :alt => "Toggle_check"), admin_<%= plural_name %>_path, :onclick => "toggleIssuesSelection(Element.up(this, &quot;form&quot;)); return false;", :title => "Check all/Uncheck all" %></th> -->
5
+ <th title="<%%=t "sort_by", :field => '#'%>"><%%= sort_link_helper t('ID'), '<%=singular_name%>', 'id' %></th>
6
+ <% for attribute in attributes -%>
7
+ <th title="<%%=t "sort_by", :field => <%= class_name %>.human_attribute_name(:<%= attribute.name %>) %>"><%%= sort_link_helper <%= class_name %>.human_attribute_name(:<%= attribute.name %>), '<%=singular_name%>', '<%= attribute.name %>' %></th>
8
+ <% end -%>
9
+ <!-- More Sort Link Helper -->
10
+ </tr>
11
+ </thead>
12
+ <tbody>
13
+ <%% unless <%= plural_name %>.empty? %>
14
+ <%% for <%= singular_name %> in <%= plural_name %> %>
15
+ <tr id="<%% dom_id(<%=singular_name%>)%>" class="hascontextmenu <%%= cycle 'odd' , 'even' %> issue">
16
+ <!-- <td class="checkbox"><input name="ids[]" type="checkbox" value="<%%#= <%=singular_name%>.id %>" /></td> -->
17
+ <td onclick="link_to(<%%= "'#{admin_<%=singular_name%>_path(<%=singular_name%>)}'" %>);"><%%= link_to <%= singular_name %>.id, [:admin, <%= singular_name %>]%></td>
18
+ <% for attribute in attributes -%>
19
+ <td onclick="link_to(<%%= "'#{admin_<%=singular_name%>_path(<%=singular_name%>)}'" %>);" class="<%= attribute.name %>"><%%=h <%= singular_name %>.<%= attribute.name %> %></td>
20
+ <% end -%>
21
+ <!-- More Fields -->
22
+ </tr>
23
+ <%% end %>
24
+ <%% else -%>
25
+ <tr class="datos">
26
+ <td colspan="100" align="center"><%%=t :no_data_available%></td>
27
+ </tr>
28
+ <%% end -%>
29
+ </tbody>
30
+ </table>
@@ -0,0 +1 @@
1
+ <li><%%= link_to 'Home', '/admin', :class => (match_controller?("home")) ? 'selected' : ''%></li>
@@ -0,0 +1,31 @@
1
+ <table class="attributes" width="100%">
2
+ <tbody>
3
+ <tr>
4
+ <td colspan="2"><br/><h3><%%= "#{<%= class_name %>.model_name.human} #{t('Information')}" %></h3></td>
5
+ </tr>
6
+ <% if options[:admin_authenticated] || options[:authenticated] -%>
7
+ <tr>
8
+ <td><b><%%= <%= class_name %>.human_attribute_name(:login) %></b></td>
9
+ <td><%%=h <%= singular_name %>.login %></td>
10
+ </tr>
11
+ <tr>
12
+ <td><b><%%= <%= class_name %>.human_attribute_name(:name) %></b></td>
13
+ <td><%%=h <%= singular_name %>.name %></td>
14
+ </tr>
15
+ <tr>
16
+ <td><b><%%= <%= class_name %>.human_attribute_name(:email) %></b></td>
17
+ <td><%%=h <%= singular_name %>.email %></td>
18
+ </tr>
19
+ <tr>
20
+ <td><b><%%= <%= class_name %>.human_attribute_name(:created_at) %></b></td>
21
+ <td><%%=h <%= singular_name %>.created_at %></td>
22
+ </tr>
23
+ <% end -%>
24
+ <% for attribute in attributes -%>
25
+ <tr>
26
+ <td><b><%%= <%= class_name %>.human_attribute_name(:<%= attribute.name %>) %></b></td>
27
+ <td><%%=h <%= singular_name %>.<%= attribute.name %> %></td>
28
+ </tr>
29
+ <% end -%>
30
+ </tbody>
31
+ </table>
@@ -0,0 +1,24 @@
1
+ <div class="contextual">
2
+ <%%= link_to t('Update'), edit_admin_<%= singular_name %>_path(@<%= singular_name %>), :accesskey => "e", :class => "icon icon-edit", :onclick => "showAndScrollTo('update','focus'); return false;"%>
3
+ <%%= link_to t('Delete'), [:admin,@<%= singular_name %>], :confirm => 'Are you sure?', :method => :delete ,:class => 'icon icon-del' %>
4
+ </div>
5
+
6
+ <h2><%%= "#{<%= class_name %>.model_name.human} ##{@<%= singular_name %>.id}" %></h2>
7
+
8
+ <div class="issue details">
9
+ <%%= render :partial => 'show' , :locals => {:<%= singular_name %> => @<%= singular_name %>} %>
10
+ </div>
11
+
12
+ <!-- More List View -->
13
+
14
+ <div id="update">
15
+ <h3><%%= t('Update') %></h3>
16
+ <div id="focus"></div>
17
+ <%%= render :partial => 'edit' , :locals => {:<%= singular_name %> => @<%= singular_name %>} %>
18
+ </div>
19
+ <div style="clear: both;"></div>
20
+
21
+ <%% content_for :sidebar do %>
22
+ <h3>Actions</h3>
23
+ <%%= link_to "#{t('Back_to')} #{<%= class_name %>.model_name.human}", admin_<%= plural_name %>_path %>
24
+ <%% end %>
@@ -0,0 +1,27 @@
1
+ <div class="contextual"></div>
2
+
3
+ <h2><%%= <%= class_name %>.model_name.human %></h2>
4
+
5
+ <!-- Somatics Filters-->
6
+ <%%= somatics_filter_for :<%= singular_name %>%>
7
+
8
+ <%%# form_tag bulk_admin_<%= plural_name %>_path, :id => :form do -%>
9
+ <div class="autoscroll">
10
+ <%%= render :partial => 'list', :locals => {:<%= plural_name %> => @<%= plural_name %>} %>
11
+ </div>
12
+ <%%= will_paginate @<%= plural_name%>, :renderer => SomaticLinkRenderer %>
13
+
14
+ <%%#= render :partial => 'bulk' %>
15
+ <%%# end %>
16
+
17
+ <!-- TODO Export-->
18
+ <p class="other-formats"><%%= t('Also_available_in') %>:
19
+ <span><%%= link_to 'CSV', admin_<%= plural_name %>_path(:format => :csv), :class => 'csv' %></span>
20
+ <span><%%= link_to 'XLS', admin_<%= plural_name %>_path(:format => :xls), :class => 'xls' %></span>
21
+ </p>
22
+ <div style="clear:both;"></div>
23
+
24
+ <%% content_for :sidebar do %>
25
+ <h3>Actions</h3>
26
+ <%%= link_to "#{t('New')} #{<%= class_name %>.model_name.human}", new_admin_<%= singular_name %>_path %>
27
+ <%% end %>
@@ -0,0 +1,14 @@
1
+ <h2><%%= "#{t('New')} #{<%= class_name %>.model_name.human}" %></h2>
2
+ <%% form_for([:admin, @<%= singular_name %>]) do |f| %>
3
+ <%%= f.error_messages %>
4
+ <div class="issue">
5
+ <%%= render :partial => 'form' , :locals => {:f => f} %>
6
+ </div>
7
+ <%%= f.submit t('Create') %>
8
+ <%% end %>
9
+ <%%= link_to t('Back'), admin_<%= plural_name %>_path %>
10
+
11
+ <%% content_for :sidebar do %>
12
+ <h3>Actions</h3>
13
+ <%%= link_to "#{t('Back_to')} #{<%= class_name %>.model_name.human}", admin_<%= plural_name %>_path %>
14
+ <%% end %>
@@ -0,0 +1,26 @@
1
+ <div class="contextual">
2
+ <%%= link_to t('Update'), edit_admin_<%= singular_name %>_path(@<%= singular_name %>), :accesskey => "e", :class => "icon icon-edit", :onclick => "showAndScrollTo('update','focus'); return false;"%>
3
+ <%%= link_to t('Delete'), [:admin,@<%= singular_name %>], :confirm => 'Are you sure?', :method => :delete ,:class => 'icon icon-del' %>
4
+ </div>
5
+
6
+ <h2><%%= "#{<%= class_name %>.model_name.human} ##{@<%= singular_name %>.id}" %></h2>
7
+
8
+ <div class="issue details">
9
+ <%%= render :partial => 'show' , :locals => {:<%= singular_name %> => @<%= singular_name %>} %>
10
+ </div>
11
+
12
+ <!-- More List View -->
13
+
14
+ <% unless options[:skip_auditing] %><%%= paper_trail_for @<%= singular_name %> %><% end %>
15
+
16
+ <div id="update" style="display:none;">
17
+ <h3><%%= t('Update') %></h3>
18
+ <div id="focus"></div>
19
+ <%%= render :partial => 'edit' , :locals => {:<%= singular_name %> => @<%= singular_name %>} %>
20
+ </div>
21
+ <div style="clear: both;"></div>
22
+
23
+ <%% content_for :sidebar do %>
24
+ <h3>Actions</h3>
25
+ <%%= link_to "#{t('Back_to')} #{<%= class_name %>.model_name.human}", admin_<%= plural_name %>_path %>
26
+ <%% end %>
@@ -0,0 +1,86 @@
1
+ require 'generators/somatics'
2
+ require 'rails/generators/rails/resource/resource_generator'
3
+ require 'rails/generators/resource_helpers'
4
+ require 'rails/generators/migration'
5
+
6
+ module Somatics
7
+ module Generators
8
+ class SettingsGenerator < Rails::Generators::Base
9
+ include Rails::Generators::Migration
10
+
11
+ def generate_model
12
+ invoke "somatics:scaffold", ["settings" , "name:string", "field_type:string", "value:text", "category:string", "description:text", "mce_editable:boolean"], {:scaffold_controller => "settings_controller"}
13
+ end
14
+
15
+ def add_name_index
16
+ inject_into_file Dir.glob("db/migrate/[0-9]*_*.rb").last, :before => "end\n\n def self.down" do
17
+ "add_index :settings, :name, :unique => true\n"
18
+ end
19
+ end
20
+
21
+ def inject_model_validators
22
+ inject_into_class 'app/models/setting.rb', 'Setting' do
23
+ <<-RUBY
24
+ GENERAL = 'General'
25
+ CATEGORIES = [GENERAL]
26
+ FIELD_TYPES = ['integer', 'string', 'float', 'text', 'boolean']
27
+
28
+ attr_protected :name, :field_type, :description, :category, :mce_editable
29
+
30
+ validates_presence_of :name
31
+ validates_uniqueness_of :name
32
+ validates_presence_of :field_type
33
+ validates_inclusion_of :field_type, :in => FIELD_TYPES
34
+ validates_presence_of :category
35
+ validates_inclusion_of :category, :in => CATEGORIES
36
+ validates_presence_of :value, :allow_blank => true
37
+ validates_numericality_of :value, :if => Proc.new {|setting| ['integer', 'float'].include?(setting.field_type) }
38
+
39
+ def self.[](name)
40
+ raise SettingNotFound unless setting = Setting.find_by_name(name)
41
+ setting.parsed_value
42
+ end
43
+
44
+ def self.[]=(name, value)
45
+ raise SettingNotFound unless setting = Setting.find_by_name(name)
46
+ setting.update_attribute(:value, value)
47
+ end
48
+
49
+ def parsed_value
50
+ case self.field_type
51
+ when 'integer'
52
+ self.value.to_i
53
+ when 'float'
54
+ self.value.to_f
55
+ when 'boolean'
56
+ self.value == '1'
57
+ else
58
+ self.value
59
+ end
60
+ end
61
+
62
+ def input_field(form)
63
+ options = {}
64
+ input_field_type = case self.field_type
65
+ when 'integer', 'string', 'float'
66
+ 'text_field'
67
+ when 'text'
68
+ options[:class] = 'mceEditor'
69
+ 'text_area'
70
+ when 'boolean'
71
+ 'check_box'
72
+ else
73
+ 'text_field'
74
+ end
75
+ form.send(input_field_type, :value, options)
76
+ end
77
+
78
+ class SettingNotFound < Exception; end
79
+
80
+ RUBY
81
+ end rescue nil
82
+
83
+ end
84
+ end
85
+ end
86
+ end