-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
45277e7
commit 079618e
Showing
10 changed files
with
88 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,23 @@ | ||
require_relative 'fake_file' | ||
|
||
module Pixelpress | ||
class Document | ||
attr_reader :html | ||
attr_reader :file_name | ||
attr_reader :filename | ||
|
||
def initialize(html, renderer, options = {}) | ||
@html = html | ||
def initialize(file, renderer, options = {}) | ||
@file = file | ||
@renderer = renderer | ||
@file_name = options[:file_name] | ||
@filename = options[:filename] | ||
end | ||
|
||
def html | ||
file.read | ||
end | ||
|
||
def pdf | ||
FakeFile.new pdf_data, original_filename: file_name | ||
@pdf ||= renderer.render(file) | ||
end | ||
|
||
private | ||
|
||
attr_accessor :renderer | ||
|
||
def pdf_data | ||
@pdf_data ||= renderer.render(html) | ||
end | ||
attr_accessor :renderer, :file | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
class Pixelpress::TestRenderer | ||
def render(html) | ||
File.binread(File.join(__dir__, "test.pdf")) | ||
def render(_) | ||
File.open(File.join(__dir__, "test.pdf")) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require 'spec_helper' | ||
|
||
describe Pixelpress do | ||
let(:renderer) { Pixelpress::TestRenderer.new } | ||
let(:document) do | ||
file = Tempfile.new | ||
file.write <<~HTML | ||
<html> | ||
<body> | ||
<h1>Invoice</h1> | ||
</body> | ||
</html> | ||
HTML | ||
file.rewind | ||
Pixelpress::Document.new(file, renderer, filename: 'invoice-1') | ||
end | ||
|
||
it 'checks if the file name of pdf is correct' do | ||
expect(document.filename).to eq 'invoice-1' | ||
end | ||
|
||
it 'checks if it is not calling weasyprint when html is called' do | ||
expect(renderer).not_to receive(:render) | ||
document.html | ||
end | ||
|
||
it 'checks if it is calling weasydocument when pdf is called' do | ||
expect(renderer).to receive(:render) | ||
document.pdf | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require 'spec_helper' | ||
|
||
describe Pixelpress::Base do | ||
let(:renderer) { Pixelpress::TestRenderer.new } | ||
let(:document) { InvoicePrinter.invoice } | ||
|
||
before(:each) do | ||
ActionController::Base.append_view_path File.join(spec_root) | ||
InvoicePrinter.renderer = renderer | ||
end | ||
|
||
class InvoicePrinter < Pixelpress::Base | ||
def invoice | ||
end | ||
|
||
def filename | ||
'sasha' | ||
end | ||
end | ||
|
||
it 'selects the right template' do | ||
expect(document.html).to include 'Invoice' | ||
end | ||
|
||
it 'checks if the file name of pdf is correct' do | ||
expect(document.filename).to eq 'sasha' | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters