Class: Sassic::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/sassic/page.rb

Instance Method Summary collapse

Constructor Details

#initialize(template) ⇒ Page

Returns a new instance of Page.



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/sassic/page.rb', line 4

def initialize(template)
  @template = template
  
  if exists?
    @template_content = File.read(template_path(template))
    @layout_content = File.read(layout_path)
  
    # Preparse template content
    content
  end
end

Instance Method Details

#body_classes(new_classes = nil) ⇒ Object



45
46
47
48
# File 'lib/sassic/page.rb', line 45

def body_classes(new_classes=nil)
  @body_classes = new_classes if new_classes
  @body_classes
end

#contentObject



28
29
30
# File 'lib/sassic/page.rb', line 28

def content
  ERB.new(@template_content).result(binding)
end

#exists?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/sassic/page.rb', line 24

def exists?
  File.exists?(template_path(@template))
end

#layout_pathObject



20
21
22
# File 'lib/sassic/page.rb', line 20

def layout_path
  Dir::pwd + '/templates/layout.html.erb'
end

#pageObject



32
33
34
# File 'lib/sassic/page.rb', line 32

def page
  @template
end

#partial(template) ⇒ Object



36
37
38
# File 'lib/sassic/page.rb', line 36

def partial(template)
  ERB.new(File.read(template_path("_#{template}"))).result(binding)
end

#renderObject



50
51
52
# File 'lib/sassic/page.rb', line 50

def render
  ERB.new(@layout_content).result(binding)
end

#template_path(template) ⇒ Object



16
17
18
# File 'lib/sassic/page.rb', line 16

def template_path(template)
  Dir::pwd + '/templates/' + template + '.html.erb'
end

#title(new_title = nil) ⇒ Object



40
41
42
43
# File 'lib/sassic/page.rb', line 40

def title(new_title=nil)
  @title = new_title if new_title
  @title
end