logaling-command 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,3 +1,19 @@
1
+ #
2
+ # Copyright (C) 2011 Miho SUZUKI
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
1
17
  source "http://rubygems.org"
2
18
 
3
19
  # Specify your gem's dependencies in logaling-command.gemspec
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ ## logaling-command
2
+
3
+ [logaling-command](http://logaling.github.com) is a CLI for managing bilingual glossary.
4
+ You can add/update/delete terms to your glossary, and search glossaries at once.
5
+
6
+ ### To install:
7
+
8
+ % gem install logaling-command
9
+
10
+ ### Usage:
11
+
12
+ Create new glossary:
13
+
14
+ % loga new my_glossary en ja
15
+
16
+ Add term to glossary:
17
+
18
+ % loga add developer 開発者
19
+
20
+ Lookup glosasry:
21
+
22
+ % loga lookup develop<br/>
23
+ developer ソフトウェア開発者 (my_glossary)
24
+
25
+ ### License
26
+
27
+ GNU GENERAL PUBLIC LICENSE Version 3. See COPYING.<br/>
28
+ (Miho Suzuki has a right to change the license including contributed patches.)
data/bin/loga CHANGED
@@ -1,4 +1,19 @@
1
1
  #!/usr/bin/env ruby
2
+ #
3
+ # Copyright (C) 2011 Miho SUZUKI
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/>.
2
17
 
3
18
  lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
4
19
  $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
@@ -1,4 +1,19 @@
1
1
  # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2011 Miho SUZUKI
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/>.
2
17
 
3
18
  require 'thor'
4
19
  require 'rainbow'
@@ -7,7 +22,7 @@ require "logaling/glossary"
7
22
  require "logaling/external_glossary"
8
23
 
9
24
  class Logaling::Command < Thor
10
- VERSION = "0.0.9"
25
+ VERSION = "0.1.0"
11
26
  LOGALING_CONFIG = '.logaling'
12
27
 
13
28
  map '-a' => :add,
@@ -30,11 +45,10 @@ class Logaling::Command < Thor
30
45
  def new(project_name, source_language, target_language=nil)
31
46
  unless File.exist?(LOGALING_CONFIG)
32
47
  FileUtils.mkdir_p(File.join(LOGALING_CONFIG, "glossary"))
33
- File.open(File.join(LOGALING_CONFIG, "config"), 'w') do |config|
34
- config.puts "--glossary #{project_name}"
35
- config.puts "--source-language #{source_language}"
36
- config.puts "--target-language #{target_language}" if target_language
37
- end
48
+ config = {"glossary" => project_name, "source-language" => source_language}
49
+ config["target-language"] = target_language if target_language
50
+ write_config(File.join(LOGALING_CONFIG, "config"), config)
51
+
38
52
  register unless options["no-register"]
39
53
  say "Successfully created #{LOGALING_CONFIG}"
40
54
  else
@@ -85,6 +99,23 @@ class Logaling::Command < Thor
85
99
  say "#{config['glossary']} is not yet registered."
86
100
  end
87
101
 
102
+ desc 'config [KEY] [VALUE] [--global(optional)]', 'Set config.'
103
+ method_option "global", type: :boolean, default: false
104
+ def config(key, value)
105
+ support_keys = %w(glossary source-language target-language)
106
+ raise Logaling::CommandFailed, "#{key} is unsupported option" unless support_keys.include?(key)
107
+
108
+ config_path = options["global"] ? File.join(LOGALING_HOME, "config") : File.join(find_dotfile, "config")
109
+ FileUtils.touch(config_path) unless File.exist?(config_path)
110
+
111
+ config = load_config(config_path)
112
+ config = merge_options({key => value}, config)
113
+ write_config(config_path, config)
114
+ say "Successfully set config."
115
+ rescue Logaling::CommandFailed => e
116
+ say e.message
117
+ end
118
+
88
119
  desc 'add [SOURCE TERM] [TARGET TERM] [NOTE(optional)]', 'Add term to glossary.'
89
120
  def add(source_term, target_term, note='')
90
121
  glossary.add(source_term, target_term, note)
@@ -122,14 +153,16 @@ class Logaling::Command < Thor
122
153
  terms = repository.lookup(source_term, config["source_language"], config["target_language"], config["glossary"])
123
154
 
124
155
  unless terms.empty?
156
+ max_str_size = terms.map{|term| term[:source_term].size}.sort.last
125
157
  terms.each do |term|
126
- str_term = "#{term[:source_term].bright}\t\t: #{term[:target_term]}"
127
- str_term << "\t# #{term[:note]}" unless term[:note].empty?
128
- if repository.registered_project_counts > 1
158
+ target_string = "#{term[:target_term].bright}"
159
+ target_string << "\t# #{term[:note]}" unless term[:note].empty?
160
+ if repository.glossary_counts > 1
129
161
  color = (term[:name] == config["glossary"]) ? :green : :cyan
130
- str_term << "\t(#{term[:name]})".color(color)
162
+ target_string << "\t(#{term[:name]})".color(color)
131
163
  end
132
- puts " #{str_term}"
164
+ source_string = term[:source_term].split(source_term).insert(1, source_term.dup.bright).join
165
+ printf(" %-#{max_str_size+10}s %s\n", source_string, target_string)
133
166
  end
134
167
  else
135
168
  "source-term <#{source_term}> not found"
@@ -168,10 +201,13 @@ class Logaling::Command < Thor
168
201
  end
169
202
 
170
203
  def load_config_and_merge_options(required={})
171
- config = load_config
172
- config["glossary"] = options["glossary"] ? options["glossary"] : config["glossary"]
173
- config["source-language"] = options["source-language"] ? options["source-language"] : config["source-language"]
174
- config["target-language"] = options["target-language"] ? options["target-language"] : config["target-language"]
204
+ config_list ||= {}
205
+ find_config.each{|type, path| config_list[type] = load_config(path)}
206
+ global_config = config_list["global_config"] ? config_list["global_config"] : {}
207
+ project_config = config_list["project_config"] ? config_list["project_config"] : {}
208
+
209
+ config = merge_options(project_config, global_config)
210
+ config = merge_options(options, config)
175
211
 
176
212
  required.each do |required_option, message|
177
213
  raise(Logaling::CommandFailed, message) unless config[required_option]
@@ -180,15 +216,29 @@ class Logaling::Command < Thor
180
216
  config
181
217
  end
182
218
 
219
+ def merge_options(options, secondary_options)
220
+ config ||={}
221
+ config["glossary"] = options["glossary"] ? options["glossary"] : secondary_options["glossary"]
222
+ config["source-language"] = options["source-language"] ? options["source-language"] : secondary_options["source-language"]
223
+ config["target-language"] = options["target-language"] ? options["target-language"] : secondary_options["target-language"]
224
+ config
225
+ end
226
+
183
227
  def find_config
184
- File.join(find_dotfile, 'config')
228
+ config ||= {}
229
+ config["project_config"] = File.join(find_dotfile, 'config')
230
+ config["global_config"] = global_config_path if global_config_path
231
+ config
185
232
  rescue Logaling::CommandFailed
186
- repository.config_path
233
+ config ||= {}
234
+ config["project_config"] = repository.config_path if repository.config_path
235
+ config["global_config"] = global_config_path if global_config_path
236
+ config
187
237
  end
188
238
 
189
- def load_config
239
+ def load_config(config_path=nil)
190
240
  config ||= {}
191
- if config_path = find_config
241
+ if config_path
192
242
  File.readlines(config_path).map{|l| l.chomp.split " "}.each do |option|
193
243
  key = option[0].sub(/^[\-]{2}/, "")
194
244
  value = option[1]
@@ -215,4 +265,17 @@ class Logaling::Command < Thor
215
265
  end
216
266
  end
217
267
  end
268
+
269
+ def global_config_path
270
+ path = File.join(LOGALING_HOME, "config")
271
+ File.exist?(path) ? path : nil
272
+ end
273
+
274
+ def write_config(config_path, config)
275
+ File.open(config_path, 'w') do |fp|
276
+ fp.puts "--glossary #{config['glossary']}" if config['glossary']
277
+ fp.puts "--source-language #{config['source-language']}" if config['source-language']
278
+ fp.puts "--target-language #{config['target-language']}" if config['target-language']
279
+ end
280
+ end
218
281
  end
@@ -1,3 +1,18 @@
1
+ # Copyright (C) 2011 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
+
1
16
  require 'open-uri'
2
17
  require 'nokogiri'
3
18
 
@@ -1,3 +1,18 @@
1
+ # Copyright (C) 2011 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
+
1
16
  require 'open-uri'
2
17
  require 'nokogiri'
3
18
 
@@ -1,3 +1,18 @@
1
+ # Copyright (C) 2011 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
+
1
16
  require 'open-uri'
2
17
  require 'nokogiri'
3
18
 
@@ -1,3 +1,18 @@
1
+ # Copyright (C) 2011 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
+
1
16
  require 'active_support/inflector'
2
17
 
3
18
  class Logaling::ExternalGlossary
@@ -1,4 +1,20 @@
1
1
  # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2011 Miho SUZUKI
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
+
2
18
  require 'psych'
3
19
  require "yaml"
4
20
  require "fileutils"
@@ -1,4 +1,19 @@
1
1
  # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2011 Miho SUZUKI
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/>.
2
17
 
3
18
  require 'psych'
4
19
  require "yaml"
@@ -1,4 +1,20 @@
1
1
  # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2011 Miho SUZUKI
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
+
2
18
  require "fileutils"
3
19
  require "logaling/glossary_db"
4
20
 
@@ -53,6 +69,7 @@ module Logaling
53
69
  end
54
70
 
55
71
  def index
72
+ return if latest_index?
56
73
  projects = Dir[File.join(@path, "projects", "*")]
57
74
 
58
75
  Logaling::GlossaryDB.open(logaling_db_home, "utf8") do |db|
@@ -66,10 +83,12 @@ module Logaling
66
83
  db.index_glossary(glossary, name, source_language, target_language)
67
84
  end
68
85
  end
86
+
87
+ FileUtils.touch(index_at_file)
69
88
  end
70
89
 
71
- def registered_project_counts
72
- Dir[File.join(logaling_projects_path, "*")].size
90
+ def glossary_counts
91
+ [registered_projects, imported_glossaries].map(&:size).inject(&:+)
73
92
  end
74
93
 
75
94
  def config_path
@@ -78,9 +97,22 @@ module Logaling
78
97
  end
79
98
 
80
99
  private
100
+ def latest_index?
101
+ if File.exist?(index_at_file)
102
+ index_at = File.mtime(index_at_file)
103
+ all_glossary_files = [cache_path, registered_projects.map{|path| File.join(path, "glossary")}].flatten.map{|path| get_all_glossary_paths(path)}.flatten
104
+ unless Dir.glob(all_glossary_files).any?{|file| File.mtime(file) >= index_at }
105
+ true
106
+ else
107
+ false
108
+ end
109
+ else
110
+ false
111
+ end
112
+ end
113
+
81
114
  def get_glossaries(path)
82
- glob_list = %w(yml tsv csv).map{|type| File.join(path, "*.#{type}") }
83
- Dir.glob(glob_list).map do |file|
115
+ Dir.glob(get_all_glossary_paths(path)).map do |file|
84
116
  name, source_language, target_language = File::basename(file, ".*").split(".")
85
117
  [Glossary.load(file), name, source_language, target_language]
86
118
  end
@@ -90,6 +122,10 @@ module Logaling
90
122
  get_glossaries(File.join(path, "glossary"))
91
123
  end
92
124
 
125
+ def get_all_glossary_paths(path)
126
+ %w(yml tsv csv).map{|type| File.join(path, "*.#{type}") }
127
+ end
128
+
93
129
  def logaling_db_home
94
130
  File.join(@path, "db")
95
131
  end
@@ -101,5 +137,17 @@ module Logaling
101
137
  def cache_path
102
138
  File.join(@path, "cache")
103
139
  end
140
+
141
+ def registered_projects
142
+ Dir[File.join(logaling_projects_path, "*")]
143
+ end
144
+
145
+ def imported_glossaries
146
+ Dir[File.join(cache_path, "*")]
147
+ end
148
+
149
+ def index_at_file
150
+ File.join(logaling_db_home, "index_at")
151
+ end
104
152
  end
105
153
  end
data/lib/logaling.rb CHANGED
@@ -1,4 +1,19 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2011 Miho SUZUKI
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/>.
2
17
 
3
18
  require "logaling/command"
4
19
 
@@ -1,4 +1,20 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2011 Miho SUZUKI
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
+
2
18
  $:.push File.expand_path("../lib", __FILE__)
3
19
  require "logaling/command"
4
20
 
@@ -22,6 +38,7 @@ Gem::Specification.new do |s|
22
38
  s.add_runtime_dependency 'bundler', ['>= 1.0']
23
39
  s.add_runtime_dependency 'rroonga', ['>= 1.3.0']
24
40
  s.add_runtime_dependency 'rainbow'
41
+ s.add_runtime_dependency 'nokogiri'
25
42
  s.add_runtime_dependency 'active_support'
26
43
 
27
44
  s.add_development_dependency 'rake'
@@ -1,4 +1,20 @@
1
1
  # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2011 Miho SUZUKI
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
+
2
18
  require File.join(File.dirname(__FILE__), "..", "spec_helper")
3
19
 
4
20
  describe Logaling::Command do
@@ -159,6 +175,53 @@ describe Logaling::Command do
159
175
  end
160
176
  end
161
177
 
178
+ describe '#config' do
179
+ let(:project_config) { File.join(Logaling::Command::LOGALING_CONFIG, 'config') }
180
+ let(:global_config) { File.join(LOGALING_HOME, 'config') }
181
+
182
+ subject { File.read(project_config) }
183
+
184
+ context 'with argument "target-language"' do
185
+ before do
186
+ command.new('spec', 'en')
187
+ command.config("target-language", "fr")
188
+ end
189
+
190
+ it 'should overwrite target-language' do
191
+ should include "--target-language fr"
192
+ end
193
+ end
194
+
195
+ context 'with argument "source-language"' do
196
+ before do
197
+ command.new('spec', 'en')
198
+ command.config("source-language", "ja")
199
+ end
200
+
201
+ it 'should overwrite source-language' do
202
+ should include "--source-language ja"
203
+ end
204
+ end
205
+
206
+ context 'with argument "--global" and "target-language"' do
207
+ before do
208
+ command.options = base_options.merge("global" => true)
209
+ command.new('spec', 'en')
210
+ command.config("target-language", "ja")
211
+ end
212
+
213
+ subject { File.read(global_config) }
214
+
215
+ it 'should create LOGALING_HOME/config and write target-language' do
216
+ should include "--target-language ja"
217
+ end
218
+
219
+ after do
220
+ FileUtils.remove_entry_secure(global_config, true)
221
+ end
222
+ end
223
+ end
224
+
162
225
  describe '#add' do
163
226
  before do
164
227
  command.new('spec', 'en', 'ja')
@@ -195,6 +258,37 @@ describe Logaling::Command do
195
258
  subject["note"].should == "備考"
196
259
  end
197
260
  end
261
+
262
+ context 'project config does not have TARGET-LANGUAGE' do
263
+ let(:command2) { Logaling::Command.new([], {}) }
264
+ let(:global_config) { File.join(LOGALING_HOME, 'config') }
265
+ before do
266
+ FileUtils.remove_entry_secure(Logaling::Command::LOGALING_CONFIG, true)
267
+ command2.new('spec2', 'en')
268
+ FileUtils.touch(global_config)
269
+ File.open(global_config, "w") do |f|
270
+ f.puts "--target-language fr"
271
+ end
272
+ end
273
+
274
+ context 'but global config have it' do
275
+ before do
276
+ command2.add('config test', '設定ファイルのテスト')
277
+ @stdout = capture(:stdout) {command2.lookup("config")}
278
+ end
279
+
280
+ it "should use global config's TARGET-LANGUAGE" do
281
+ @stdout.should include "config"
282
+ @stdout.should include "test"
283
+ @stdout.should include "設定ファイルのテスト"
284
+ @stdout.should include "(spec2)"
285
+ end
286
+ end
287
+
288
+ after do
289
+ FileUtils.remove_entry_secure(global_config, true)
290
+ end
291
+ end
198
292
  end
199
293
 
200
294
  describe "#update" do
@@ -244,29 +338,9 @@ describe Logaling::Command do
244
338
  end
245
339
 
246
340
  it 'succeed at find by term without command.index' do
247
- @stdout.should include "spec : スペック # 備考"
248
- end
249
- end
250
-
251
- context 'only one project exist in LOGALING_HOME/projects' do
252
- before do
253
- Dir.should_receive(:entries).with(File.join(LOGALING_HOME, "projects")).and_return([".", "..", "spec"])
254
- @stdout = capture(:stdout) {command.lookup("spec")}
255
- end
256
-
257
- it 'should not show glossary name' do
258
- @stdout.should_not include "(spec)"
259
- end
260
- end
261
-
262
- context 'some projects exist in LOGALING_HOME/projects' do
263
- before do
264
- Dir.should_receive(:entries).with(File.join(LOGALING_HOME, "projects")).and_return([".", "..", "spec", "spec2"])
265
- @stdout = capture(:stdout) {command.lookup("spec")}
266
- end
267
-
268
- it 'should show glossary name' do
269
- @stdout.should include "(spec)"
341
+ @stdout.should include "spec"
342
+ @stdout.should include "スペック"
343
+ @stdout.should include "# 備考"
270
344
  end
271
345
  end
272
346
  end
@@ -1,4 +1,20 @@
1
1
  # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2011 Miho SUZUKI
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
+
2
18
  require File.join(File.dirname(__FILE__), "..", "spec_helper")
3
19
  require "fileutils"
4
20
 
@@ -77,26 +93,26 @@ module Logaling
77
93
  describe '#delete' do
78
94
  context 'bilingual pair exists' do
79
95
  before do
80
- glossary.add("delete", "てすと1", "備考")
81
- glossary.add("delete", "てすと2", "備考")
82
- glossary.delete("delete", "てすと1")
96
+ glossary.add("delete_logaling", "てすと1", "備考")
97
+ glossary.add("delete_logaling", "てすと2", "備考")
98
+ glossary.delete("delete_logaling", "てすと1")
83
99
  repository.index
84
- @result = repository.lookup("delete", "en", "ja", project)
100
+ @result = repository.lookup("delete_logaling", "en", "ja", project)
85
101
  end
86
102
 
87
103
  it 'should delete the bilingual pair' do
88
- @result.should include({:name=>"spec", :source_language=>"en", :target_language=>"ja", :source_term=>"delete", :target_term=>"てすと2", :note=>"備考"})
89
- @result.should_not include({:name=>"spec", :source_language=>"en", :target_language=>"ja", :source_term=>"delete", :target_term=>"てすと1", :note=>"備考"})
104
+ @result.should include({:name=>"spec", :source_language=>"en", :target_language=>"ja", :source_term=>"delete_logaling", :target_term=>"てすと2", :note=>"備考"})
105
+ @result.should_not include({:name=>"spec", :source_language=>"en", :target_language=>"ja", :source_term=>"delete_logaling", :target_term=>"てすと1", :note=>"備考"})
90
106
  end
91
107
  end
92
108
 
93
109
  context 'bilingual pair does not exist' do
94
110
  before do
95
- glossary.add("user", "ユーザ", "ユーザーではない")
111
+ glossary.add("user_logaling", "ユーザ", "ユーザーではない")
96
112
  end
97
113
 
98
114
  it {
99
- -> { glossary.delete("user", "ユーザー") }.should raise_error(Logaling::TermError)
115
+ -> { glossary.delete("user_logaling", "ユーザー") }.should raise_error(Logaling::TermError)
100
116
  }
101
117
  end
102
118
  end
@@ -104,46 +120,46 @@ module Logaling
104
120
  describe '#delete_all' do
105
121
  context 'source_term not found' do
106
122
  before do
107
- glossary.add("user", "ユーザ", "備考")
123
+ glossary.add("user_logaling", "ユーザ", "備考")
108
124
  end
109
125
 
110
126
  it {
111
- -> { glossary.delete_all("usr") }.should raise_error(Logaling::TermError)
127
+ -> { glossary.delete_all("usr_logaling") }.should raise_error(Logaling::TermError)
112
128
  }
113
129
  end
114
130
 
115
131
  context 'source_term found' do
116
132
  context 'there is only 1 bilingual pair' do
117
133
  before do
118
- glossary.add("user", "ユーザ", "備考")
119
- glossary.delete_all("user")
134
+ glossary.add("user_logaling", "ユーザ", "備考")
135
+ glossary.delete_all("user_logaling")
120
136
  repository.index
121
- @result = repository.lookup("user", "en", "ja", project)
137
+ @result = repository.lookup("user_logaling", "en", "ja", project)
122
138
  end
123
139
 
124
140
  it 'should delete the term' do
125
- @result.should_not include({:name=>"spec", :source_language=>"en", :target_language=>"ja", :source_term=>"user", :target_term=>"ユーザ", :note=>"備考"})
141
+ @result.should_not include({:name=>"spec", :source_language=>"en", :target_language=>"ja", :source_term=>"user_logaling", :target_term=>"ユーザ", :note=>"備考"})
126
142
  end
127
143
  end
128
144
 
129
145
  context 'there are more than 1 bilingual pair' do
130
146
  before do
131
- glossary.add("user", "ユーザ1", "備考")
132
- glossary.add("user", "ユーザ2", "備考")
133
- glossary.add("delete", "てすと1", "備考")
134
- glossary.add("delete", "てすと2", "備考")
135
- glossary.delete_all("delete", true)
147
+ glossary.add("user_logaling", "ユーザ1", "備考")
148
+ glossary.add("user_logaling", "ユーザ2", "備考")
149
+ glossary.add("delete_logaling", "てすと1", "備考")
150
+ glossary.add("delete_logaling", "てすと2", "備考")
151
+ glossary.delete_all("delete_logaling", true)
136
152
  repository.index
137
- @result = repository.lookup("delete", "en", "ja", project)
153
+ @result = repository.lookup("delete_logaling", "en", "ja", project)
138
154
  end
139
155
 
140
156
  it {
141
- -> { glossary.delete_all("user") }.should raise_error(Logaling::TermError)
157
+ -> { glossary.delete_all("user_logaling") }.should raise_error(Logaling::TermError)
142
158
  }
143
159
 
144
160
  it "should delete terms when force option is true" do
145
- @result.should_not include({:name=>"spec", :source_language=>"en", :target_language=>"ja", :source_term=>"delete", :target_term=>"てすと1", :note=>"備考"})
146
- @result.should_not include({:name=>"spec", :source_language=>"en", :target_language=>"ja", :source_term=>"delete", :target_term=>"てすと2", :note=>"備考"})
161
+ @result.should_not include({:name=>"spec", :source_language=>"en", :target_language=>"ja", :source_term=>"delete_loglaing", :target_term=>"てすと1", :note=>"備考"})
162
+ @result.should_not include({:name=>"spec", :source_language=>"en", :target_language=>"ja", :source_term=>"delete_logaling", :target_term=>"てすと2", :note=>"備考"})
147
163
  end
148
164
  end
149
165
  end
@@ -1,4 +1,20 @@
1
1
  # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2011 Miho SUZUKI
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
+
2
18
  require File.join(File.dirname(__FILE__), "..", "spec_helper")
3
19
  require "fileutils"
4
20
 
@@ -41,7 +57,7 @@ module Logaling
41
57
  subject {repository.lookup("user", "en", "ja", project)}
42
58
 
43
59
  it 'succeed at find by term' do
44
- should be_include({:name=>"spec", :source_language=>"en", :target_language=>"ja", :source_term=>"user", :target_term=>"ユーザー", :note=>''})
60
+ should be_include({:name=>"spec", :source_language=>"en", :target_language=>"ja", :source_term=>"user", :target_term=>"ユーザー", :note=>""})
45
61
  end
46
62
 
47
63
  after do
@@ -60,14 +76,14 @@ module Logaling
60
76
  before do
61
77
  FileUtils.mkdir_p(File.dirname(glossary_path))
62
78
  FileUtils.touch(glossary_path)
63
- glossary.add("spec", "スペック", "備考")
79
+ glossary.add("spec_logaling", "スペック", "備考")
64
80
  repository.index
65
81
  end
66
82
 
67
- subject { logaling_db.open(db_home, "utf8"){|db| logaling_db.lookup("spec")} }
83
+ subject { logaling_db.open(db_home, "utf8"){|db| logaling_db.lookup("spec_logaling")} }
68
84
 
69
85
  it 'glossaries should be indexed' do
70
- should be_include({:name=>"spec", :source_language=>"en", :target_language=>"ja", :source_term=>"spec", :target_term=>"スペック", :note=>"備考"})
86
+ should be_include({:name=>"spec", :source_language=>"en", :target_language=>"ja", :source_term=>"spec_logaling", :target_term=>"スペック", :note=>"備考"})
71
87
  end
72
88
 
73
89
  after do
@@ -86,7 +102,7 @@ module Logaling
86
102
  subject { logaling_db.open(db_home, "utf8"){|db| logaling_db.lookup("user")} }
87
103
 
88
104
  it 'glossaries should be indexed' do
89
- should == [{:name=>"spec", :source_language=>"en", :target_language=>"ja", :source_term=>"user", :target_term=>"ユーザ", :note=>''}]
105
+ should be_include({:name=>"spec", :source_language=>"en", :target_language=>"ja", :source_term=>"user", :target_term=>"ユーザ", :note=>''})
90
106
  end
91
107
 
92
108
  after do
@@ -98,14 +114,14 @@ module Logaling
98
114
  before do
99
115
  FileUtils.mkdir_p(File.dirname(glossary_path))
100
116
  FileUtils.touch(csv_path)
101
- File.open(csv_path, "w"){|f| f.puts "test,テスト"}
117
+ File.open(csv_path, "w"){|f| f.puts "test_logaling,テスト"}
102
118
  repository.index
103
119
  end
104
120
 
105
- subject { logaling_db.open(db_home, "utf8"){|db| logaling_db.lookup("test")} }
121
+ subject { logaling_db.open(db_home, "utf8"){|db| logaling_db.lookup("test_logaling")} }
106
122
 
107
123
  it 'glossaries should be indexed' do
108
- should == [{:name=>"spec", :source_language=>"en", :target_language=>"ja", :source_term=>"test", :target_term=>"テスト", :note=>''}]
124
+ should be_include({:name=>"spec", :source_language=>"en", :target_language=>"ja", :source_term=>"test_logaling", :target_term=>"テスト", :note=>""})
109
125
  end
110
126
 
111
127
  after do
@@ -114,6 +130,23 @@ module Logaling
114
130
  end
115
131
  end
116
132
 
133
+ context 'when glossary exist but not modified' do
134
+ let(:index_at) { File.join(LOGALING_HOME, 'db', 'index_at') }
135
+ before do
136
+ glossary.add("index_test", "インデックスのテスト", "備考")
137
+ repository.index
138
+ @timestamp = File.mtime(index_at)
139
+ sleep(1)
140
+ repository.index
141
+ end
142
+
143
+ subject { File.mtime(index_at) }
144
+
145
+ it 'should not be indexed' do
146
+ should == @timestamp
147
+ end
148
+ end
149
+
117
150
  after do
118
151
  FileUtils.remove_entry_secure(File.join(LOGALING_HOME, 'projects', 'spec'), true)
119
152
  end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,18 @@
1
+ # Copyright (C) 2011 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
+
1
16
  $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
2
17
  require 'logaling'
3
18
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logaling-command
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,11 +13,11 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2011-12-13 00:00:00.000000000Z
16
+ date: 2011-12-20 00:00:00.000000000Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: thor
20
- requirement: &2157016460 !ruby/object:Gem::Requirement
20
+ requirement: &2151838860 !ruby/object:Gem::Requirement
21
21
  none: false
22
22
  requirements:
23
23
  - - ! '>='
@@ -25,10 +25,10 @@ dependencies:
25
25
  version: 0.14.6
26
26
  type: :runtime
27
27
  prerelease: false
28
- version_requirements: *2157016460
28
+ version_requirements: *2151838860
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: bundler
31
- requirement: &2157015780 !ruby/object:Gem::Requirement
31
+ requirement: &2151837280 !ruby/object:Gem::Requirement
32
32
  none: false
33
33
  requirements:
34
34
  - - ! '>='
@@ -36,10 +36,10 @@ dependencies:
36
36
  version: '1.0'
37
37
  type: :runtime
38
38
  prerelease: false
39
- version_requirements: *2157015780
39
+ version_requirements: *2151837280
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: rroonga
42
- requirement: &2157014820 !ruby/object:Gem::Requirement
42
+ requirement: &2151835860 !ruby/object:Gem::Requirement
43
43
  none: false
44
44
  requirements:
45
45
  - - ! '>='
@@ -47,10 +47,10 @@ dependencies:
47
47
  version: 1.3.0
48
48
  type: :runtime
49
49
  prerelease: false
50
- version_requirements: *2157014820
50
+ version_requirements: *2151835860
51
51
  - !ruby/object:Gem::Dependency
52
52
  name: rainbow
53
- requirement: &2157006900 !ruby/object:Gem::Requirement
53
+ requirement: &2151835220 !ruby/object:Gem::Requirement
54
54
  none: false
55
55
  requirements:
56
56
  - - ! '>='
@@ -58,10 +58,21 @@ dependencies:
58
58
  version: '0'
59
59
  type: :runtime
60
60
  prerelease: false
61
- version_requirements: *2157006900
61
+ version_requirements: *2151835220
62
+ - !ruby/object:Gem::Dependency
63
+ name: nokogiri
64
+ requirement: &2151834440 !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: *2151834440
62
73
  - !ruby/object:Gem::Dependency
63
74
  name: active_support
64
- requirement: &2157005540 !ruby/object:Gem::Requirement
75
+ requirement: &2151833260 !ruby/object:Gem::Requirement
65
76
  none: false
66
77
  requirements:
67
78
  - - ! '>='
@@ -69,10 +80,10 @@ dependencies:
69
80
  version: '0'
70
81
  type: :runtime
71
82
  prerelease: false
72
- version_requirements: *2157005540
83
+ version_requirements: *2151833260
73
84
  - !ruby/object:Gem::Dependency
74
85
  name: rake
75
- requirement: &2157005040 !ruby/object:Gem::Requirement
86
+ requirement: &2151832320 !ruby/object:Gem::Requirement
76
87
  none: false
77
88
  requirements:
78
89
  - - ! '>='
@@ -80,10 +91,10 @@ dependencies:
80
91
  version: '0'
81
92
  type: :development
82
93
  prerelease: false
83
- version_requirements: *2157005040
94
+ version_requirements: *2151832320
84
95
  - !ruby/object:Gem::Dependency
85
96
  name: rspec
86
- requirement: &2157004520 !ruby/object:Gem::Requirement
97
+ requirement: &2151831400 !ruby/object:Gem::Requirement
87
98
  none: false
88
99
  requirements:
89
100
  - - ! '>='
@@ -91,7 +102,7 @@ dependencies:
91
102
  version: '0'
92
103
  type: :development
93
104
  prerelease: false
94
- version_requirements: *2157004520
105
+ version_requirements: *2151831400
95
106
  description: A command line interface for logaling.
96
107
  email:
97
108
  - koji.shimada@enishi-tech.com
@@ -108,6 +119,7 @@ files:
108
119
  - .rspec
109
120
  - COPYING
110
121
  - Gemfile
122
+ - README.md
111
123
  - Rakefile
112
124
  - bin/loga
113
125
  - lib/logaling.rb