Class: CVGen::Converter

Inherits:
Kramdown::Converter::Pdf
  • Object
show all
Defined in:
lib/cvgen/converter.rb

Constant Summary collapse

HEADER_SIZES =
[nil, 24, 16, 16, 12, 12, 12]
HEADER_TOP_PADDING =
[nil, 0, 10, 10, 0, 0, 0]
HEADER_BOTTOM_PADDING =
[nil, 4, 4, 6, 0, 0, 0]

Instance Method Summary collapse

Constructor Details

#initialize(root, options) ⇒ Converter

Returns a new instance of Converter.



12
13
14
15
# File 'lib/cvgen/converter.rb', line 12

def initialize(root, options)
  @current_padding = 0
  super
end

Instance Method Details

#document_options(root) ⇒ Object



63
64
65
66
67
68
# File 'lib/cvgen/converter.rb', line 63

def document_options(root)
  h = super.update(:margin => 72)
  h[:info][:Creator] = 'cvgen (using kramdown PDF converter)'
  h[:info].update(@options[:'document-info']) if @options[:'document-info']
  h
end

#dt_options(el, opts) ⇒ Object



55
56
57
# File 'lib/cvgen/converter.rb', line 55

def dt_options(el, opts)
  super.update(:styles => [:italic])
end

#header_options(el, opts) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/cvgen/converter.rb', line 21

def header_options(el, opts)
  h = super
  h[:font] = opts[:header_font] if opts[:header_font]
  h.update({
    :size => HEADER_SIZES[el.options[:level]],
    :styles => [],
    :bottom_padding => HEADER_BOTTOM_PADDING[el.options[:level]],
    :top_padding => HEADER_TOP_PADDING[el.options[:level]]})
end

#p_options(el, opts) ⇒ Object



59
60
61
# File 'lib/cvgen/converter.rb', line 59

def p_options(el, opts)
  {:bottom_padding => 0}
end

#render_header(el, opts) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cvgen/converter.rb', line 31

def render_header(el, opts)
  if el.options['date']
    @pdf.float do
      with_block_padding(el, opts, true) do
        @pdf.formatted_text [opts.merge(:text =>el.options['date'])], :align => :right
      end
    end
  end
  super
  if el.options[:level] == 2
    @pdf.stroke_horizontal_rule
    @pdf.move_down 12
    @current_padding += 12
  end
end

#render_ul(el, opts) ⇒ Object



51
52
53
# File 'lib/cvgen/converter.rb', line 51

def render_ul(el, opts)
  @pdf.indent(15) { super }
end

#root_options(root, opts) ⇒ Object



17
18
19
# File 'lib/cvgen/converter.rb', line 17

def root_options(root, opts)
  super.update(:font => "Helvetica", :leading => 1, :kerning => true, :header_font => @options[:'header-font'])
end

#ul_options(el, opts) ⇒ Object



47
48
49
# File 'lib/cvgen/converter.rb', line 47

def ul_options(el, opts)
  {}
end

#with_block_padding(el, opts, floated = false) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/cvgen/converter.rb', line 70

def with_block_padding(el, opts, floated = false)
  
  if opts.has_key?(:top_padding)
    top = opts[:top_padding]
    if top > @current_padding
      @pdf.move_down(top - @current_padding)
    end
  end
  @current_padding = 0 unless floated
  yield
  if opts.has_key?(:bottom_padding)
    @pdf.move_down(opts[:bottom_padding])
    @current_padding = opts[:bottom_padding] unless floated
  end
end