trimmer 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -3,4 +3,53 @@ Trimmer Controller
3
3
 
4
4
  Rack endpoint to make templates and i18n translations available in javascript.
5
5
 
6
- See specs for details.
6
+ See specs for more details.
7
+
8
+ How it works
9
+ ------------
10
+
11
+ Trimmer adds additional routes to your app:
12
+
13
+ - /trimmer/en.js
14
+ - /trimmer/es.js
15
+ - etc
16
+
17
+ This defines two variables in your app: I18n.translations and Templates.
18
+
19
+ Translations
20
+ ------------
21
+
22
+ Trimmer will serve the translations you define from your config/locales files available as a JS object.
23
+
24
+ Templates
25
+ ---------
26
+
27
+ This is the cool part. You can define your own structure of client-side templates which will be:
28
+
29
+ 1. Rendered by Rails (where you can access ERB, helpers and Rails i18n)
30
+ 2. Available in JS as templates
31
+
32
+ To add templates, create a folder structure like this:
33
+
34
+ app/
35
+ templates/
36
+ users/
37
+ index.jade.erb
38
+ show.jade.erb
39
+ settings.jade.erb
40
+
41
+ This will create a JS object with this structure:
42
+
43
+ Templates = {
44
+ users: {
45
+ index: "...",
46
+ show: "..."
47
+ },
48
+ settings: "..."
49
+ }
50
+
51
+
52
+
53
+
54
+
55
+
@@ -3,6 +3,7 @@ require 'rack/request'
3
3
  require 'json'
4
4
  require 'tilt'
5
5
  require 'i18n'
6
+ require 'active_support/ordered_hash'
6
7
 
7
8
  module Trimmer
8
9
 
@@ -101,7 +102,7 @@ module Trimmer
101
102
  end
102
103
  end
103
104
  end
104
- templates
105
+ ActiveSupport::OrderedHash[templates.sort]
105
106
  end
106
107
 
107
108
  # Dumps all the translations. Options you can pass:
data/lib/trimmer/i18n.rb CHANGED
@@ -4,7 +4,7 @@ module Trimmer
4
4
  module I18n
5
5
 
6
6
  def raise_all_exceptions(*args)
7
- raise args.first
7
+ raise args.first.to_exception
8
8
  end
9
9
 
10
10
  def with_exception_handler(tmp_exception_handler = nil)
@@ -1,3 +1,3 @@
1
1
  module Trimmer
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -25,6 +25,10 @@ VALUE
25
25
 
26
26
  @def_templates_en = <<-VALUE.strip
27
27
  Templates = ({"foo":{"bar":"<span>trimmer</span>\\n"}});
28
+ VALUE
29
+
30
+ @def_complex_templates_en = <<-VALUE.strip
31
+ Templates = ({"bar":{"deportes":"ES UN BAR\\n"},"foo":{"manchu":"ES UN CHINO\\n","mar":"ES MALO\\n"}});
28
32
  VALUE
29
33
 
30
34
  @def_resources_es = <<-VALUE.strip
@@ -156,5 +160,8 @@ RESP
156
160
  end
157
161
  end
158
162
 
163
+ specify "should return templates in alphabetical order" do
164
+ request(:path=>'/trimmer/en/templates.js', :templates_dir => complex_templates_dir).body.should.equal(@def_complex_templates_en)
165
+ end
159
166
  end
160
167
 
@@ -0,0 +1 @@
1
+ ES UN BAR
@@ -0,0 +1 @@
1
+ ES UN CHINO
@@ -0,0 +1 @@
1
+ ES MALO
data/test/test_helper.rb CHANGED
@@ -48,6 +48,10 @@ class Test::Unit::TestCase
48
48
  File.dirname(__FILE__) + '/test_data/templates_missing_t'
49
49
  end
50
50
 
51
+ def complex_templates_dir
52
+ File.dirname(__FILE__) + '/test_data/complex_templates'
53
+ end
54
+
51
55
  end
52
56
 
53
57
 
data/trimmer.gemspec CHANGED
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
+ s.add_dependency 'activesupport', '>= 3.0'
20
21
  s.add_dependency 'rack', '~> 1.1'
21
22
  s.add_dependency 'i18n', '~> 0.6.0'
22
23
  s.add_dependency 'tilt', '~> 1.3.3'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trimmer
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease: false
4
+ hash: 23
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Pablo Villalba
@@ -16,13 +16,28 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-10-13 00:00:00 +02:00
19
+ date: 2012-01-25 00:00:00 +01:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
- name: rack
23
+ name: activesupport
24
24
  prerelease: false
