Skip to content

Commit

Permalink
Merge branch 'release-0.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
walle committed Aug 25, 2011
2 parents 35af280 + 8108a40 commit 9ca73ba
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 30 deletions.
7 changes: 6 additions & 1 deletion bin/gimli
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)) + '/../lib/')

require 'gimli'

Gimli.process!
if ARGV.flags.version?
puts "Version: #{Gimli::Version}"
exit
end

Gimli.process! ARGV.flags.file, ARGV.flags.recursive?, ARGV.flags.merge?, ARGV.flags.outputfilename, ARGV.flags.outputdir, ARGV.flags.stylesheet

1 change: 1 addition & 0 deletions gimli.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Gem::Specification.new do |s|
s.add_dependency 'pdfkit', '~> 0.5.2'
s.add_dependency 'optiflag', '~> 0.7'

s.add_development_dependency 'rake'
s.add_development_dependency 'rspec'
s.add_development_dependency 'rr'
s.add_development_dependency 'bundler'
Expand Down
10 changes: 3 additions & 7 deletions lib/gimli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@
module Gimli

# Starts the processing of selected files
def self.process!
def self.process!(file, recursive = false, merge = false, output_filename = nil, output_dir = nil, stylesheet = nil)

if ARGV.flags.version?
puts "Version: #{Gimli::Version}"
return
end

@files = Path.list_valid(ARGV.flags.file, ARGV.flags.recursive?).map { |file| MarkupFile.new(file) }
Converter.new(@files).convert!(ARGV.flags.merge?)
@files = Path.list_valid(file, recursive).map { |file| MarkupFile.new(file) }
Converter.new(@files, output_filename, output_dir, stylesheet).convert!(merge)
end
end
15 changes: 9 additions & 6 deletions lib/gimli/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ class Converter

# Initialize the converter with a File
# @param [Array] files The list of Gimli::MarkupFile to convert (passing a single file will still work)
def initialize(files)
def initialize(files, output_filename = nil, output_dir = nil, stylesheet = nil)
@files = files
@output_filename = output_filename
@output_dir = output_dir
@stylesheet = stylesheet
end

# Convert the file and save it as a PDF file
Expand Down Expand Up @@ -81,13 +84,13 @@ def load_stylesheets(kit)
# Returns the selected stylesheet. Defaults to ./gimli.css
# @return [String]
def stylesheet
ARGV.flags.stylesheet? ? ARGV.flags.stylesheet : 'gimli.css'
@stylesheet.nil? ? 'gimli.css' : @stylesheet
end

# Returns the directory where to save the output. Defaults to ./
# @return [String]
def output_dir
output_dir = ARGV.flags.outputdir? ? ARGV.flags.outputdir : Dir.getwd
output_dir = @output_dir.nil? ? Dir.getwd : @output_dir
FileUtils.mkdir_p(output_dir) unless ::File.directory?(output_dir)
output_dir
end
Expand All @@ -98,13 +101,13 @@ def output_dir
def output_file(file = nil)
if file
output_filename = file.name
if ARGV.flags.outputfilename? && @files.length == 1
output_filename = ARGV.flags.outputfilename
if !@output_filename.nil? && @files.length == 1
output_filename = @output_filename
end
else
output_filename = Time.now.to_s.split(' ').join('_')
output_filename = @files.last.name if @files.length == 1 || ARGV.flags.merge?
output_filename = ARGV.flags.outputfilename if ARGV.flags.outputfilename?
output_filename = @output_filename unless @output_filename.nil?
end

::File.join(output_dir, "#{output_filename}.pdf")
Expand Down
2 changes: 1 addition & 1 deletion lib/gimli/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Gimli

Version = "0.1.9"
Version = "0.2.0"

end

21 changes: 6 additions & 15 deletions spec/gimli/converter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@
file = Gimli::MarkupFile.new 'fake'
output_filename = 'my_file'

converter = Gimli::Converter.new [file]
converter = Gimli::Converter.new [file], output_filename
mock(converter).output_dir { Dir.getwd }
mock(ARGV).flags.mock!.outputfilename? { true }
mock(ARGV).flags.mock!.outputfilename { output_filename }

converter.output_file.should == File.join(Dir.getwd, "#{output_filename}.pdf")
end
Expand All @@ -52,34 +50,27 @@
dir = '/tmp/out'

file = Gimli::MarkupFile.new 'fake'
converter = Gimli::Converter.new file
converter = Gimli::Converter.new file, nil, dir

mock(ARGV).flags.mock!.outputdir? { true }
mock(ARGV).flags.mock!.outputdir { dir }
mock(File).directory?(dir) { true }

converter.output_dir.should == dir
end

it 'should use stylesheet if exists in folder' do
it 'should use default stylesheet if none given' do
file = Gimli::MarkupFile.new 'fake'
converter = Gimli::Converter.new file

mock(ARGV).flags.mock!.stylesheet? { false }

converter.stylesheet.should == 'gimli.css'
end

it 'should use stylesheet if given' do
file = Gimli::MarkupFile.new 'fake'
converter = Gimli::Converter.new file

style = '/home/me/gimli/my-style.css'
stylesheet = '/home/me/gimli/my-style.css'

mock(ARGV).flags.mock!.stylesheet? { true }
mock(ARGV).flags.mock!.stylesheet { style }
converter = Gimli::Converter.new file, nil, nil, stylesheet

converter.stylesheet.should == style
converter.stylesheet.should == stylesheet
end

it 'should convert relative image urls to absolute' do
Expand Down

0 comments on commit 9ca73ba

Please sign in to comment.