polyglot-sync 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +11 -42
  4. data/Rakefile +27 -7
  5. data/app/assets/config/polyglot_sync_manifest.js +1 -0
  6. data/app/assets/stylesheets/polyglot/sync/application.css +15 -0
  7. data/app/controllers/polyglot/sync/application_controller.rb +7 -0
  8. data/app/controllers/polyglot/sync/hooks_controller.rb +15 -0
  9. data/app/helpers/polyglot/sync/application_helper.rb +6 -0
  10. data/app/jobs/polyglot/sync/application_job.rb +6 -0
  11. data/app/mailers/polyglot/sync/application_mailer.rb +8 -0
  12. data/app/models/polyglot/sync/application_record.rb +7 -0
  13. data/app/services/AwsService.rb +52 -0
  14. data/app/services/ConverterService.rb +48 -0
  15. data/app/views/layouts/polyglot/sync/application.html.erb +15 -0
  16. data/config/routes.rb +4 -0
  17. data/lib/generators/polyglot_sync/install_generator.rb +12 -0
  18. data/lib/polyglot/sync.rb +1 -2
  19. data/lib/polyglot/sync/engine.rb +13 -0
  20. data/lib/polyglot/sync/version.rb +1 -1
  21. data/lib/tasks/polyglot/export.rake +11 -0
  22. data/lib/tasks/polyglot/import.rake +13 -0
  23. metadata +52 -23
  24. data/.gitignore +0 -11
  25. data/.rspec +0 -3
  26. data/.travis.yml +0 -7
  27. data/Gemfile +0 -4
  28. data/Gemfile.lock +0 -91
  29. data/LICENSE.txt +0 -21
  30. data/bin/console +0 -14
  31. data/bin/setup +0 -8
  32. data/lib/generators/polyglot/install_generator.rb +0 -14
  33. data/lib/polyglot/aws_service.rb +0 -57
  34. data/lib/polyglot/json_to_yml_converter.rb +0 -36
  35. data/lib/polyglot/railtie.rb +0 -13
  36. data/lib/polyglot/tasks/export.rake +0 -17
  37. data/lib/polyglot/tasks/import.rake +0 -13
  38. data/lib/polyglot/yml_to_json_converter.rb +0 -41
  39. data/polyglot-sync.gemspec +0 -37
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 58f13a85389aed49af07bfe23cf37b9958e4cea157f63cc0a5afc256df3eb3e0
4
- data.tar.gz: f516a5c9184c26a804d9ba71de8a9f62c442ae698e38759e087196f327725108
3
+ metadata.gz: 48e9e187f2ae086afa07b772ecc9e29b80177067b62b7c1bf1d53c0e14e12ed8
4
+ data.tar.gz: 1414db725a3d781154c08cab58f61c80181635c483874436b25daddff2ce6fb4
5
5
  SHA512:
6
- metadata.gz: cb1fc6427f8ddbbc8c7d23ad198708f920e88d0d607d3b9e86cfc8bad011a0c27f32b20e927575f4cd5258937446aad1238db9aecdc9eae5af8d4f25be0b346a
7
- data.tar.gz: 484fc42fd6cb9862b45dcdb2a3b5b3d67016caedbf7f028b40e68458b5246fa31b14b357a646e9cab9e1e02cfcf47a55730080ff0069e08e0886dec6a4848fe3
6
+ metadata.gz: 7c7cad7cabcc405f190ee2845a3d5d93bb535d6315e95fbaa6b521824d81364cfb9d0e781250e3fd998590260e7f28f2bc67b1b430be4179b4b560d4162ef201
7
+ data.tar.gz: 2f2d0178948b82f5a60cd0b89fa842cb2fb7d389940d5c6ae5d55f40cf728a0c23b75eb71fa5e773c5cd7354b3fd0f949cb07b574007af3d5e58b03be78978a2
@@ -0,0 +1,20 @@
1
+ Copyright 2020 Sian Stone
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.md CHANGED
@@ -1,9 +1,10 @@
1
- # Polyglot-Sync
1
+ # Polyglot::Sync
2
+ Short description and motivation.
2
3
 
3
- A gem to sync translation strings between your Rails backend & the Polyglot API.
4
+ ## Usage
5
+ How to use my plugin.
4
6
 
