File: etanni.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 (27 lines) | stat: -rw-r--r-- 590 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
require 'tilt/template'

module Tilt
  class EtanniTemplate < Template
    def prepare
      separator = data.hash.abs
      chomp = "<<#{separator}.chomp!"
      start = "\n_out_ << #{chomp}\n"
      stop = "\n#{separator}\n"
      replacement = "#{stop}\\1#{start}"

      temp = data.strip
      temp.gsub!(/<\?r\s+(.*?)\s+\?>/m, replacement)

      @code = "_out_ = [<<#{separator}.chomp!]\n#{temp}#{stop}_out_.join"
    end

    def precompiled_template(locals)
      @code
    end

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