string.rb 471 B

123456789101112131415161718192021
  1. require 'tilt/template'
  2. module Tilt
  3. # The template source is evaluated as a Ruby string. The #{} interpolation
  4. # syntax can be used to generated dynamic output.
  5. class StringTemplate < Template
  6. def prepare
  7. hash = "TILT#{data.hash.abs}"
  8. @code = "<<#{hash}.chomp\n#{data}\n#{hash}"
  9. end
  10. def precompiled_template(locals)
  11. @code
  12. end
  13. def precompiled(locals)
  14. source, offset = super
  15. [source, offset + 1]
  16. end
  17. end
  18. end