Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to specify output directory. #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/gly/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ class CLI < Thor

desc 'gabc FILE ...', 'convert gly to gabc'
option :output, type: :string, aliases: :o, banner: 'specify output file name (or template of file names)'
option :output_directory, aliases: :d, type: :string, banner: 'specify output directory'
def gabc(*files)
files.each do |f|
DocumentGabcConvertor.new(parser.parse(f), output_file: options[:output]).convert
DocumentGabcConvertor.new(parser.parse(f), output_file: options[:output], output_directory: options[:output_directory]).convert
end
rescue Gly::Exception => ex
error_exit! ex
Expand All @@ -25,6 +26,7 @@ def gabc(*files)
option :no_document, type: :boolean, aliases: :D, banner: 'produce main LaTeX file without document definition; in this case --no-build is applied automatically'
option :full_headers, type: :boolean, aliases: :H, banner: 'include full document and score headers'
option :template, aliases: :t, banner: 'use custom document template'
option :output_directory, aliases: :d, type: :string, banner: 'specify output directory'
def preview(*files)
tpl = nil
if options[:template]
Expand Down Expand Up @@ -89,11 +91,12 @@ def list(*files)
end

desc 'ly FILE ...', 'transform gly document to lilypond document'
option :output_directory, aliases: :d, type: :string, banner: 'specify output directory'
def ly(*files)
check_lygre_available!

files.each do |f|
DocumentLyConvertor.new(parser.parse(f)).convert
DocumentLyConvertor.new(parser.parse(f), output_directory: options[:output_directory]).convert
end

rescue Gly::Exception => ex
Expand Down
3 changes: 2 additions & 1 deletion lib/gly/document_gabc_convertor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ def initialize(document, options={})
@doc = document
@options = options
@output_name_base = @options[:output_file] || File.basename(@doc.path)
@output_directory = @options[:output_directory] || '.'
end

def convert
each_score_with_gabcname do |score, out_fname|
if @output_name_base == '-'
convert_to STDOUT, score
else
File.open(out_fname, 'w') do |fw|
File.open("#{@output_directory}/#{out_fname}", 'w') do |fw|
convert_to fw, score
end
end
Expand Down
6 changes: 4 additions & 2 deletions lib/gly/document_ly_convertor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ module Gly
# expects the 'lygre' gem
# (which is only an optional dependency of gly)
class DocumentLyConvertor
def initialize(document)
def initialize(document, options={})
@doc = document
@options = options
@output_directory = @options[:output_directory] || '.'
end

def convert
Expand Down Expand Up @@ -37,7 +39,7 @@ def convert
end

out_fname = File.basename(@doc.path) + '.ly'
File.open(out_fname, 'w') do |fw|
File.open("#{@output_directory}/#{out_fname}", 'w') do |fw|
fw.puts ly_output.string
end
end
Expand Down
15 changes: 9 additions & 6 deletions lib/gly/preview_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ module Gly
# *builds* the pdf preview from assets prepared
# by PreviewGenerator
class PreviewBuilder
def initialize
def initialize(**options)
@gabcs = []
@main_tex = nil
@options = options.delete(:options) || {}
end

def add_gabc(path)
Expand All @@ -14,12 +15,14 @@ def add_gabc(path)
attr_accessor :main_tex

def build
@gabcs.each do |g|
outfile = g.sub /(\.gabc)?$/i, '.gtex'
benevolent_exec('gregorio', '-o', outfile, g)
output_directory = @options[:output_directory] || '.'
Dir.chdir(output_directory) do
@gabcs.each do |g|
outfile = g.sub /(\.gabc)?$/i, '.gtex'
benevolent_exec('gregorio', '-o', outfile, g)
end
exec 'lualatex', '--interaction=nonstopmode', @main_tex
end

exec 'lualatex', '--interaction=nonstopmode', @main_tex
end

private
Expand Down
5 changes: 3 additions & 2 deletions lib/gly/preview_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ def initialize(**options)
@preview_dest = nil

@template = options.delete(:template) || default_template
@builder = options.delete(:builder) || PreviewBuilder.new
@options = options.delete(:options) || {}
@builder = options.delete(:builder) || PreviewBuilder.new(options: @options)
end

# IO to which the main LaTeX document should be written.
Expand Down Expand Up @@ -101,7 +101,8 @@ def with_preview_io(src_name)
return
end

File.open(preview_fname(src_name), 'w') do |fw|
output_directory = @options[:output_directory] || '.'
File.open("#{output_directory}/#{preview_fname(src_name)}", 'w') do |fw|
yield fw
end
end
Expand Down