trimmer 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,24 @@
1
+ rvm:
2
+ - 1.9.3
3
+
4
+ branches:
5
+ only:
6
+ - master
7
+
8
+ bundler_args: --deployment
9
+
10
+ git:
11
+ depth: 10
12
+
13
+ env:
14
+ global:
15
+ matrix:
16
+ - CMD='bundle exec ruby test/spec_trimmer_controller.rb'
17
+
18
+ notifications:
19
+ email: false
20
+
21
+ script: "$CMD"
22
+
23
+ source_key: "LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlFcEFJQkFBS0NBUUVBck9BYXE4eVBiV0Zobng2ajlxUGhhdEUrVGh4MXRodHc4RzdxTExNZlhXZk9oeWJxCmtuYUlJcFovS00xd1VBa1l2d2diTS9BWWM2SDluNlhzcWR4SEZzeHVOSEJzTlZNMmRHN1FmN252c0N5aXBIWFAKSWRhUWlmeWVYNEx1OTFBUjdVQy9OVlBBWUhSMjVqNzBJQS9YbUlqSHBNRmZpVGdjOFlVVWkzcjZpTUw4Q1JlZwovRmMxZVBvdnBjMkZBRUc0ZmYweFpsSjVjREsraXRwVlFxZlhMMWkvV2c3VWEvWWx4YzNRZ25wdzNyektMN3VJCmg2Slo5aUlUL3N5OGRPUGg4cVVRMWtLT1RjZEtDNExDYkJsMEQ1bzNxcVRaWitaeTZNTFJhRjhVZitVRkxEQkkKQURvQUtZKzlLYTNIekVlOGYrNnlaR3U2RWFZZE1Cd3RrNUJVbFFJREFRQUJBb0lCQVFDV3M2b3NkOS9VZjE3bApvb1ZXM2RnRkVURmFVSThBMkgwazY5dXlhZGYreWg2TlRReVI3MGlQdGxoVmpubkpHNVQ1K3l3VG84cjlDb3NaCklFRG1kb04yU1hJTXZyQmw4QXQ1aHB5MXE3WmFBeDhwZFJYREx0UERwbmU5VlZ2U05uZmFObVk1SzdCNXBTMTkKWEFYZTZWQ054VGNjMWdIZGtoQVJMMjBRaG4xZXVBUzQ3WXR4NE0wQ1FGYWZn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EROVwp4TDdjZEtXQk9iQ0loWUI2NFltSjRxY3VKUDJTVTc2SHBpbmFFay9mT2cvZWgyWG80eFQyNThOZVNGY045VnoyCnp4STh0eWtDZ1lCeEFNb09nSXFWU1VySmJPRDBCNmtpMlpyTGdoVk5zVnltTk42WkRiZlNadmkxRjMrOG5VeWoKUUVsV3JUTzVQaGRTdEZxR3h5RHMxbDVCTUtQdXJQWHBGSGFkL2xxNDhhRURFbFN0WHp4eVE0d1lQSXhsVjNsQQpONFhnMUR4cWZUdzFCSU5wS2grVHh1WUFqSEZFTTNRTzZzK0RaaDI1MUw1KzBqOGYvaHFmNVE9PQotLS0tLUVORCBSU0EgUFJJVkFURSBLRVktLS0tLQo="
24
+
data/History.md CHANGED
@@ -20,3 +20,8 @@
20
20
 
21
21
  * Fix /trimmer/en/{translations/templates}.js routes
22
22
 
23
+ * Version 0.0.6
24
+ #####Changed
25
+
26
+ * Allow further filtering of keys via :allowed_keys param
27
+
@@ -26,13 +26,13 @@ module Trimmer
26
26
  case request.path
27
27
  when /\/trimmer(\/([^\/]+))*\/translations\.([js]+)$/
28
28
  validate_locale($2) if $2 || ($2 && $2.empty?)
29
- response = translations($2, $3)
29
+ response = translations($2, $3, request.params)
30
30
  when /\/trimmer\/([^\/]+)\/templates\.([js]+)$/
31
31
  validate_locale($1)
32
32
  response = templates($1, $2)
33
33
  when /\/trimmer\/([^\.|\/]+)\.([js]+)$/
34
34
  validate_locale($1)
35
- response = resources($1, $2)
35
+ response = resources($1, $2, request.params)
36
36
  else
37
37
  response = @app.call(env)
38
38
  end
