localized_scaffold 0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/Gemfile +6 -0
  2. data/README.rdoc +273 -0
  3. data/generators/locales/standard.de-FO.yml +106 -0
  4. data/generators/locales/standard.de.yml +106 -0
  5. data/generators/locales/standard.en.yml +106 -0
  6. data/generators/localized_devise_views_generator.rb +100 -0
  7. data/generators/localized_scaffold_generator.rb +624 -0
  8. data/generators/templates/devise/locales/devise.de-FO.yml +45 -0
  9. data/generators/templates/devise/locales/devise.de.yml +60 -0
  10. data/generators/templates/devise/locales/devise_views.de.yml +78 -0
  11. data/generators/templates/devise/locales/devise_views.en.yml +79 -0
  12. data/generators/templates/devise/views/confirmations/new.html.erb +23 -0
  13. data/generators/templates/devise/views/mailer/confirmation_instructions.html.erb +6 -0
  14. data/generators/templates/devise/views/mailer/reset_password_instructions.html.erb +8 -0
  15. data/generators/templates/devise/views/mailer/unlock_instructions.html.erb +6 -0
  16. data/generators/templates/devise/views/passwords/edit.html.erb +30 -0
  17. data/generators/templates/devise/views/passwords/new.html.erb +23 -0
  18. data/generators/templates/devise/views/registrations/edit.html.erb +54 -0
  19. data/generators/templates/devise/views/registrations/new.html.erb +34 -0
  20. data/generators/templates/devise/views/sessions/new.html.erb +32 -0
  21. data/generators/templates/devise/views/shared/_links.erb +25 -0
  22. data/generators/templates/devise/views/unlocks/new.html.erb +23 -0
  23. data/generators/templates/erb/scaffold/_form.html.erb +11 -0
  24. data/generators/templates/erb/scaffold/_index.html.erb +54 -0
  25. data/generators/templates/erb/scaffold/edit.html.erb +20 -0
  26. data/generators/templates/erb/scaffold/index.html.erb +73 -0
  27. data/generators/templates/erb/scaffold/layout.html.erb +51 -0
  28. data/generators/templates/erb/scaffold/new.html.erb +18 -0
  29. data/generators/templates/erb/scaffold/scaffold_generator.rb +57 -0
  30. data/generators/templates/erb/scaffold/show.html.erb +22 -0
  31. data/generators/templates/locales/de.yml +61 -0
  32. data/generators/templates/locales/en.yml +61 -0
  33. data/generators/templates/rails/helper/helper.rb +118 -0
  34. data/generators/templates/rails/helper/scaffold_helper.rb +53 -0
  35. data/generators/templates/rails/scaffold_controller/controller.rb +338 -0
  36. data/generators/templates/rails/stylesheets/templates/scaffold.css +203 -0
  37. data/generators/templates/test_unit/scaffold/templates/functional_test.rb +117 -0
  38. data/init.rb +3 -0
  39. data/install.rb +1 -0
  40. data/lib/tasks/localized_scaffold.rake +39 -0
  41. data/localized_scaffold.rb +7 -0
  42. data/rails/init.rb +3 -0
  43. data/test/localized_scaffold_test.rb +8 -0
  44. data/test/test_helper.rb +3 -0
  45. data/uninstall.rb +1 -0
  46. metadata +120 -0
