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
Added auto-closing #4
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require "rubygems" | ||
$:.push File.join(File.dirname(__FILE__), "../lib") | ||
require "prawn-print" | ||
|
||
FILENAME = "/tmp/prawn_autoprint_named.pdf" | ||
|
||
pdf = Prawn::Document.new | ||
pdf.text "Help! I am trapped in a PDF factory!" | ||
pdf.autoprint "LaserJet", true | ||
pdf.render_file FILENAME | ||
|
||
`open -a "Adobe Reader" #{FILENAME}` if system("which open") | ||
puts "Done." |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,23 +7,23 @@ module Print | |
include JS | ||
|
||
def print | ||
print_with_auto_to_printer(false, nil) | ||
print_with_auto_to_printer(false, nil, nil) | ||
end | ||
|
||
def autoprint(printer=nil) | ||
print_with_auto_to_printer(true, printer) | ||
def autoprint(printer=nil, close=nil) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right... Still practising ruby... |
||
print_with_auto_to_printer(true, close, printer) | ||
end | ||
|
||
private | ||
|
||
def print_with_auto_to_printer(auto, printer) | ||
def print_with_auto_to_printer(auto, close, printer) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd expect a method named There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
add_docopen_js("print", <<-JS) | ||
|
||
var pp = this.getPrintParams(); | ||
#{interactive_js(auto)} | ||
#{select_printer_js(printer)} | ||
this.print(pp); | ||
|
||
#{close_js(close)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could simplify this by just inlining it. Probably not worth having an extra method. So just |
||
JS | ||
end | ||
|
||
|
@@ -55,6 +55,14 @@ def select_printer_js(printer) | |
end | ||
end | ||
|
||
def close_js(close) | ||
if close | ||
<<-JS | ||
this.closeDoc(); | ||
JS | ||
end | ||
end | ||
|
||
end | ||
end | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module Prawn | ||
module Print | ||
VERSION = "0.0.3" | ||
VERSION = "0.0.4" | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,18 +7,23 @@ | |
describe Prawn::Print, "#print" do | ||
it "should work without arguments" do | ||
pdf = Prawn::Document.new | ||
lambda { pdf.print }.should_not raise_error | ||
expect(lambda { pdf.print }).not_to raise_error | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just |
||
end | ||
end | ||
|
||
describe Prawn::Print, "#autoprint" do | ||
it "should work without arguments" do | ||
pdf = Prawn::Document.new | ||
lambda { pdf.autoprint }.should_not raise_error | ||
expect(lambda { pdf.autoprint }).not_to raise_error | ||
end | ||
|
||
it "should work with an argument" do | ||
pdf = Prawn::Document.new | ||
lambda { pdf.autoprint("LaserJet") }.should_not raise_error | ||
expect(lambda { pdf.autoprint("LaserJet") }).not_to raise_error | ||
end | ||
|
||
it "should work with two arguments" do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tests were admittedly awful before, but "with two arguments" is quite unclear. Maybe |
||
pdf = Prawn::Document.new | ||
expect(lambda { pdf.autoprint("LaserJet", true) }).not_to raise_error | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, weird default for a boolean.