rieles 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +2 -2
- data/lib/{generators/rieles/templates → config/initializer}/inflections.rb +8 -8
- data/lib/{generators/rieles/templates → config/locales}/es.yml +0 -0
- data/lib/generators/rieles/USAGE +1 -1
- data/lib/generators/rieles/install_generator.rb +36 -0
- data/lib/rieles.rb +13 -2
- data/lib/rieles/version.rb +1 -1
- data/lib/{generators/rieles/templates → templates/erb/scaffold}/_form.html.erb +0 -0
- data/lib/{generators/rieles/templates → templates/erb/scaffold}/edit.html.erb +0 -0
- data/lib/{generators/rieles/templates → templates/erb/scaffold}/index.html.erb +1 -1
- data/lib/{generators/rieles/templates → templates/erb/scaffold}/new.html.erb +0 -0
- data/lib/{generators/rieles/templates → templates/erb/scaffold}/show.html.erb +0 -0
- data/rieles.gemspec +2 -0
- data/spec/inflections_spec.rb +75 -0
- metadata +31 -14
- data/lib/generators/rieles/rieles_generator.rb +0 -22
- data/lib/generators/rieles/templates/_error_messages.html.erb +0 -17
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Rieles
|
2
2
|
|
3
|
-
|
3
|
+
TODO: Write a gem description
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,7 +18,7 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
TODO: Write usage instructions here
|
22
22
|
|
23
23
|
## Contributing
|
24
24
|
|
@@ -1,21 +1,21 @@
|
|
1
1
|
# Be sure to restart your server when you modify this file.
|
2
2
|
|
3
3
|
ActiveSupport::Inflector.inflections do |inflect|
|
4
|
-
inflect.plural(/([
|
4
|
+
inflect.plural(/([rndlj])([A-Z]|_|$)/, '\1es\2')
|
5
5
|
inflect.plural(/([aeiou])([A-Z]|_|$)/, '\1s\2')
|
6
|
-
inflect.plural(/([aeiou])([A-Z]|_)([a-z]+)([
|
6
|
+
inflect.plural(/([aeiou])([A-Z]|_)([a-z]+)([rndlj])([A-Z]|_|$)/,
|
7
7
|
'\1s\2\3\4es\5')
|
8
|
-
inflect.plural(/([
|
8
|
+
inflect.plural(/([rndlj])([A-Z]|_)([a-z]+)([aeiou])([A-Z]|_|$)/,
|
9
9
|
'\1es\2\3\4s\5')
|
10
10
|
inflect.plural(/(z)$/i, 'ces')
|
11
11
|
|
12
|
-
|
13
|
-
final_plural_vocal = /((?<![aeiou][
|
14
|
-
palabra_compuesta_1 = /#{
|
15
|
-
palabra_compuesta_2 = /#{final_plural_vocal}([a-z]+)#{
|
12
|
+
final_plural_rndlj = /([aeiou][rndlj])es([A-Z]|_|$)/
|
13
|
+
final_plural_vocal = /((?<![aeiou][rndlj])[aeiou])s([A-Z]|_|$)/
|
14
|
+
palabra_compuesta_1 = /#{final_plural_rndlj}([a-z]+)#{final_plural_vocal}/
|
15
|
+
palabra_compuesta_2 = /#{final_plural_vocal}([a-z]+)#{final_plural_rndlj}/
|
16
16
|
|
17
17
|
inflect.singular(/(ia)$/i, '\1')
|
18
|
-
inflect.singular(
|
18
|
+
inflect.singular(final_plural_rndlj, '\1\2')
|
19
19
|
inflect.singular(final_plural_vocal, '\1\2')
|
20
20
|
inflect.singular(palabra_compuesta_1, '\1\2\3\4\5')
|
21
21
|
inflect.singular(palabra_compuesta_2, '\1\2\3\4\5')
|
File without changes
|
data/lib/generators/rieles/USAGE
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
Description:
|
2
|
-
Genera un archivo de inflections para obtener el plural y singular de las palabras
|
2
|
+
Genera un archivo de inflections para obtener el plural y singular de las palabras según las reglas en Español, incluye la traducción por omisión de rails para el locale es.yml y los templates para que al utilizar el scaffold las vistas sean generadas también en Español
|
3
3
|
|
4
4
|
Example:
|
5
5
|
rails generate rieles
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rails/generators'
|
3
|
+
|
4
|
+
module Rieles
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
source_root File.expand_path('../../../templates/erb/scaffold', __FILE__)
|
7
|
+
class_option :keep_current_inflections,
|
8
|
+
:type => :boolean,
|
9
|
+
:default => false,
|
10
|
+
:desc => 'Indica si en lugar de tratar de sobreescribir el archivo de inflections, se debe crear un archivo adicional (inflections_es)'
|
11
|
+
class_option :skip_templates,
|
12
|
+
:type => :boolean,
|
13
|
+
:default => false,
|
14
|
+
:desc => 'Indica si debe omitir los templates de las vistas para el scaffold'
|
15
|
+
|
16
|
+
def copy_files
|
17
|
+
copy_file '../../../config/initializer/inflections.rb', "config/initializers/#{file_name}.rb"
|
18
|
+
copy_file '../../../config/locales/es.yml', 'config/locales/es.yml'
|
19
|
+
|
20
|
+
unless options.skip_templates?
|
21
|
+
copy_file 'index.html.erb', 'lib/templates/erb/scaffold/index.html.erb'
|
22
|
+
copy_file 'edit.html.erb', 'lib/templates/erb/scaffold/edit.html.erb'
|
23
|
+
copy_file 'new.html.erb', 'lib/templates/erb/scaffold/new.html.erb'
|
24
|
+
copy_file 'show.html.erb', 'lib/templates/erb/scaffold/show.html.erb'
|
25
|
+
copy_file '_form.html.erb', 'lib/templates/erb/scaffold/_form.html.erb'
|
26
|
+
copy_file '../../../../app/views/application/_error_messages.html.erb', 'app/views/application/_error_messages.html.erb'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def file_name
|
33
|
+
file_name = options.keep_current? ? 'inflections_es' : 'inflections'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/rieles.rb
CHANGED
@@ -1,5 +1,16 @@
|
|
1
|
-
require
|
1
|
+
require 'rieles/version'
|
2
|
+
require 'config/initializer/inflections.rb'
|
2
3
|
|
3
4
|
module Rieles
|
4
|
-
|
5
|
+
I18n.load_path += Dir.glob( File.dirname(__FILE__) + "/config/locales/*.{rb,yml}" )
|
6
|
+
|
7
|
+
class Railtie < Rails::Railtie
|
8
|
+
config.app_generators do |g|
|
9
|
+
g.templates.unshift File::expand_path('../templates', __FILE__)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Engine < Rails::Engine
|
14
|
+
end
|
5
15
|
end
|
16
|
+
|
data/lib/rieles/version.rb
CHANGED
File without changes
|
File without changes
|
@@ -28,4 +28,4 @@
|
|
28
28
|
|
29
29
|
<br />
|
30
30
|
<% nuevo = singular_table_name.split('_')[0].ends_with?("a") ? 'Nueva' : 'Nuevo' -%>
|
31
|
-
<%%= link_to '<%= nuevo %> <%= human_name %>', new_<%= singular_table_name %>_path
|
31
|
+
<%%= link_to '<%= nuevo %> <%= human_name %>', new_<%= singular_table_name %>_path %>
|
File without changes
|
File without changes
|
data/rieles.gemspec
CHANGED
@@ -0,0 +1,75 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rails'
|
3
|
+
require 'rieles'
|
4
|
+
|
5
|
+
describe 'Inflections' do
|
6
|
+
def singulares
|
7
|
+
%w(riel camion hospital universidad reloj semestre mesa calle)
|
8
|
+
end
|
9
|
+
|
10
|
+
def plurales
|
11
|
+
%w(rieles camiones hospitales universidades relojes semestres mesas calles)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'Pluralizaciones' do
|
15
|
+
it 'debe pluralizar palabras sencillas' do
|
16
|
+
singulares.each_with_index do |s, i|
|
17
|
+
s.pluralize.should == plurales[i]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'debe pluralizar palabras compuestas' do
|
22
|
+
singulares_compuestas = singulares.permutation(2).to_a.collect{ |e| e.join('_') }
|
23
|
+
plurales_compuestas = plurales.permutation(2).to_a.collect{ |e| e.join('_') }
|
24
|
+
singulares_compuestas.each_with_index do |s, i|
|
25
|
+
s.pluralize.should == plurales_compuestas[i]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'debe pluralizar casos especiales' do
|
30
|
+
'pais'.pluralize.should == 'paises'
|
31
|
+
'maiz'.pluralize.should == 'maices'
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'no debe pluralizar palabras que ya estén en plural' do
|
35
|
+
'camiones'.pluralize.should == 'camiones'
|
36
|
+
'camiones_grandes'.pluralize.should == 'camiones_grandes'
|
37
|
+
'universidades_hospitales_doctores'.pluralize.should == 'universidades_hospitales_doctores'
|
38
|
+
'paises'.pluralize.should == 'paises'
|
39
|
+
'lunes'.singularize.should == 'lunes'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
#########################################################
|
44
|
+
# Sección que prueba las conversiones al singular
|
45
|
+
#########################################################
|
46
|
+
|
47
|
+
describe 'Singularizaciones' do
|
48
|
+
it 'debe singularizar palabras sencillas' do
|
49
|
+
plurales.each_with_index do |p, i|
|
50
|
+
p.singularize.should == singulares[i]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'debe pluralizar palabras compuestas' do
|
55
|
+
singulares_compuestas = singulares.permutation(2).to_a.collect{ |e| e.join('_') }
|
56
|
+
plurales_compuestas = plurales.permutation(2).to_a.collect{ |e| e.join('_') }
|
57
|
+
plurales_compuestas.each_with_index do |p, i|
|
58
|
+
p.singularize.should == singulares_compuestas[i]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'debe singularize casos especiales' do
|
63
|
+
'paises'.singularize.should == 'pais'
|
64
|
+
'maices'.singularize.should == 'maiz'
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'no debe singularizar palabras que ya estén en singular' do
|
68
|
+
'camion'.singularize.should == 'camion'
|
69
|
+
'camion_grande'.singularize.should == 'camion_grande'
|
70
|
+
'universidad_hospital_doctor'.singularize.should == 'universidad_hospital_doctor'
|
71
|
+
'pais'.singularize.should == 'pais'
|
72
|
+
'lunes'.singularize.should == 'lunes'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rieles
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
13
|
-
dependencies:
|
12
|
+
date: 2012-04-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
14
30
|
description: Instala el archivo de inflections para pluralizar y singularizar según
|
15
31
|
las reglas en Español, incluye el locale en Español y agrega templates erb para
|
16
32
|
que el scaffold genere las vistas en Español.
|
@@ -25,19 +41,19 @@ files:
|
|
25
41
|
- LICENSE
|
26
42
|
- README.md
|
27
43
|
- Rakefile
|
44
|
+
- lib/config/initializer/inflections.rb
|
45
|
+
- lib/config/locales/es.yml
|
28
46
|
- lib/generators/rieles/USAGE
|
29
|
-
- lib/generators/rieles/
|
30
|
-
- lib/generators/rieles/templates/_error_messages.html.erb
|
31
|
-
- lib/generators/rieles/templates/_form.html.erb
|
32
|
-
- lib/generators/rieles/templates/edit.html.erb
|
33
|
-
- lib/generators/rieles/templates/es.yml
|
34
|
-
- lib/generators/rieles/templates/index.html.erb
|
35
|
-
- lib/generators/rieles/templates/inflections.rb
|
36
|
-
- lib/generators/rieles/templates/new.html.erb
|
37
|
-
- lib/generators/rieles/templates/show.html.erb
|
47
|
+
- lib/generators/rieles/install_generator.rb
|
38
48
|
- lib/rieles.rb
|
39
49
|
- lib/rieles/version.rb
|
50
|
+
- lib/templates/erb/scaffold/_form.html.erb
|
51
|
+
- lib/templates/erb/scaffold/edit.html.erb
|
52
|
+
- lib/templates/erb/scaffold/index.html.erb
|
53
|
+
- lib/templates/erb/scaffold/new.html.erb
|
54
|
+
- lib/templates/erb/scaffold/show.html.erb
|
40
55
|
- rieles.gemspec
|
56
|
+
- spec/inflections_spec.rb
|
41
57
|
homepage: ''
|
42
58
|
licenses: []
|
43
59
|
post_install_message:
|
@@ -58,8 +74,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
74
|
version: '0'
|
59
75
|
requirements: []
|
60
76
|
rubyforge_project:
|
61
|
-
rubygems_version: 1.8.
|
77
|
+
rubygems_version: 1.8.24
|
62
78
|
signing_key:
|
63
79
|
specification_version: 3
|
64
80
|
summary: Instala inflections, locales y templates de scaffold para trabajar en Español.
|
65
|
-
test_files:
|
81
|
+
test_files:
|
82
|
+
- spec/inflections_spec.rb
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
class RielesGenerator < Rails::Generators::Base
|
3
|
-
source_root File.expand_path('../templates', __FILE__)
|
4
|
-
class_option :keep_current_inflections, :type => :boolean, :default => false, :desc => 'Indica si en lugar de tratar de sobreescribir el archivo de inflections, se debe crear un archivo adicional (inflections_es)'
|
5
|
-
|
6
|
-
def copy_files
|
7
|
-
copy_file 'inflections.rb', "config/initializers/#{file_name}.rb"
|
8
|
-
copy_file 'es.yml', 'config/locales/es.yml'
|
9
|
-
copy_file 'index.html.erb', 'lib/templates/erb/scaffold/index.html.erb'
|
10
|
-
copy_file 'edit.html.erb', 'lib/templates/erb/scaffold/edit.html.erb'
|
11
|
-
copy_file 'new.html.erb', 'lib/templates/erb/scaffold/new.html.erb'
|
12
|
-
copy_file 'show.html.erb', 'lib/templates/erb/scaffold/show.html.erb'
|
13
|
-
copy_file '_form.html.erb', 'lib/templates/erb/scaffold/_form.html.erb'
|
14
|
-
copy_file '_error_messages.html.erb', 'app/views/application/_error_messages.html.erb'
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def file_name
|
20
|
-
file_name = options.keep_current? ? 'inflections_es' : 'inflections'
|
21
|
-
end
|
22
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
<% if target.errors.any? %>
|
2
|
-
<% gender ||= target.class.name.ends_with?("a") ? "female" : "male" %>
|
3
|
-
<% model_name ||= target.class.name.underscore.humanize.downcase %>
|
4
|
-
<div id="error_explanation">
|
5
|
-
<h2>
|
6
|
-
<%= t('activerecord.errors.template.header', :count => target.errors.count, :model => model_name, :article => (gender == "male" ? "El" : "La")) %>
|
7
|
-
</h2>
|
8
|
-
<%= t('activerecord.errors.template.body') %>
|
9
|
-
<ul>
|
10
|
-
<% target.errors.full_messages.each do |msg| %>
|
11
|
-
<li>
|
12
|
-
<%= msg %>
|
13
|
-
</li>
|
14
|
-
<% end %>
|
15
|
-
</ul>
|
16
|
-
</div>
|
17
|
-
<% end %>
|