lastobelus-merb_global 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/activerecord_generators/translations_migration/USAGE +4 -0
  2. data/activerecord_generators/translations_migration/templates/translations_migration.erb +30 -0
  3. data/activerecord_generators/translations_migration/translations_migration_generator.rb +31 -0
  4. data/examples/active_record_example/README.txt +9 -0
  5. data/examples/active_record_example/application.rb +5 -0
  6. data/examples/active_record_example/config/database.yml +9 -0
  7. data/examples/active_record_example/config/framework.rb +5 -0
  8. data/examples/active_record_example/config/init.rb +24 -0
  9. data/examples/active_record_example/config/plugins.yml +3 -0
  10. data/examples/data_mapper_example/README.txt +9 -0
  11. data/examples/data_mapper_example/application.rb +5 -0
  12. data/examples/data_mapper_example/config/database.yml +9 -0
  13. data/examples/data_mapper_example/config/framework.rb +5 -0
  14. data/examples/data_mapper_example/config/init.rb +24 -0
  15. data/examples/data_mapper_example/config/plugins.yml +3 -0
  16. data/examples/database.sql +28 -0
  17. data/examples/gettext_example/README.txt +9 -0
  18. data/examples/gettext_example/application.rb +8 -0
  19. data/examples/gettext_example/config/framework.rb +5 -0
  20. data/examples/gettext_example/config/init.rb +24 -0
  21. data/examples/gettext_example/config/plugins.yml +4 -0
  22. data/examples/gettext_example/locale/merbapp.pot +21 -0
  23. data/examples/gettext_example/locale/pl/LC_MESSAGES/merbapp.mo +0 -0
  24. data/examples/gettext_example/locale/pl.po +23 -0
  25. data/examples/mock_example/README.txt +9 -0
  26. data/examples/mock_example/application.rb +5 -0
  27. data/examples/mock_example/config/framework.rb +5 -0
  28. data/examples/mock_example/config/init.rb +23 -0
  29. data/examples/mock_example/config/plugins.yml +3 -0
  30. data/examples/sequel_example/README.txt +9 -0
  31. data/examples/sequel_example/application.rb +5 -0
  32. data/examples/sequel_example/config/database.yml +9 -0
  33. data/examples/sequel_example/config/framework.rb +5 -0
  34. data/examples/sequel_example/config/init.rb +24 -0
  35. data/examples/sequel_example/config/plugins.yml +3 -0
  36. data/examples/yaml_example/README.txt +9 -0
  37. data/examples/yaml_example/application.rb +5 -0
  38. data/examples/yaml_example/config/framework.rb +5 -0
  39. data/examples/yaml_example/config/init.rb +24 -0
  40. data/examples/yaml_example/config/plugins.yml +4 -0
  41. data/examples/yaml_example/locale/en.yaml +2 -0
  42. data/examples/yaml_example/locale/pl.yaml +2 -0
  43. data/lib/merb_global/base.rb +105 -0
  44. data/lib/merb_global/config.rb +36 -0
  45. data/lib/merb_global/controller.rb +38 -0
  46. data/lib/merb_global/date_providers/fork.rb +35 -0
  47. data/lib/merb_global/date_providers.rb +47 -0
  48. data/lib/merb_global/locale.rb +139 -0
  49. data/lib/merb_global/merbrake.rb +37 -0
  50. data/lib/merb_global/message_providers/active_record.rb +113 -0
  51. data/lib/merb_global/message_providers/data_mapper.rb +113 -0
  52. data/lib/merb_global/message_providers/gettext.rb +123 -0
  53. data/lib/merb_global/message_providers/gettext.treetop +60 -0
  54. data/lib/merb_global/message_providers/mock.rb +17 -0
  55. data/lib/merb_global/message_providers/sequel.rb +99 -0
  56. data/lib/merb_global/message_providers/yaml.rb +92 -0
  57. data/lib/merb_global/message_providers.rb +146 -0
  58. data/lib/merb_global/numeric_providers/fork.rb +35 -0
  59. data/lib/merb_global/numeric_providers/java.rb +15 -0
  60. data/lib/merb_global/numeric_providers.rb +48 -0
  61. data/lib/merb_global/plural.rb +20 -0
  62. data/lib/merb_global/plural.treetop +267 -0
  63. data/lib/merb_global/providers.rb +40 -0
  64. data/lib/merb_global.rb +8 -0
  65. data/sequel_generators/translations_migration/USAGE +4 -0
  66. data/sequel_generators/translations_migration/templates/translations_migration.erb +28 -0
  67. data/sequel_generators/translations_migration/translations_migration_generator.rb +32 -0
  68. metadata +92 -1
