Module: Sinatra::W2TagsHooked

Included in:
Base, EventContext
Defined in:
lib/w2tags/sinatra_hook.rb,
lib/w2tags/sinatra_hook.rb

Constant Summary collapse

W2TAGS =
W2Tags::Parser.new

Instance Method Summary collapse

Instance Method Details

#lookup_template(engine, template, options = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/w2tags/sinatra_hook.rb', line 35

def lookup_template(engine, template, views_dir, filename = nil, line = nil)
  case template
  when Symbol
    if cached = self.class.templates[template]
      lookup_template(engine, cached[:template], views_dir, cached[:filename], cached[:line])
    else
      path = ::File.join(views_dir, "#{template}.#{engine}")
      src = path.gsub(path[/(\.\w+)$/,1],'.w2'<<$1[1,9])
      W2TAGS.parse_file(src,true,true)
      [ ::File.read(path), path, 1 ]
    end
  when Proc
    filename, line = self.class.caller_locations.first if filename.nil?
    [ template.call, filename, line.to_i ]
  when String
    filename, line = self.class.caller_locations.first if filename.nil?
    [ template, filename, line.to_i ]
  else
    raise ArgumentError
  end
end

#read_template_file(renderer, template, options, scream = true) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/w2tags/sinatra_hook.rb', line 10

def read_template_file(renderer, template, options, scream = true)
  path = File.join(
    options[:views_directory] || Sinatra.application.options.views,
    "#{template}.#{renderer}"
  )
  src = path.gsub(path[/(\.\w+)$/,1],'.w2'<<$1[1,9])
  W2TAGS.parse_file(src,true,true)
  super 
end