5
7
  ## Installation
6
-
7
8
  Add this line to your application's Gemfile:
8
9
 
9
10
  ```ruby
@@ -11,49 +12,17 @@ gem 'polyglot-sync'
11
12
  ```
12
13
 
13
14
  And then execute:
14
-
15
- $ bundle
15
+ ```bash
16
+ $ bundle
17
+ ```
16
18
 
17
19
  Or install it yourself as:
18
-
19
- $ gem install polyglot-sync
20
-
21
- To run the generator:
22
-
23
- $ rails g polyglot:install
24
-
25
- Or create the polyglot_sync.rb initializer file yourself, containing the following:
26
-
27
- Polyglot::Sync.configure do |config|
28
- config.aws_s3_bucket_name = 'BUCKET NAME'
29
-
30
- config.project_slug = 'PROJECT SLUG'
31
-
32
- config.organization_secret_key = 'SECRET KEY'
33
-
34
- config.aws_cloudfront_host = 'CLOUDFRONT HOST'
35
-
36
- config.aws_region = 'AWS REGION'
37
- end
38
-
39
- If you do not know the details of your AWS configuration for the Polyglot API, you will need to contact Gaspard+Bruno directly.
40
-
41
- ## Usage
42
-
43
- To download existing project strings from your Polyglot API dashboard, run the following command in your terminal:
44
-
45
- $ rake sync:import
46
-
47
- To upload the .yml files located in config/locales, run the following command in your terminal:
48
-
49
- $ rake sync:export
50
-
51
- Be aware that importing or exporting will override alternative strings at the destination.
20
+ ```bash
21
+ $ gem install polyglot-sync
22
+ ```
52
23
 
53
24
  ## Contributing
54
-
55
- Bug reports and pull requests are welcome on GitHub at https://github.com/Gaspard-Bruno/polyglot-sync.
25
+ Contribution directions go here.
56
26
 
57
27
  ## License
58
-
59
28
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1,12 +1,32 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
3
6
 
4
- require 'polyglot/sync'
7
+ require 'rdoc/task'
5
8
 
6
- RSpec::Core::RakeTask.new(:spec)
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Polyglot::Sync'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
7
16
 
8
- task :default => :spec
17
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
18
+ load 'rails/tasks/engine.rake'
9
19
 
10
- path = File.expand_path(__dir__)
11
- Dir.glob("#{path}/lib/polyglot/tasks/*.rake").each { |f| import f }
20
+ load 'rails/tasks/statistics.rake'
12
21
 