@@ -0,0 +1,267 @@
1
+ module Merb
2
+ module Global
3
+ grammar Plural
4
+ rule expression
5
+ comma
6
+ end
7
+
8
+ rule comma
9
+ ternary ',' comma {
10
+ def to_lambda
11
+ comma.to_lambda
12
+ end
13
+ }
14
+ /
15
+ ternary
16
+ end
17
+
18
+ rule ternary
19
+ logop '?' if_true:ternary ':' if_false:ternary {
20
+ def to_lambda
21
+ lambda do |n|
22
+ if logop.to_lambda.call(n) != 0
23
+ if_true.to_lambda.call(n)
24
+ else
25
+ if_false.to_lambda.call(n)
26
+ end
27
+ end
28
+ end
29
+ }
30
+ /
31
+ logop
32
+ end
33
+
34
+ rule logop
35
+ bitop '&&' logop {
36
+ def to_lambda
37
+ lambda do |n|
38
+ bitop.to_lambda.call(n) && logop.to_lambda.call(n) ? 1 : 0
39
+ end
40
+ end
41
+ }
42
+ /
43
+ bitop '||' bitop {
44
+ def to_lambda
45
+ lambda do |n|
46
+ bitop.to_lambda.call(n) || logop.to_lambda.call(n) ? 1 : 0
47
+ end
48
+ end
49
+ }
50
+ /
51
+ bitop
52
+ end
53
+
54
+ rule bitop
55
+ equality '&' bitop {
56
+ def to_lambda
57
+ lambda do |n|
58
+ equality.to_lambda.call(n) & bitop.to_lambda.call(n)
59
+ end
60
+ end
61
+ }
62
+ /
63
+ equality '^' bitop {
64
+ def to_lambda
65
+ lambda do |n|
66
+ equality.to_lambda.call(n) ^ bitop.to_lambda.call(n)
67
+ end
68
+ end
69
+ }
70
+ /
71
+ equality '|' bitop {
72
+ def to_lambda
73
+ lambda do |n|
74
+ equality.to_lambda.call(n) | bitop.to_lambda.call(n)
75
+ end
76
+ end
77
+ }
78
+ /
79
+ equality
80
+ end
81
+
82
+ rule equality
83
+ relation '==' equality {
84
+ def to_lambda
85
+ lambda do |n|
86
+ relation.to_lambda.call(n) == equality.to_lambda.call(n) ? 1 : 0
87
+ end
88
+ end
89
+ }
90
+ /
91
+ relation '!=' equality {
92
+ def to_lambda
93
+ lambda do |n|
94
+ relation.to_lambda.call(n) != equality.to_lambda.call(n) ? 0 : 1
95
+ end
96
+ end
97
+ }
98
+ /
99
+ relation
100
+ end
101
+
102
+ rule relation
103
+ bitwise '<' relation {
104
+ def to_lambda
105
+ lambda do |n|
106
+ bitwise.to_lambda.call(n) < relation.to_lambda.call(n) ? 1 : 0
107
+ end
108
+ end
109
+ }
110
+ /
111
+ bitwise '<=' relation {
112
+ def to_lambda
113
+ lambda do |n|
114
+ bitwise.to_lambda.call(n) <= relation.to_lambda.call(n) ? 1 : 0
115
+ end
116
+ end
117
+ }
118
+ /
119
+ bitwise '>' relation {
120
+ def to_lambda
121
+ lambda do |n|
122
+ bitwise.to_lambda.call(n) > relation.to_lambda.call(n) ? 1 : 0
123
+ end
124
+ end
125
+ }
126
+ /
127
+ bitwise '>=' relation {
128
+ def to_lambda
129
+ lambda do |n|
130
+ bitwise.to_lambda.call(n) >= relation.to_lambda.call(n) ? 1 : 0
131
+ end
132
+ end
133
+ }
134
+ /
135
+ bitwise
136
+ end
137
+
138
+ rule bitwise
139
+ addition '<<' bitwise {
140
+ def to_lambda
141
+ lambda do |n|
142
+ addition.to_lambda.call(n) << bitwise.to_lambda.call(n)
143
+ end
144
+ end
145
+ }
146
+ /
147
+ addition '>>' bitwise {
148
+ def to_lambda
149
+ lambda do |n|
150
+ addition.to_lambda.call(n) >> bitwise.to_lambda.call(n)
151
+ end
152
+ end
153
+ }
154
+ /
155
+ addition
156
+ end
157
+
158
+ rule addition
159
+ multiplication '+' addition {
160
+ def to_lambda
161
+ lambda do |n|
162
+ multiplication.to_lambda.call(n) + addition.to_lambda.call(n)
163
+ end
164
+ end
165
+ }
166
+ /
167
+ multiplication '-' addition {
168
+ def to_lambda
169
+ lambda do |n|
170
+ multiplication.to_lambda.call(n) - addition.to_lambda.call(n)
171
+ end
172
+ end
173
+ }
174
+ /
175
+ multiplication
176
+ end
177
+
178
+ rule multiplication
179
+ unary '*' multiplication {
180
+ def to_lambda
181
+ lambda do |n|
182
+ unary.to_lambda.call(n) * multiplication.to_lambda.call(n)
183
+ end
184
+ end
185
+ }
186
+ /
187
+ unary '/' multiplication {
188
+ def to_lambda
189
+ lambda do |n|
190
+ unary.to_lambda.call(n) / multiplication.to_lambda.call(n)
191
+ end
192
+ end
193
+ }
194
+ /
195
+ unary '%' multiplication {
196
+ def to_lambda
197
+ lambda do |n|
198
+ unary.to_lambda.call(n) % multiplication.to_lambda.call(n)
199
+ end
200
+ end
201
+ }
202
+ /
203
+ unary
204
+ end
205
+
206
+ rule unary
207
+ '+' base {
208
+ def to_lambda
209
+ base.to_lambda
210
+ end
211
+ }
212
+ /
213
+ '-' base {
214
+ def to_lambda
215
+ lambda {|n| -base.to_lambda.call(n)}
216
+ end
217
+ }
218
+ /
219
+ '!' base {
220
+ def to_lambda
221
+ lambda {|n| base.to_lambda.call(n) == 0 ? 1 : 0}
222
+ end
223
+ }
224
+ /
225
+ '~' base {
226
+ def to_lambda
227
+ lambda {|n| ~base.call(n)}
228
+ end
229
+ }
230
+ /
231
+ base
232
+ end
233
+
234
+ rule base
235
+ space* base_wospace space* {
236
+ def to_lambda
237
+ base_wospace.to_lambda
238
+ end
239
+ }
240
+ end
241
+
242
+ rule base_wospace
243
+ '(' expression ')' {
244
+ def to_lambda
245
+ expression.to_lambda
246
+ end
247
+ }
248
+ /
249
+ 'n' {
250
+ def to_lambda
251
+ lambda {|n| n}
252
+ end
253
+ }
254
+ /
255
+ [0-9]+ {
256
+ def to_lambda
257
+ lambda {|n| text_value.to_i}
258
+ end
259
+ }
260
+ end
261
+
262
+ rule space
263
+ " " / "\n" / "\t"
264
+ end
265
+ end
266
+ end
267
+ end
@@ -0,0 +1,40 @@
1
+ module Merb
2
+ module Global
3
+ module Providers
4
+ def self.included(mod) #:nodoc:
5
+ mod.module_eval do
6
+ @@providers = {}
7
+ @@providers_classes = {}
8
+ ##
9
+ # Creates a provider and/or returns already created one
10
+ #
11
+ # ==== Parames
12
+ # provider<~to_s,~to_sym>:: A name of provider
13
+ #
14
+ # ==== Returns
15
+ # provider<Provider>:: A new provider
16
+ def self.[](provider)
17
+ unless @@providers.include? provider.to_sym
18
+ if @@providers_classes[provider.to_sym]
19
+ @@providers[provider.to_sym] =
20
+ @@providers_classes[provider.to_sym].new
21
+ else
22
+ require "merb_global/#{self.name.split("::").last.snake_case}/#{provider.to_s}"
23
+ @@providers[provider.to_sym] = self.const_get(provider.camel_case).new
24
+ end
25
+ end
26
+ @@providers[provider.to_sym]
27
+ end
28
+ # Registers the class under the given name
29
+ #
30
+ # ==== Parameters
31
+ # name<~to_sym>:: Name under which it is registered
32
+ # klass<Class>:: Class of the provider
33
+ def self.register(name, klass)
34
+ @@providers_classes[name.to_sym] = klass
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,8 @@
1
+ require 'pathname'
2
+
3
+ if defined? Merb::Plugins
4
+ require Pathname(__FILE__).dirname.expand_path + 'merb_global/base'
5
+ require Pathname(__FILE__).dirname.expand_path + 'merb_global/controller'
6
+
7
+ Merb::Plugins.add_rakefiles(Pathname(__FILE__).dirname.expand_path + 'merb_global/merbrake')
8
+ end
@@ -0,0 +1,4 @@
1
+ Description:
2
+
3
+
4
+ Usage:
@@ -0,0 +1,28 @@
1
+ #<% if false %>
2
+ # This is quick hack to avoid naming confict in specs
3
+ class Merb::Global::MessageProviders::Sequel
4
+ #<% end %>
5
+ class AddTranslationsMigration < Sequel::Migration
6
+ def up
7
+ create_table :merb_global_languages do
8
+ primary_key :id
9
+ varchar :name, :size => 16, :unique => true
10
+ integer :nplural
11
+ varchar :plural, :size => 128
12
+ end
13
+ create_table :merb_global_translations do
14
+ foreign_key :language_id, :null => false
15
+ text :msgid, :null => false
16
+ text :msgid_plural
17
+ text :msgstr, :null => false
18
+ integer :msgstr_index, :null => true
19
+ primary_key [:language_id, :msgid, :msgstr_index]
20
+ end
21
+ end
22
+ def down
23
+ drop_table :merb_global_languages, :merb_global_translations
24
+ end
25
+ end
26
+ #<% if false %>
27
+ end
28
+ #<% end %>
@@ -0,0 +1,32 @@
1
+ class TranslationMigrationGenerator < Merb::GeneratorBase
2
+ protected :banner
3
+
4
+ def initialize runtime_args, runtime_options = {}
5
+ runtime_args.push ''
6
+ super
7
+ @name = 'translations'
8
+ end
9
+
10
+ def mainfest
11
+ record do |m|
12
+ m.directory 'schema/migrations'
13
+ highest_migration = Dir[Dir.pwd+'/schema/migrations/*'].map do |f|
14
+ File.basename(f) =~ /^(\d+)/
15
+ $1
16
+ end.max
17
+ filename = format "%03d_%s", (highest_migration.to_i+1), @name.snake_case
18
+ m.template 'translation_migration.erb',
19
+ "schema/migrations/#{filename}.rb"
20
+ puts banner
21
+ end
22
+ end
23
+
24
+ def banner
25
+ <<-EOS
26
+ A migration to add translation tables to your database has been created.
27
+ Run 'rake sequel:db:migrate' to add the translations migration to your
28
+ database.
29
+
30
+ EOS
31
+ end
32
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lastobelus-merb_global
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Coles
@@ -51,6 +51,97 @@ files:
51
51
  - Rakefile
