html5-to-pdf
Version:
HTML5 to PDF converter
60 lines (48 loc) • 1.73 kB
text/coffeescript
_ = require 'lodash'
fs = require 'fs-extra'
path = require 'path'
debug = require('debug')('html5-to-pdf:options')
class Options
constructor: (options) ->
debug 'pre-options', options
options
debug 'post-options',
set: (key, value) =>
return _.set , key, value
get: (key) =>
return _.get , key
_set: (options={}) =>
unless options.inputPath? or options.inputBody?
throw new Error 'Missing inputPath or inputBody'
throw new Error 'Missing outputPath' unless options.outputPath?
defaults =
options: {}
renderDelay: 0
template: 'html5bp'
= _.defaults defaults, options
unless .templatePath?
.templatePath = .template
.inputPath = .inputPath unless .inputBody?
.outputPath = .outputPath
.inputBody ?= fs.readFileSync(.inputPath)
.include = _.map .include, ({ type, filePath }) =>
throw new Error 'Invalid include item, must be type css or js' unless type in ['css', 'js']
return {
type,
filePath: (filePath)
}
.include.push {
filePath: ('pdf.css')
type: 'css'
}
.include.push {
filePath: ('highlight.css')
type: 'css'
}
templatePath: (filePath) =>
return path.resolve path.join(__dirname, '../', 'templates', filePath)
convertPath: (filePath) =>
debug 'convertPath', filePath
return filePath if path.isAbsolute filePath
return path.resolve process.cwd(), filePath
module.exports = Options