i18n-generators 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/Gemfile +3 -0
- data/History.txt +143 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +74 -0
- data/Rakefile +2 -0
- data/generators/i18n/USAGE +11 -0
- data/generators/i18n/i18n_generator.rb +88 -0
- data/generators/i18n/lib/yaml.rb +187 -0
- data/generators/i18n/templates/base.yml +0 -0
- data/generators/i18n/templates/i18n_config.rb +4 -0
- data/generators/i18n/templates/translation.yml +1 -0
- data/generators/i18n_locale/USAGE +10 -0
- data/generators/i18n_locale/i18n_locale_command.rb +141 -0
- data/generators/i18n_locale/i18n_locale_generator.rb +8 -0
- data/generators/i18n_locale/lib/cldr.rb +138 -0
- data/generators/i18n_scaffold/i18n_scaffold_generator.rb +2 -0
- data/generators/i18n_scaffold/templates/controller.rb +85 -0
- data/generators/i18n_scaffold/templates/functional_test.rb +45 -0
- data/generators/i18n_scaffold/templates/helper.rb +2 -0
- data/generators/i18n_scaffold/templates/helper_test.rb +4 -0
- data/generators/i18n_scaffold/templates/layout.html.erb +17 -0
- data/generators/i18n_scaffold/templates/style.css +54 -0
- data/generators/i18n_scaffold/templates/view_edit.html.erb +18 -0
- data/generators/i18n_scaffold/templates/view_index.html.erb +24 -0
- data/generators/i18n_scaffold/templates/view_new.html.erb +17 -0
- data/generators/i18n_scaffold/templates/view_show.html.erb +10 -0
- data/generators/i18n_translation/USAGE +8 -0
- data/generators/i18n_translation/i18n_translation_command.rb +124 -0
- data/generators/i18n_translation/i18n_translation_generator.rb +8 -0
- data/generators/i18n_translation/lib/erb_executer.rb +30 -0
- data/generators/i18n_translation/lib/recording_backend.rb +15 -0
- data/generators/i18n_translation/lib/through_ryoku.rb +7 -0
- data/generators/i18n_translation/lib/translator.rb +27 -0
- data/i18n-generators.gemspec +26 -0
- data/lib/generators/i18n/all/USAGE +12 -0
- data/lib/generators/i18n/all/i18n_generator.rb +19 -0
- data/lib/generators/i18n/locale/USAGE +10 -0
- data/lib/generators/i18n/locale/locale_generator.rb +49 -0
- data/lib/generators/i18n/translation/USAGE +8 -0
- data/lib/generators/i18n/translation/lib/translator.rb +59 -0
- data/lib/generators/i18n/translation/lib/yaml.rb +137 -0
- data/lib/generators/i18n/translation/lib/yaml_waml.rb +35 -0
- data/lib/generators/i18n/translation/translation_generator.rb +108 -0
- data/lib/i18n_generators/version.rb +3 -0
- data/spec/cldr_spec.rb +54 -0
- data/spec/data/cldr/ja.html +3112 -0
- data/spec/data/yml/active_record/en-US.yml +54 -0
- data/spec/i18n_locale_command_spec.rb +63 -0
- data/spec/i18n_translation_command_spec.rb +24 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/translator_spec.rb +46 -0
- data/spec/yaml_spec.rb +123 -0
- metadata +122 -0
@@ -0,0 +1,141 @@
|
|
1
|
+
require 'net/https'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rails_generator'
|
4
|
+
require 'rails_generator/commands'
|
5
|
+
gem 'gettext', '<2'
|
6
|
+
require 'gettext'
|
7
|
+
require File.join(File.dirname(__FILE__), '../i18n/lib/yaml')
|
8
|
+
require File.join(File.dirname(__FILE__), 'lib/cldr')
|
9
|
+
include I18nLocaleGeneratorModule
|
10
|
+
|
11
|
+
module I18nGenerator::Generator
|
12
|
+
module Commands #:nodoc:
|
13
|
+
module Create
|
14
|
+
def generate_configuration
|
15
|
+
return if I18n.default_locale == locale_name
|
16
|
+
if Rails.configuration.respond_to? :i18n # >= 2.2.2
|
17
|
+
# edit environment.rb file
|
18
|
+
environment = add_locale_config File.read(File.join(Rails.root, 'config/environment.rb'))
|
19
|
+
File.open File.join(Rails.root, 'config/environment.rb'), 'w' do |f|
|
20
|
+
f.puts environment
|
21
|
+
end
|
22
|
+
puts " update config/environment.rb"
|
23
|
+
else
|
24
|
+
template 'i18n:i18n_config.rb', 'config/initializers/i18n_config.rb', :assigns => {:locale_name => locale_name}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def fetch_from_rails_i18n_repository
|
29
|
+
file('i18n:base.yml', "config/locales/#{locale_name}.yml") do |f|
|
30
|
+
uri = URI.parse "https://github.com/svenfuchs/rails-i18n/raw/master/rails/locale/#{locale_name}.yml"
|
31
|
+
http = Net::HTTP.new uri.host, uri.port
|
32
|
+
http.use_ssl = true
|
33
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
34
|
+
req = Net::HTTP::Get.new uri.request_uri
|
35
|
+
res = http.request req
|
36
|
+
res.body
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def active_support_yaml
|
41
|
+
open_yaml('active_support') do |yaml|
|
42
|
+
yaml[locale_name].descendant_nodes do |node|
|
43
|
+
v = cldr.lookup(node.path)
|
44
|
+
node.value = v if !v.nil? && !(v.is_a?(Array) && v.any? {|e| e.nil?})
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def active_record_yaml
|
50
|
+
open_yaml('active_record') do |yaml|
|
51
|
+
yaml[locale_name]['activerecord']['errors']['messages'].children.each do |node|
|
52
|
+
unless node.value.nil?
|
53
|
+
node.value = transfer_format('%{fn} ' + node.value.gsub('{{count}}', '%d')) do |v|
|
54
|
+
GetText._(v)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def action_view_yaml
|
62
|
+
open_yaml('action_view') do |yaml|
|
63
|
+
yaml[locale_name]['datetime']['distance_in_words'].children.each do |node|
|
64
|
+
if !node.value.nil?
|
65
|
+
node.value = GetText._(node.value)
|
66
|
+
elsif ((children = node.children).size == 2) && (children.map(&:key) == %w[one other])
|
67
|
+
children['one'].value, children['other'].value = translate_one_and_other(children.map(&:value))
|
68
|
+
end
|
69
|
+
end
|
70
|
+
yaml[locale_name]['activerecord']['errors']['template'].children.each do |node|
|
71
|
+
if !node.value.nil?
|
72
|
+
node.value = if node.value == 'There were problems with the following fields:'
|
73
|
+
GetText.n_('There was a problem with the following field:', node.value, 2)
|
74
|
+
else
|
75
|
+
GetText._(node.value)
|
76
|
+
end
|
77
|
+
elsif ((children = node.children).size == 2) && (children.map(&:key) == %w[one other])
|
78
|
+
children['one'].value, children['other'].value = if children['one'].value == '1 error prohibited this {{model}} from being saved'
|
79
|
+
translate_one_and_other(['%{num} error prohibited this {{model}} from being saved', children['other']])
|
80
|
+
else
|
81
|
+
translate_one_and_other(children.map(&:value))
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
yaml[locale_name]['number'].descendant_nodes do |node|
|
86
|
+
v = cldr.lookup(node.path)
|
87
|
+
node.value = v if !v.nil? && !(v.is_a?(Array) && v.any? {|e| e.nil?})
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
def add_locale_config(environment_contents)
|
94
|
+
(arr = environment_contents.split("\n")).each_with_index do |l, i|
|
95
|
+
if l =~ /^\s*config\.i18n\.default_locale = /
|
96
|
+
arr[i] = " config.i18n.default_locale = '#{locale_name}'"
|
97
|
+
return arr.join("\n")
|
98
|
+
end
|
99
|
+
end
|
100
|
+
arr.each_with_index do |l, i|
|
101
|
+
if l =~ /^\s*#?\s*config\.i18n\.default_locale = /
|
102
|
+
arr[i] = " config.i18n.default_locale = '#{locale_name}'"
|
103
|
+
return arr.join("\n")
|
104
|
+
end
|
105
|
+
end
|
106
|
+
arr.each_with_index do |l, i|
|
107
|
+
if l =~ /Rails::Initializer\.run do \|config\|/
|
108
|
+
arr[i] = "Rails::Initializer.run do |config|\n config.i18n.default_locale = '#{locale_name}'"
|
109
|
+
return arr.join("\n")
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end_row = RUBY_VERSION >= '1.8.7' ? arr.rindex {|l| l =~ /^\s*end\s*/} : arr.size - 1
|
113
|
+
((arr[0...end_row] << " config.i18n.default_locale = '#{locale_name}'") + arr[end_row..-1]).join("\n")
|
114
|
+
end
|
115
|
+
|
116
|
+
def open_yaml(filename_base)
|
117
|
+
original_yml = I18n.load_path.detect {|lp| lp =~ /\/lib\/#{filename_base}\/locale\/(en|en-US)\.yml$/}
|
118
|
+
doc = YamlDocument.new(original_yml, locale_name)
|
119
|
+
yield doc
|
120
|
+
file('i18n:base.yml', "config/locales/#{filename_base}_#{locale_name}.yml") do |f|
|
121
|
+
doc.to_s
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def transfer_format(args)
|
126
|
+
vals = if args.is_a?(Array)
|
127
|
+
args.map {|v| v.gsub('{{count}}', '%d').gsub('{{model}}', '%{record}')}
|
128
|
+
else
|
129
|
+
args.gsub('{{count}}', '%d').gsub('{{model}}', '%{record}')
|
130
|
+
end
|
131
|
+
result = yield vals
|
132
|
+
result.gsub(/^%\{fn\}/, '').gsub('%d', '{{count}}').gsub('%{record}', '{{model}}').gsub('%{num}', '{{count}}').strip
|
133
|
+
end
|
134
|
+
|
135
|
+
def translate_one_and_other(values)
|
136
|
+
values = values.map {|v| v.is_a?(Node) ? v.value : v}
|
137
|
+
[transfer_format(values) {|v| GetText.n_(v.first, v.second, 1)}, transfer_format(values) {|v| GetText.n_(v.first, v.second, 2)}]
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$KCODE = 'U'
|
3
|
+
|
4
|
+
require 'open-uri'
|
5
|
+
|
6
|
+
module I18nLocaleGeneratorModule
|
7
|
+
class CldrDocument
|
8
|
+
extend ActiveSupport::Memoizable
|
9
|
+
|
10
|
+
def initialize(locale_name)
|
11
|
+
@locale_name = locale_name
|
12
|
+
end
|
13
|
+
|
14
|
+
def lookup(path)
|
15
|
+
case path.sub(/^\/#{@locale_name}\//, '')
|
16
|
+
when 'date/formats/default'
|
17
|
+
convert_date_pattern search('calendar-gregorian', 'pattern', 'date-medium')
|
18
|
+
when 'date/formats/short'
|
19
|
+
convert_date_pattern search('calendar-gregorian', 'pattern', 'date-short')
|
20
|
+
when 'date/formats/long'
|
21
|
+
convert_date_pattern search('calendar-gregorian', 'pattern', 'date-full')
|
22
|
+
when 'date/day_names'
|
23
|
+
[search('calendar-gregorian', 'day', 'sunday:format-wide'),
|
24
|
+
search('calendar-gregorian', 'day', 'monday:format-wide'),
|
25
|
+
search('calendar-gregorian', 'day', 'tuesday:format-wide'),
|
26
|
+
search('calendar-gregorian', 'day', 'wednesday:format-wide'),
|
27
|
+
search('calendar-gregorian', 'day', 'thursday:format-wide'),
|
28
|
+
search('calendar-gregorian', 'day', 'friday:format-wide'),
|
29
|
+
search('calendar-gregorian', 'day', 'saturday:format-wide')]
|
30
|
+
when 'date/abbr_day_names'
|
31
|
+
[search('calendar-gregorian', 'day', 'sunday:format-abbreviated'),
|
32
|
+
search('calendar-gregorian', 'day', 'monday:format-abbreviated'),
|
33
|
+
search('calendar-gregorian', 'day', 'tuesday:format-abbreviated'),
|
34
|
+
search('calendar-gregorian', 'day', 'wednesday:format-abbreviated'),
|
35
|
+
search('calendar-gregorian', 'day', 'thursday:format-abbreviated'),
|
36
|
+
search('calendar-gregorian', 'day', 'friday:format-abbreviated'),
|
37
|
+
search('calendar-gregorian', 'day', 'saturday:format-abbreviated')]
|
38
|
+
when 'date/month_names'
|
39
|
+
['~',
|
40
|
+
search('calendar-gregorian', 'month', '[01]-format-wide'),
|
41
|
+
search('calendar-gregorian', 'month', '[02]-format-wide'),
|
42
|
+
search('calendar-gregorian', 'month', '[03]-format-wide'),
|
43
|
+
search('calendar-gregorian', 'month', '[04]-format-wide'),
|
44
|
+
search('calendar-gregorian', 'month', '[05]-format-wide'),
|
45
|
+
search('calendar-gregorian', 'month', '[06]-format-wide'),
|
46
|
+
search('calendar-gregorian', 'month', '[07]-format-wide'),
|
47
|
+
search('calendar-gregorian', 'month', '[08]-format-wide'),
|
48
|
+
search('calendar-gregorian', 'month', '[09]-format-wide'),
|
49
|
+
search('calendar-gregorian', 'month', '[10]-format-wide'),
|
50
|
+
search('calendar-gregorian', 'month', '[11]-format-wide'),
|
51
|
+
search('calendar-gregorian', 'month', '[12]-format-wide')]
|
52
|
+
when 'date/abbr_month_names'
|
53
|
+
['~',
|
54
|
+
search('calendar-gregorian', 'month', '[01]-format-abbreviated'),
|
55
|
+
search('calendar-gregorian', 'month', '[02]-format-abbreviated'),
|
56
|
+
search('calendar-gregorian', 'month', '[03]-format-abbreviated'),
|
57
|
+
search('calendar-gregorian', 'month', '[04]-format-abbreviated'),
|
58
|
+
search('calendar-gregorian', 'month', '[05]-format-abbreviated'),
|
59
|
+
search('calendar-gregorian', 'month', '[06]-format-abbreviated'),
|
60
|
+
search('calendar-gregorian', 'month', '[07]-format-abbreviated'),
|
61
|
+
search('calendar-gregorian', 'month', '[08]-format-abbreviated'),
|
62
|
+
search('calendar-gregorian', 'month', '[09]-format-abbreviated'),
|
63
|
+
search('calendar-gregorian', 'month', '[10]-format-abbreviated'),
|
64
|
+
search('calendar-gregorian', 'month', '[11]-format-abbreviated'),
|
65
|
+
search('calendar-gregorian', 'month', '[12]-format-abbreviated')]
|
66
|
+
# when 'date/order'
|
67
|
+
when 'time/formats/default'
|
68
|
+
format = search('calendar-gregorian', 'pattern', 'date+time')
|
69
|
+
date = convert_date_pattern search('calendar-gregorian', 'pattern', 'date-medium')
|
70
|
+
time = convert_date_pattern search('calendar-gregorian', 'pattern', 'time-medium')
|
71
|
+
(format.nil? || date.nil? || time.nil?) ? nil : format.sub('{0}', time).sub('{1}', date)
|
72
|
+
when 'time/formats/short'
|
73
|
+
format = search('calendar-gregorian', 'pattern', 'date+time')
|
74
|
+
date = convert_date_pattern search('calendar-gregorian', 'pattern', 'date-short')
|
75
|
+
time = convert_date_pattern search('calendar-gregorian', 'pattern', 'time-short')
|
76
|
+
(format.nil? || date.nil? || time.nil?) ? nil : format.sub('{0}', time).sub('{1}', date)
|
77
|
+
when 'time/formats/long'
|
78
|
+
format = search('calendar-gregorian', 'pattern', 'date+time')
|
79
|
+
date = convert_date_pattern search('calendar-gregorian', 'pattern', 'date-full')
|
80
|
+
time = convert_date_pattern search('calendar-gregorian', 'pattern', 'time-full')
|
81
|
+
(format.nil? || date.nil? || time.nil?) ? nil : format.sub('{0}', time).sub('{1}', date)
|
82
|
+
when 'time/am'
|
83
|
+
search('calendar-gregorian', 'day-period', 'am')
|
84
|
+
when 'time/pm'
|
85
|
+
search('calendar-gregorian', 'day-period', 'pm')
|
86
|
+
# action_view
|
87
|
+
when 'number/format/separator'
|
88
|
+
search('number', 'symbol', 'decimal')
|
89
|
+
when 'number/format/separator'
|
90
|
+
search('number', 'symbol', 'group')
|
91
|
+
when 'number/currency/format/format'
|
92
|
+
format = search('number', 'currency', 'name-pattern/other')
|
93
|
+
format.nil? ? nil : format.tr(' ', '').sub('{0}', '%u').sub('{1}', '%n')
|
94
|
+
else
|
95
|
+
nil
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
private
|
100
|
+
def summaries
|
101
|
+
returning [load_cldr_data(@locale_name.tr('-', '_'))] do |s|
|
102
|
+
if @locale_name =~ /^[a-zA-Z]{2}[-_][a-zA-Z]{2}$/
|
103
|
+
s << load_cldr_data(@locale_name.to(1))
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
memoize :summaries
|
108
|
+
|
109
|
+
def load_cldr_data(locale_name)
|
110
|
+
cldr = begin
|
111
|
+
OpenURI.open_uri("http://www.unicode.org/cldr/data/charts/summary/#{locale_name}.html").read
|
112
|
+
rescue
|
113
|
+
puts "WARNING: Couldn't find locale data for #{locale_name} on the web."
|
114
|
+
''
|
115
|
+
end
|
116
|
+
lines = cldr.split("\n").grep(/^<tr>/)
|
117
|
+
lines.delete_if {|r| r =~ /^<tr><td>\d*<\/td><td class='[gn]'>names<\/td>/}
|
118
|
+
'Ruby 1.9'.respond_to?(:force_encoding) ? lines.map {|l| l.force_encoding 'UTF-8'} : lines
|
119
|
+
end
|
120
|
+
|
121
|
+
def search(n1, n2, g)
|
122
|
+
pattern = Regexp.new /<tr><td>\d*<\/td><td class='[ng]'>#{Regexp.quote(n1)}<\/td><td class='[ng]'>#{Regexp.quote(n2)}<\/td><td class='[ng]'>#{Regexp.quote(g)}<\/td>/
|
123
|
+
extract_pattern = /<td class='v'>(?:<span.*?>)?(.*?)(?:<\/span>)?<\/td><td>/
|
124
|
+
summaries.each do |summary|
|
125
|
+
_, value = *extract_pattern.match(summary.grep(pattern).first)
|
126
|
+
return value unless value.nil?
|
127
|
+
end
|
128
|
+
nil
|
129
|
+
end
|
130
|
+
|
131
|
+
def convert_date_pattern(val)
|
132
|
+
return val if val.nil?
|
133
|
+
val = val.sub('MMMM', '%B').sub('MMM', '%b')
|
134
|
+
val = val.sub('yyyy', '%Y').sub('yy', '%y').sub('MM', '%m').sub('M', '%m').sub(/dd|d/, '%d')
|
135
|
+
val.sub('EEEEE', '%a').sub('EEEE', '%A').sub('H', '%H').sub('mm', '%M').sub('ss', '%S').sub('v', '%Z')
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
class <%= controller_class_name %>Controller < ApplicationController
|
2
|
+
# GET /<%= table_name %>
|
3
|
+
# GET /<%= table_name %>.xml
|
4
|
+
def index
|
5
|
+
@<%= table_name %> = <%= class_name %>.find(:all)
|
6
|
+
|
7
|
+
respond_to do |format|
|
8
|
+
format.html # index.html.erb
|
9
|
+
format.xml { render :xml => @<%= table_name %> }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# GET /<%= table_name %>/1
|
14
|
+
# GET /<%= table_name %>/1.xml
|
15
|
+
def show
|
16
|
+
@<%= file_name %> = <%= class_name %>.find(params[:id])
|
17
|
+
|
18
|
+
respond_to do |format|
|
19
|
+
format.html # show.html.erb
|
20
|
+
format.xml { render :xml => @<%= file_name %> }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# GET /<%= table_name %>/new
|
25
|
+
# GET /<%= table_name %>/new.xml
|
26
|
+
def new
|
27
|
+
@<%= file_name %> = <%= class_name %>.new
|
28
|
+
|
29
|
+
respond_to do |format|
|
30
|
+
format.html # new.html.erb
|
31
|
+
format.xml { render :xml => @<%= file_name %> }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# GET /<%= table_name %>/1/edit
|
36
|
+
def edit
|
37
|
+
@<%= file_name %> = <%= class_name %>.find(params[:id])
|
38
|
+
end
|
39
|
+
|
40
|
+
# POST /<%= table_name %>
|
41
|
+
# POST /<%= table_name %>.xml
|
42
|
+
def create
|
43
|
+
@<%= file_name %> = <%= class_name %>.new(params[:<%= file_name %>])
|
44
|
+
|
45
|
+
respond_to do |format|
|
46
|
+
if @<%= file_name %>.save
|
47
|
+
flash[:notice] = I18n.t(:created_success, :default => '%{model} was successfully created.', :model => <%= class_name %>.human_name, :scope => [:railties, :scaffold])
|
48
|
+
format.html { redirect_to(@<%= file_name %>) }
|
49
|
+
format.xml { render :xml => @<%= file_name %>, :status => :created, :location => @<%= file_name %> }
|
50
|
+
else
|
51
|
+
format.html { render :action => "new" }
|
52
|
+
format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# PUT /<%= table_name %>/1
|
58
|
+
# PUT /<%= table_name %>/1.xml
|
59
|
+
def update
|
60
|
+
@<%= file_name %> = <%= class_name %>.find(params[:id])
|
61
|
+
|
62
|
+
respond_to do |format|
|
63
|
+
if @<%= file_name %>.update_attributes(params[:<%= file_name %>])
|
64
|
+
flash[:notice] = I18n.t(:updated_success, :default => '%{model} was successfully updated.', :model => <%= class_name %>.human_name, :scope => [:railties, :scaffold])
|
65
|
+
format.html { redirect_to(@<%= file_name %>) }
|
66
|
+
format.xml { head :ok }
|
67
|
+
else
|
68
|
+
format.html { render :action => "edit" }
|
69
|
+
format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# DELETE /<%= table_name %>/1
|
75
|
+
# DELETE /<%= table_name %>/1.xml
|
76
|
+
def destroy
|
77
|
+
@<%= file_name %> = <%= class_name %>.find(params[:id])
|
78
|
+
@<%= file_name %>.destroy
|
79
|
+
|
80
|
+
respond_to do |format|
|
81
|
+
format.html { redirect_to(<%= table_name %>_url) }
|
82
|
+
format.xml { head :ok }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class <%= controller_class_name %>ControllerTest < ActionController::TestCase
|
4
|
+
test "should get index" do
|
5
|
+
get :index
|
6
|
+
assert_response :success
|
7
|
+
assert_not_nil assigns(:<%= table_name %>)
|
8
|
+
end
|
9
|
+
|
10
|
+
test "should get new" do
|
11
|
+
get :new
|
12
|
+
assert_response :success
|
13
|
+
end
|
14
|
+
|
15
|
+
test "should create <%= file_name %>" do
|
16
|
+
assert_difference('<%= class_name %>.count') do
|
17
|
+
post :create, :<%= file_name %> => { }
|
18
|
+
end
|
19
|
+
|
20
|
+
assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>))
|
21
|
+
end
|
22
|
+
|
23
|
+
test "should show <%= file_name %>" do
|
24
|
+
get :show, :id => <%= table_name %>(:one).id
|
25
|
+
assert_response :success
|
26
|
+
end
|
27
|
+
|
28
|
+
test "should get edit" do
|
29
|
+
get :edit, :id => <%= table_name %>(:one).id
|
30
|
+
assert_response :success
|
31
|
+
end
|
32
|
+
|
33
|
+
test "should update <%= file_name %>" do
|
34
|
+
put :update, :id => <%= table_name %>(:one).id, :<%= file_name %> => { }
|
35
|
+
assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>))
|
36
|
+
end
|
37
|
+
|
38
|
+
test "should destroy <%= file_name %>" do
|
39
|
+
assert_difference('<%= class_name %>.count', -1) do
|
40
|
+
delete :destroy, :id => <%= table_name %>(:one).id
|
41
|
+
end
|
42
|
+
|
43
|
+
assert_redirected_to <%= table_name %>_path
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
|
7
|
+
<title><%= controller_class_name %>: <%%= controller.action_name %></title>
|
8
|
+
<%%= stylesheet_link_tag 'scaffold' %>
|
9
|
+
</head>
|
10
|
+
<body>
|
11
|
+
|
12
|
+
<p style="color: green"><%%= flash[:notice] %></p>
|
13
|
+
|
14
|
+
<%%= yield %>
|
15
|
+
|
16
|
+
</body>
|
17
|
+
</html>
|
@@ -0,0 +1,54 @@
|
|
1
|
+
body { background-color: #fff; color: #333; }
|
2
|
+
|
3
|
+
body, p, ol, ul, td {
|
4
|
+
font-family: verdana, arial, helvetica, sans-serif;
|
5
|
+
font-size: 13px;
|
6
|
+
line-height: 18px;
|
7
|
+
}
|
8
|
+
|
9
|
+
pre {
|
10
|
+
background-color: #eee;
|
11
|
+
padding: 10px;
|
12
|
+
font-size: 11px;
|
13
|
+
}
|
14
|
+
|
15
|
+
a { color: #000; }
|
16
|
+
a:visited { color: #666; }
|
17
|
+
a:hover { color: #fff; background-color:#000; }
|
18
|
+
|
19
|
+
.fieldWithErrors {
|
20
|
+
padding: 2px;
|
21
|
+
background-color: red;
|
22
|
+
display: table;
|
23
|
+
}
|
24
|
+
|
25
|
+
#errorExplanation {
|
26
|
+
width: 400px;
|
27
|
+
border: 2px solid red;
|
28
|
+
padding: 7px;
|
29
|
+
padding-bottom: 12px;
|
30
|
+
margin-bottom: 20px;
|
31
|
+
background-color: #f0f0f0;
|
32
|
+
}
|
33
|
+
|
34
|
+
#errorExplanation h2 {
|
35
|
+
text-align: left;
|
36
|
+
font-weight: bold;
|
37
|
+
padding: 5px 5px 5px 15px;
|
38
|
+
font-size: 12px;
|
39
|
+
margin: -7px;
|
40
|
+
background-color: #c00;
|
41
|
+
color: #fff;
|
42
|
+
}
|
43
|
+
|
44
|
+
#errorExplanation p {
|
45
|
+
color: #333;
|
46
|
+
margin-bottom: 0;
|
47
|
+
padding: 5px;
|
48
|
+
}
|
49
|
+
|
50
|
+
#errorExplanation ul li {
|
51
|
+
font-size: 12px;
|
52
|
+
list-style: square;
|
53
|
+
}
|
54
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<h1><%% translate(:editing, :default => "Editing %{model}", :model => <%= class_name %>.human_name, :scope => [:railties, :scaffold]) %></h1>
|
2
|
+
|
3
|
+
<%% form_for(@<%= singular_name %>) do |f| %>
|
4
|
+
<%%= f.error_messages %>
|
5
|
+
|
6
|
+
<% for attribute in attributes -%>
|
7
|
+
<p>
|
8
|
+
<%%= f.label :<%= attribute.name %> %><br />
|
9
|
+
<%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
|
10
|
+
</p>
|
11
|
+
<% end -%>
|
12
|
+
<p>
|
13
|
+
<%%= f.submit translate(:update, :default => "Update", :scope => [:railties, :scaffold]) %>
|
14
|
+
</p>
|
15
|
+
<%% end %>
|
16
|
+
|
17
|
+
<%%= link_to translate(:show, :default => 'Show', :scope => [:railties, :scaffold]), @<%= singular_name %> %> |
|
18
|
+
<%%= link_to translate(:back, :default => 'Back', :scope => [:railties, :scaffold]), <%= plural_name %>_path %>
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<h1><%%= translate(:listing, :default => "Listing %{model}", :model => <%= class_name %>.human_name(:count => @<%= plural_name %>.size), :count => @<%= plural_name %>.size, :scope => [:railties, :scaffold]) %></h1>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<tr>
|
5
|
+
<% for attribute in attributes -%>
|
6
|
+
<th><%%= <%= class_name %>.human_attribute_name('<%= attribute.column.name %>') %></th>
|
7
|
+
<% end -%>
|
8
|
+
</tr>
|
9
|
+
|
10
|
+
<%% for <%= singular_name %> in @<%= plural_name %> %>
|
11
|
+
<tr>
|
12
|
+
<% for attribute in attributes -%>
|
13
|
+
<td><%%=h <%= singular_name %>.<%= attribute.name %> %></td>
|
14
|
+
<% end -%>
|
15
|
+
<td><%%= link_to translate(:show, :default => 'Show', :scope => [:railties, :scaffold]), <%= singular_name %> %></td>
|
16
|
+
<td><%%= link_to translate(:edit, :default => 'Edit', :scope => [:railties, :scaffold]), edit_<%= singular_name %>_path(<%= singular_name %>) %></td>
|
17
|
+
<td><%%= link_to translate(:destroy, :default => 'Destroy', :scope => [:railties, :scaffold]), <%= singular_name %>, :confirm => translate(:confirmation, :default => 'Are you sure?', :scope => [:railties, :scaffold]), :method => :delete %></td>
|
18
|
+
</tr>
|
19
|
+
<%% end %>
|
20
|
+
</table>
|
21
|
+
|
22
|
+
<br />
|
23
|
+
|
24
|
+
<%%= link_to translate(:new, :default => "New {{model}}", :model => <%= class_name %>.human_name, :scope => [:railties, :scaffold]), new_<%= singular_name %>_path %>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<h1><%%= translate(:new, :default => "New %{model}", :model => <%= class_name %>.human_name, :scope => [:railties, :scaffold]) %></h1>
|
2
|
+
|
3
|
+
<%% form_for(@<%= singular_name %>) do |f| %>
|
4
|
+
<%%= f.error_messages %>
|
5
|
+
|
6
|
+
<% for attribute in attributes -%>
|
7
|
+
<p>
|
8
|
+
<%%= f.label :<%= attribute.name %> %><br />
|
9
|
+
<%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
|
10
|
+
</p>
|
11
|
+
<% end -%>
|
12
|
+
<p>
|
13
|
+
<%%= f.submit translate(:create, :default => "Create", :scope => [:railties, :scaffold]) %>
|
14
|
+
</p>
|
15
|
+
<%% end %>
|
16
|
+
|
17
|
+
<%%= link_to translate(:back, :default => 'Back', :scope => [:railties, :scaffold]), <%= plural_name %>_path %>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<% for attribute in attributes -%>
|
2
|
+
<p>
|
3
|
+
<b><%%= <%= class_name %>.human_attribute_name('<%= attribute.column.name %>') %>:</b>
|
4
|
+
<%%=h @<%= singular_name %>.<%= attribute.name %> %>
|
5
|
+
</p>
|
6
|
+
|
7
|
+
<% end -%>
|
8
|
+
|
9
|
+
<%%= link_to translate(:edit, :default => 'Edit', :scope => [:railties, :scaffold]), edit_<%= singular_name %>_path(@<%= singular_name %>) %> |
|
10
|
+
<%%= link_to translate(:back, :default => 'Back', :scope => [:railties, :scaffold]), <%= plural_name %>_path %>
|