Class: Tiltd::Content

Inherits:
Object
  • Object
show all
Defined in:
lib/tiltd/content.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Content

Returns a new instance of Content.



16
17
18
19
# File 'lib/tiltd/content.rb', line 16

def initialize(path)
  @template_class = Tilt[path]
  @template = @template_class.new(path)
end

Class Method Details

.find(relative) ⇒ Object



3
4
5
6
7
# File 'lib/tiltd/content.rb', line 3

def self.find(relative)
  relative = relative.gsub(%r{^/}, '')
  path = Dir.glob(relative + '.*').first
  path if path && File.file?(path)
end

.locate(path) ⇒ Object



9
10
11
12
13
14
# File 'lib/tiltd/content.rb', line 9

def self.locate(path)
  actual   = find(path)
  actual   = find(File.join(path, "index")) unless actual

  new(actual) if actual
end

Instance Method Details

#bodyObject



25
26
27
# File 'lib/tiltd/content.rb', line 25

def body
  @template.render
end

#mime_typeObject



21
22
23
# File 'lib/tiltd/content.rb', line 21

def mime_type
  @template_class.default_mime_type
end