22
+ require 'bundler/gem_tasks'
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'test'
28
+ t.pattern = 'test/**/*_test.rb'
29
+ t.verbose = false
30
+ end
31
+
32
+ task default: :test
@@ -0,0 +1 @@
1
+ //= link_directory ../stylesheets/polyglot/sync .css
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,7 @@
1
+ module Polyglot
2
+ module Sync
3
+ class ApplicationController < ::ApplicationController
4
+
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ require_dependency "polyglot/sync/application_controller"
2
+
3
+ module Polyglot
4
+ module Sync
5
+ class HooksController < ApplicationController
6
+ def aws_string_update
7
+ aws_service = AwsService.new
8
+ converter = ConverterService.new(aws_service.json)
9
+ converter.parse_json_to_yml
10
+
11
+ render :json => { :status => "OK" }
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,6 @@
1
+ module Polyglot
2
+ module Sync
3
+ module ApplicationHelper
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Polyglot
2
+ module Sync
3
+ class ApplicationJob < ActiveJob::Base
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ module Polyglot
2
+ module Sync
3
+ class ApplicationMailer < ActionMailer::Base
4
+ default from: 'from@example.com'
5
+ layout 'mailer'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module Polyglot
2
+ module Sync
3
+ class ApplicationRecord < ActiveRecord::Base
4
+ self.abstract_class = true
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,52 @@
1
+ require 'net/http'
2
+ require 'json'
3
+
4
+ class AwsService
5
+ attr_reader :json
6
+ attr_reader :get_path
7
+ def initialize
8
+ # @aws_s3_bucket_name = 'polyglot-assets'
9
+ @aws_s3_bucket_name = Polyglot::Sync.configuration.aws_s3_bucket_name
10
+
11
+ # @aws_cloudfront_host = 'd8wlqn7pvlrac.cloudfront.net'
12
+ @aws_cloudfront_host = Polyglot::Sync.configuration.aws_cloudfront_host
13
+
14
+ # @organization_secret_key = 'c4ca4238a0b923820dcc509a6f75849b'
15
+ @organization_secret_key = Polyglot::Sync.configuration.organization_secret_key
16
+
17
+ # @project_slug = 'polyglot'
18
+ @project_slug = Polyglot::Sync.configuration.project_slug
19
+
20
+ # @aws_region = 'eu-west-1'
21
+ @aws_region = Polyglot::Sync.configuration.aws_region
22
+
23
+ @json = fetch_project_json
24
+ end
25
+
26
+ def fetch_project_json
27
+ # @get_path = "https://#{@aws_cloudfront_host}/#{@organization_secret_key}/#{@project_slug}/all.json"
28
+ @get_path = "https://#{@aws_s3_bucket_name}.s3-#{@aws_region}.amazonaws.com/#{@organization_secret_key}/#{@project_slug}/all.json"
29
+ uri = URI(@get_path)
30
+ result = Net::HTTP.get(uri)
31
+
32
+ json = JSON.parse(result)
33
+ end
34
+
35
+ def publish_project_json(json)
36
+ path_to_file = "all.json"
37
+
38
+ File.delete(path_to_file) if File.exist?(path_to_file)
39
+ json_file = File.new(path_to_file, 'a')
40
+ json_file.write(json)
41
+ json_file.close
42
+
43
+ s3 = Aws::S3::Resource.new(region: @aws_region)
44
+
45
+ obj = s3.bucket(@aws_s3_bucket_name).object("#{@organization_secret_key}/#{@project_slug}/#{path_to_file}")
46
+
47
+ obj.upload_file(path_to_file, content_type: 'application/json')
48
+
49
+ File.delete(path_to_file) if File.exist?(path_to_file)
50
+
51
+ end
52
+ end
@@ -0,0 +1,48 @@
1
+ class ConverterService
2
+ attr_reader :json_file
3
+ attr_reader :locales_path
4
+
5
+ def initialize(json_file={})
6
+ @locales_path = get_file_path
7
+ @json_file = json_file
8
+ end
9
+
10
+ def get_file_path
11
+ if Kernel.const_defined? 'Rails'
12
+ File.join(Rails.root, 'config/locales')
13
+ else
14
+ raise 'I need Rails to run!'
15
+ end
16
+ end
17
+
18
+ # method for I M P O R T I N G
19
+ def parse_json_to_yml # creates individual ymls for each locale
20
+ locale_arr = []
21
+ @json_file.keys.each { |key| locale_arr << {key => @json_file[key]} }
22
+
23
+ locale_arr.each do |locale|
24
+ y_file = File.open("#{@locales_path}/#{locale.keys.first}.yml", 'w')
25
+ y_file.write(YAML.dump(locale))
26
+ y_file.close
27
+ end
28
+ end
29
+
30
+
31
+ # methods for E X P O R T I N G
32
+ def parse_yml_to_json(yml_file)
33
+ j_file = YAML.load_file(File.open("#{yml_file}", 'r'))
34
+ end
35
+
36
+ def iterate_locale_dir # returns full json of all ymls
37
+ Dir.foreach(@locales_path) do |filename|
38
+
39
+ next if filename == '.' or filename == '..' or filename.include? "devise"
40
+
41
+ parsed_yml = parse_yml_to_json("#{@locales_path}/#{filename}")
42
+ key = parsed_yml.keys.first
43
+
44
+ @json_file[key] = parsed_yml[key]
45
+ end
46
+ @json_file = @json_file.to_json
47
+ end
48
+ end
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Polyglot sync</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+
8
+ <%= stylesheet_link_tag "polyglot/sync/application", media: "all" %>
9
+ </head>
10
+ <body>
11
+
12
+ <%= yield %>
13
+
14
+ </body>
15
+ </html>
@@ -0,0 +1,4 @@
1
+ Polyglot::Sync::Engine.routes.draw do
2
+ post 'aws_string_update' => 'hooks#aws_string_update', as: 'aws_string_update'
3
+
4
+ end
@@ -0,0 +1,12 @@
1
+ module PolyglotSync
2
+ class InstallGenerator < Rails::Generators::Base
3
+ source_root File.expand_path("../../templates", __FILE__)
4
+ desc "Creates initializer for polyglot-sync"
5
+
6
+ def copy_initializer
7
+ template "polyglot_sync_initializer.rb", "config/initializers/polyglot_sync.rb"
8
+
9
+ puts "Install complete!"
10
+ end
11
+ end
12
+ end
@@ -4,9 +4,8 @@ require 'fileutils'
4
4
  require 'pry'
5
5
 
6
6
  require "polyglot/sync/version"
7
- require "polyglot/json_to_yml_converter.rb"
8
7
 
9
- require 'polyglot/railtie' if defined?(Rails)
8
+ require 'polyglot/sync/engine' if defined?(Rails)
10
9
 
11
10
  module Polyglot
12
11
  module Sync
@@ -0,0 +1,13 @@
1
+ module Polyglot
2
+ module Sync
3
+ class Engine < ::Rails::Engine
4
+ isolate_namespace Polyglot::Sync
5
+
6
+ # initializer "Set up webhook endpoint", before: :load_config_initializers do |app|
7
+ # Rails.application.routes.append do
8
+ # mount Polyglot::Sync::Engine, at: "/something"
9
+ # end
10
+ # end
11
+ end
12
+ end
13
+ end
@@ -1,5 +1,5 @@
1
1
  module Polyglot
2
2
  module Sync
3
- VERSION = "0.1.1"
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
@@ -0,0 +1,11 @@
1
+ namespace :sync do
2
+ desc "Converts the yml files in config/locales into a single json object"
3
+
4
+ task :export do
5
+ converter = ConverterService.new
6
+ aws_service = AwsService.new
7
+
8
+ converter.iterate_locale_dir
9
+ aws_service.publish_project_json(converter.json_file)
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ # require 'polyglot/json_to_yml_converter'
2
+ # require 'polyglot/aws_service'
3
+
4
+ namespace :sync do
5
+ desc "Converts json & generates yml files in config/locales for i18n"
6
+
7
+ task :import do
8
+ aws_service = AwsService.new
9
+ converter = ConverterService.new(aws_service.json)
10
+
11
+ converter.parse_json_to_yml
12
+ end
13
+ end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polyglot-sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
- - Carlos Uva Silva
7
+ - Gaspard+Bruno
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-19 00:00:00.000000000 Z
11
+ date: 2020-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 6.0.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 6.0.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: pg
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.18.4
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.18.4
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: pry
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -72,42 +100,43 @@ dependencies:
72
100
  requirements:
73
101
  - - "~>"
74
102
  - !ruby/object:Gem::Version
75
- version: '5'
103
+ version: 6.0.3
76
104
  type: :development
77
105
  prerelease: false
78
106
  version_requirements: !ruby/object:Gem::Requirement
79
107
  requirements:
80
108
  - - "~>"
81
109
  - !ruby/object:Gem::Version
82
- version: '5'
110
+ version: 6.0.3
83
111
  description: Gem to sync a project with the Polyglot API
84
112
  email:
85
- - carlos.uva.silva@gmail.com
113
+ - ops@gaspardbruno.com
86
114
  executables: []
87
115
  extensions: []
88
116
  extra_rdoc_files: []
89
117
  files:
90
- - ".gitignore"
91
- - ".rspec"
92
- - ".travis.yml"
93
- - Gemfile
94
- - Gemfile.lock
95
- - LICENSE.txt
118
+ - MIT-LICENSE
96
119
  - README.md
97
120
  - Rakefile
98
- - bin/console
99
- - bin/setup
100
- - lib/generators/polyglot/install_generator.rb
121
+ - app/assets/config/polyglot_sync_manifest.js
122
+ - app/assets/stylesheets/polyglot/sync/application.css
123
+ - app/controllers/polyglot/sync/application_controller.rb
124
+ - app/controllers/polyglot/sync/hooks_controller.rb
125
+ - app/helpers/polyglot/sync/application_helper.rb
126
+ - app/jobs/polyglot/sync/application_job.rb
127
+ - app/mailers/polyglot/sync/application_mailer.rb
128
+ - app/models/polyglot/sync/application_record.rb
129
+ - app/services/AwsService.rb
130
+ - app/services/ConverterService.rb
131
+ - app/views/layouts/polyglot/sync/application.html.erb
132
+ - config/routes.rb
133
+ - lib/generators/polyglot_sync/install_generator.rb
101
134
  - lib/generators/templates/polyglot_sync_initializer.rb
