Module: Dominate::HTML

Extended by:
HTML
Included in:
HTML
Defined in:
lib/dominate/html.rb

Constant Summary collapse

VIEW_TYPES =
%w(html slim haml erb md markdown mkd mab)

Instance Method Summary collapse

Instance Method Details

#file(file, instance = false, config = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/dominate/html.rb', line 7

def file file, instance = false, config = {}
  c    = (Dominate.config.to_h.merge config).to_deep_ostruct
  path = "#{c.view_path}/#{file}"
  dom = load_file path, c, instance

  # todo> try https://github.com/ohler55/ox instead 
  # dom  = Dom.new html, instance, config
  #
  # if File.file? path + '.dom'
  #   dom = Instance.new(instance, c).instance_eval File.read(path + '.dom')
  # end
  #
  dom
end

#load_file(path, c, instance) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/dominate/html.rb', line 22

def load_file path, c, instance
  html = _cache.fetch(path) {
    template = false

    VIEW_TYPES.each do |type|
      f = "#{path}.#{type}"

      if File.file? f
        template = Tilt.new f, 1, outvar: '@_output'
        break
      end
    end

    unless template
      raise Dominate::NoFileFound,
        "Could't find file: #{path} with any of these extensions: #{VIEW_TYPES.join(', ')}."
    end

    template
  }.render instance, c.to_h

  html
end