@@ -0,0 +1,51 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+
3
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" lang="<%%= I18n.locale
7
+ -%>" xml:lang="<%%= I18n.locale -%>">
8
+ <head>
9
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
10
+
11
+ <%%- if (title = yield(:title)).blank? -%>
12
+ <title><%%= controller.controller_name.humanize %></title>
13
+ <%%- else -%>
14
+ <title><%%= title %></title>
15
+ <%%- end -%>
16
+
17
+ <%%= stylesheet_link_tag 'scaffold' %>
18
+
19
+ <%- if has_javascript_jquery? -%>
20
+ <%%= javascript_include_tag 'jquery', 'application' %>
21
+ <% elsif has_javascript_prototype? -%>
22
+ <%%= javascript_include_tag :defaults %>
23
+ <% end -%>
24
+
25
+ <%%= csrf_meta_tag %>
26
+
27
+ <%%= yield :head -%>
28
+ </head>
29
+ <body>
30
+
31
+ <%%- if not (breadcrumbs = yield(:breadcrumbs)).blank? -%>
32
+ <%%= breadcrumbs %>
33
+ <%%- end -%>
34
+
35
+ <div id="flashMessages">
36
+ <%%= ActiveSupport::SafeBuffer.new([:notice, :warning, :error].collect do |type|
37
+ content_tag(:div, flash[type], :id => type, :class => type) if flash[type]
38
+ end.to_s) %>
39
+ </div>
40
+
41
+ <%%- unless title.blank? -%>
42
+ <h1><%%= title %></h1>
43
+ <%%- end -%>
44
+
45
+ <%%= yield %>
46
+ <%- if has_javascript_jquery? or has_javascript_prototype? -%>
47
+
48
+ <%%= yield :patches -%>
49
+ <%- end -%>
50
+ </body>
51
+ </html>
@@ -0,0 +1,18 @@
1
+ <%% title(t('<%= file_name %>.new.title'), <%= file_name %>_breadcrumbs) %>
2
+
3
+ <%%= form_for(@<%= singular_name %>, :url => <%= path_of_with_belongsto_if_any(:value1 => "@#{singular_name}") %>,
4
+ :html => { :multipart => true }) do |f| %>
5
+ <%%= f.error_messages :header_message => t('<%= file_name %>.errors.template.header_message'),
6
+ :message => t('<%= file_name %>.errors.template.message') %>
7
+
8
+ <%%= render :partial => 'form', :locals => { :f => f } %>
9
+
10
+ <p>
11
+ <%%= f.submit t('standard.cmds.create') %>
12
+
13
+ <span class="decent">
14
+ <%%= t('standard.labels.or') %>
15
+ <%%= link_to t('standard.cmds.cancel'), <%= path_of_with_belongsto_if_any %> %>
16
+ </span>
17
+ </p>
18
+ <%% end %>
@@ -0,0 +1,57 @@
1
+ require 'rails/generators/erb'
2
+ require 'rails/generators/resource_helpers'
3
+ require 'rails/generators/erb/scaffold/scaffold_generator'
4
+
5
+ module Erb
6
+ module Generators
7
+ class ScaffoldGenerator < Base
8
+ def self.generator_path(filename = '')
9
+ return File.join(File.expand_path(File.dirname(__FILE__)), filename)
10
+ end
11
+
12
+ include Rails::Generators::ResourceHelpers
13
+
14
+ argument :attributes, :type => :array, :default => [], :banner => 'field:type field:type'
15
+
16
+ class_option :layout, :type => :boolean
17
+ class_option :singleton, :type => :boolean, :desc => 'Supply to skip index view'
18
+
19
+ # Creates the views directory.
20
+
21
+ def create_root_folder
22
+ empty_directory File.join('app', 'views', controller_file_path)
23
+ end
24
+
25
+ # Generates all views in the views directory.
26
+
27
+ def copy_view_files
28
+ views = available_views
29
+ views.delete('index') if options[:singleton]
30
+ views.delete('_index') if not embed?
31
+ views.delete('show') if not generate_showview?
32
+
33
+ views.each do |view|
34
+ filename = filename_with_extensions(view)
35
+
36
+ template ScaffoldGenerator.generator_path(filename),
37
+ File.join('app', 'views', controller_file_path, filename)
38
+ end
39
+ end
40
+
41
+ # Forces a copy of the layout file.
42
+
43
+ def force_copy_layout_file
44
+ template ScaffoldGenerator.generator_path(filename_with_extensions(:layout)),
45
+ File.join('app', 'views', 'layouts', filename_with_extensions('scaffold'))
46
+ end
47
+
48
+ protected
49
+
50
+ # Returns the views to generate.
51
+
52
+ def available_views
53
+ %w(index edit show new _form _index)
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,22 @@
1
+ <%% title(@<%= file_name %>.to_s, <%= file_name %>_breadcrumbs) %>
2
+
3
+ <% for attribute in attributes -%>
4
+ <p>
5
+ <b><%%= t('activerecord.attributes.<%= file_name %>.<%= attribute.name %>') %>:</b>
6
+ <%- if listifies.include? attribute.name -%>
7
+ <%%= <%= class_name %>.<%= attribute.name %>_label(@<%= singular_name %>.<%= attribute.name %>) %>
8
+ <%- else -%>
9
+ <%%=h @<%= singular_name %>.<%= attribute.name %> %>
10
+ <%- end -%>
11
+ </p>
12
+
13
+ <%- end -%>
14
+
15
+ <p>
16
+ <%%= link_to t('standard.cmds.back'), <%= path_of_with_belongsto_if_any(:extraargs => (has_searchbar? ? ":q => @#{file_name}.#{searchbar}.first" : nil)) %> %>
17
+
18
+ <span class="decent">
19
+ <%%= t('standard.labels.or') %>
20
+ <%%= link_to t('standard.cmds.edit'), <%= path_of_with_belongsto_if_any(:method => :edit) %> %>
21
+ </span>
22
+ </p>
@@ -0,0 +1,61 @@
1
+ de:
2
+ activerecord:
3
+ models:
4
+ <%= file_name %>: "<%= class_name %>"
5
+
6
+ attributes:
7
+ <%= file_name %>:
8
+ <%- attributes.each do |a| -%>
9
+ <%= a.name %>: "<%= a.name.humanize %>"
10
+ <%- end -%>
11
+
12
+ <%= file_name %>:
13
+ cmds:
14
+ breadcrumb: "<%= plural_name.humanize %>"
15
+ list: "<%= plural_name.humanize %> anzeigen"
16
+ new: "<%= class_name %> anlegen"
17
+
18
+ <%- if not listifies.empty? -%>
19
+ selects:
20
+ <%- listifies.each do |field, values| -%>
21
+ <%= field %>:
22
+ <%- values.each do |value| -%>
23
+ <%= value.downcase %>: "<%= value.humanize %>"
24
+ <%- end -%>
25
+
26
+ <%- end -%>
27
+ <%- end -%>
28
+ errors:
29
+ template:
30
+ header_message: "<%= singular_name.humanize %> konnte nicht gespeichert werden."
31
+ message: "Bitte folgende Felder überprüfen:"
32
+
33
+ not_found: "<%= class_name %> nicht gefunden."
34
+
35
+ create:
36
+ flash: "<%= class_name %> erfolgreich angelegt."
37
+
38
+ destroy:
39
+ flash: "<%= class_name %> erfolgreich gelöscht."
40
+
41
+ edit:
42
+ title: "<%= class_name %> bearbeiten"
43
+ <% unless options[:singleton] %>
44
+ index:
45
+ <%- if has_belongsto? -%>
46
+ title: "<%= plural_name.humanize %> von <%= belongsto.singular_name.humanize %> {{parent}}"
47
+ <%- else -%>
48
+ title: "<%= plural_name.humanize %>"
49
+ <%- end -%>
50
+ <%- end -%>
51
+ <%- if embed? %>
52
+ indexpartial:
53
+ title: "<%= plural_name.humanize %>"
54
+ empty: "Bisher keine <%= plural_name.humanize %>"
55
+ <%- end -%>
56
+
57
+ new:
58
+ title: "<%= class_name %> anlegen"
59
+
60
+ update:
61
+ flash: "<%= class_name %> erfolgreich gespeichert."
@@ -0,0 +1,61 @@
1
+ en:
2
+ activerecord:
3
+ models:
4
+ <%= file_name %>: "<%= class_name %>"
5
+
6
+ attributes:
7
+ <%= file_name %>:
8
+ <%- attributes.each do |a| -%>
9
+ <%= a.name %>: "<%= a.name.humanize %>"
10
+ <%- end -%>
11
+
12
+ <%= file_name %>:
13
+ cmds:
14
+ breadcrumb: "<%= plural_name.humanize %>"
15
+ list: "List <%= plural_name %>"
16
+ new: "New <%= singular_name %>"
17
+
18
+ <%- if not listifies.empty? -%>
19
+ selects:
20
+ <%- listifies.each do |field, values| -%>
21
+ <%= field %>:
22
+ <%- values.each do |value| -%>
23
+ <%= value.downcase %>: "<%= value.humanize %>"
24
+ <%- end -%>
25
+
26
+ <%- end -%>
27
+ <%- end -%>
28
+ errors:
29
+ template:
30
+ header_message: "<%= singular_name.humanize %> could not be saved."
31
+ message: "Please check the following fields:"
32
+
33
+ not_found: "<%= class_name %> not found."
34
+
35
+ create:
36
+ flash: "<%= class_name %> was successfully created."
37
+
38
+ destroy:
39
+ flash: "<%= class_name %> was successfully deleted."
40
+
41
+ edit:
42
+ title: "Editing <%= singular_name %>"
43
+ <% unless options[:singleton] %>
44
+ index:
45
+ <%- if has_belongsto? -%>
46
+ title: "<%= plural_name.humanize %> of <%= belongsto.singular_name %> {{parent}}"
47
+ <%- else -%>
48
+ title: "<%= plural_name.humanize %>"
49
+ <%- end -%>
50
+ <%- end -%>
51
+ <%- if embed? %>
52
+ indexpartial:
53
+ title: "<%= plural_name.humanize %>"
54
+ empty: "No <%= plural_name %> so far"
55
+ <%- end -%>
56
+
57
+ new:
58
+ title: "New <%= singular_name %>"
59
+
60
+ update:
61
+ flash: "<%= class_name %> was successfully updated."
@@ -0,0 +1,118 @@
1
+ # The code in this file implements helper class <%= class_name %>Helper.
2
+
3
+ # Class <%= class_name %>Helper provides helpers available in all views of
4
+ # the <%= class_name %>Controller.
5
+
6
+ module <%= class_name %>Helper
7
+
8
+ # Returns a breadcrumbs for the current object (if any).
9
+
10
+ def <%= shell.base.file_name %>_breadcrumbs
11
+ <%- if shell.base.has_belongsto? -%>
12
+ breadcrumbs = [[root_path, t('standard.cmds.home')],
13
+ [<%= shell.base.belongsto.plural_name %>_path, t('<%= shell.base.belongsto.file_name %>.cmds.breadcrumb')],
14
+ [<%= shell.base.belongsto.file_name %>_path(@<%= shell.base.belongsto.file_name %>), @<%= shell.base.belongsto.file_name %>.to_s]]
15
+
16
+ if defined? @<%= shell.base.file_name %> and not @<%= shell.base.file_name %>.blank?
17
+ <%- if shell.base.embed? -%>
18
+ if @<%= shell.base.file_name %>.<%= shell.base.belongsto.file_name %>.<%= shell.base.table_name %>.count > <%= shell.base.class_name %>::PARENT_EMBED
19
+ breadcrumbs << [<%= shell.base.path_of_with_belongsto_if_any %>, t('<%= shell.base.file_name %>.cmds.breadcrumb')]
20
+ end
21
+
22
+ <%- else -%>
23
+ breadcrumbs << [<%= shell.base.path_of_with_belongsto_if_any %>, t('<%= shell.base.file_name %>.cmds.breadcrumb')]
24
+ <%- end -%>
25
+ breadcrumbs << @<%= shell.base.file_name %>.to_s if not @<%= shell.base.file_name %>.new_record?
26
+ else
27
+ breadcrumbs << t('<%= shell.base.file_name %>.cmds.breadcrumb')
28
+ end
29
+ <%- else -%>
30
+ breadcrumbs = [[root_path, t('standard.cmds.home')]]
31
+
32
+ if defined? @<%= shell.base.file_name %> and not @<%= shell.base.file_name %>.blank?
33
+ breadcrumbs << [<%= shell.base.path_of_with_belongsto_if_any %>, t('<%= shell.base.file_name %>.cmds.breadcrumb')]
34
+ breadcrumbs << @<%= shell.base.file_name %>.to_s if not @<%= shell.base.file_name %>.new_record?
35
+ else
36
+ breadcrumbs << t('<%= shell.base.file_name %>.cmds.breadcrumb')
37
+ end
38
+ <%- end -%>
39
+
40
+ return breadcrumbs
41
+ end
42
+
43
+ <%- if shell.base.has_will_paginate? -%>
44
+
45
+ # Returns an interface for pagination using the will_paginate library.
46
+ #
47
+ # Parameters:
48
+ #
49
+ # [collection] Collection to paginate with
50
+ # [options] Options to customize pager with plus own :delimiter option
51
+
52
+ def <%= shell.base.file_name %>_pagination(collection, options = {})
53
+ delimiter = options.delete(:delimiter) || '|'
54
+
55
+ if collection.total_pages > 1
56
+ pager = will_paginate(collection, { :inner_window => 10,
57
+ :next_label => t('standard.cmds.next_page'),
58
+ :previous_label => t('standard.cmds.previous_page') }.merge(options))
59
+
60
+ return (pager + ' ' + delimiter) if not pager.blank?
61
+ end
62
+
63
+ return ''
64
+ end
65
+ <%- end -%>
66
+ <%- if shell.base.has_searchbar? -%>
67
+
68
+ # Returns HTML for a searchbar with an A B C picker and a small form for
69
+ # searching a <%= shell.base.searchbar %>.
70
+ #
71
+ # Parameters:
72
+ #
73
+ # [chars] Array with chars the <%= shell.base.searchbar %> of existing <%= plural_name %> start with
74
+ # [term] Search term to render with
75
+ # [:options] Options to customize
76
+ #
77
+ # Options:
78
+ #
79
+ # [:type] What to render (:abc, :form or :both)
80
+ # [:default] Default search term to show in input field (localized value)
81
+ # [:size] Size of input field (defaults to 12)
82
+
83
+ def <%= shell.base.file_name %>_searchbar(chars, term, options = {})
84
+ type = options[:type] || 'both'
85
+ default = options[:default] || t('standard.cmds.search')
86
+ size = options[:size] || 12
87
+
88
+ if type == :form
89
+ cols = []
90
+ else
91
+ cols = ('a'..'z').collect do |c|
92
+ if (same = ((not term.blank?) and c.upcase == term.upcase))
93
+ inner = content_tag(:strong, c.upcase)
94
+ elsif chars.include? c
95
+ inner = link_to(c.upcase, <%= shell.base.path_of_with_belongsto_if_any(:extraargs => ':q => c') %>)
96
+ else
97
+ inner = c.upcase
98
+ end
99
+
100
+ content_tag(:td, inner, :class => (same ? 'selected' : nil))
101
+ end
102
+ end
103
+
104
+ if type != :abc
105
+ value = (term.blank? or term.length > 1) ? term : default
106
+ form = content_tag(:form, tag(:input, :type => :text,
107
+ :id => 'searchbar-term', :name => 'q', :size => size,
108
+ :value => value), :method => 'get', :id => 'searchbar-form',
109
+ :action => <%= shell.base.path_of_with_belongsto_if_any %>)
110
+
111
+ cols << content_tag(:td, form)
112
+ end
113
+
114
+ return content_tag(:table, content_tag(:tr,
115
+ ActiveSupport::SafeBuffer.new(cols.join)), :class => 'searchbar')
116
+ end
117
+ <%- end -%>
118
+ end
@@ -0,0 +1,53 @@
1
+ # The code in this file implements helper class ScaffoldHelper.
2
+
3
+ # Class ScaffoldHelper provides helpers available in all views and controllers
4
+ # using localized scaffolding.
5
+
6
+ module ScaffoldHelper
7
+
8
+ # Sets the title and headline to display (actually done in the layout file)
9
+ # and optional breadcrumbs. The latter has to be an array of arrays with
10
+ # path and label or label if not linkable.
11
+ #
12
+ # Parameters:
13
+ #
14
+ # [title] Title to set
15
+ # [breadcrumbs] Optional breadcrumbs to set
16
+
17
+ def title(title, breadcrumbs = nil)
18
+ content_for(:title) { title }
19
+
20
+ if not breadcrumbs.blank?
21
+ content_for(:breadcrumbs) {
22
+ cols = breadcrumbs.collect do |b|
23
+ if b.kind_of? Array then
24
+ content_tag(:li, link_to(b.last, b.first))
25
+ else
26
+ content_tag(:li, b, :class => 'decent')
27
+ end
28
+ end
29
+
30
+ content_tag(:ul, ActiveSupport::SafeBuffer.new(cols.join),
31
+ :id => 'breadcrumbs')
32
+ }
33
+ end
34
+ end
35
+
36
+ if not defined? root_path
37
+
38
+ # Returns a default root path if no other route has been defined so far.
39
+
40
+ def root_path
41
+ return url_for('/')
42
+ end
43
+ end
44
+
45
+ if not defined? root_path
46
+
47
+ # Returns a default root URL if no other route has been defined so far.
48
+
49
+ def root_url
50
+ return url_for('/')
51
+ end
52
+ end
53
+ end