@@ -42,18 +42,36 @@ module Trimmer
42
42
 
43
43
  protected
44
44
 
45
+ ##
46
+ # Allow passing 'allowed_keys' parameter to filter returned keys.
47
+ #
48
+ # Note: Will only ever return keys that have already been allowed in the initializer.
49
+ #
50
+ # @param [Hash] Request parameters
51
+ #
52
+ # @return [Array] List of allowed keys (either those configured or filtered list)
53
+ def filter_by_param(params={})
54
+ if (sub_keys = params["allowed_keys"])
55
+ sub_keys.split(',').select do |key|
56
+ self.allowed_keys.any? {|allowed_key| key.start_with?(allowed_key)}
57
+ end
58
+ else
59
+ self.allowed_keys
60
+ end
61
+ end
62
+
45
63
  def templates(locale, ext)
46
64
  [200, {'Content-Type' => 'text/javascript'}, [templates_to_js(locale)]]
47
65
  end
48
66
 
49
67
 
50
- def translations(locale, ext)
51
- [200, {'Content-Type' => 'text/javascript'}, [translations_to_js(:locale => locale, :only => allowed_keys)]]
68
+ def translations(locale, ext, params={})
69
+ [200, {'Content-Type' => 'text/javascript'}, [translations_to_js(:locale => locale, :only => filter_by_param(params))]]
52
70
  end
53
71
 
54
72
  # Exports templates and translations in a single request
55
- def resources(locale, ext)
56
- opts = {:only => allowed_keys}
73
+ def resources(locale, ext, params={})
74
+ opts = {:only => filter_by_param(params)}
57
75
  opts[:locale] = locale if locale && !locale.empty?
58
76
 
59
77
  response = translations_to_js(opts)
@@ -1,3 +1,3 @@
1
1
  module Trimmer
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+
3
+ bundle install --deployment
4
+
5
+ echo "Running specs..."
6
+ bundle exec ruby test/spec_trimmer_controller.rb
@@ -14,12 +14,17 @@ context Trimmer::Controller do
14
14
 
15
15
  @def_resources_en = <<-VALUE.strip
16
16
  if(typeof(I18n) == 'undefined') { I18n = {}; };
