Class: Brite::Page

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

Overview

Models a site page.

Direct Known Subclasses

Post

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#[], #[]=, #config, #method_missing, #part, #rendering_fields, #to_binding, #to_h, #update

Constructor Details

#initialize(site, file, copy = {}) ⇒ Page

New Page.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/brite/page.rb', line 9

def initialize(site, file, copy={})
  @site = site
  @file = file

  initialize_defaults

  update(copy)

  @_template = Neapolitan.file(file, :stencil=>site.config.stencil) #site.page_defaults)

  update(@_template.)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Brite::Model

Instance Attribute Details

#authorObject

Author of page.



48
49
50
# File 'lib/brite/page.rb', line 48

def author
  @author
end

#categoryObject

Category (“a glorified tag”)



61
62
63
# File 'lib/brite/page.rb', line 61

def category
  @category
end

#dateObject

Publish date.



54
55
56
# File 'lib/brite/page.rb', line 54

def date
  @date
end

#draftObject Also known as: draft?

Is this page a draft? If so it will not be rendered.



64
65
66
# File 'lib/brite/page.rb', line 64

def draft
  @draft
end

#fileObject (readonly)

The ‘.page` file.



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

def file
  @file
end

#layoutObject

Layout to use for page.



73
74
75
# File 'lib/brite/page.rb', line 73

def layout
  @layout
end

#routeObject

Output route.



70
71
72
# File 'lib/brite/page.rb', line 70

def route
  @route
end

#siteObject (readonly)

Instance of Site class to which this page belongs.



42
43
44
# File 'lib/brite/page.rb', line 42

def site
  @site
end

#summaryObject

Summary is the rendering of the first part.



165
166
167
# File 'lib/brite/page.rb', line 165

def summary
  @summary
end

#tagsObject

Tags (labels)



76
77
78
# File 'lib/brite/page.rb', line 76

def tags
  @tags
end

#titleObject

Title of page/post.



51
52
53
# File 'lib/brite/page.rb', line 51

def title
  @title
end

Instance Method Details

#extensionObject

Output extension (defualts to ‘html’).



145
146
147
# File 'lib/brite/page.rb', line 145

def extension
  @extension #||= '.html'
end

#extension=(extname) ⇒ Object

Set output extension.

Parameters:

  • extname (String)

    The file extension.



154
155
156
157
158
159
160
# File 'lib/brite/page.rb', line 154

def extension=(extname)
  @extension = (
    e = (extname || 'html').to_s
    e = '.' + e unless e.start_with?('.')
    e
  )
end

#initialize_defaultsObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/brite/page.rb', line 23

def initialize_defaults
  @tags   = []
  @author = site.config.author
  @route  = site.config.page_route
  @layout = site.config.page_layout

  @extension = '.html'

  # these are filled-out as needed, but the instance variable
  # must define up front to ensure #to_h will pick them up.
  # Probably this should be done in a different way in the future.
  @output = nil
  @path   = nil
  @name   = nil
  @url    = nil
  @root   = nil
end

#inspectObject



173
174
175
# File 'lib/brite/page.rb', line 173

def inspect
  "#<#{self.class} #{@file}>"
end

#nameObject

The ‘name` is same as `output` but without any file extension.



120
121
122
# File 'lib/brite/page.rb', line 120

def name
  @name ||= output.chomp(extension)
end

#outputObject

The page’s route, which is effectively the “Save As” output file.



95
96
97
# File 'lib/brite/page.rb', line 95

def output
  @output ||= calculate_output
end

#output=(path) ⇒ Object Also known as: permalink=

Set route directly, relative to file, overriding any slug.



100
101
102
# File 'lib/brite/page.rb', line 100

def output=(path)
  @output = path.sub(/^\//,'')
end

Same as output but prefixed with ‘/`.



108
109
110
# File 'lib/brite/page.rb', line 108

def permalink
  '/' + output
end

#rootString

Relative path difference between the route and the site’s root. The return value is a string of ‘..` paths, e.g. `“../../”`.

Returns:

  • (String)

    multiples of ‘../`.



139
140
141
142
# File 'lib/brite/page.rb', line 139

def root
  #@root ||= '../' * file.count('/')
  @root ||= '../' * (output.count('/') - (output.scan('../').length*2))
end

#to_sObject

Renders page template.



168
169
170
# File 'lib/brite/page.rb', line 168

def to_s
  render
end