Module: Troy::Helpers

Defined in:
lib/troy/helpers.rb

Instance Method Summary collapse

Instance Method Details

#h(content) ⇒ Object



5
6
7
# File 'lib/troy/helpers.rb', line 5

def h(content)
  CGI.escapeHTML(content)
end

#inline_file(path) ⇒ Object



29
30
31
# File 'lib/troy/helpers.rb', line 29

def inline_file(path)
  site.root.join(path).read
end

#markdown(text) ⇒ Object



33
34
35
# File 'lib/troy/helpers.rb', line 33

def markdown(text)
  Troy::Markdown.new(text).to_html
end

#partial(name, locals = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/troy/helpers.rb', line 13

def partial(name, locals = {})
  name = name.to_s
  basename = File.basename(name)
  dirname = File.dirname(name)
  partial = []
  partial << dirname unless dirname.start_with?(".")
  partial << "_#{basename}.erb"
  partial = partial.join("/")

  path = site.root.join("partials/#{partial}")
  locals = locals.merge(site: site, page: page)
  EmbeddedRuby.new(path.read, locals).render
rescue Exception => error
  raise "Unable to render #{path}; #{error.message}"
end

#t(*args) ⇒ Object



9
10
11
# File 'lib/troy/helpers.rb', line 9

def t(*args)
  I18n.t(*args)
end