Module: Ki::Middleware::Helpers::HamlCompiler

Included in:
KiApp
Defined in:
lib/ki/middleware/helpers/haml_compiler_helper.rb

Instance Method Summary collapse

Instance Method Details

#render_haml(s) ⇒ Object



21
22
23
# File 'lib/ki/middleware/helpers/haml_compiler_helper.rb', line 21

def render_haml(s)
  Haml::Engine.new("- extend Ki::Helpers\n" + s)
end

#render_haml_file(file_path, layout = true) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ki/middleware/helpers/haml_compiler_helper.rb', line 5

def render_haml_file(file_path, layout = true)
  file_contents = File.read(file_path)

  if layout && view_exists?('layout')
    layout_contents = File.read(view_path('layout'))
  else
    layout_contents = '= yield'
  end

  html = render_haml(layout_contents).render do
    render_haml(file_contents).render
  end

  html
end