File: etanni.rb

package info (click to toggle)
ruby-tilt 2.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 632 kB
  • sloc: ruby: 4,975; makefile: 7
file content (35 lines) | stat: -rw-r--r-- 686 bytes parent folder | download
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
28
29
30
31
32
33
34
35
# frozen_string_literal: true

# = Etanni
#
# === Related module
#
# * Tilt::EtanniTemplate

require_relative '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