manatee 0.0.1.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +23 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.mdown +55 -0
  5. data/Rakefile +7 -0
  6. data/app/assets/javascripts/manatee.js +1 -0
  7. data/app/assets/javascripts/manatee/helpers.js +4 -0
  8. data/app/assets/javascripts/manatee/helpers/asset_tag.jsh.coffee +138 -0
  9. data/app/assets/javascripts/manatee/helpers/asset_url.jsh.coffee +90 -0
  10. data/app/assets/javascripts/manatee/helpers/csrf.jsh.coffee +5 -0
  11. data/app/assets/javascripts/manatee/helpers/date.jsh.coffee +54 -0
  12. data/app/assets/javascripts/manatee/helpers/debug.jsh.coffee +2 -0
  13. data/app/assets/javascripts/manatee/helpers/form.jsh.coffee +25 -0
  14. data/app/assets/javascripts/manatee/helpers/form_builder.jsh.coffee +24 -0
  15. data/app/assets/javascripts/manatee/helpers/form_options.jsh.coffee +267 -0
  16. data/app/assets/javascripts/manatee/helpers/form_tag.jsh.coffee +204 -0
  17. data/app/assets/javascripts/manatee/helpers/javascript.jsh.coffee +15 -0
  18. data/app/assets/javascripts/manatee/helpers/number.jsh.coffee +58 -0
  19. data/app/assets/javascripts/manatee/helpers/sanitize.jsh.coffee +5 -0
  20. data/app/assets/javascripts/manatee/helpers/tag.jsh.coffee +58 -0
  21. data/app/assets/javascripts/manatee/helpers/text.jsh.coffee +12 -0
  22. data/app/assets/javascripts/manatee/helpers/translation.jsh.coffee +7 -0
  23. data/app/assets/javascripts/manatee/helpers/url.jsh.coffee +36 -0
  24. data/app/assets/javascripts/manatee/helpers/util.jsh.coffee +41 -0
  25. data/app/assets/javascripts/manatee/rails_helpers.js +2 -0
  26. data/app/assets/javascripts/manatee/rails_helpers/routes.js.erb +195 -0
  27. data/app/assets/javascripts/manatee/rails_routes.js +1 -0
  28. data/app/assets/javascripts/manatee/renderer.js.erb +53 -0
  29. data/app/assets/javascripts/manatee_railsless.js +1 -0
  30. data/lib/manatee.rb +87 -0
  31. data/lib/manatee/config.rb +51 -0
  32. data/lib/manatee/handler.rb +45 -0
  33. data/lib/manatee/rails.rb +6 -0
  34. data/lib/manatee/rails/extensions.rb +23 -0
  35. data/lib/manatee/rails/handler.rb +16 -0
  36. data/lib/manatee/rails/hash_visitor.rb +35 -0
  37. data/lib/manatee/rails/helper.rb +9 -0
  38. data/lib/manatee/rails/resolver.rb +70 -0
  39. data/lib/manatee/rails/routes_compiler.rb +34 -0
  40. data/lib/manatee/sprockets.rb +8 -0
  41. data/lib/manatee/sprockets/jsh_processor_2x.rb +32 -0
  42. data/lib/manatee/sprockets/jsh_processor_3x.rb +31 -0
  43. data/lib/manatee/version.rb +3 -0
  44. data/manatee.gemspec +32 -0
  45. data/test/example/renderer.js.erb +8 -0
  46. data/test/example/translations.en.yml +410 -0
  47. data/test/example/views/index.jst.eco +12 -0
  48. data/test/helpers/asset_tag_test.rb +175 -0
  49. data/test/helpers/asset_url_test.rb +349 -0
  50. data/test/helpers/form_options_test.rb +718 -0
  51. data/test/helpers/form_tag_test.rb +387 -0
  52. data/test/helpers/javascript_test.rb +39 -0
  53. data/test/helpers/number_test.rb +111 -0
  54. data/test/helpers/tag_test.rb +71 -0
  55. data/test/support/dom_assertion.rb +49 -0
  56. data/test/support/view_test.rb +91 -0
  57. data/test/test_helper.rb +17 -0
  58. metadata +213 -0
@@ -0,0 +1,8 @@
1
+ if Sprockets::VERSION.match /\A3\./
2
+ require 'manatee/sprockets/jsh_processor_3x'
3
+ elsif Sprockets::VERSION.match /\A2\./
4
+ require 'manatee/sprockets/jsh_processor_2x'
5
+ else
6
+ raise 'Manatee requires Sprockets version 2.x or 3.x'
7
+ end
8
+
@@ -0,0 +1,32 @@
1
+ require 'tilt'
2
+
3
+ module Manatee
4
+ module Sprockets
5
+ class JshProcessor < Tilt::Template
6
+ attr_reader :namespace
7
+
8
+ self.default_mime_type = 'application/javascript'
9
+
10
+ def prepare
11
+ @namespace = self.class.default_namespace
12
+ end
13
+
14
+ def evaluate(scope, locals, &block)
15
+ "( function(helper, alias){ #{indent(data)}; } ).call(#{namespace}, #{namespace}.helper, #{namespace}.alias);"
16
+ end
17
+
18
+ private
19
+ def indent(string)
20
+ string.gsub(/$(.)/m, "\\1 ").strip
21
+ end
22
+
23
+ def self.default_namespace
24
+ 'this.Renderer'
25
+ end
26
+
27
+ def self.subscribe(environment)
28
+ environment.register_engine '.jsh', Manatee::Sprockets::JshProcessor
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,31 @@
1
+ module Manatee
2
+ module Sprockets
3
+ class JshProcessor
4
+ def self.call(input)
5
+ instance.call(input)
6
+ end
7
+
8
+ def initialize(options = {})
9
+ @namespace = options[:namespace] || self.class.default_namespace
10
+ end
11
+
12
+ def call(input)
13
+ data = input[:data].gsub(/$(.)/m, "\\1 ").strip
14
+ key = input[:name]
15
+ "( function(helper, alias){ #{data}; } ).call(#{@namespace}, #{@namespace}.helper, #{@namespace}.alias);"
16
+ end
17
+
18
+ def self.instance
19
+ @instance ||= new
20
+ end
21
+
22
+ def self.default_namespace
23
+ 'this.Renderer'
24
+ end
25
+
26
+ def self.subscribe(environment)
27
+ environment.register_engine '.jsh', Manatee::Sprockets::JshProcessor, mime_type: 'application/javascript'
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module Manatee
2
+ VERSION = '0.0.1.pre1'
3
+ end
data/manatee.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'manatee/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'manatee'
8
+ spec.version = Manatee::VERSION
9
+ spec.summary = %q{Javascript Template Render [for Rails]?}
10
+ spec.description = %q{Renders javascript templates with ease on client and server sides}
11
+ spec.homepage = ''
12
+ spec.license = 'MIT'
13
+
14
+ spec.authors = ['Dalton Pinto', 'Felipe JAPM']
15
+ spec.email = ['dalton@akidog.com.br', 'felipe@akidog.com.br']
16
+
17
+ spec.files = Dir['{app,bin,lib,test,spec}/**/*'] + ['manatee.gemspec', 'LICENSE.txt', 'Rakefile', 'Gemfile', 'README.mdown']
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.executables = spec.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
20
+
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_dependency 'i18n-js'
24
+
25
+ spec.add_dependency 'execjs'
26
+ spec.add_dependency 'sprockets'
27
+ spec.add_dependency 'coffee-script'
28
+
29
+ spec.add_development_dependency 'rake'
30
+ spec.add_development_dependency 'bundler'
31
+ spec.add_development_dependency 'nokogiri'
32
+ end
@@ -0,0 +1,8 @@
1
+ //= require manatee_railsless
2
+ //= require_tree ./views
3
+
4
+ <% if Manatee.protect_from_forgery && defined? Manatee::ViewTest %>
5
+ Renderer.csrfToken = <%= Manatee::ViewTest::CSRF_TOKEN.inspect %>;
6
+ <% end %>
7
+
8
+ I18n.translations = <%= YAML.load_file( File.expand_path('../translations.en.yml', __FILE__) ).to_json %>;
@@ -0,0 +1,410 @@
1
+ en:
2
+ date:
3
+ abbr_day_names:
4
+ - Sun
5
+ - Mon
6
+ - Tue
7
+ - Wed
8
+ - Thu
9
+ - Fri
10
+ - Sat
11
+ abbr_month_names:
12
+ -
13
+ - Jan
14
+ - Feb
15
+ - Mar
16
+ - Apr
17
+ - May
18
+ - Jun
19
+ - Jul
20
+ - Aug
21
+ - Sep
22
+ - Oct
23
+ - Nov
24
+ - Dec
25
+ day_names:
26
+ - Sunday
27
+ - Monday
28
+ - Tuesday
29
+ - Wednesday
30
+ - Thursday
31
+ - Friday
32
+ - Saturday
33
+ formats:
34
+ default: ! '%Y-%m-%d'
35
+ long: ! '%B %d, %Y'
36
+ short: ! '%b %d'
37
+ month_names:
38
+ -
39
+ - January
40
+ - February
41
+ - March
42
+ - April
43
+ - May
44
+ - June
45
+ - July
46
+ - August
47
+ - September
48
+ - October
49
+ - November
50
+ - December
51
+ order:
52
+ - :year
53
+ - :month
54
+ - :day
55
+ datetime:
56
+ distance_in_words:
57
+ about_x_hours:
58
+ one: about 1 hour
59
+ other: about %{count} hours
60
+ about_x_months:
61
+ one: about 1 month
62
+ other: about %{count} months
63
+ about_x_years:
64
+ one: about 1 year
65
+ other: about %{count} years
66
+ almost_x_years:
67
+ one: almost 1 year
68
+ other: almost %{count} years
69
+ half_a_minute: half a minute
70
+ less_than_x_minutes:
71
+ one: less than a minute
72
+ other: less than %{count} minutes
73
+ less_than_x_seconds:
74
+ one: less than 1 second
75
+ other: less than %{count} seconds
76
+ over_x_years:
77
+ one: over 1 year
78
+ other: over %{count} years
79
+ x_days:
80
+ one: 1 day
81
+ other: ! '%{count} days'
82
+ x_minutes:
83
+ one: 1 minute
84
+ other: ! '%{count} minutes'
85
+ x_months:
86
+ one: 1 month
87
+ other: ! '%{count} months'
88
+ x_seconds:
89
+ one: 1 second
90
+ other: ! '%{count} seconds'
91
+ prompts:
92
+ day: Day
93
+ hour: Hour
94
+ minute: Minute
95
+ month: Month
96
+ second: Seconds
97
+ year: Year
98
+ errors:
99
+ format: ! '%{attribute} %{message}'
100
+ messages:
101
+ accepted: must be accepted
102
+ blank: can't be blank
103
+ present: must be blank
104
+ confirmation: ! "doesn't match %{attribute}"
105
+ empty: can't be empty
106
+ equal_to: must be equal to %{count}
107
+ even: must be even
108
+ exclusion: is reserved
109
+ greater_than: must be greater than %{count}
110
+ greater_than_or_equal_to: must be greater than or equal to %{count}
111
+ inclusion: is not included in the list
112
+ invalid: is invalid
113
+ less_than: must be less than %{count}
114
+ less_than_or_equal_to: must be less than or equal to %{count}
115
+ not_a_number: is not a number
116
+ not_an_integer: must be an integer
117
+ odd: must be odd
118
+ record_invalid: ! 'Validation failed: %{errors}'
119
+ restrict_dependent_destroy:
120
+ one: "Cannot delete record because a dependent %{record} exists"
121
+ many: "Cannot delete record because dependent %{record} exist"
122
+ taken: has already been taken
123
+ too_long:
124
+ one: is too long (maximum is 1 character)
125
+ other: is too long (maximum is %{count} characters)
126
+ too_short:
127
+ one: is too short (minimum is 1 character)
128
+ other: is too short (minimum is %{count} characters)
129
+ wrong_length:
130
+ one: is the wrong length (should be 1 character)
131
+ other: is the wrong length (should be %{count} characters)
132
+ other_than: "must be other than %{count}"
133
+ template:
134
+ body: ! 'There were problems with the following fields:'
135
+ header:
136
+ one: 1 error prohibited this %{model} from being saved
137
+ other: ! '%{count} errors prohibited this %{model} from being saved'
138
+ helpers:
139
+ select:
140
+ prompt: Please select
141
+ submit:
142
+ create: Create %{model}
143
+ submit: Save %{model}
144
+ update: Update %{model}
145
+ number:
146
+ currency:
147
+ format:
148
+ delimiter: ! ','
149
+ format: ! '%u%n'
150
+ precision: 2
151
+ separator: .
152
+ significant: false
153
+ strip_insignificant_zeros: false
154
+ unit: $
155
+ format:
156
+ delimiter: ! ','
157
+ precision: 3
158
+ separator: .
159
+ significant: false
160
+ strip_insignificant_zeros: false
161
+ human:
162
+ decimal_units:
163
+ format: ! '%n %u'
164
+ units:
165
+ billion: Billion
166
+ million: Million
167
+ quadrillion: Quadrillion
168
+ thousand: Thousand
169
+ trillion: Trillion
170
+ unit: ''
171
+ format:
172
+ delimiter: ''
173
+ precision: 3
174
+ significant: true
175
+ strip_insignificant_zeros: true
176
+ storage_units:
177
+ format: ! '%n %u'
178
+ units:
179
+ byte:
180
+ one: Byte
181
+ other: Bytes
182
+ gb: GB
183
+ kb: KB
184
+ mb: MB
185
+ tb: TB
186
+ percentage:
187
+ format:
188
+ delimiter: ''
189
+ format: "%n%"
190
+ precision:
191
+ format:
192
+ delimiter: ''
193
+ support:
194
+ array:
195
+ last_word_connector: ! ', and '
196
+ two_words_connector: ! ' and '
197
+ words_connector: ! ', '
198
+ time:
199
+ am: am
200
+ formats:
201
+ default: ! '%a, %d %b %Y %H:%M:%S %z'
202
+ long: ! '%B %d, %Y %H:%M'
203
+ short: ! '%d %b %H:%M'
204
+ pm: pm
205
+ pt-BR:
206
+ date:
207
+ abbr_day_names:
208
+ - Dom
209
+ - Seg
210
+ - Ter
211
+ - Qua
212
+ - Qui
213
+ - Sex
214
+ - Sáb
215
+ abbr_month_names:
216
+ -
217
+ - Jan
218
+ - Fev
219
+ - Mar
220
+ - Abr
221
+ - Mai
222
+ - Jun
223
+ - Jul
224
+ - Ago
225
+ - Set
226
+ - Out
227
+ - Nov
228
+ - Dez
229
+ day_names:
230
+ - Domingo
231
+ - Segunda
232
+ - Terça
233
+ - Quarta
234
+ - Quinta
235
+ - Sexta
236
+ - Sábado
237
+ formats:
238
+ default: ! '%d/%m/%Y'
239
+ long: ! '%d de %B de %Y'
240
+ short: ! '%d de %B'
241
+ month_names:
242
+ -
243
+ - Janeiro
244
+ - Fevereiro
245
+ - Março
246
+ - Abril
247
+ - Maio
248
+ - Junho
249
+ - Julho
250
+ - Agosto
251
+ - Setembro
252
+ - Outubro
253
+ - Novembro
254
+ - Dezembro
255
+ order:
256
+ - :day
257
+ - :month
258
+ - :year
259
+ datetime:
260
+ distance_in_words:
261
+ about_x_hours:
262
+ one: aproximadamente 1 hora
263
+ other: aproximadamente %{count} horas
264
+ about_x_months:
265
+ one: aproximadamente 1 mês
266
+ other: aproximadamente %{count} meses
267
+ about_x_years:
268
+ one: aproximadamente 1 ano
269
+ other: aproximadamente %{count} anos
270
+ almost_x_years:
271
+ one: quase 1 ano
272
+ other: quase %{count} anos
273
+ half_a_minute: meio minuto
274
+ less_than_x_minutes:
275
+ one: menos de um minuto
276
+ other: menos de %{count} minutos
277
+ less_than_x_seconds:
278
+ one: menos de 1 segundo
279
+ other: menos de %{count} segundos
280
+ over_x_years:
281
+ one: mais de 1 ano
282
+ other: mais de %{count} anos
283
+ x_days:
284
+ one: 1 dia
285
+ other: ! '%{count} dias'
286
+ x_minutes:
287
+ one: 1 minuto
288
+ other: ! '%{count} minutos'
289
+ x_months:
290
+ one: 1 mês
291
+ other: ! '%{count} meses'
292
+ x_seconds:
293
+ one: 1 segundo
294
+ other: ! '%{count} segundos'
295
+ prompts:
296
+ day: Dia
297
+ hour: Hora
298
+ minute: Minuto
299
+ month: Mês
300
+ second: Segundo
301
+ year: Ano
302
+ errors:
303
+ format: ! '%{attribute} %{message}'
304
+ messages:
305
+ accepted: deve ser aceito
306
+ blank: não pode ficar em branco
307
+ present: deve ficar em branco
308
+ confirmation: não é igual a %{attribute}
309
+ empty: não pode ficar vazio
310
+ equal_to: deve ser igual a %{count}
311
+ even: deve ser par
312
+ exclusion: não está disponível
313
+ greater_than: deve ser maior que %{count}
314
+ greater_than_or_equal_to: deve ser maior ou igual a %{count}
315
+ inclusion: não está incluído na lista
316
+ invalid: não é válido
317
+ less_than: deve ser menor que %{count}
318
+ less_than_or_equal_to: deve ser menor ou igual a %{count}
319
+ not_a_number: não é um número
320
+ not_an_integer: não é um número inteiro
321
+ odd: deve ser ímpar
322
+ record_invalid: ! 'A validação falhou: %{errors}'
323
+ restrict_dependent_destroy:
324
+ one: "Não é possível excluir o registro pois existe um %{record} dependente"
325
+ many: "Não é possível excluir o registro pois existem %{record} dependentes"
326
+ taken: já está em uso
327
+ too_long: ! 'é muito longo (máximo: %{count} caracteres)'
328
+ too_short: ! 'é muito curto (mínimo: %{count} caracteres)'
329
+ wrong_length: não possui o tamanho esperado (%{count} caracteres)
330
+ other_than: "deve ser diferente de %{count}"
331
+ template:
332
+ body: ! 'Por favor, verifique o(s) seguinte(s) campo(s):'
333
+ header:
334
+ one: ! 'Não foi possível gravar %{model}: 1 erro'
335
+ other: ! 'Não foi possível gravar %{model}: %{count} erros.'
336
+ helpers:
337
+ select:
338
+ prompt: Por favor selecione
339
+ submit:
340
+ create: Criar %{model}
341
+ submit: Salvar %{model}
342
+ update: Atualizar %{model}
343
+ number:
344
+ currency:
345
+ format:
346
+ delimiter: .
347
+ format: ! '%u %n'
348
+ precision: 2
349
+ separator: ! ','
350
+ significant: false
351
+ strip_insignificant_zeros: false
352
+ unit: R$
353
+ format:
354
+ delimiter: .
355
+ precision: 3
356
+ separator: ! ','
357
+ significant: false
358
+ strip_insignificant_zeros: false
359
+ human:
360
+ decimal_units:
361
+ format: ! '%n %u'
362
+ units:
363
+ billion:
364
+ one: bilhão
365
+ other: bilhões
366
+ million:
367
+ one: milhão
368
+ other: milhões
369
+ quadrillion:
370
+ one: quatrilhão
371
+ other: quatrilhões
372
+ thousand: mil
373
+ trillion:
374
+ one: trilhão
375
+ other: trilhões
376
+ unit: ''
377
+ format:
378
+ delimiter: .
379
+ precision: 2
380
+ significant: true
381
+ strip_insignificant_zeros: true
382
+ storage_units:
383
+ format: ! '%n %u'
384
+ units:
385
+ byte:
386
+ one: Byte
387
+ other: Bytes
388
+ gb: GB
389
+ kb: KB
390
+ mb: MB
391
+ tb: TB
392
+ percentage:
393
+ format:
394
+ delimiter: .
395
+ format: "%n%"
396
+ precision:
397
+ format:
398
+ delimiter: .
399
+ support:
400
+ array:
401
+ last_word_connector: ! ' e '
402
+ two_words_connector: ! ' e '
403
+ words_connector: ! ', '
404
+ time:
405
+ am: ''
406
+ formats:
407
+ default: ! '%a, %d de %B de %Y, %H:%M:%S %z'
408
+ long: ! '%d de %B de %Y, %H:%M'
409
+ short: ! '%d de %B, %H:%M'
410
+ pm: ''