mygengo_string 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "jeweler", "~> 1.6.2"
10
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,15 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.6.2)
6
+ bundler (~> 1.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rake (0.8.3)
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ jeweler (~> 1.6.2)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Ilya Katz
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = mygengo_string
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to mygengo_string
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Ilya Katz. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,52 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ gem.name = "mygengo_string"
17
+ gem.homepage = "http://github.com/ilyakatz/mygengo_string"
18
+ gem.license = "MIT"
19
+ gem.summary = %Q{A rake task to download locale files from mygengo account}
20
+ gem.description = %Q{A rake task to download locale files from mygengo account}
21
+ gem.email = "ilyakatz@gmail.com"
22
+ gem.authors = ["Ilya Katz"]
23
+ # dependencies defined in Gemfile
24
+ end
25
+ Jeweler::RubygemsDotOrgTasks.new
26
+
27
+ #require 'rake/testtask'
28
+ #Rake::TestTask.new(:test) do |test|
29
+ # test.libs << 'lib' << 'test'
30
+ # test.pattern = 'test/**/test_*.rb'
31
+ # test.verbose = true
32
+ #end
33
+ #
34
+ #require 'rcov/rcovtask'
35
+ #Rcov::RcovTask.new do |test|
36
+ # test.libs << 'test'
37
+ # test.pattern = 'test/**/test_*.rb'
38
+ # test.verbose = true
39
+ # test.rcov_opts << '--exclude "gems/*"'
40
+ #end
41
+ #
42
+ #task :default => :test
43
+ #
44
+ #require 'rake/rdoctask'
45
+ #Rake::RDocTask.new do |rdoc|
46
+ # version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
+ #
48
+ # rdoc.rdoc_dir = 'rdoc'
49
+ # rdoc.title = "mygengo_string #{version}"
50
+ # rdoc.rdoc_files.include('README*')
51
+ # rdoc.rdoc_files.include('lib/**/*.rb')
52
+ #end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,58 @@
1
+ class MyGengoLocaleDownloader
2
+
3
+ require "zip/zip"
4
+
5
+ def initialize(token, project, requested_language="en", tmp_dir="tmp/locale")
6
+ @requested_language=requested_language
7
+ @dir = tmp_dir
8
+ @locale_dir = "#{Rails.root}/config/locales"
9
+ @token=token
10
+ @project = project
11
+
12
+ Dir.mkdir(@dir) if !Dir.exists?(@dir)
13
+ end
14
+
15
+ def download_locale_files
16
+ res = download_zip_file(@project, @requested_language, @token)
17
+ requested_file_name = save_to_tmp_file(res)
18
+ unzip_files(requested_file_name, @locale_dir)
19
+ end
20
+
21
+ protected
22
+
23
+ def save_to_tmp_file(res)
24
+ requested_file_name="#{@dir}/#{@requested_language}.zip"
25
+ open("#{requested_file_name}", "wb") { |file|
26
+ file.write(res.body)
27
+ }
28
+ requested_file_name
29
+ end
30
+
31
+
32
+ def download_zip_file(project, requested_language, token)
33
+ url = URI.parse("https://mygengo.com/string/p/#{project}/export/language/#{requested_language}/#{token}")
34
+ req = Net::HTTP::Get.new(url.path)
35
+ res = Net::HTTP.start(url.host, url.port, :use_ssl=>true) { |http|
36
+ http.request(req)
37
+ }
38
+ res
39
+ end
40
+
41
+ def unzip_files(requested_file_name, locale_dir)
42
+ Zip::ZipFile.foreach(requested_file_name) { |zipfile|
43
+ zipfile.to_s =~ /(.{2})\/(.+).yaml/
44
+ language = $1
45
+ file = $2
46
+ if language and file
47
+ name = "#{locale_dir}/#{file}.#{language}.yml"
48
+ File.delete(name) if File.exists?(name)
49
+ zipfile.extract(name)
50
+ puts "extracted #{name}"
51
+ else
52
+ puts "unexpected name format"
53
+ end
54
+
55
+ }
56
+ end
57
+
58
+ end
File without changes
@@ -0,0 +1,51 @@
1
+ require 'my_gengo_locale_downloader'
2
+
3
+ #Add a mygengo.yml file to your #{Rails.root.to_s}/config directory with the following lines
4
+ #development:
5
+ # token: TOKEN
6
+ # project: PROJECT_NAME
7
+ #
8
+ #You man optionally add default languages that you would be pulling most often
9
+ #development:
10
+ # token: TOKEN
11
+ # project: PROJECT_NAME
12
+ # languages: en,ru
13
+ #
14
+ #After this is configured you can run the rake task
15
+ # rake mygengo:locale
16
+ #
17
+ #In addition, if you would like to pull down only specific languages
18
+ #
19
+ #rake mygengo:locale languages=ru
20
+
21
+ namespace :mygengo do
22
+ desc "Download locale files from mygengo string account"
23
+ task :locale do
24
+ config_file = "#{Rails.root.to_s}/config/mygengo.yml"
25
+
26
+ opts = YAML.load(ERB.new(File.read(config_file)).result)[Rails.env]
27
+ token=opts["token"]
28
+ project=opts["project"]
29
+ langs=opts["languages"] || "en"
30
+
31
+ if token.nil?
32
+ puts "!!!Please provide token in #{config_file}"
33
+ elsif project.nil?
34
+ puts "!!!Please provide project name in #{config_file}"
35
+ else
36
+ if ENV['languages']
37
+ languages = ENV['languages']
38
+ elsif langs
39
+ languages = langs
40
+ else
41
+ languages = "en"
42
+ end
43
+ languages.split(",").each do |language|
44
+ gengo = MyGengoLocaleDownloader.new(token, project, language)
45
+ gengo.download_locale_files
46
+ end
47
+ end
48
+
49
+ end
50
+ end
51
+
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'mygengo_string'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestMygengoString < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mygengo_string
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 0
10
+ version: 0.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Ilya Katz
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-06-26 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ hash: 11
28
+ segments:
29
+ - 1
30
+ - 6
31
+ - 2
32
+ version: 1.6.2
33
+ type: :development
34
+ name: jeweler
35
+ prerelease: false
36
+ version_requirements: *id001
37
+ description: A rake task to download locale files from mygengo account
38
+ email: ilyakatz@gmail.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files:
44
+ - LICENSE.txt
45
+ - README.rdoc
46
+ files:
47
+ - .document
48
+ - Gemfile
49
+ - Gemfile.lock
50
+ - LICENSE.txt
51
+ - README.rdoc
52
+ - Rakefile
53
+ - VERSION
54
+ - lib/my_gengo_locale_downloader.rb
55
+ - lib/mygengo_string.rb
56
+ - lib/tasks/mygengo.rake
57
+ - test/helper.rb
58
+ - test/test_mygengo_string.rb
59
+ has_rdoc: true
60
+ homepage: http://github.com/ilyakatz/mygengo_string
61
+ licenses:
62
+ - MIT
63
+ post_install_message:
64
+ rdoc_options: []
65
+
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ hash: 3
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ requirements: []
87
+
88
+ rubyforge_project:
89
+ rubygems_version: 1.3.7
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: A rake task to download locale files from mygengo account
93
+ test_files: []
94
+