logaling-command 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +6 -0
- data/lib/logaling/command/application.rb +73 -137
- data/lib/logaling/command/pager.rb +36 -0
- data/lib/logaling/command/renderers.rb +134 -0
- data/lib/logaling/command/version.rb +1 -1
- data/lib/logaling/command.rb +2 -0
- data/lib/logaling/external_glossaries/tmx.rb +4 -4
- data/lib/logaling/external_glossary.rb +14 -14
- data/lib/logaling/glossary.rb +57 -121
- data/lib/logaling/glossary_db.rb +101 -91
- data/lib/logaling/glossary_source.rb +35 -0
- data/lib/logaling/glossary_sources/base.rb +42 -0
- data/lib/logaling/glossary_sources/glossary_csv_source.rb +33 -0
- data/lib/logaling/glossary_sources/glossary_tsv_source.rb +33 -0
- data/lib/logaling/glossary_sources/glossary_yaml_source.rb +125 -0
- data/lib/logaling/project.rb +79 -0
- data/lib/logaling/repository.rb +41 -92
- data/lib/logaling.rb +1 -0
- data/logaling-command.gemspec +1 -1
- data/spec/logaling/command_spec.rb +10 -9
- data/spec/logaling/glossary_spec.rb +7 -8
- data/spec/logaling/repository_spec.rb +11 -19
- metadata +68 -20
@@ -0,0 +1,33 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2012 Koji SHIMADA <koji.shimada@enishi-tech.com>
|
4
|
+
#
|
5
|
+
# This program is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
require "logaling/glossary_sources/base"
|
19
|
+
require "csv"
|
20
|
+
|
21
|
+
module Logaling::GlossarySources
|
22
|
+
class GlossaryTsvSource < Base
|
23
|
+
def load
|
24
|
+
glossary_source = []
|
25
|
+
CSV.open(source_path, "r:utf-8", {:col_sep => "\t"}) do |tsv|
|
26
|
+
tsv.each do |row|
|
27
|
+
glossary_source << {"source_term" => row[0], "target_term" => row[1], "note" => ""} if row.size >= 2
|
28
|
+
end
|
29
|
+
end
|
30
|
+
glossary_source
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2012 Koji SHIMADA <koji.shimada@enishi-tech.com>
|
4
|
+
#
|
5
|
+
# This program is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
require "logaling/glossary_sources/base"
|
19
|
+
begin
|
20
|
+
require 'psych'
|
21
|
+
rescue LoadError => e
|
22
|
+
raise LoadError unless e.message =~ /psych/
|
23
|
+
puts "please install psych first."
|
24
|
+
end
|
25
|
+
require "yaml"
|
26
|
+
require "fileutils"
|
27
|
+
|
28
|
+
module Logaling::GlossarySources
|
29
|
+
class GlossaryYamlSource < Base
|
30
|
+
def load
|
31
|
+
YAML::load_file(source_path) || []
|
32
|
+
rescue TypeError
|
33
|
+
[]
|
34
|
+
end
|
35
|
+
|
36
|
+
def add(source_term, target_term, note)
|
37
|
+
FileUtils.touch(source_path) unless File.exist?(source_path)
|
38
|
+
|
39
|
+
glossary_source = self.load
|
40
|
+
glossary_source << build_term(source_term, target_term, note)
|
41
|
+
dump_glossary_source(glossary_source)
|
42
|
+
rescue
|
43
|
+
raise Logaling::GlossaryNotFound
|
44
|
+
end
|
45
|
+
|
46
|
+
def update(source_term, target_term, new_target_term, note)
|
47
|
+
raise Logaling::GlossaryNotFound unless File.exist?(source_path)
|
48
|
+
|
49
|
+
glossary_source = self.load
|
50
|
+
target_index = find_term_index(glossary_source, source_term, target_term)
|
51
|
+
if target_index
|
52
|
+
glossary_source[target_index] = rebuild_term(glossary_source[target_index], source_term, new_target_term, note)
|
53
|
+
dump_glossary_source(glossary_source)
|
54
|
+
else
|
55
|
+
raise Logaling::TermError, "Can't found term '#{source_term}: #{target_term}' in '#{@glossary.name}'"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def delete(source_term, target_term)
|
60
|
+
raise Logaling::GlossaryNotFound unless File.exist?(source_path)
|
61
|
+
|
62
|
+
glossary_source = self.load
|
63
|
+
target_index = find_term_index(glossary_source, source_term, target_term)
|
64
|
+
unless target_index
|
65
|
+
raise Logaling::TermError, "Can't found term '#{source_term} #{target_term}' in '#{@glossary.name}'" unless target_index
|
66
|
+
end
|
67
|
+
|
68
|
+
glossary_source.delete_at(target_index)
|
69
|
+
dump_glossary_source(glossary_source)
|
70
|
+
end
|
71
|
+
|
72
|
+
def delete_all(source_term, force=false)
|
73
|
+
raise Logaling::GlossaryNotFound unless File.exist?(source_path)
|
74
|
+
|
75
|
+
glossary_source = self.load
|
76
|
+
delete_candidates = target_terms(glossary_source, source_term)
|
77
|
+
if delete_candidates.empty?
|
78
|
+
raise Logaling::TermError, "Can't found term '#{source_term} in '#{@glossary.name}'"
|
79
|
+
end
|
80
|
+
|
81
|
+
if delete_candidates.size == 1 || force
|
82
|
+
glossary_source.delete_if{|term| term['source_term'] == source_term }
|
83
|
+
dump_glossary_source(glossary_source)
|
84
|
+
else
|
85
|
+
raise Logaling::TermError, "There are duplicate terms in glossary.\n" +
|
86
|
+
"If you really want to delete, please put `loga delete [SOURCE_TERM] --force`\n" +
|
87
|
+
" or `loga delete [SOURCE_TERM] [TARGET_TERM]`"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
def build_term(source_term, target_term, note)
|
93
|
+
note ||= ''
|
94
|
+
{'source_term' => source_term, 'target_term' => target_term, 'note' => note}
|
95
|
+
end
|
96
|
+
|
97
|
+
def rebuild_term(current, source_term, target_term, note)
|
98
|
+
if current['target_term'] != target_term && (note.nil? || note == "")
|
99
|
+
note = current['note']
|
100
|
+
end
|
101
|
+
target_term = current['target_term'] if target_term == ""
|
102
|
+
build_term(source_term, target_term, note)
|
103
|
+
end
|
104
|
+
|
105
|
+
def find_term_index(glossary_source, source_term, target_term='')
|
106
|
+
glossary_source.find_index do |term|
|
107
|
+
if target_term.empty?
|
108
|
+
term['source_term'] == source_term
|
109
|
+
else
|
110
|
+
term['source_term'] == source_term && term['target_term'] == target_term
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def target_terms(glossary_source, source_term)
|
116
|
+
glossary_source.select {|term| term['source_term'] == source_term }
|
117
|
+
end
|
118
|
+
|
119
|
+
def dump_glossary_source(glossary_source)
|
120
|
+
File.open(source_path, "w") do |f|
|
121
|
+
f.puts(glossary_source.to_yaml)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# Copyright (C) 2012 Miho SUZUKI
|
2
|
+
#
|
3
|
+
# This program is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License
|
14
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
module Logaling
|
17
|
+
class Project
|
18
|
+
class << self
|
19
|
+
def find_dotfile(base_dir=Dir.pwd)
|
20
|
+
searched_path = []
|
21
|
+
dir = base_dir
|
22
|
+
loop do
|
23
|
+
path = File.join(dir, '.logaling')
|
24
|
+
if File.exist?(path)
|
25
|
+
return path
|
26
|
+
else
|
27
|
+
unless Pathname.new(dir).root?
|
28
|
+
searched_path << dir
|
29
|
+
dir = File.dirname(dir)
|
30
|
+
else
|
31
|
+
raise Logaling::ProjectNotFound, "Can't found .logaling in #{searched_path}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
attr_reader :path, :repository
|
38
|
+
|
39
|
+
def initialize(path, repository=nil)
|
40
|
+
@path = path
|
41
|
+
@repository = repository
|
42
|
+
end
|
43
|
+
|
44
|
+
def name
|
45
|
+
File.basename(@path)
|
46
|
+
end
|
47
|
+
|
48
|
+
def find_glossary(source_language, target_language)
|
49
|
+
Logaling::Glossary.new(name, source_language, target_language, self)
|
50
|
+
end
|
51
|
+
|
52
|
+
def glossary_source_path
|
53
|
+
File.join(@path, "glossary")
|
54
|
+
end
|
55
|
+
|
56
|
+
def glossary_db_path
|
57
|
+
@repository.logaling_db_home
|
58
|
+
end
|
59
|
+
|
60
|
+
def glossary_sources
|
61
|
+
all_glossary_source_path = Dir.glob(File.join(glossary_source_path, "*"))
|
62
|
+
all_glossary_source_path.map do |source_path|
|
63
|
+
name, source_language, target_language, type = File.basename(source_path).split(/\./)
|
64
|
+
GlossarySource.create(source_path, find_glossary(source_language, target_language))
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
class ImportedProject < Project
|
70
|
+
def name
|
71
|
+
File.basename(@path).split(/\./).first
|
72
|
+
end
|
73
|
+
|
74
|
+
def glossary_sources
|
75
|
+
name, source_language, target_language, type = File.basename(@path).split(/\./)
|
76
|
+
[GlossarySource.create(@path, find_glossary(source_language, target_language))]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
data/lib/logaling/repository.rb
CHANGED
@@ -17,6 +17,7 @@
|
|
17
17
|
|
18
18
|
require "fileutils"
|
19
19
|
require "logaling/glossary_db"
|
20
|
+
require "logaling/project"
|
20
21
|
|
21
22
|
module Logaling
|
22
23
|
class Repository
|
@@ -25,107 +26,90 @@ module Logaling
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def register(dot_logaling_path, register_name)
|
28
|
-
FileUtils.mkdir_p(logaling_projects_path)
|
29
|
+
FileUtils.mkdir_p(logaling_projects_path)
|
29
30
|
symlink_path = File.join(logaling_projects_path, register_name)
|
30
31
|
unless File.exist?(symlink_path)
|
31
32
|
FileUtils.ln_s(dot_logaling_path, symlink_path)
|
32
33
|
else
|
33
|
-
raise GlossaryAlreadyRegistered, register_name
|
34
|
+
raise Logaling::GlossaryAlreadyRegistered, register_name
|
34
35
|
end
|
36
|
+
rescue Logaling::GlossaryAlreadyRegistered => e
|
37
|
+
raise e
|
35
38
|
rescue
|
36
39
|
raise Logaling::CommandFailed, "Failed register #{register_name} to #{logaling_projects_path}."
|
37
40
|
end
|
38
41
|
|
39
|
-
def unregister(
|
40
|
-
|
41
|
-
|
42
|
-
FileUtils.remove_entry_secure(symlink_path, true)
|
43
|
-
else
|
44
|
-
raise GlossaryNotFound, register_name
|
45
|
-
end
|
42
|
+
def unregister(project)
|
43
|
+
raise Logaling::ProjectNotFound unless project
|
44
|
+
FileUtils.remove_entry_secure(project.path, true)
|
46
45
|
end
|
47
46
|
|
48
|
-
def import(
|
49
|
-
FileUtils.mkdir_p(cache_path)
|
47
|
+
def import(glossary_source)
|
48
|
+
FileUtils.mkdir_p(cache_path)
|
50
49
|
Dir.chdir(cache_path) do
|
51
|
-
|
50
|
+
glossary_source.import
|
52
51
|
end
|
53
52
|
rescue
|
54
|
-
raise Logaling::CommandFailed, "Failed import #{
|
53
|
+
raise Logaling::CommandFailed, "Failed import #{glossary_source.class.name} to #{cache_path}."
|
55
54
|
end
|
56
55
|
|
57
|
-
def import_tmx(glossary,
|
58
|
-
FileUtils.mkdir_p(cache_path)
|
56
|
+
def import_tmx(glossary_source, glossary, url)
|
57
|
+
FileUtils.mkdir_p(cache_path)
|
59
58
|
Dir.chdir(cache_path) do
|
60
|
-
|
59
|
+
glossary_source.import(glossary, url)
|
61
60
|
end
|
62
61
|
rescue Logaling::GlossaryNotFound => e
|
63
62
|
raise e
|
64
63
|
rescue
|
65
|
-
raise Logaling::CommandFailed, "Failed import_tmx #{
|
64
|
+
raise Logaling::CommandFailed, "Failed import_tmx #{glossary_source.class.name} to #{cache_path}."
|
66
65
|
end
|
67
66
|
|
68
|
-
def lookup(source_term,
|
69
|
-
raise GlossaryDBNotFound unless File.exist?(logaling_db_home)
|
67
|
+
def lookup(source_term, glossary, dictionary=false)
|
68
|
+
raise Logaling::GlossaryDBNotFound unless File.exist?(logaling_db_home)
|
70
69
|
|
71
70
|
terms = []
|
72
71
|
Logaling::GlossaryDB.open(logaling_db_home, "utf8") do |db|
|
73
72
|
if dictionary
|
74
73
|
terms = db.lookup_dictionary(source_term)
|
75
74
|
else
|
76
|
-
terms = db.lookup(source_term,
|
75
|
+
terms = db.lookup(source_term, glossary)
|
77
76
|
end
|
78
77
|
end
|
79
78
|
terms
|
80
79
|
end
|
81
80
|
|
82
|
-
def
|
83
|
-
|
84
|
-
|
85
|
-
terms = []
|
86
|
-
Logaling::GlossaryDB.open(logaling_db_home, "utf8") do |db|
|
87
|
-
terms = db.translation_list(glossary_source)
|
81
|
+
def projects
|
82
|
+
projects = registered_project_paths.map do |project_path|
|
83
|
+
Logaling::Project.new(project_path, self)
|
88
84
|
end
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
def list
|
93
|
-
raise GlossaryDBNotFound unless File.exist?(logaling_db_home)
|
94
|
-
|
95
|
-
glossaries = []
|
96
|
-
Logaling::GlossaryDB.open(logaling_db_home, "utf8") do |db|
|
97
|
-
glossaries = db.get_all_glossary
|
85
|
+
projects += imported_glossary_paths.map do |imported_project_path|
|
86
|
+
Logaling::ImportedProject.new(imported_project_path, self)
|
98
87
|
end
|
99
|
-
|
88
|
+
projects.sort_by(&:path)
|
100
89
|
end
|
101
90
|
|
102
91
|
def index
|
103
|
-
|
104
|
-
Dir.glob(get_all_glossary_sources(File.join(project, "glossary")))
|
105
|
-
end
|
106
|
-
imported_glossaries = Dir.glob(get_all_glossary_sources(cache_path))
|
107
|
-
all_glossaries = project_glossaries.flatten + imported_glossaries
|
92
|
+
all_glossary_sources = projects.map{|project| project.glossary_sources}.flatten
|
108
93
|
|
109
94
|
Logaling::GlossaryDB.open(logaling_db_home, "utf8") do |db|
|
110
95
|
db.recreate_table
|
111
|
-
|
112
|
-
|
113
|
-
unless db.glossary_source_exist?(glossary_source
|
114
|
-
|
115
|
-
|
116
|
-
db.index_glossary(Glossary.load(glossary_source), glossary_name, glossary_source, source_language, target_language, indexed_at)
|
96
|
+
all_glossary_sources.each do |glossary_source|
|
97
|
+
glossary = glossary_source.glossary
|
98
|
+
unless db.glossary_source_exist?(glossary_source)
|
99
|
+
puts "now index #{glossary.name}..."
|
100
|
+
db.index_glossary(glossary, glossary_source)
|
117
101
|
end
|
118
102
|
end
|
119
|
-
(db.
|
120
|
-
|
121
|
-
puts "now deindex #{
|
122
|
-
db.deindex_glossary(
|
103
|
+
(db.get_all_glossary_sources - all_glossary_sources).each do |glossary_source|
|
104
|
+
glossary = glossary_source.glossary
|
105
|
+
puts "now deindex #{glossary.name}..."
|
106
|
+
db.deindex_glossary(glossary, glossary_source)
|
123
107
|
end
|
124
108
|
end
|
125
109
|
end
|
126
110
|
|
127
111
|
def glossary_counts
|
128
|
-
[
|
112
|
+
[registered_project_paths, imported_glossary_paths].map(&:size).inject(&:+)
|
129
113
|
end
|
130
114
|
|
131
115
|
def config_path
|
@@ -133,50 +117,15 @@ module Logaling
|
|
133
117
|
File.exist?(path) ? path : nil
|
134
118
|
end
|
135
119
|
|
136
|
-
def
|
137
|
-
|
138
|
-
|
139
|
-
terms = []
|
140
|
-
Logaling::GlossaryDB.open(logaling_db_home, "utf8") do |db|
|
141
|
-
terms = db.get_bilingual_pair(source_term, target_term, glossary)
|
142
|
-
end
|
143
|
-
|
144
|
-
if terms.size > 0
|
145
|
-
true
|
146
|
-
else
|
147
|
-
false
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
def bilingual_pair_exists_and_has_same_note?(source_term, target_term, note, glossary)
|
152
|
-
raise GlossaryDBNotFound unless File.exist?(logaling_db_home)
|
153
|
-
|
154
|
-
terms = []
|
155
|
-
Logaling::GlossaryDB.open(logaling_db_home, "utf8") do |db|
|
156
|
-
terms = db.get_bilingual_pair_with_note(source_term, target_term, note, glossary)
|
157
|
-
end
|
158
|
-
|
159
|
-
if terms.size > 0
|
160
|
-
true
|
161
|
-
else
|
162
|
-
false
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
private
|
167
|
-
def get_glossary(path)
|
168
|
-
glossary_name, source_language, target_language = File::basename(path, ".*").split(".")
|
169
|
-
[glossary_name, source_language, target_language]
|
170
|
-
end
|
171
|
-
|
172
|
-
def get_all_glossary_sources(path)
|
173
|
-
%w(yml tsv csv).map{|type| File.join(path, "*.#{type}") }
|
120
|
+
def find_project(project_name)
|
121
|
+
project = projects.detect{|project| project.name == project_name}
|
174
122
|
end
|
175
123
|
|
176
124
|
def logaling_db_home
|
177
125
|
File.join(@path, "db")
|
178
126
|
end
|
179
127
|
|
128
|
+
private
|
180
129
|
def logaling_projects_path
|
181
130
|
File.join(@path, "projects")
|
182
131
|
end
|
@@ -185,11 +134,11 @@ module Logaling
|
|
185
134
|
File.join(@path, "cache")
|
186
135
|
end
|
187
136
|
|
188
|
-
def
|
137
|
+
def registered_project_paths
|
189
138
|
Dir[File.join(logaling_projects_path, "*")]
|
190
139
|
end
|
191
140
|
|
192
|
-
def
|
141
|
+
def imported_glossary_paths
|
193
142
|
Dir[File.join(cache_path, "*")]
|
194
143
|
end
|
195
144
|
end
|
data/lib/logaling.rb
CHANGED
data/logaling-command.gemspec
CHANGED
@@ -38,7 +38,7 @@ Gem::Specification.new do |s|
|
|
38
38
|
|
39
39
|
s.add_runtime_dependency 'thor', ['>= 0.14.6']
|
40
40
|
s.add_runtime_dependency 'bundler', ['>= 1.0']
|
41
|
-
s.add_runtime_dependency 'rroonga', ['>=
|
41
|
+
s.add_runtime_dependency 'rroonga', ['>= 2.0.3']
|
42
42
|
s.add_runtime_dependency 'rainbow'
|
43
43
|
s.add_runtime_dependency 'nokogiri'
|
44
44
|
s.add_runtime_dependency 'activesupport'
|
@@ -22,10 +22,10 @@ describe Logaling::Command::Application do
|
|
22
22
|
let(:logaling_config) { File.join(File.dirname(__FILE__), "..", "tmp", ".logaling") }
|
23
23
|
let(:base_options) { {"glossary"=>"spec", "source-language"=>"en", "target-language"=>"ja", "logaling-config" => logaling_config} }
|
24
24
|
let(:command) { Logaling::Command::Application.new([], base_options) }
|
25
|
-
let(:glossary) { Logaling::Glossary.new('spec', 'en', 'ja', logaling_home) }
|
26
|
-
let(:glossary_path) { glossary.source_path }
|
27
25
|
let(:target_project_path) { File.join(logaling_home, "projects", "spec") }
|
28
26
|
let(:repository) { Logaling::Repository.new(logaling_home) }
|
27
|
+
let(:glossary) { repository.find_project('spec').find_glossary('en', 'ja') }
|
28
|
+
let(:glossary_source_path) { glossary.glossary_source.source_path }
|
29
29
|
|
30
30
|
before do
|
31
31
|
FileUtils.rm_rf(File.join(logaling_home, 'projects', 'spec'))
|
@@ -265,7 +265,7 @@ describe Logaling::Command::Application do
|
|
265
265
|
command.add("spec", "テスト")
|
266
266
|
end
|
267
267
|
|
268
|
-
subject { YAML::load_file(
|
268
|
+
subject { YAML::load_file(glossary_source_path).find{|h| h["source_term"] == "spec" }}
|
269
269
|
|
270
270
|
it "glossary yaml should contain that term" do
|
271
271
|
subject["target_term"].should == "テスト"
|
@@ -282,7 +282,7 @@ describe Logaling::Command::Application do
|
|
282
282
|
command.add("spec", "テスト", "備考")
|
283
283
|
end
|
284
284
|
|
285
|
-
subject { YAML::load_file(
|
285
|
+
subject { YAML::load_file(glossary_source_path).find{|h| h["source_term"] == "spec" }}
|
286
286
|
|
287
287
|
it "glossary yaml should contain that term" do
|
288
288
|
subject["target_term"].should == "テスト"
|
@@ -331,7 +331,7 @@ describe Logaling::Command::Application do
|
|
331
331
|
context "with arguments except note" do
|
332
332
|
before do
|
333
333
|
command.update("spec", "テスト", "スペック")
|
334
|
-
@yaml = YAML::load_file(
|
334
|
+
@yaml = YAML::load_file(glossary_source_path).find{|h| h["source_term"] == "spec" }
|
335
335
|
end
|
336
336
|
|
337
337
|
it "term's target_term should be updated" do
|
@@ -352,7 +352,7 @@ describe Logaling::Command::Application do
|
|
352
352
|
context 'with existing bilingual pair and different note' do
|
353
353
|
before do
|
354
354
|
command.update("spec", "テスト", "テスト", "備考だけ書き換え")
|
355
|
-
@yaml = YAML::load_file(
|
355
|
+
@yaml = YAML::load_file(glossary_source_path).find{|h| h["source_term"] == "spec" }
|
356
356
|
end
|
357
357
|
|
358
358
|
it "should update note" do
|
@@ -450,12 +450,12 @@ describe Logaling::Command::Application do
|
|
450
450
|
end
|
451
451
|
|
452
452
|
describe "#show" do
|
453
|
-
let(:csv_path) { File.join(File.dirname(
|
453
|
+
let(:csv_path) { File.join(File.dirname(glossary_source_path), "spec.ja.en.csv") }
|
454
454
|
before do
|
455
455
|
command.new('spec', 'en', 'ja')
|
456
456
|
command.add("spec-test", "スペックてすと", "備考")
|
457
457
|
|
458
|
-
FileUtils.mkdir_p(File.dirname(
|
458
|
+
FileUtils.mkdir_p(File.dirname(glossary_source_path))
|
459
459
|
FileUtils.touch(csv_path)
|
460
460
|
File.open(csv_path, "w"){|f| f.puts "test_logaling,テストろがりん"}
|
461
461
|
end
|
@@ -496,7 +496,8 @@ describe Logaling::Command::Application do
|
|
496
496
|
|
497
497
|
context 'when a glossary is unregistered' do
|
498
498
|
before do
|
499
|
-
repository.
|
499
|
+
project = repository.find_project('spec')
|
500
|
+
repository.unregister(project)
|
500
501
|
command.options = base_options.merge("no-pager" => true)
|
501
502
|
@stdout = capture(:stdout) {command.list}
|
502
503
|
end
|
@@ -20,15 +20,14 @@ require "fileutils"
|
|
20
20
|
|
21
21
|
module Logaling
|
22
22
|
describe Glossary do
|
23
|
-
let(:project) { "spec" }
|
24
23
|
let(:logaling_home) { @logaling_home }
|
25
|
-
let(:glossary) { Glossary.new(project, 'en', 'ja', logaling_home) }
|
26
|
-
let(:glossary_path) { glossary.source_path }
|
27
24
|
let(:repository) { Logaling::Repository.new(logaling_home) }
|
25
|
+
let(:glossary) { repository.find_project('spec').find_glossary('en', 'ja') }
|
26
|
+
let(:glossary_source_path) { glossary.glossary_source.source_path }
|
28
27
|
|
29
28
|
before do
|
30
29
|
FileUtils.remove_entry_secure(File.join(logaling_home, 'projects', 'spec'), true)
|
31
|
-
FileUtils.mkdir_p(File.
|
30
|
+
FileUtils.mkdir_p(File.join(logaling_home, 'projects', 'spec'))
|
32
31
|
end
|
33
32
|
|
34
33
|
describe '#add' do
|
@@ -38,7 +37,7 @@ module Logaling
|
|
38
37
|
end
|
39
38
|
|
40
39
|
it 'glossary yaml should have that bilingual pair' do
|
41
|
-
yaml = YAML::load_file(
|
40
|
+
yaml = YAML::load_file(glossary_source_path)
|
42
41
|
term = yaml.index({"source_term"=>"spec", "target_term"=>"スペック", "note"=>"テストスペック"})
|
43
42
|
term.should_not be_nil
|
44
43
|
end
|
@@ -50,7 +49,7 @@ module Logaling
|
|
50
49
|
end
|
51
50
|
|
52
51
|
it "should create the glossary and add term" do
|
53
|
-
yaml = YAML::load_file(
|
52
|
+
yaml = YAML::load_file(glossary_source_path)
|
54
53
|
term = yaml.index({"source_term"=>"test", "target_term"=>"テスト", "note"=>"テスト"})
|
55
54
|
term.should_not be_nil
|
56
55
|
end
|
@@ -86,7 +85,7 @@ module Logaling
|
|
86
85
|
end
|
87
86
|
|
88
87
|
it 'should clear note' do
|
89
|
-
yaml = YAML::load_file(
|
88
|
+
yaml = YAML::load_file(glossary_source_path)
|
90
89
|
term = yaml.index({"source_term"=>"user", "target_term"=>"ユーザ", "note"=>""})
|
91
90
|
term.should_not be_nil
|
92
91
|
end
|
@@ -153,7 +152,7 @@ module Logaling
|
|
153
152
|
glossary.add("delete_logaling", "てすと1", "備考")
|
154
153
|
glossary.add("delete_logaling", "てすと2", "備考")
|
155
154
|
glossary.delete_all("delete_logaling", true)
|
156
|
-
@result = Logaling::
|
155
|
+
@result = Logaling::GlossarySource.create(glossary_source_path, glossary).load
|
157
156
|
end
|
158
157
|
|
159
158
|
it {
|