17
- I18n.translations = ({\"foo\":{\"trimmer\":\"trimmer\"}});
17
+ I18n.translations = ({\"foo\":{\"trimmer\":\"trimmer\"},\"bif\":{\"key\":\"value\"}});
18
18
  Templates = ({"foo":{"bar":"<span>trimmer</span>\\n"}});
19
19
  VALUE
20
20
 
21
21
  @def_translations_en = <<-VALUE.strip
22
22
  if(typeof(I18n) == 'undefined') { I18n = {}; };
23
+ I18n.translations = ({\"foo\":{\"trimmer\":\"trimmer\"},\"bif\":{\"key\":\"value\"}});
24
+ VALUE
25
+
26
+ @def_translations_en_filtered = <<-VALUE.strip
27
+ if(typeof(I18n) == 'undefined') { I18n = {}; };
23
28
  I18n.translations = ({\"foo\":{\"trimmer\":\"trimmer\"}});
24
29
  VALUE
25
30
 
@@ -33,13 +38,13 @@ VALUE
33
38
 
34
39
  @def_resources_es = <<-VALUE.strip
35
40
  if(typeof(I18n) == 'undefined') { I18n = {}; };
36
- I18n.translations = ({\"foo\":{\"trimmer\":\"recortadora\"}});
41
+ I18n.translations = ({\"foo\":{\"trimmer\":\"recortadora\"},\"bif\":{\"key\":\"valor\"}});
37
42
  Templates = ({"foo":{"bar":"<span>recortadora</span>\\n"}});
38
43
  VALUE
39
44
 
40
45
  @def_translations_es = <<-VALUE.strip
41
46
  if(typeof(I18n) == 'undefined') { I18n = {}; };
42
- I18n.translations = ({\"foo\":{\"trimmer\":\"recortadora\"}});
47
+ I18n.translations = ({\"foo\":{\"trimmer\":\"recortadora\"},\"bif\":{\"key\":\"valor\"}});
43
48
  VALUE
44
49
 
45
50
  @def_templates_es = <<-VALUE.strip
@@ -48,7 +53,7 @@ VALUE
48
53
 
49
54
  @def_resources_ca = <<-VALUE.strip
50
55
  if(typeof(I18n) == 'undefined') { I18n = {}; };
51
- I18n.translations = ({\"foo\":{\"trimmer\":\"trimmer\"}});
56
+ I18n.translations = ({\"foo\":{\"trimmer\":\"trimmer\"},\"bif\":{\"key\":\"value\"}});
52
57
  Templates = ({"foo":{"bar":"<span>recortadora</span>\\n"}});
53
58
  VALUE
54
59
 
@@ -139,12 +144,17 @@ VALUE
139
144
 
140
145
  specify "should filter translations if allowed_keys option set on Trimmer::Controller instance" do
141
146
  request(:path=>'/trimmer/en/translations.js', :allowed_keys => "*.baz").body.should.equal("if(typeof(I18n) == 'undefined') { I18n = {}; };\nI18n.translations = ({});")
142
- request(:path=>'/trimmer/en/translations.js', :allowed_keys => "*.foo").body.should.equal(@def_translations_en)
147
+ request(:path=>'/trimmer/en/translations.js', :allowed_keys => "*.foo").body.should.equal(@def_translations_en_filtered)
148
+ request(:path=>'/trimmer/en/translations.js', :allowed_keys => ["*.foo", "*.bif"]).body.should.equal(@def_translations_en)
149
+ end
150
+
151
+ specify "should further filter translations if allowed_keys is passed as a parameter" do
152
+ request(:path=>'/trimmer/en/translations.js?allowed_keys=*.foo', :allowed_keys => ["*.bif", "*.foo"]).body.should.equal(@def_translations_en_filtered)
143
153
  end
144
154
 
145
155
  specify "should render all translations if no locale" do
146
156
  request(:path=>'/trimmer/translations.js').body.should.equal(<<-RESP.strip)
147
- if(typeof(I18n) == 'undefined') { I18n = {}; };\nI18n.translations = ({\"foo\":{\"trimmer\":\"trimmer\"},\"en\":{\"foo\":{\"trimmer\":\"trimmer\"}},\"es\":{\"foo\":{\"trimmer\":\"recortadora\"}}});
157
+ if(typeof(I18n) == 'undefined') { I18n = {}; };\nI18n.translations = ({\"foo\":{\"trimmer\":\"trimmer\"},\"bif\":{\"key\":\"value\"},\"en\":{\"foo\":{\"trimmer\":\"trimmer\"},\"bif\":{\"key\":\"value\"}},\"es\":{\"foo\":{\"trimmer\":\"recortadora\"},\"bif\":{\"key\":\"valor\"}}});
148
158
  RESP
149
159
  end
150
160
 
@@ -1,3 +1,5 @@
1
1
  en:
2
2
  foo:
3
3
  trimmer: "trimmer"
4
+ bif:
5
+ key: "value"
@@ -1,3 +1,5 @@
1
1
  es:
2
2
  foo:
3
3
  trimmer: "recortadora"
4
+ bif:
5
+ key: "valor"
@@ -4,6 +4,7 @@ require "trimmer/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "trimmer"
7
+ s.license = "MIT"
7
8
  s.version = Trimmer::VERSION
8
9
  s.platform = Gem::Platform::RUBY
9
10
  s.authors = ["Pablo Villalba", "Saimon Moore"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trimmer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-07-17 00:00:00.000000000 Z
13
+ date: 2013-07-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -133,7 +133,9 @@ extensions: []
133
133
  extra_rdoc_files: []
134
134
  files:
135
135
  - .gitignore
136
+ - .travis.yml
136
137
  - Gemfile
138
+ - Gemfile.lock
137
139
  - History.md
138
140
  - README.md
139
141
  - Rakefile
@@ -142,6 +144,7 @@ files:
142
144
  - lib/trimmer/core.rb
143
145
  - lib/trimmer/i18n.rb
144
146
  - lib/trimmer/version.rb
147
+ - script/jenkins
145
148
  - test/spec_trimmer_controller.rb
146
149
  - test/test_data/complex_templates/bar/deportes.haml
147
150
  - test/test_data/complex_templates/foo/manchu.haml
@@ -154,7 +157,8 @@ files:
154
157
  - test/test_helper.rb
155
158
  - trimmer.gemspec
156
159
  homepage: https://github.com/teambox/trimmer
157
- licenses: []
160
+ licenses:
161
+ - MIT
158
162
  post_install_message:
159
163
  rdoc_options: []
160
164
  require_paths: