Class: JekyllPandocMultipleFormats::Unite

Inherits:
Printer
  • Object
show all
Defined in:
lib/jekyll-pandoc-multiple-formats/unite.rb

Constant Summary collapse

TEMPLATE =
<<-EOT.gsub(/^\s+/, '')
\\documentclass{article}
\\usepackage{pdfpages}

\\begin{document}
  @@include@@
\\end{document}
EOT
INCLUDE_TEMPLATE =
'\\includepdf[fitpaper=true,pages=-]{@@document@@}'

Constants inherited from Printer

Printer::SHEET_SIZES

Instance Attribute Summary collapse

Attributes inherited from Printer

#extra_options, #nup, #original_file, #output_file, #pages, #papersize, #relative_path, #sheetsize

Instance Method Summary collapse

Methods inherited from Printer

#is_landscape?, #round_to_nearest, #write

Constructor Details

#initialize(output_file, files) ⇒ Unite

Returns a new instance of Unite.



39
40
41
42
43
44
45
46
47
# File 'lib/jekyll-pandoc-multiple-formats/unite.rb', line 39

def initialize(output_file, files)
  raise ArgumentError.new 'An array of filenames is required' unless files.is_a? Array

  @output_file = output_file
  self.files   = files

  render_template
  self
end

Instance Attribute Details

#filesObject

Returns the value of attribute files.



37
38
39
# File 'lib/jekyll-pandoc-multiple-formats/unite.rb', line 37

def files
  @files
end

#templateObject

Returns the value of attribute template.



37
38
39
# File 'lib/jekyll-pandoc-multiple-formats/unite.rb', line 37

def template
  @template
end

Instance Method Details

#<<(file) ⇒ Object



49
50
51
52
# File 'lib/jekyll-pandoc-multiple-formats/unite.rb', line 49

def <<(file)
  @files ||= []
  @files << File.realpath(file) if /\.pdf\Z/ =~ file
end

#render_templateObject



62
63
64
65
66
67
68
# File 'lib/jekyll-pandoc-multiple-formats/unite.rb', line 62

def render_template
  includes = @files.map do |f|
    INCLUDE_TEMPLATE.gsub(/@@document@@/, f)
  end

  @template = TEMPLATE.gsub('@@include@@', includes.join("\n"))
end