SHIMADA Koji
null+****@clear*****
Mon Aug 13 20:53:36 JST 2012
SHIMADA Koji 2012-08-13 20:53:36 +0900 (Mon, 13 Aug 2012) New Revision: 3c52a9bd4a68e74ebb87a9530541ba96eb37e0b9 https://github.com/logaling/logaling-command/commit/3c52a9bd4a68e74ebb87a9530541ba96eb37e0b9 Log: Enable wip annotation - add @wip to note if term is now WIP - you want to show wip list on your glossary, execute show command like this: -- %loga show -A(or --annotation) wip Modified files: lib/logaling/command/application.rb lib/logaling/glossary.rb lib/logaling/glossary_db.rb spec/logaling/command_spec.rb Modified: lib/logaling/command/application.rb (+2 -1) =================================================================== --- lib/logaling/command/application.rb 2012-08-13 20:19:28 +0900 (0367f1f) +++ lib/logaling/command/application.rb 2012-08-13 20:53:36 +0900 (5cc9213) @@ -308,6 +308,7 @@ module Logaling::Command desc 'show', 'Show terms in glossary.' method_option "no-pager", type: :boolean, default: false + method_option "annotation", type: :string, aliases: "-A" def show required_options = { "glossary" => "input glossary name '-g <glossary name>'", @@ -319,7 +320,7 @@ module Logaling::Command project =****@repos*****_project(@config.glossary) raise Logaling::ProjectNotFound unless project glossary = project.glossary(@config.source_language, @config.target_language) - terms = glossary.terms + terms = glossary.terms(options["annotation"]) unless terms.empty? run_pager terms.each do |term| Modified: lib/logaling/glossary.rb (+4 -2) =================================================================== --- lib/logaling/glossary.rb 2012-08-13 20:19:28 +0900 (c301518) +++ lib/logaling/glossary.rb 2012-08-13 20:53:36 +0900 (7850010) @@ -17,6 +17,7 @@ module Logaling class Glossary SUPPORTED_FILE_TYPE = %w(yml tsv csv) + SUPPORTED_ANNOTATION = %w(wip) attr_reader :name, :source_language, :target_language @@ -27,12 +28,13 @@ module Logaling @project = project end - def terms + def terms(annotation_word) raise Logaling::GlossaryDBNotFound unless File.exist?(@project.glossary_db_path) index terms = [] + filter_option = annotation_word ? '@' + annotation_word : annotation_word Logaling::GlossaryDB.open(@project.glossary_db_path, "utf8") do |db| - terms = db.translation_list(self) + terms = db.translation_list(self, filter_option) end terms end Modified: lib/logaling/glossary_db.rb (+15 -6) =================================================================== --- lib/logaling/glossary_db.rb 2012-08-13 20:19:28 +0900 (ebc0ed0) +++ lib/logaling/glossary_db.rb 2012-08-13 20:53:36 +0900 (189dcb3) @@ -168,13 +168,22 @@ module Logaling struct_result(records, snippet) end - def translation_list(glossary, order='ascending') + def translation_list(glossary, filter_option, order='ascending') records_raw = Groonga["translations"].select do |record| - [ - record.glossary == glossary.name, - record.source_language == glossary.source_language, - record.target_language == glossary.target_language - ] + if filter_option + [ + record.glossary == glossary.name, + record.source_language == glossary.source_language, + record.target_language == glossary.target_language, + record.note =~ filter_option + ] + else + [ + record.glossary == glossary.name, + record.source_language == glossary.source_language, + record.target_language == glossary.target_language + ] + end end records = records_raw.sort([ Modified: spec/logaling/command_spec.rb (+44 -1) =================================================================== --- spec/logaling/command_spec.rb 2012-08-13 20:19:28 +0900 (4aaec17) +++ spec/logaling/command_spec.rb 2012-08-13 20:53:36 +0900 (bedfa56) @@ -463,7 +463,7 @@ describe Logaling::Command::Application do context 'when .logaling exists' do before do command.options = base_options.merge("no-pager" => true) - @stdout = capture(:stdout) {command.show} + @stdout = capture(:stdout) { command.show } end it 'should show translation list' do @@ -477,6 +477,49 @@ describe Logaling::Command::Application do end end + describe "#show with annotation option" do + before do + command.new('spec', 'en', 'ja') + command.add("spec-test2", "スペックてすと2", "@wip") + command.add("spec-test", "スペックてすと1", "備考") + end + + context 'when glossary contains annotated word' do + before do + command.options = base_options.merge("no-pager" => true) + command.options.merge!("annotation" => "wip") + @stdout = capture(:stdout) { command.show } + end + + it 'should show annotated word' do + @stdout.should include "スペックてすと2" + end + + context 'after annotation removed' do + before do + command.options = base_options.clone + command.update("spec-test2", "スペックてすと2", "スペックてすと2", "") + end + + it 'should not show annotated word' do + @stdout.should_not include "スペックてすと1" + end + end + end + + context 'when glossary does not contain annotated word' do + before do + command.options = base_options.merge("no-pager" => true) + command.options.merge!("annotation" => "wip") + @stdout = capture(:stdout) { command.show } + end + + it 'should not show un-annotated word' do + @stdout.should_not include "スペックてすと1" + end + end + end + describe '#list' do before do command.new('spec', 'en', 'ja') -------------- next part -------------- An HTML attachment was scrubbed... Download