Method: Docgenerator::Element#texkeyval
- Defined in:
- lib/docgenerator/element.rb
#texkeyval ⇒ Object
Build key-val options from attributs. Used e.g. by includegraphics.
If the value is true, the value is added without ‘=’. false-values are ignored.
If you need a “value=true”, then add ‘true’ as a string.
Example (Packages::IncludePDF):
class IncludePDF < Element
add_attribute :pages, Attribute.create( [ :texkeyval], [ String ] )
add_attribute :nup, Attribute.create( [ :texkeyval], [ /\d+x\d+/ ] ) #multiple logical pages onto each sheet of paper.
add_attribute :landscape, Attribute.create( [ :texkeyval], [ true, false ] ) #multiple logical pages onto each sheet of paper.
#...
add_output( :latex, '#{linebreak(@crbefore)}\includepdf[#{texkeyval()}]{#{@content}}#{linebreak(@crafter)}')
end
x = element(:includepdf, { :pages => '1-5', :nup => '2x2', :landscape => true }, 'filename')
puts x.texkeyval #pages={1-5}, nup={2x2}, landscape
x = element(:includepdf, { :pages => '1-5', :nup => '2x2', :landscape => false }, 'filename')
puts x.texkeyval #pages={1-5}, nup={2x2}
439 440 441 442 443 444 445 446 447 448 449 450 451 |
# File 'lib/docgenerator/element.rb', line 439 def texkeyval() keyval = [] @attr.sort_by{|k,v| v.sortkey }.each{|k,v| next unless v.texkeyval? case v.content when true, [true]; keyval << "#{k}" when false, [false] #ignore else #take the value keyval << "#{k}={#{v}}" unless v.to_s.empty? end } return keyval.join(', ') end |