rori18n-rails 1.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c8c49e7c74fc30821db32ed869c698211245a5c89df34ba7e2f2ed6334ac8005
4
+ data.tar.gz: 3c2f7300ac6a78679fc69b79850329d3f7ef73b4db91dd6674896eafd3073405
5
+ SHA512:
6
+ metadata.gz: 23c94d808d6f69d3c929ea5975a677177f3659c135a35bdb06ae2318a5cf2bd695ecb2aa46b529126143702759da30dca35015c106078649b15c4cb7813ee83e
7
+ data.tar.gz: 44ddc37a740aede0b62a9619e90e2ce6f3bb25bb11944504cb2ac34a3fcee5b74e0836bdf748396a8b3c54f672cf15a59a132fd55f6a33933d993e6d8350df0b
data/exe/rori18n ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../lib/rori18n-rails"
5
+
6
+ Rori18n::Runner.run(ARGV)
@@ -0,0 +1,33 @@
1
+ require "rails/generators"
2
+
3
+ module Rori18n
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ source_root File.expand_path("templates", __dir__)
7
+
8
+ desc "Creates bin/rori18n binstub in your Rails app"
9
+
10
+ def create_binstub
11
+ template "binstub.tt", "bin/rori18n"
12
+ chmod "bin/rori18n", 0o755
13
+ end
14
+
15
+ def print_instructions
16
+ say "\n"
17
+ say " rori18n installed!", :green
18
+ say "\n"
19
+ say " Usage:"
20
+ say " bin/rori18n report --root ."
21
+ say " bin/rori18n generate --fix --root ."
22
+ say " bin/rori18n translate --root . --to es,fr"
23
+ say "\n"
24
+ say " Or via Rake:"
25
+ say " bundle exec rake rori18n:run ARGS='generate --fix --root .'"
26
+ say "\n"
27
+ say " The Go binary is cached at ~/.rori18n/bin/ and downloaded on first run."
28
+ say " Add that path to .gitignore if you don't want it tracked."
29
+ say "\n"
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "rori18n-rails"
6
+
7
+ Rori18n::Runner.run(ARGV)
@@ -0,0 +1,79 @@
1
+ require "fileutils"
2
+ require "net/http"
3
+ require "tmpdir"
4
+ require "uri"
5
+
6
+ module Rori18n
7
+ module Installer
8
+ GITHUB_REPO = "bobadilla-tech/rori18n"
9
+
10
+ def self.cache_dir
11
+ File.expand_path("~/.rori18n/bin")
12
+ end
13
+
14
+ def self.binary_path
15
+ File.join(cache_dir, "rori18n-#{CLI_VERSION}-#{Platform.asset_name}")
16
+ end
17
+
18
+ def self.installed?
19
+ File.exist?(binary_path) && File.executable?(binary_path)
20
+ end
21
+
22
+ def self.install!
23
+ return if installed?
24
+
25
+ asset = Platform.asset_name
26
+ url = "https://github.com/#{GITHUB_REPO}/releases/download/v#{CLI_VERSION}/#{asset}"
27
+
28
+ $stderr.puts "[rori18n] Downloading binary for #{asset} (v#{CLI_VERSION})..."
29
+ $stderr.puts "[rori18n] Source: #{url}"
30
+
31
+ FileUtils.mkdir_p(cache_dir)
32
+
33
+ download(url, binary_path)
34
+ FileUtils.chmod(0o755, binary_path)
35
+
36
+ $stderr.puts "[rori18n] Installed to #{binary_path}"
37
+ rescue Rori18n::Error
38
+ raise
39
+ rescue => e
40
+ raise Rori18n::Error, "Failed to install rori18n binary: #{e.message}\n" \
41
+ "You can manually download from https://github.com/#{GITHUB_REPO}/releases"
42
+ end
43
+
44
+ def self.download(url, dest)
45
+ uri = URI.parse(url)
46
+ tmp = "#{dest}.tmp"
47
+
48
+ begin
49
+ fetch(uri, tmp)
50
+ size = File.size(tmp)
51
+ raise Rori18n::Error, "Downloaded file is empty (#{url})" if size.zero?
52
+ FileUtils.mv(tmp, dest)
53
+ ensure
54
+ File.unlink(tmp) if File.exist?(tmp)
55
+ end
56
+ end
57
+ private_class_method :download
58
+
59
+ def self.fetch(uri, dest, redirect_limit = 5)
60
+ raise Rori18n::Error, "Too many redirects for #{uri}" if redirect_limit.zero?
61
+
62
+ Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") do |http|
63
+ http.request(Net::HTTP::Get.new(uri)) do |response|
64
+ case response
65
+ when Net::HTTPSuccess
66
+ File.open(dest, "wb") { |f| response.read_body { |chunk| f.write(chunk) } }
67
+ when Net::HTTPRedirection
68
+ fetch(URI.parse(response["location"]), dest, redirect_limit - 1)
69
+ else
70
+ raise Rori18n::Error,
71
+ "HTTP #{response.code} downloading rori18n binary from #{uri}\n" \
72
+ "Check that v#{CLI_VERSION} exists at https://github.com/#{GITHUB_REPO}/releases"
73
+ end
74
+ end
75
+ end
76
+ end
77
+ private_class_method :fetch
78
+ end
79
+ end
@@ -0,0 +1,30 @@
1
+ require "rbconfig"
2
+
3
+ module Rori18n
4
+ module Platform
5
+ SUPPORTED = {
6
+ ["darwin", "arm64"] => "rori18n_darwin_arm64",
7
+ ["darwin", "x86_64"] => "rori18n_darwin_amd64",
8
+ ["linux", "x86_64"] => "rori18n_linux_amd64",
9
+ }.freeze
10
+
11
+ def self.asset_name
12
+ os = normalize_os(RbConfig::CONFIG["host_os"])
13
+ cpu = RbConfig::CONFIG["host_cpu"]
14
+ SUPPORTED.fetch([os, cpu]) do
15
+ raise Rori18n::Error,
16
+ "Unsupported platform: #{os}-#{cpu}. " \
17
+ "Supported: #{SUPPORTED.keys.map { |k| k.join('-') }.join(', ')}"
18
+ end
19
+ end
20
+
21
+ def self.normalize_os(raw)
22
+ case raw
23
+ when /darwin/ then "darwin"
24
+ when /linux/ then "linux"
25
+ else raw.split("-").first
26
+ end
27
+ end
28
+ private_class_method :normalize_os
29
+ end
30
+ end
@@ -0,0 +1,9 @@
1
+ require "rails/railtie"
2
+
3
+ module Rori18n
4
+ class Railtie < Rails::Railtie
5
+ rake_tasks do
6
+ load File.expand_path("../../tasks/rori18n.rake", __dir__)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ module Rori18n
2
+ module Runner
3
+ def self.run(args = ARGV)
4
+ Installer.install!
5
+ exec(Installer.binary_path, *args.map(&:to_s))
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ module Rori18n
2
+ VERSION = "1.0.0"
3
+ CLI_VERSION = VERSION
4
+ end
@@ -0,0 +1,13 @@
1
+ require "rori18n/version"
2
+
3
+ module Rori18n
4
+ class Error < StandardError; end
5
+ end
6
+
7
+ require "rori18n/platform"
8
+ require "rori18n/installer"
9
+ require "rori18n/runner"
10
+
11
+ if defined?(Rails::Railtie)
12
+ require "rori18n/railtie"
13
+ end
@@ -0,0 +1,21 @@
1
+ namespace :rori18n do
2
+ desc "Run rori18n CLI. Set ARGS='generate --fix' or any subcommand."
3
+ task :run do
4
+ require "rori18n-rails"
5
+ args = (ENV["ARGS"] || "").split
6
+ if args.empty?
7
+ $stderr.puts "Usage: bundle exec rake rori18n:run ARGS='<command> [flags]'"
8
+ $stderr.puts "Commands: report, generate, merge-fragments, lint, audit, " \
9
+ "add-key, prune, translate, analyze, consolidate, refactor-key"
10
+ exit 1
11
+ end
12
+ Rori18n::Runner.run(args)
13
+ end
14
+
15
+ desc "Download the rori18n binary without running a command"
16
+ task :install do
17
+ require "rori18n-rails"
18
+ Rori18n::Installer.install!
19
+ puts "rori18n binary ready: #{Rori18n::Installer.binary_path}"
20
+ end
21
+ end
@@ -0,0 +1,31 @@
1
+ require_relative "lib/rori18n/version"
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "rori18n-rails"
5
+ s.version = Rori18n::VERSION
6
+ s.authors = ["Eliaz Bobadilla"]
7
+ s.email = ["eliaz.bobadilladev@gmail.com"]
8
+ s.summary = "Use rori18n Go CLI as a Rails development dependency"
9
+ s.description = "Wraps the rori18n Go CLI tool so it behaves like a native Rails dev dependency. " \
10
+ "Downloads the correct binary on first run. No manual installation required."
11
+ s.homepage = "https://github.com/bobadilla-tech/rori18n"
12
+ s.license = "MIT"
13
+
14
+ s.required_ruby_version = ">= 3.0"
15
+
16
+ s.files = Dir[
17
+ "lib/**/*",
18
+ "exe/*",
19
+ "*.md",
20
+ "*.gemspec",
21
+ ]
22
+
23
+ s.bindir = "exe"
24
+ s.executables = ["rori18n"]
25
+ s.require_paths = ["lib"]
26
+
27
+ s.metadata = {
28
+ "source_code_uri" => "https://github.com/bobadilla-tech/rori18n",
29
+ "changelog_uri" => "https://github.com/bobadilla-tech/rori18n/releases",
30
+ }
31
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rori18n-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Eliaz Bobadilla
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: Wraps the rori18n Go CLI tool so it behaves like a native Rails dev dependency.
13
+ Downloads the correct binary on first run. No manual installation required.
14
+ email:
15
+ - eliaz.bobadilladev@gmail.com
16
+ executables:
17
+ - rori18n
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - exe/rori18n
22
+ - lib/generators/rori18n/install/install_generator.rb
23
+ - lib/generators/rori18n/install/templates/binstub.tt
24
+ - lib/rori18n-rails.rb
25
+ - lib/rori18n/installer.rb
26
+ - lib/rori18n/platform.rb
27
+ - lib/rori18n/railtie.rb
28
+ - lib/rori18n/runner.rb
29
+ - lib/rori18n/version.rb
30
+ - lib/tasks/rori18n.rake
31
+ - rori18n-rails.gemspec
32
+ homepage: https://github.com/bobadilla-tech/rori18n
33
+ licenses:
34
+ - MIT
35
+ metadata:
36
+ source_code_uri: https://github.com/bobadilla-tech/rori18n
37
+ changelog_uri: https://github.com/bobadilla-tech/rori18n/releases
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '3.0'
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubygems_version: 4.0.6
53
+ specification_version: 4
54
+ summary: Use rori18n Go CLI as a Rails development dependency
55
+ test_files: []