Welcome to mirror list, hosted at ThFree Co, Russian Federation.

template.rb « template « changelog « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0ff2852d6d486db0acb998373194a90c9f94a9be (plain)
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
# frozen_string_literal: true

module Gitlab
  module Changelog
    module Template
      # A wrapper around an ERB template user for rendering changelogs.
      class Template
        TemplateError = Class.new(StandardError)

        def initialize(erb)
          # Don't change the trim mode, as this may require changes to the
          # regular expressions used to turn the template syntax into ERB
          # tags.
          @erb = ERB.new(erb, trim_mode: '-')
        end

        def render(data)
          context = Context.new(data).get_binding

          # ERB produces a SyntaxError when processing templates, as it
          # internally uses eval() for this.
          @erb.result(context)
        rescue SyntaxError
          raise TemplateError.new("The template's syntax is invalid")
        end
      end
    end
  end
end