summaryrefslogtreecommitdiff
path: root/lib/web/template_expansion.rb
blob: 9871caeb04ddabb7a9d7ee7dfcb30a33f463ef69 (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
require "erb_template"

module Booty
  class TemplateExpansion
    def initialize(root_path)
      @root_path = root_path
    end

    def expand(file, model)
      template_for(file).expand(binding_for(model))
    end

    private

    def read_from(file)
      File.read(File.join(@root_path, file))
    end

    def binding_for(model)
      model.extend(Nasty::ExposeBinding)
      model.get_binder
    end

    def template_for(file)
      ERBTemplate.new(read_from(file))
    end
  end
end