Class: Sassic::Page
- Inherits:
-
Object
- Object
- Sassic::Page
- Defined in:
- lib/sassic/page.rb
Instance Method Summary collapse
- #body_classes(new_classes = nil) ⇒ Object
- #content ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(template) ⇒ Page
constructor
A new instance of Page.
- #layout_path ⇒ Object
- #page ⇒ Object
- #partial(template) ⇒ Object
- #render ⇒ Object
- #template_path(template) ⇒ Object
- #title(new_title = nil) ⇒ Object
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 |
#content ⇒ Object
28 29 30 |
# File 'lib/sassic/page.rb', line 28 def content ERB.new(@template_content).result(binding) end |
#exists? ⇒ Boolean
24 25 26 |
# File 'lib/sassic/page.rb', line 24 def exists? File.exists?(template_path(@template)) end |
#layout_path ⇒ Object
20 21 22 |
# File 'lib/sassic/page.rb', line 20 def layout_path Dir::pwd + '/templates/layout.html.erb' end |
#page ⇒ Object
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 |
#render ⇒ Object
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 |