phrase_assembler 1.2.5 → 1.2.6
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.
- data/lib/pa_proxies/pa_composite_proxy.rb +2 -0
- data/lib/pa_proxies/pa_csv_proxy.rb +87 -0
- data/lib/pa_proxies/pa_lang_proxy.rb +0 -2
- data/lib/pa_proxies/pa_link_proxy.rb +1 -1
- data/lib/pa_proxies/pa_token_proxy.rb +1 -45
- data/lib/pa_proxies/pa_token_proxy_options.rb +44 -0
- data/lib/tasks/phrase_assembler.rake +28 -0
- metadata +7 -4
@@ -1,8 +1,10 @@
|
|
1
1
|
require 'pa_proxies/pa_automate_proxy'
|
2
2
|
require 'pa_proxies/pa_string_proxy'
|
3
|
+
require 'pa_proxies/pa_csv_proxy'
|
3
4
|
require 'pa_proxies/pa_cache_proxy'
|
4
5
|
class PACompositeProxy < PAAutomateProxy
|
5
6
|
include PAStringProxy
|
7
|
+
include PACsvProxy
|
6
8
|
include PACacheProxy
|
7
9
|
|
8
10
|
attr_accessor :proxy_cache
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'pa_proxies/pa_token_proxy_options'
|
2
|
+
module PACsvProxy
|
3
|
+
attr_accessor :current_replace_token
|
4
|
+
|
5
|
+
def inc_replace_token
|
6
|
+
self.current_replace_token = "#{self.current_replace_token[0...1].succ * 3}"
|
7
|
+
self.current_replace_token = "AAA" if self.current_replace_token == "ZZZ"
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_csv(file_name, options = {})
|
11
|
+
self.current_replace_token = "AAA"
|
12
|
+
substitute_default_tokens(data, options)
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_csv_safe_string_line(s)
|
16
|
+
return "\"#{s.gsub('"', '""')}\"\n"
|
17
|
+
end
|
18
|
+
|
19
|
+
def substitute_default_tokens(p_data, p_options)
|
20
|
+
if p_data.is_a? Hash
|
21
|
+
t_text = ""
|
22
|
+
p_data.keys.sort{|a, b| a.to_s <=> b.to_s}.each{|k| t_text << substitute_default_tokens(p_data[k], p_options)}
|
23
|
+
return t_text
|
24
|
+
elsif p_data.is_a? Array
|
25
|
+
t_text = ""
|
26
|
+
p_data.each{|v| t_text << substitute_default_tokens(v, p_options)}
|
27
|
+
return t_text
|
28
|
+
elsif p_data.is_a? String
|
29
|
+
return substitute_default_token(String.new(p_data), p_options)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def substitute_default_token(p_data, p_options)
|
34
|
+
add_options = {}
|
35
|
+
result = ""
|
36
|
+
|
37
|
+
#Default tokeni za linkove
|
38
|
+
p_data.gsub(/\{\*[^\{\*\})]+->[^\{\*\})]+\*\}/){|link_token|
|
39
|
+
link_data = link_token.split("->")
|
40
|
+
link_text = link_data[0][2..-1]
|
41
|
+
link_url = link_data[1][0...-2]
|
42
|
+
|
43
|
+
if(link_text.index(/'[^'"]+'/).nil? and link_text.index(/"[^'"]+"/).nil?)
|
44
|
+
add_options[link_text.to_sym] = "Tekst linka"
|
45
|
+
end
|
46
|
+
|
47
|
+
if (link_url.index(/'[^'"]+'/).nil?)
|
48
|
+
add_options[link_url.to_sym] = "www.testlink.hr"
|
49
|
+
end
|
50
|
+
}
|
51
|
+
|
52
|
+
#Promijeni obicne tokene
|
53
|
+
p_data.gsub(/\{\*[^\{\}\*\?>]+\*\}/){|token|
|
54
|
+
sym_token = token[2...-2]
|
55
|
+
if sym_token[0...1]!="!"
|
56
|
+
add_options[sym_token.to_sym] = self.current_replace_token
|
57
|
+
self.inc_replace_token
|
58
|
+
end
|
59
|
+
}
|
60
|
+
|
61
|
+
#Odi po svim vrijednostim za jezik
|
62
|
+
p_data.gsub(/\{\*[^\{\}\*\?]+\?[^\{\}\*:]+(:[^\{\}\*:]+)+\*\}/){|token|
|
63
|
+
clear_token = token[2...-2]
|
64
|
+
key = clear_token[/[^\?]+/]
|
65
|
+
key = key[/[^(\(.+\))]+/]
|
66
|
+
keys = key.split('_')
|
67
|
+
if keys.length <= 1
|
68
|
+
options_key = "default"
|
69
|
+
grammar_key = keys[0]
|
70
|
+
else
|
71
|
+
options_key = keys[0...keys.length-1].join("_")
|
72
|
+
grammar_key = keys[keys.length - 1]
|
73
|
+
end
|
74
|
+
self.grammar[grammar_key.to_s.to_sym].keys.sort{|a, b| a.to_s <=> b.to_s}.each{|k|
|
75
|
+
if k == :default
|
76
|
+
add_options["#{options_key}_#{grammar_key}".to_sym] = nil
|
77
|
+
else
|
78
|
+
add_options["#{options_key}_#{grammar_key}".to_sym] = k.to_s
|
79
|
+
end
|
80
|
+
result << get_csv_safe_string_line(substitute_token(String.new(p_data), p_options, PATokenProxyOptions.new_if_needed(add_options)))
|
81
|
+
}
|
82
|
+
}
|
83
|
+
result << get_csv_safe_string_line(substitute_token(p_data, p_options, PATokenProxyOptions.new_if_needed(add_options))) if result == ""
|
84
|
+
return result
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
@@ -64,9 +64,7 @@ class PALangProxy < PATokenProxy
|
|
64
64
|
options_key = keys[0...keys.length-1].join("_")
|
65
65
|
grammar_key = keys[keys.length - 1]
|
66
66
|
end
|
67
|
-
|
68
67
|
values = clear_token[/\?.+/][1..-1].split(':')
|
69
|
-
|
70
68
|
if p_options.options_hash.has_key?(options_key.to_sym)
|
71
69
|
if opt_params.nil?
|
72
70
|
grammar_value = p_options.options_hash[options_key.to_sym].send(:"get_#{grammar_key}")
|
@@ -19,7 +19,7 @@ class PALinkProxy < PALangProxy
|
|
19
19
|
end
|
20
20
|
|
21
21
|
add_attributes = ""
|
22
|
-
if p_options.options_hash[link_url.to_sym].is_a? Hash
|
22
|
+
if (link_url.index(/'[^'"]+'/).nil? and link_url.index(/"[^'"]+"/).nil?) and p_options.options_hash[link_url.to_sym].is_a? Hash
|
23
23
|
identifier = "!link_url_#{link_url.object_id}"
|
24
24
|
add_options[identifier] = p_options.options_hash[link_url.to_sym][:href]
|
25
25
|
|
@@ -1,50 +1,6 @@
|
|
1
1
|
require 'erb'
|
2
2
|
require 'pa_proxies/pa_proxy'
|
3
|
-
|
4
|
-
attr_accessor :options_hash
|
5
|
-
attr_accessor :indices_hash
|
6
|
-
|
7
|
-
def self.new_if_needed(p_options)
|
8
|
-
if (p_options.is_a? PATokenProxyOptions)
|
9
|
-
return p_options
|
10
|
-
else
|
11
|
-
return self.new(p_options)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def reset
|
16
|
-
calculate_indices(options_hash) if !@added_indices
|
17
|
-
@added_indices = true
|
18
|
-
end
|
19
|
-
|
20
|
-
def initialize(p_options)
|
21
|
-
self.options_hash = p_options
|
22
|
-
self.indices_hash = {}
|
23
|
-
reset
|
24
|
-
end
|
25
|
-
|
26
|
-
def get_current_index(array)
|
27
|
-
return indices_hash[array.object_id.to_s]
|
28
|
-
end
|
29
|
-
|
30
|
-
def inc_index(array)
|
31
|
-
indices_hash[array.object_id.to_s] = indices_hash[array.object_id.to_s] + 1
|
32
|
-
if indices_hash[array.object_id.to_s] >= array.length
|
33
|
-
indices_hash[array.object_id.to_s]= 0
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
def calculate_indices(hash)
|
39
|
-
if hash.is_a? Array
|
40
|
-
indices_hash[hash.object_id.to_s] = 0
|
41
|
-
hash.each{|hash_element| calculate_indices(hash_element)}
|
42
|
-
elsif hash.is_a? Hash
|
43
|
-
hash.each_value{|val| calculate_indices(val)}
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
3
|
+
require 'pa_proxies/pa_token_proxy_options'
|
48
4
|
class PATokenProxy < PAProxy
|
49
5
|
include ERB::Util
|
50
6
|
|
@@ -0,0 +1,44 @@
|
|
1
|
+
class PATokenProxyOptions
|
2
|
+
attr_accessor :options_hash
|
3
|
+
attr_accessor :indices_hash
|
4
|
+
|
5
|
+
def self.new_if_needed(p_options)
|
6
|
+
if (p_options.is_a? PATokenProxyOptions)
|
7
|
+
return p_options
|
8
|
+
else
|
9
|
+
return self.new(p_options)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def reset
|
14
|
+
calculate_indices(options_hash) if !@added_indices
|
15
|
+
@added_indices = true
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(p_options)
|
19
|
+
self.options_hash = p_options
|
20
|
+
self.indices_hash = {}
|
21
|
+
reset
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_current_index(array)
|
25
|
+
return indices_hash[array.object_id.to_s]
|
26
|
+
end
|
27
|
+
|
28
|
+
def inc_index(array)
|
29
|
+
indices_hash[array.object_id.to_s] = indices_hash[array.object_id.to_s] + 1
|
30
|
+
if indices_hash[array.object_id.to_s] >= array.length
|
31
|
+
indices_hash[array.object_id.to_s]= 0
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
def calculate_indices(hash)
|
37
|
+
if hash.is_a? Array
|
38
|
+
indices_hash[hash.object_id.to_s] = 0
|
39
|
+
hash.each{|hash_element| calculate_indices(hash_element)}
|
40
|
+
elsif hash.is_a? Hash
|
41
|
+
hash.each_value{|val| calculate_indices(val)}
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
namespace :phrase_assembler do
|
2
|
+
task(:get_csv_file) do
|
3
|
+
if ENV['out'].nil?
|
4
|
+
raise 'Must specify output file out='
|
5
|
+
end
|
6
|
+
if ENV['language'].nil?
|
7
|
+
file_name = 'croatian.yml'
|
8
|
+
else
|
9
|
+
file_name = ENV['language']
|
10
|
+
end
|
11
|
+
if ENV['grammar'].nil?
|
12
|
+
grammar_file_name = 'croatian_grammar.yml'
|
13
|
+
else
|
14
|
+
grammar_file_name = ENV['grammar']
|
15
|
+
end
|
16
|
+
if ENV['default_dir'].nil?
|
17
|
+
default_dir = File.join(::Rails.root.to_s, 'app', 'yaml', 'languages')
|
18
|
+
else
|
19
|
+
default_dir = ENV['default_dir']
|
20
|
+
end
|
21
|
+
|
22
|
+
cache = {}
|
23
|
+
PACompositeProxy.new(cache)
|
24
|
+
PACompositeProxy.load(File.join(default_dir, file_name))
|
25
|
+
PACompositeProxy.load_grammar(File.join(default_dir, grammar_file_name))
|
26
|
+
PACompositeProxy.to_csv(ENV['out'])
|
27
|
+
end
|
28
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phrase_assembler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 1.2.
|
9
|
+
- 6
|
10
|
+
version: 1.2.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Lovro \xC5\xBDmak, Radan Skori\xC4\x87, Drap"
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-02-
|
18
|
+
date: 2011-02-21 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -46,6 +46,7 @@ files:
|
|
46
46
|
- lib/pa_proxies/pa_automate_proxy.rb
|
47
47
|
- lib/pa_proxies/pa_cache_proxy.rb
|
48
48
|
- lib/pa_proxies/pa_composite_proxy.rb
|
49
|
+
- lib/pa_proxies/pa_csv_proxy.rb
|
49
50
|
- lib/pa_proxies/pa_error_proxy.rb
|
50
51
|
- lib/pa_proxies/pa_lang_proxy.rb
|
51
52
|
- lib/pa_proxies/pa_link_proxy.rb
|
@@ -53,8 +54,10 @@ files:
|
|
53
54
|
- lib/pa_proxies/pa_proxy_data.rb
|
54
55
|
- lib/pa_proxies/pa_string_proxy.rb
|
55
56
|
- lib/pa_proxies/pa_token_proxy.rb
|
57
|
+
- lib/pa_proxies/pa_token_proxy_options.rb
|
56
58
|
- lib/pa_proxies/pa_user_proxy.rb
|
57
59
|
- lib/phrase_assembler.rb
|
60
|
+
- lib/tasks/phrase_assembler.rake
|
58
61
|
- lib/utils/hash_add_on.rb
|
59
62
|
- lib/utils/r_array.rb
|
60
63
|
has_rdoc: true
|