File: string.rb

package info (click to toggle)
ruby-tilt 2.0.0%2Breally1.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 476 kB
  • ctags: 411
  • sloc: ruby: 3,546; makefile: 5
file content (21 lines) | stat: -rw-r--r-- 471 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
require 'tilt/template'

module Tilt
  # The template source is evaluated as a Ruby string. The #{} interpolation
  # syntax can be used to generated dynamic output.
  class StringTemplate < Template
    def prepare
      hash = "TILT#{data.hash.abs}"
      @code = "<<#{hash}.chomp\n#{data}\n#{hash}"
    end

    def precompiled_template(locals)
      @code
    end

    def precompiled(locals)
      source, offset = super
      [source, offset + 1]
    end
  end
end