mundo-pepino 0.1.6 → 0.1.7
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/History.txt +32 -0
- data/README.markdown +12 -1
- data/README_es.markdown +126 -60
- data/lib/mundo_pepino/en_US/definitions.rb +8 -0
- data/lib/mundo_pepino/en_US/mappings.rb +1 -3
- data/lib/mundo_pepino/en_US/matchers.rb +9 -0
- data/lib/mundo_pepino/en_US.rb +1 -1
- data/lib/mundo_pepino/es_ES/definitions.rb +28 -74
- data/lib/mundo_pepino/es_ES/mappings.rb +53 -8
- data/lib/mundo_pepino/es_ES/matchers.rb +24 -6
- data/lib/mundo_pepino/es_ES.rb +1 -1
- data/lib/mundo_pepino/implementations.rb +22 -4
- data/lib/mundo_pepino/implementations_api.rb +77 -65
- data/lib/mundo_pepino/resources_history.rb +23 -15
- data/lib/mundo_pepino/version.rb +1 -1
- data/lib/mundo_pepino.rb +5 -10
- data/rails_generators/mundo_pepino/templates/mundo_pepino_es_ES.rb +16 -0
- data/rails_generators/mundo_pepino_steps/templates/mundo_pepino_es_ES.rb +16 -0
- metadata +2 -2
@@ -37,7 +37,7 @@ module MundoPepino
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
class NotFoundInDatabase
|
40
|
+
class NotFoundInDatabase < ResourceNotFound
|
41
41
|
def initialize(model, value='')
|
42
42
|
super "#{model} #{value} not found in database"
|
43
43
|
end
|
@@ -88,10 +88,10 @@ module MundoPepino
|
|
88
88
|
pile_up res
|
89
89
|
end
|
90
90
|
|
91
|
-
def add_resource_from_database(
|
92
|
-
model =
|
91
|
+
def add_resource_from_database(raw_model, name)
|
92
|
+
model = raw_model.to_unquoted.to_model
|
93
93
|
field = field_for(model)
|
94
|
-
if resource = model.send("find_by_#{field}",
|
94
|
+
if resource = model.send("find_by_#{field}", name)
|
95
95
|
pile_up resource
|
96
96
|
else
|
97
97
|
NotFoundInDatabase.new(model, name)
|
@@ -123,27 +123,31 @@ module MundoPepino
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
|
-
def last_mentioned_of(
|
127
|
-
if model =
|
126
|
+
def last_mentioned_of(raw_model, with_name = nil)
|
127
|
+
if model = raw_model.to_model
|
128
128
|
resource = if with_name
|
129
|
-
detect_first
|
129
|
+
if mentioned = detect_first(resources_flatten, [model, with_name])
|
130
|
+
mentioned
|
131
|
+
else
|
132
|
+
add_resource_from_database(raw_model, with_name)
|
133
|
+
end
|
130
134
|
elsif(last_mentioned.mr_model == model)
|
131
135
|
last_mentioned
|
132
136
|
else
|
133
137
|
if group = recursive_group_search(model, @resources[1..-1])
|
134
138
|
group
|
135
139
|
else
|
136
|
-
detect_first
|
140
|
+
detect_first resources_flatten, model
|
137
141
|
end
|
138
142
|
end
|
139
143
|
resource || raise(ResourceNotFound.new("model:#{model.name}, name:#{with_name||'nil'}"))
|
140
144
|
else
|
141
|
-
raise ModelNotMapped.new(
|
145
|
+
raise ModelNotMapped.new(raw_model)
|
142
146
|
end
|
143
147
|
end
|
144
148
|
|
145
149
|
def last_mentioned_called(name)
|
146
|
-
detect_first
|
150
|
+
detect_first resources_flatten, name
|
147
151
|
end
|
148
152
|
|
149
153
|
def recursive_group_search(model, resources)
|
@@ -181,22 +185,26 @@ module MundoPepino
|
|
181
185
|
if valores.size == mentioned.size
|
182
186
|
[mentioned, valores]
|
183
187
|
else
|
184
|
-
[mentioned, [
|
188
|
+
[mentioned, [valor] * mentioned.size]
|
185
189
|
end
|
186
190
|
else
|
187
|
-
[[
|
191
|
+
[[mentioned], [valor]]
|
188
192
|
end
|
189
193
|
field, values = if (child_model = campo.to_model)
|
190
|
-
child_name_field = field_for(
|
194
|
+
child_name_field = field_for(child_model)
|
191
195
|
values = add_resource(child_model,
|
192
196
|
valores.map { |val| { child_name_field => val } })
|
193
197
|
values = [ values ] unless values.is_a?(Array)
|
194
|
-
[ campo
|
198
|
+
[field_for(mentioned.mr_model, campo) || child_model.name.underscore, values]
|
195
199
|
else
|
196
|
-
[
|
200
|
+
[field_for(mentioned.mr_model, campo), valores]
|
197
201
|
end
|
198
202
|
[resources, field, values]
|
199
203
|
end
|
204
|
+
|
205
|
+
def resources_flatten
|
206
|
+
(@resources || []).flatten
|
207
|
+
end
|
200
208
|
|
201
209
|
def method_missing(method, *args, &block)
|
202
210
|
if (method.to_s =~ /^last_mentioned_(.+)$/)
|
data/lib/mundo_pepino/version.rb
CHANGED
data/lib/mundo_pepino.rb
CHANGED
@@ -35,9 +35,10 @@ module MundoPepino
|
|
35
35
|
String.add_mapper(:content_type,
|
36
36
|
/\.png$/ => 'image/png',
|
37
37
|
/\.jpe?g$/ => 'image/jpg',
|
38
|
-
/\.gif$/ => 'image/gif') {
|
39
|
-
String.add_mapper(:underscored) {
|
40
|
-
String.add_mapper(:unquoted) {
|
38
|
+
/\.gif$/ => 'image/gif') {|str| 'text/plain'}
|
39
|
+
String.add_mapper(:underscored) {|string| string.gsub(/ +/, '_')}
|
40
|
+
String.add_mapper(:unquoted) {|str| str =~ /^['"](.*)['"]$/ ? $1 : str}
|
41
|
+
String.add_mapper(:regexp) {|str| str =~ /\/.+\/[a-z]*/ ? eval(str) : /#{Regexp.escape(str)}/m }
|
41
42
|
String.add_mapper(:translated) do |str|
|
42
43
|
if str =~ /^[a-z_]+\.[a-z_]+[a-z_\.]+$/
|
43
44
|
I18n.translate(str, :default => str)
|
@@ -47,13 +48,7 @@ module MundoPepino
|
|
47
48
|
str
|
48
49
|
end
|
49
50
|
end
|
50
|
-
String.add_mapper(:url)
|
51
|
-
if world.respond_to? :path_to
|
52
|
-
world.path_to string
|
53
|
-
else
|
54
|
-
string if string =~ /^\/.*$|^https?:\/\//i
|
55
|
-
end
|
56
|
-
end
|
51
|
+
String.add_mapper(:url) {|str| str if str =~ /^\/.*$|^https?:\/\//i}
|
57
52
|
end
|
58
53
|
|
59
54
|
def config
|
@@ -24,6 +24,22 @@ MundoPepino.configure do |config|
|
|
24
24
|
# TRADUCCIÓN ESPECÍFICA PARA UN MODELO
|
25
25
|
# /^Orchard::longitud(es)?$/ => :longitude
|
26
26
|
}
|
27
|
+
|
28
|
+
config.url_mappings = {
|
29
|
+
# TRADUCCIÓN DE RUTAS/URLS AQUÍ
|
30
|
+
# Hardcoded
|
31
|
+
#/^la página de registro/i => '/users/new',
|
32
|
+
# From app routes:
|
33
|
+
#/^la página de inicio de sesión/i => lambda {
|
34
|
+
# MundoPepino.world.new_session_path
|
35
|
+
#},
|
36
|
+
# And the fancy one: specific resource page
|
37
|
+
#/^la página de(?:l| la) (.+) ["'](.+)['"]$/ => lambda {|captures|
|
38
|
+
# if model = captures[0].to_model
|
39
|
+
# MundoPepino.world.send "#{model.name.underscore}_path", model.find_by_name(captures[1])
|
40
|
+
# end
|
41
|
+
#}
|
42
|
+
}
|
27
43
|
end
|
28
44
|
|
29
45
|
Before do
|
@@ -26,6 +26,22 @@ MundoPepino.configure do |config|
|
|
26
26
|
# TRADUCCIÓN ESPECÍFICA PARA UN MODELO
|
27
27
|
# /^Orchard::longitud(es)?$/ => 'longitude'
|
28
28
|
}
|
29
|
+
|
30
|
+
config.url_mappings = {
|
31
|
+
# TRADUCCIÓN DE RUTAS/URLS AQUÍ
|
32
|
+
# Hardcoded
|
33
|
+
#/^la página de registro/i => '/users/new',
|
34
|
+
# From app routes:
|
35
|
+
#/^la página de inicio de sesión/i => lambda {
|
36
|
+
# MundoPepino.world.new_session_path
|
37
|
+
#},
|
38
|
+
# And the fancy one: specific resource page
|
39
|
+
#/^la página de(?:l| la) (.+) ["'](.+)['"]$/ => lambda {|captures|
|
40
|
+
# if model = captures[0].to_model
|
41
|
+
# MundoPepino.world.send "#{model.name.underscore}_path", model.find_by_name(captures[1])
|
42
|
+
# end
|
43
|
+
#}
|
44
|
+
}
|
29
45
|
end
|
30
46
|
|
31
47
|
Before do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mundo-pepino
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Fernando Garc\xC3\xADa Samblas"
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-23 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|