Module: Gotenberg::Chromium::Files
- Included in:
- Gotenberg::Chromium
- Defined in:
- lib/gotenberg/chromium/files.rb
Instance Method Summary collapse
- #assets(assets) ⇒ Object
-
#binary_assets(assets) ⇒ Object
Sets the additional files, like images, fonts, stylesheets, and so on.
- #files ⇒ Object
-
#footer(footer) ⇒ Object
Adds a footer to each page.
-
#header(header) ⇒ Object
Adds a header to each page.
-
#html(index) ⇒ Object
Converts an HTML document to PDF.
-
#markdown(index, markdowns = []) ⇒ Object
Converts one or more markdown files to PDF.
Instance Method Details
#assets(assets) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/gotenberg/chromium/files.rb', line 71 def assets assets assets.each do |f| files << multipart_file(IO.binread(f), File.basename(f)) end self end |
#binary_assets(assets) ⇒ Object
Sets the additional files, like images, fonts, stylesheets, and so on.
63 64 65 66 67 68 69 |
# File 'lib/gotenberg/chromium/files.rb', line 63 def binary_assets assets assets.each do |(io, filename)| files << multipart_file(io, filename) end self end |
#files ⇒ Object
79 80 81 |
# File 'lib/gotenberg/chromium/files.rb', line 79 def files @files ||= [] end |
#footer(footer) ⇒ Object
Adds a footer to each page. Note: it automatically sets the filename to “footer.html”, as required by Gotenberg.
20 21 22 23 24 25 26 |
# File 'lib/gotenberg/chromium/files.rb', line 20 def compiler = Compiler.new() #File.open('footer.html', 'w') { |f| f.write(compiler.body) } files << multipart_file(compiler.body, 'footer.html', 'text/html') end |
#header(header) ⇒ Object
Adds a header to each page. Note: it automatically sets the filename to “header.html”, as required by Gotenberg.
10 11 12 13 14 15 16 |
# File 'lib/gotenberg/chromium/files.rb', line 10 def header header compiler = Compiler.new(header) #File.open('header.html', 'w') { |f| f.write(compiler.body) } files << multipart_file(compiler.body, 'header.html', 'text/html') end |
#html(index) ⇒ Object
Converts an HTML document to PDF. Note: it automatically sets the index filename to “index.html”, as required by Gotenberg. See gotenberg.dev/docs/modules/chromium#html.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/gotenberg/chromium/files.rb', line 31 def html index compiler = Compiler.new(index) ((compiler.body)) files << multipart_file(compiler.body, 'index.html', 'text/html') binary_assets(compiler.assets) #File.open('index.html', 'w') { |f| f.write(compiler.body) } @endpoint = '/forms/chromium/convert/html' self end |
#markdown(index, markdowns = []) ⇒ Object
Converts one or more markdown files to PDF. Note: it automatically sets the index filename to “index.html”, as required by Gotenberg. See gotenberg.dev/docs/modules/chromium#markdown.
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/gotenberg/chromium/files.rb', line 50 def markdown index, markdowns = [] files << multipart_file(index, 'index.html', 'text/html') markdowns.each do |f| files << multipart_file(IO.binread(f), File.basename(f), 'text/markdown') end @endpoint = '/forms/chromium/convert/markdown' self end |