25
25
  requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 7
31
+ segments:
32
+ - 3
33
+ - 0
34
+ version: "3.0"
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rack
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
26
41
  none: false
27
42
  requirements:
28
43
  - - ~>
@@ -33,11 +48,11 @@ dependencies:
33
48
  - 1
34
49
  version: "1.1"
35
50
  type: :runtime
36
- version_requirements: *id001
51
+ version_requirements: *id002
37
52
  - !ruby/object:Gem::Dependency
38
53
  name: i18n
39
54
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
55
+ requirement: &id003 !ruby/object:Gem::Requirement
41
56
  none: false
42
57
  requirements:
43
58
  - - ~>
@@ -49,11 +64,11 @@ dependencies:
49
64
  - 0
50
65
  version: 0.6.0
51
66
  type: :runtime
52
- version_requirements: *id002
67
+ version_requirements: *id003
53
68
  - !ruby/object:Gem::Dependency
54
69
  name: tilt
55
70
  prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
71
+ requirement: &id004 !ruby/object:Gem::Requirement
57
72
  none: false
58
73
  requirements:
59
74
  - - ~>
@@ -65,11 +80,11 @@ dependencies:
65
80
  - 3
66
81
  version: 1.3.3
67
82
  type: :runtime
68
- version_requirements: *id003
83
+ version_requirements: *id004
69
84
  - !ruby/object:Gem::Dependency
70
85
  name: test-spec
71
86
  prerelease: false
72
- requirement: &id004 !ruby/object:Gem::Requirement
87
+ requirement: &id005 !ruby/object:Gem::Requirement
73
88
  none: false
74
89
  requirements:
75
90
  - - ~>
@@ -81,11 +96,11 @@ dependencies:
81
96
  - 0
82
97
  version: 0.9.0
83
98
  type: :development
84
- version_requirements: *id004
99
+ version_requirements: *id005
85
100
  - !ruby/object:Gem::Dependency
86
101
  name: haml
87
102
  prerelease: false
88
- requirement: &id005 !ruby/object:Gem::Requirement
103
+ requirement: &id006 !ruby/object:Gem::Requirement
89
104
  none: false
90
105
  requirements:
91
106
  - - ~>
@@ -97,11 +112,11 @@ dependencies:
97
112
  - 25
98
113
  version: 3.0.25
99
114
  type: :development
100
- version_requirements: *id005
115
+ version_requirements: *id006
101
116
  - !ruby/object:Gem::Dependency
102
117
  name: json
103
118
  prerelease: false
104
- requirement: &id006 !ruby/object:Gem::Requirement
119
+ requirement: &id007 !ruby/object:Gem::Requirement
105
120
  none: false
106
121
  requirements:
107
122
  - - ~>
@@ -112,7 +127,7 @@ dependencies:
112
127
  - 1
113
128
  version: "1.1"
114
129
  type: :development
115
- version_requirements: *id006
130
+ version_requirements: *id007
116
131
  description:
117
132
  email:
118
133
  - pablo@teambox.com
@@ -135,6 +150,9 @@ files:
135
150
  - lib/trimmer/i18n.rb
136
151
  - lib/trimmer/version.rb
137
152
  - test/spec_trimmer_controller.rb
153
+ - test/test_data/complex_templates/bar/deportes.haml
154
+ - test/test_data/complex_templates/foo/manchu.haml
155
+ - test/test_data/complex_templates/foo/mar.haml
138
156
  - test/test_data/locales/ca.yml
139
157
  - test/test_data/locales/en.yml
140
158
  - test/test_data/locales/es.yml
@@ -172,12 +190,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
172
190
  requirements: []
173
191
 
174
192
  rubyforge_project: trimmer
175
- rubygems_version: 1.3.7
193
+ rubygems_version: 1.6.2
176
194
  signing_key:
177
195
  specification_version: 3
178
196
  summary: Rack endpoint to make templates and i18n translations available in javascript
179
197
  test_files:
180
198
  - test/spec_trimmer_controller.rb
199
+ - test/test_data/complex_templates/bar/deportes.haml
200
+ - test/test_data/complex_templates/foo/manchu.haml
201
+ - test/test_data/complex_templates/foo/mar.haml
181
202
  - test/test_data/locales/ca.yml
182
203
  - test/test_data/locales/en.yml
183
204
  - test/test_data/locales/es.yml