52
52
  - TODO
53
53
  - HISTORY
54
+ - lib/merb_global
55
+ - lib/merb_global/base.rb
56
+ - lib/merb_global/config.rb
57
+ - lib/merb_global/controller.rb
58
+ - lib/merb_global/date_providers
59
+ - lib/merb_global/date_providers/fork.rb
60
+ - lib/merb_global/date_providers.rb
61
+ - lib/merb_global/locale.rb
62
+ - lib/merb_global/merbrake.rb
63
+ - lib/merb_global/message_providers
64
+ - lib/merb_global/message_providers/active_record.rb
65
+ - lib/merb_global/message_providers/data_mapper.rb
66
+ - lib/merb_global/message_providers/gettext.rb
67
+ - lib/merb_global/message_providers/gettext.treetop
68
+ - lib/merb_global/message_providers/mock.rb
69
+ - lib/merb_global/message_providers/sequel.rb
70
+ - lib/merb_global/message_providers/yaml.rb
71
+ - lib/merb_global/message_providers.rb
72
+ - lib/merb_global/numeric_providers
73
+ - lib/merb_global/numeric_providers/fork.rb
74
+ - lib/merb_global/numeric_providers/java.rb
75
+ - lib/merb_global/numeric_providers.rb
76
+ - lib/merb_global/plural.rb
77
+ - lib/merb_global/plural.treetop
78
+ - lib/merb_global/providers.rb
79
+ - lib/merb_global.rb
80
+ - activerecord_generators/translations_migration
81
+ - activerecord_generators/translations_migration/templates
82
+ - activerecord_generators/translations_migration/templates/translations_migration.erb
83
+ - activerecord_generators/translations_migration/translations_migration_generator.rb
84
+ - activerecord_generators/translations_migration/USAGE
85
+ - sequel_generators/translations_migration
86
+ - sequel_generators/translations_migration/templates
87
+ - sequel_generators/translations_migration/templates/translations_migration.erb
88
+ - sequel_generators/translations_migration/translations_migration_generator.rb
89
+ - sequel_generators/translations_migration/USAGE
90
+ - examples/active_record_example
91
+ - examples/active_record_example/application.rb
92
+ - examples/active_record_example/config
93
+ - examples/active_record_example/config/database.yml
94
+ - examples/active_record_example/config/framework.rb
95
+ - examples/active_record_example/config/init.rb
96
+ - examples/active_record_example/config/plugins.yml
97
+ - examples/active_record_example/README.txt
98
+ - examples/data_mapper_example
99
+ - examples/data_mapper_example/application.rb
100
+ - examples/data_mapper_example/config
101
+ - examples/data_mapper_example/config/database.yml
102
+ - examples/data_mapper_example/config/framework.rb
103
+ - examples/data_mapper_example/config/init.rb
104
+ - examples/data_mapper_example/config/plugins.yml
105
+ - examples/data_mapper_example/README.txt
106
+ - examples/database.sql
107
+ - examples/gettext_example
108
+ - examples/gettext_example/application.rb
109
+ - examples/gettext_example/config
110
+ - examples/gettext_example/config/framework.rb
111
+ - examples/gettext_example/config/init.rb
112
+ - examples/gettext_example/config/plugins.yml
113
+ - examples/gettext_example/locale
114
+ - examples/gettext_example/locale/merbapp.pot
115
+ - examples/gettext_example/locale/pl
116
+ - examples/gettext_example/locale/pl/LC_MESSAGES
117
+ - examples/gettext_example/locale/pl/LC_MESSAGES/merbapp.mo
118
+ - examples/gettext_example/locale/pl.po
119
+ - examples/gettext_example/README.txt
120
+ - examples/mock_example
121
+ - examples/mock_example/application.rb
122
+ - examples/mock_example/config
123
+ - examples/mock_example/config/framework.rb
124
+ - examples/mock_example/config/init.rb
125
+ - examples/mock_example/config/plugins.yml
126
+ - examples/mock_example/README.txt
127
+ - examples/sequel_example
128
+ - examples/sequel_example/application.rb
129
+ - examples/sequel_example/config
130
+ - examples/sequel_example/config/database.yml
131
+ - examples/sequel_example/config/framework.rb
132
+ - examples/sequel_example/config/init.rb
133
+ - examples/sequel_example/config/plugins.yml
134
+ - examples/sequel_example/README.txt
135
+ - examples/yaml_example
136
+ - examples/yaml_example/application.rb
137
+ - examples/yaml_example/config
138
+ - examples/yaml_example/config/framework.rb
139
+ - examples/yaml_example/config/init.rb
140
+ - examples/yaml_example/config/plugins.yml
141
+ - examples/yaml_example/locale
142
+ - examples/yaml_example/locale/en.yaml
143
+ - examples/yaml_example/locale/pl.yaml
144
+ - examples/yaml_example/README.txt
54
145
  has_rdoc: true
55
146
  homepage: http://trac.ikonoklastik.com/merb_global/
56
147
  post_install_message: