Module: Gotenberg::Chromium::Files
- Included in:
- Gotenberg::Chromium
- Defined in:
- lib/gotenberg/chromium/files.rb
Instance Method Summary collapse
- #assets(sources) ⇒ Object
-
#binary_assets(sources) ⇒ Object
Sets the additional files, like images, fonts, stylesheets, and so on.
-
#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(sources) ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/gotenberg/chromium/files.rb', line 69 def assets sources sources.each do |f| files << multipart_file(IO.binread(f), File.basename(f)) end self end |
#binary_assets(sources) ⇒ Object
Sets the additional files, like images, fonts, stylesheets, and so on.
61 62 63 64 65 66 67 |
# File 'lib/gotenberg/chromium/files.rb', line 61 def binary_assets sources sources.each do |(io, filename)| files << multipart_file(io, filename) end self 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() files << multipart_file(compiler.body, 'footer.html', 'text/html') self 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) files << multipart_file(compiler.body, 'header.html', 'text/html') self 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 |
# 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) @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.
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/gotenberg/chromium/files.rb', line 48 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 |