102
- - lib/polyglot/aws_service.rb
103
- - lib/polyglot/json_to_yml_converter.rb
104
- - lib/polyglot/railtie.rb
105
135
  - lib/polyglot/sync.rb
136
+ - lib/polyglot/sync/engine.rb
106
137
  - lib/polyglot/sync/version.rb
107
- - lib/polyglot/tasks/export.rake
108
- - lib/polyglot/tasks/import.rake
109
- - lib/polyglot/yml_to_json_converter.rb
110
- - polyglot-sync.gemspec
138
+ - lib/tasks/polyglot/export.rake
139
+ - lib/tasks/polyglot/import.rake
111
140
  homepage: https://github.com/Gaspard-Bruno/polyglot-sync
112
141
  licenses:
113
142
  - MIT
data/.gitignore DELETED
@@ -1,11 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
-
10
- # rspec failure tracking
11
- .rspec_status
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
@@ -1,7 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.6.3
7
- before_install: gem install bundler -v 2.0.2
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in polyglot-sync.gemspec
4
- gemspec
@@ -1,91 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- polyglot-sync (0.1.1)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- actionpack (5.2.4.2)
10
- actionview (= 5.2.4.2)
11
- activesupport (= 5.2.4.2)
12
- rack (~> 2.0, >= 2.0.8)
13
- rack-test (>= 0.6.3)
14
- rails-dom-testing (~> 2.0)
15
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
16
- actionview (5.2.4.2)
17
- activesupport (= 5.2.4.2)
18
- builder (~> 3.1)
19
- erubi (~> 1.4)
20
- rails-dom-testing (~> 2.0)
21
- rails-html-sanitizer (~> 1.0, >= 1.0.3)
22
- activesupport (5.2.4.2)
23
- concurrent-ruby (~> 1.0, >= 1.0.2)
24
- i18n (>= 0.7, < 2)
25
- minitest (~> 5.1)
26
- tzinfo (~> 1.1)
27
- builder (3.2.4)
28
- coderay (1.1.2)
29
- concurrent-ruby (1.1.6)
30
- crass (1.0.6)
31
- diff-lcs (1.3)
32
- erubi (1.9.0)
33
- i18n (1.8.2)
34
- concurrent-ruby (~> 1.0)
35
- loofah (2.5.0)
36
- crass (~> 1.0.2)
37
- nokogiri (>= 1.5.9)
38
- method_source (1.0.0)
39
- mini_portile2 (2.4.0)
40
- minitest (5.14.0)
41
- nokogiri (1.10.9)
42
- mini_portile2 (~> 2.4.0)
43
- pry (0.13.1)
44
- coderay (~> 1.1)
45
- method_source (~> 1.0)
46
- rack (2.2.2)
47
- rack-test (1.1.0)
48
- rack (>= 1.0, < 3)
49
- rails-dom-testing (2.0.3)
50
- activesupport (>= 4.2.0)
51
- nokogiri (>= 1.6)
52
- rails-html-sanitizer (1.3.0)
53
- loofah (~> 2.3)
54
- railties (5.2.4.2)
55
- actionpack (= 5.2.4.2)
56
- activesupport (= 5.2.4.2)
57
- method_source
58
- rake (>= 0.8.7)
59
- thor (>= 0.19.0, < 2.0)
60
- rake (10.5.0)
61
- rspec (3.9.0)
62
- rspec-core (~> 3.9.0)
63
- rspec-expectations (~> 3.9.0)
64
- rspec-mocks (~> 3.9.0)
65
- rspec-core (3.9.1)
66
- rspec-support (~> 3.9.1)
67
- rspec-expectations (3.9.1)
68
- diff-lcs (>= 1.2.0, < 2.0)
69
- rspec-support (~> 3.9.0)
70
- rspec-mocks (3.9.1)
71
- diff-lcs (>= 1.2.0, < 2.0)
72
- rspec-support (~> 3.9.0)
73
- rspec-support (3.9.2)
74
- thor (1.0.1)
75
- thread_safe (0.3.6)
76
- tzinfo (1.2.7)
77
- thread_safe (~> 0.1)
78
-
79
- PLATFORMS
80
- ruby
81
-
82
- DEPENDENCIES
83
- bundler (~> 2.0)
84
- polyglot-sync!
85
- pry
86
- railties (~> 5)
87
- rake (~> 10.0)
88
- rspec (~> 3.0)
89
-
90
- BUNDLED WITH
91
- 2.1.4
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2020 Carlos Uva Silva
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "polyglot/sync"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -1,14 +0,0 @@
1
- module Polyglot
2
- module Generators
3
- class InstallGenerator < Rails::Generators::Base
4
- source_root File.expand_path("../../templates", __FILE__)
5
- desc "Creates initializer for polyglot-sync"
6
-
7
- def copy_initializer
8
- template "polyglot_sync_initializer.rb", "config/initializers/polyglot_sync.rb"
9
-
10
- puts "Install complete!"
11
- end
12
- end
13
- end
14
- end
@@ -1,57 +0,0 @@
1
- require 'net/http'
2
- require 'json'
3
-
4
- module Polyglot
5
- module Sync
6
- class AwsService
7
- attr_reader :json
8
- def initialize
9
- # @aws_s3_bucket_name = 'polyglot-assets'
10
- @aws_s3_bucket_name = Polyglot::Sync.configuration.aws_s3_bucket_name
11
-
12
- # @aws_cloudfront_host = 'd8wlqn7pvlrac.cloudfront.net'
13
- @aws_cloudfront_host = Polyglot::Sync.configuration.aws_cloudfront_host
14
-
15
- # @organization_secret_key = 'c4ca4238a0b923820dcc509a6f75849b'
16
- @organization_secret_key = Polyglot::Sync.configuration.organization_secret_key
17
-
18
- # @project_slug = 'polyglot'
19
- @project_slug = Polyglot::Sync.configuration.project_slug
20
-
21
- # @aws_region = 'eu-west-1'
22
- @aws_region = Polyglot::Sync.configuration.aws_region
23
-
24
- @json = fetch_project_json
25
- end
26
-
27
- def fetch_project_json
28
- # get_path = "https://#{@aws_cloudfront_host}/#{@organization_secret_key}/#{@project_slug}/all.json"
29
- get_path = "https://#{@aws_s3_bucket_name}.s3-#{@aws_region}.amazonaws.com/#{@organization_secret_key}/#{@project_slug}/all.json"
30
- uri = URI(get_path)
31
- result = Net::HTTP.get(uri)
32
-
33
- json = JSON.parse(result)
34
- end
35
-
36
- def publish_project_json(json)
37
- post_path = "http://localhost:3000/api/books"
38
-
39
- path_to_file = "all.json"
40
-
41
- File.delete(path_to_file) if File.exist?(path_to_file)
42
- json_file = File.new(path_to_file, 'a')
43
- json_file.write(json)
44
- json_file.close
45
-
46
- s3 = Aws::S3::Resource.new(region: @aws_region)
47
-
48
- obj = s3.bucket(@aws_s3_bucket_name).object("#{@organization_secret_key}/#{@project_slug}/#{path_to_file}")
49
-
50
- obj.upload_file(path_to_file, content_type: 'application/json')
51
-
52
- File.delete(path_to_file) if File.exist?(path_to_file)
53
-
54
- end
55
- end
56
- end
57
- end
@@ -1,36 +0,0 @@
1
- module Polyglot
2
- module Sync
3
- class JsonToYmlConverter
4
- attr_reader :json_file
5
- attr_reader :locales_path
6
-
7
- def initialize(json_file)
8
- @locales_path = get_file_path
9
- @json_file = json_file
10
- end
11
-
12
- def fetch_api_data
13
-
14
- end
15
-
16
- def get_file_path
17
- if Kernel.const_defined? 'Rails'
18
- File.join(Rails.root, 'config/locales')
19
- else
20
- raise 'I need Rails to run!'
21
- end
22
- end
23
-
24
- def parse_json_to_yml # creates individual ymls for each locale
25
- locale_arr = []
26
- @json_file.keys.each { |key| locale_arr << {key => @json_file[key]} }
27
-
28
- locale_arr.each do |locale|
29
- y_file = File.open("#{@locales_path}/#{locale.keys.first}.yml", 'w')
30
- y_file.write(YAML.dump(locale))
31
- y_file.close
32
- end
33
- end
34
- end
35
- end
36
- end
@@ -1,13 +0,0 @@
1
- require 'polyglot/sync'
2
- require 'rails'
3
-
4
- module Polyglot
5
- class Railtie < Rails::Railtie
6
- railtie_name :polyglot_sync
7
-
8
- rake_tasks do
9
- path = File.expand_path(__dir__)
10
- Dir.glob("#{path}/tasks/*.rake").each { |f| load f }
11
- end
12
- end
13
- end
@@ -1,17 +0,0 @@
1
- require 'polyglot/yml_to_json_converter'
2
- require 'polyglot/aws_service'
3
- require 'json'
4
-
5
- namespace :sync do
6
- desc "Converts the yml files in config/locales into a single json object"
7
-
8
- task :export do
9
- puts "updating json"
10
-
11
- converter = Polyglot::Sync::YmlToJsonConverter.new
12
- converter.iterate_locale_dir
13
-
14
- aws_service = Polyglot::Sync::AwsService.new
15
- aws_service.publish_project_json(converter.json)
16
- end
17
- end
@@ -1,13 +0,0 @@
1
- require 'polyglot/json_to_yml_converter'
2
- require 'polyglot/aws_service'
3
-
4
- namespace :sync do
5
- desc "Converts json & generates yml files in config/locales for i18n"
6
-
7
- task :import do
8
- aws_service = Polyglot::Sync::AwsService.new
9
-
10
- converter = Polyglot::Sync::JsonToYmlConverter.new(aws_service.json)
11
- converter.parse_json_to_yml
12
- end
13
- end
@@ -1,41 +0,0 @@
1
- module Polyglot
2
- module Sync
3
- class YmlToJsonConverter
4
- attr_reader :json
5
- def initialize
6
- @locales_path = get_file_path
7
- @json = {}
8
- end
9
-
10
- def return_json
11
- iterate_locale_dir
12
- end
13
-
14
- def get_file_path
15
- if Kernel.const_defined? 'Rails'
16
- File.join(Rails.root, 'config/locales')
17
- else
18
- raise 'I need Rails to run!'
19
- end
20
- end
21
-
22
- def parse_yml_to_json(yml_file)
23
- j_file = YAML.load_file(File.open("#{yml_file}", 'r'))
24
- end
25
-
26
- def iterate_locale_dir # returns full json of all ymls
27
- Dir.foreach(@locales_path) do |filename|
28
-
29
- next if filename == '.' or filename == '..' or filename.include? "devise"
30
-
31
- parsed_yml = parse_yml_to_json("#{@locales_path}/#{filename}")
32
- key = parsed_yml.keys.first
33
-
34
- @json[key] = parsed_yml[key]
35
- end
36
- @json = @json.to_json
37
- end
38
-
39
- end
40
- end
41
- end
@@ -1,37 +0,0 @@
1
- lib = File.expand_path("lib", __dir__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require "polyglot/sync/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "polyglot-sync"
7
- spec.version = Polyglot::Sync::VERSION
8
- spec.authors = ["Carlos Uva Silva"]
9
- spec.email = ["carlos.uva.silva@gmail.com"]
10
-
11
- spec.summary = "Gem to sync a project with the Polyglot API"
12
- spec.description = "Gem to sync a project with the Polyglot API"
13
- spec.homepage = "https://github.com/Gaspard-Bruno/polyglot-sync"
14
- spec.license = "MIT"
15
-
16
- # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
17
-
18
- # spec.metadata["homepage_uri"] = spec.homepage
19
- # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
20
- # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
21
-
22
- # Specify which files should be added to the gem when it is released.
23
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
25
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
- end
27
- spec.bindir = "exe"
28
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
- spec.require_paths = ["lib"]
30
-
31
- spec.add_development_dependency "pry"
32
-
33
- spec.add_development_dependency "bundler", "~> 2.0"
34
- spec.add_development_dependency "rake", "~> 10.0"
35
- spec.add_development_dependency "rspec", "~> 3.0"
36
- spec.add_development_dependency 'railties', '~> 5'
37
- end