Class: ErbLatex::Context
- Inherits:
-
Object
- Object
- ErbLatex::Context
- Defined in:
- lib/erb_latex/context.rb
Overview
Is the execution context for ERB evaluation
Constant Summary collapse
- ESCAPE =
List of characters that need to be escaped and their escaped values
{ "#"=>"\\#", "$"=>"\\$", "%"=>"\\%", "&"=>"\\&", "~"=>"\\~{}", "_"=>"\\_", "^"=>"\\^{}", "\\"=>"\\textbackslash{}", "{"=>"\\{", "}"=>"\\}" }
Instance Method Summary collapse
-
#break_lines(txt) ⇒ Object
convert newline characters into latex ‘\linebreak’.
-
#getBinding ⇒ Object
return a reference to the instance’s scope or ‘binding’.
-
#initialize(directory, data) ⇒ Context
constructor
create new Context.
-
#partial(template, data = {}) ⇒ Object
include another latex file into the current template.
-
#q(text) ⇒ String
escape using latex escaping rules.
Constructor Details
#initialize(directory, data) ⇒ Context
create new Context
25 26 27 28 29 |
# File 'lib/erb_latex/context.rb', line 25 def initialize( directory, data ) @directory = directory @data = data data.each{ |k,v| instance_variable_set( '@'+k.to_s, v ) } end |
Instance Method Details
#break_lines(txt) ⇒ Object
convert newline characters into latex ‘\linebreak’
38 39 40 |
# File 'lib/erb_latex/context.rb', line 38 def break_lines( txt ) q(txt.to_s).gsub("\n",'\\linebreak ') end |
#getBinding ⇒ Object
return a reference to the instance’s scope or ‘binding’
43 44 45 |
# File 'lib/erb_latex/context.rb', line 43 def getBinding return binding() end |
#partial(template, data = {}) ⇒ Object
include another latex file into the current template
32 33 34 35 |
# File 'lib/erb_latex/context.rb', line 32 def partial( template, data={} ) context = self.class.new( @directory, data ) ErbLatex::File.evaluate(Pathname.new(template), context.getBinding, @directory) end |
#q(text) ⇒ String
escape using latex escaping rules
50 51 52 |
# File 'lib/erb_latex/context.rb', line 50 def q(text) text.to_s.gsub( /([\^\%~\\\\#\$%&_\{\}])/ ) { |s| ESCAPE[s] } end |