italian-ruby 0.5.9 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/bin/italian-rspec +4 -2
- data/lib/italian/ruby.rb +9 -0
- data/lib/italian/ruby/core_ext/kernel.rb +35 -15
- data/lib/italian/ruby/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2928e098120452f555eff573f0d8062e76c111763e30605232b67cd607c9c085
|
4
|
+
data.tar.gz: 1e765b113a325fbe8386cbff11514815ba634f96022cbd9ee27c12bd393b4336
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c1f878878db7ebe45eceb58ad381b225bd7590f3c5c23c06823d5961687cfbad599b8c5d8929cdf134b5c896c04bcb9045306e9e62332441c7e1007485c0a77
|
7
|
+
data.tar.gz: b64217e3825727127a74282c7817cc5df123237e4768b91ef3784232fdcbdff168e05c80452fbb9e0da5685f7067e5031e730e5001844545206dba4a73aaee34
|
data/README.md
CHANGED
@@ -100,7 +100,7 @@ Bato però ha solo un binario che permette di eseguire codice filippino. Italian
|
|
100
100
|
|
101
101
|
Per concludere, ci sono degli avvertimenti.
|
102
102
|
1. il namespace verrà sporcato. Ho fatto del mio meglio per essere più chirurgico possibile, ma se fate `require "italian/ruby"` sappiate che verranno su un sacco di classi e di alias nuovi (es. `Oggetto.nuovo` ecc.).
|
103
|
-
2. il `richiedi` e `richiedi_relativo` funzionano traducendo un file sorgente in italiano nella
|
103
|
+
2. il `richiedi` e `richiedi_relativo` funzionano traducendo un file sorgente in italiano nella cartella `.italian-ruby`, che viene creata in automatico nella home dell'utente. Viene ricreato l'intero percorso del file, in modo tale da preservarne l'unicità e il riferimento con il sorgente iniziale. Unaa volta tradotto, il file viene caricato in memoria con il `require` di Ruby. Non so se questo possa creare problemi. Immagino di no. Ma vi ho avvertito!
|
104
104
|
|
105
105
|
## Contribuire
|
106
106
|
|
data/bin/italian-rspec
CHANGED
@@ -5,7 +5,9 @@ require "rspec"
|
|
5
5
|
require "italian/ruby"
|
6
6
|
|
7
7
|
def translate_spec(spec_file)
|
8
|
-
translated_spec_file = "
|
8
|
+
translated_spec_file = ".italian-ruby/#{File.dirname spec_file}/#{File.basename(spec_file, ".ir")}.rb"
|
9
|
+
translated_spec_dir = File.dirname translated_spec_file
|
10
|
+
FileUtils.mkdir_p translated_spec_dir unless Dir.exists? translated_spec_dir
|
9
11
|
File.write translated_spec_file, Italian::Ruby::Traduttore.traduci(spec_file)
|
10
12
|
translated_spec_file
|
11
13
|
end
|
@@ -26,4 +28,4 @@ end
|
|
26
28
|
|
27
29
|
translated_spec_files = spec_files.map { |file| translate_spec file }
|
28
30
|
RSpec::Core::Runner.run(translated_spec_files, STDIN, STDOUT)
|
29
|
-
translated_spec_files.each { |file| destroy_spec file }
|
31
|
+
# translated_spec_files.each { |file| destroy_spec file }
|
data/lib/italian/ruby.rb
CHANGED
@@ -10,5 +10,14 @@ require "italian/ruby/core_ext"
|
|
10
10
|
|
11
11
|
module Italian
|
12
12
|
module Ruby
|
13
|
+
class << self
|
14
|
+
|
15
|
+
def translations_dir_path
|
16
|
+
path = File.join File.expand_path("~"), ".italian-ruby", "translations"
|
17
|
+
FileUtils.mkdir_p path unless Dir.exists? path
|
18
|
+
path
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
13
22
|
end
|
14
23
|
end
|
@@ -15,26 +15,36 @@ module Kernel
|
|
15
15
|
|
16
16
|
def richiedi(name)
|
17
17
|
file_to_require = $:.map { |dir| Dir["#{dir}/**/#{name}.ir"] }.flatten.compact.first
|
18
|
-
raise LoadError.new("cannot load such file -- #{name}") if file_to_require.nil?
|
19
18
|
|
20
|
-
|
19
|
+
if file_to_require.nil?
|
20
|
+
require name
|
21
|
+
else
|
22
|
+
traduci_e_carica file_to_require
|
23
|
+
end
|
21
24
|
end
|
22
25
|
|
23
26
|
def richiedi_relativo(name)
|
24
27
|
caller_location_dir = File.dirname caller_locations.first.absolute_path
|
25
|
-
|
28
|
+
if caller_location_dir.start_with?(Italian::Ruby.translations_dir_path)
|
29
|
+
caller_location_dir = caller_location_dir[Italian::Ruby.translations_dir_path.length..-1]
|
30
|
+
end
|
31
|
+
caller_location_file = File.expand_path "#{caller_location_dir}/#{name}"
|
32
|
+
file_to_require = Dir["#{caller_location_file}.{ir,rb}"].compact.first
|
26
33
|
raise LoadError.new("cannot load such file -- #{name}") unless File.exist? file_to_require
|
27
34
|
|
28
|
-
|
35
|
+
traduci_e_carica file_to_require
|
29
36
|
end
|
30
37
|
|
31
38
|
def richiedi_assoluto(file)
|
32
|
-
raise LoadError.new("cannot load
|
33
|
-
|
39
|
+
raise LoadError.new("cannot load such file -- #{file}") unless File.exist? file
|
40
|
+
traduci_e_carica file
|
34
41
|
end
|
35
42
|
|
36
43
|
def richiedi_tutti(dir)
|
37
44
|
caller_location_dir = "#{File.dirname caller_locations.first.absolute_path}/#{dir}"
|
45
|
+
if caller_location_dir.start_with?(Italian::Ruby.translations_dir_path)
|
46
|
+
caller_location_dir = caller_location_dir[Italian::Ruby.translations_dir_path.length..-1]
|
47
|
+
end
|
38
48
|
raise LoadError.new("cannot load such directory -- #{dir}") unless Dir.exist? caller_location_dir
|
39
49
|
|
40
50
|
Dir["#{caller_location_dir}/**/*.ir"].each do |file|
|
@@ -44,16 +54,26 @@ module Kernel
|
|
44
54
|
|
45
55
|
private
|
46
56
|
|
47
|
-
def
|
48
|
-
|
49
|
-
|
50
|
-
file_to_require_basename = File.basename
|
51
|
-
|
57
|
+
def traduci_e_carica(file_to_require)
|
58
|
+
file_to_require_dir = File.dirname file_to_require
|
59
|
+
file_to_require_ext = File.extname file_to_require
|
60
|
+
file_to_require_basename = File.basename file_to_require, file_to_require_ext
|
61
|
+
|
62
|
+
parsed_dir = File.join Italian::Ruby.translations_dir_path, file_to_require_dir
|
63
|
+
FileUtils.mkdir_p parsed_dir unless Dir.exists? parsed_dir
|
64
|
+
parsed_file = File.join parsed_dir, "#{file_to_require_basename}.rb"
|
65
|
+
|
66
|
+
if file_to_require_ext == ".rb"
|
67
|
+
parsed_code = File.read file_to_require
|
68
|
+
else
|
69
|
+
parsed_code = Italian::Ruby::Traduttore.traduci file_to_require
|
70
|
+
end
|
52
71
|
|
53
|
-
File.write
|
54
|
-
|
55
|
-
|
56
|
-
|
72
|
+
File.write parsed_file, parsed_code
|
73
|
+
require parsed_file
|
74
|
+
# require_output = require tmp_parsed_file
|
75
|
+
# File.delete tmp_parsed_file if File.exist? tmp_parsed_file
|
76
|
+
#require_output
|
57
77
|
end
|
58
78
|
|
59
79
|
end
|
data/lib/italian/ruby/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: italian-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Francesco Ballardin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby2ruby
|