null+****@clear*****
null+****@clear*****
Thu Jun 28 12:02:37 JST 2012
SHIMADA Koji 2012-06-07 16:19:42 +0900 (Thu, 07 Jun 2012) New Revision: 9b6efa1979c3ea20ec9a90763ca9ebdd68811813 https://github.com/logaling/logaling-command/commit/9b6efa1979c3ea20ec9a90763ca9ebdd68811813 Merged 7228757: Merge pull request #60 from logaling/refactor-structure Log: Change to be able to specify the output of the renderer Modified files: lib/logaling/command/application.rb lib/logaling/command/renderers.rb Modified: lib/logaling/command/application.rb (+3 -3) =================================================================== --- lib/logaling/command/application.rb 2012-06-06 22:27:50 +0900 (457e0f1) +++ lib/logaling/command/application.rb 2012-06-07 16:19:42 +0900 (4ee72c5) @@ -241,15 +241,15 @@ module Logaling::Command when "terminal" term_renderer = Logaling::Command::Renderers::TermDefaultRenderer.new(term, @repository, @config, options) term_renderer.max_str_size = max_str_size - term_renderer.render + term_renderer.render($stdout) when "csv" term_renderer = Logaling::Command::Renderers::TermCsvRenderer.new(term, @repository, @config, options) - term_renderer.render + term_renderer.render($stdout) when "json" term_renderer = Logaling::Command::Renderers::TermJsonRenderer.new(term, @repository, @config, options) term_renderer.index = i term_renderer.last_index = terms.length - term_renderer.render + term_renderer.render($stdout) end end else Modified: lib/logaling/command/renderers.rb (+9 -9) =================================================================== --- lib/logaling/command/renderers.rb 2012-06-06 22:27:50 +0900 (8750238) +++ lib/logaling/command/renderers.rb 2012-06-07 16:19:42 +0900 (84e27ec) @@ -8,7 +8,7 @@ module Logaling::Command @options = options end - def render; end + def render(out); end def glossary_name if****@repos*****_counts > 1 @@ -61,9 +61,9 @@ module Logaling::Command @max_str_size = 0 end - def render + def render(out) format = [target_term, note, glossary_name].compact.join("\t") - printf(" %-#{@max_str_size+10}s %s\n", source_term, format) + out.printf(" %-#{@max_str_size+10}s %s\n", source_term, format) end def note @@ -73,10 +73,10 @@ module Logaling::Command end class TermCsvRenderer < TermRenderer - def render + def render(out) items = [source_term, target_term, note, @config.source_language, @config.target_language] - print(CSV.generate {|csv| csv << items}) + out.print(CSV.generate {|csv| csv << items}) end end @@ -89,15 +89,15 @@ module Logaling::Command @last_index = 0 end - def render - first_line? ? puts("[") : puts(",") + def render(out) + first_line? ? out.puts("[") : out.puts(",") record = { :source => source_term, :target => target_term, :note => note, :source_language => @config.source_language, :target_language => @config.target_language } - print JSON.pretty_generate(record) - puts("\n]") if last_line? + out.print JSON.pretty_generate(record) + out.puts("\n]") if last_line? end private -------------- next part -------------- An HTML attachment was scrubbed... 下載