i18n-assets 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OTRhZjRlMjIxODI2MzI2NjUwYzQ0M2UwZjQwOTNjYTgwNjlmNzQwZg==
5
+ data.tar.gz: !binary |-
6
+ Yzg4ZWEzZWQ4ZWE0NDZhODZlYzhiZGQwYzQwYWNkODcxYWNjNzExNA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YTE0MGE0NTk4Y2VhOTRjYzE4NDljZmNiNWI3NDE5YzY0MjAxNWEwMGZlMDEy
10
+ ODg4ZDExMmQ1ODY0NmVjYzk4MzJhYjQ3OGMwMmVkN2M0YTU5ZjZmM2U5NGIz
11
+ ZTJiYWQ2YjhkMjEwY2QyZDFhYmVlN2M5MmE2OWQyZTVmNjUzNmY=
12
+ data.tar.gz: !binary |-
13
+ OGExYWFmMTA1NWIyZTI1NmM3OGJkZDBiMDRlY2YwZjAzY2RmODQ0MTdhNzU3
14
+ MjhkNDhiMDUzOTYwNjRjODViMjAwNWRmZDQ1YTgwYjc1ODFhNzIzZDY3ZDNk
15
+ MTZkMzAzNTc5NDM5MTFhNDQ1NjJjMzc0ZDIwNWJiZDkwZWNmOTA=
data/.gitignore ADDED
@@ -0,0 +1,24 @@
1
+ *.rbc
2
+ capybara-*.html
3
+ .rspec
4
+ /log
5
+ /tmp
6
+ /db/*.sqlite3
7
+ /public/system
8
+ /coverage/
9
+ /spec/tmp
10
+ **.orig
11
+ rerun.txt
12
+ pickle-email-*.html
13
+ config/initializers/secret_token.rb
14
+ config/secrets.yml
15
+
16
+ ## Environment normalisation:
17
+ /.bundle
18
+ /vendor/bundle
19
+
20
+ # these should all be checked in to normalise the environment:
21
+ # Gemfile.lock, .ruby-version, .ruby-gemset
22
+
23
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
24
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in i18n-assets.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Maxim Gladkov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # I18n assets
2
+
3
+ Ever wanted to use rails localization helpers inside your assets? Your dream just came true!
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'i18n-assets'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install i18n-assets
18
+
19
+ ## Usage
20
+
21
+ Just add `.erb` extension to your `.js` and `.css` files and use standard I18n helpers inside your files.
22
+
23
+ On assets precompilation localized versions of your files will be generated.
24
+
25
+ ## Example
26
+
27
+ You can check an example usage here: https://github.com/maximgladkov/localized_assets_precompilation_example_app
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it ( http://github.com/<my-github-username>/i18n-assets/fork )
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'i18n/assets/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "i18n-assets"
8
+ spec.version = I18n::Assets::VERSION
9
+ spec.authors = ["Maxim Gladkov"]
10
+ spec.email = ["contact@maximgladkov.com"]
11
+ spec.summary = %q{Rails assets localization made easy}
12
+ spec.description = %q{Ever wanted to use rails localization helpers inside your assets? Your dream just came true!}
13
+ spec.homepage = "https://github.com/maximgladkov/i18n-assets"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency 'sprockets', "~> 2.2.2"
25
+ end
@@ -0,0 +1,8 @@
1
+ require "i18n/assets/version"
2
+ require "i18n/assets/manifest"
3
+
4
+ module I18n
5
+ module Assets
6
+
7
+ end
8
+ end
@@ -0,0 +1,89 @@
1
+ require 'sprockets'
2
+
3
+ module Sprockets
4
+ LOCALIZABLE_ASSETS_REGEX = /\.(?:js|css)/
5
+
6
+ module Helpers
7
+ module RailsHelper
8
+
9
+ # add locale to asset_prefix, if assets compiled
10
+ def asset_prefix_with_locale
11
+ if Rails.env.development?
12
+ Rails.application.config.assets.prefix
13
+ else
14
+ "#{ Rails.application.config.assets.prefix }/#{ I18n.locale }"
15
+ end
16
+ end
17
+
18
+ alias_method :asset_path_without_locale, :asset_path
19
+
20
+ # prevent asset from caching by adding timestamp
21
+ def asset_path(source, options = {})
22
+ assert_prefix = asset_prefix_with_locale
23
+ asset_path = asset_path_without_locale(source, options)
24
+
25
+ if asset_path =~ LOCALIZABLE_ASSETS_REGEX
26
+ separator = asset_path =~ /\?/ ? '&' : '?'
27
+ "#{ asset_path }#{ separator }locale=#{ I18n.locale }&t=#{ Time.now.to_i }"
28
+ else
29
+ asset_path
30
+ end
31
+ end
32
+
33
+ alias_method :path_to_asset, :asset_path
34
+
35
+ end
36
+ end
37
+
38
+ class StaticCompiler
39
+
40
+ alias_method :compile_without_manifest, :compile
41
+
42
+ # run compile for each available locale
43
+ def compile(*paths)
44
+ I18n.available_locales.each do |locale|
45
+ env.logger.info "Compiling assets for #{ locale.upcase } locale..."
46
+
47
+ I18n.locale = locale
48
+
49
+ manifest = Sprockets::Manifest.new(env, target)
50
+ manifest.compile *paths
51
+ end
52
+
53
+ I18n.locale = I18n.default_locale
54
+ end
55
+
56
+ end
57
+
58
+ class Asset
59
+
60
+ alias_method :digest_path_without_locale, :digest_path
61
+
62
+ # add locale for css and js files
63
+ def digest_path
64
+ digest_path = digest_path_without_locale
65
+ if digest_path =~ LOCALIZABLE_ASSETS_REGEX
66
+ "#{ I18n.locale }/#{ digest_path }"
67
+ else
68
+ digest_path
69
+ end
70
+ end
71
+
72
+ end
73
+
74
+ class Base
75
+
76
+ # set locale for asset request
77
+ def call(env)
78
+ I18n.locale = Rack::Request.new(env).params['locale'] || I18n.default_locale
79
+ super
80
+ end
81
+
82
+ # add locale to assets cache key
83
+ def cache_key_for(path, options)
84
+ "#{path}:#{I18n.locale}:#{options[:bundle] ? '1' : '0'}"
85
+ end
86
+
87
+ end
88
+
89
+ end
@@ -0,0 +1,5 @@
1
+ module I18n
2
+ module Assets
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: i18n-assets
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Maxim Gladkov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sprockets
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 2.2.2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.2.2
55
+ description: Ever wanted to use rails localization helpers inside your assets? Your
56
+ dream just came true!
57
+ email:
58
+ - contact@maximgladkov.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - i18n-assets.gemspec
69
+ - lib/i18n/assets.rb
70
+ - lib/i18n/assets/manifest.rb
71
+ - lib/i18n/assets/version.rb
72
+ homepage: https://github.com/maximgladkov/i18n-assets
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.2.2
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Rails assets localization made easy
96
+ test_files: []
97
+ has_rdoc: