Class: Glue::Template::Helper

Inherits:
Object
  • Object
show all
Defined in:
lib/glue/template/helper.rb

Instance Method Summary collapse

Instance Method Details

#configObject



4
5
6
# File 'lib/glue/template/helper.rb', line 4

def config
  @config ||= Glue::Config.new
end

#feed_tagObject



8
9
10
# File 'lib/glue/template/helper.rb', line 8

def feed_tag
  haml '%link{"href" => url_for("feed.xml", :full => true), "rel" => "alternate", "title" => config[:site][:title], "type" => "application/atom+xml"}'
end

#haml(text) ⇒ Object



39
40
41
# File 'lib/glue/template/helper.rb', line 39

def haml(text)
  Haml::Engine.new(text).to_html(self, $meta.data)
end

#markdown(text) ⇒ Object



31
32
33
# File 'lib/glue/template/helper.rb', line 31

def markdown(text)
  RDiscount.new(text).to_html
end

#render(path) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/glue/template/helper.rb', line 43

def render(path)
  parts = [GLUE_ROOT, "views", File.dirname(path), "_" + File.basename(path)]
  parts.reject! {|p| p == "." }
  
  path = File.join(*parts)
  
  if File.exists?(file = "#{path}.haml")
    haml File.read(file)
  elsif File.exists?(file = "#{path}.markdown")
    markdown File.read(file)
  elsif File.exists?(file = "#{path}.textile")
    textile File.read(file)
  else
    "Missing partial at <strong>#{path}</strong>"
  end
end

#textile(text) ⇒ Object



35
36
37
# File 'lib/glue/template/helper.rb', line 35

def textile(text)
  RedCloth.new(text).to_html
end

#url_for(path, options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/glue/template/helper.rb', line 12

def url_for(path, options={})
  uri = URI.parse(config[:site][:base_url])
  
  host = uri.scheme + "://" + uri.host
  host << ":#{uri.port}" unless (uri.scheme == "http" && uri.port == 80) || (uri.scheme == "https" && uri.port == 443)
  
  base_path = uri.path.chomp("/")
  
  parts = []
  parts << host if options[:full]
  parts << base_path
  parts << path
  
  url = File.join(*parts)
  
  url << ".html" if config[:site][:friendly_url] == false && url !~ /\.[a-z0-9]+$/
  url
end