Class: Spandex::Page
- Inherits:
-
Object
- Object
- Spandex::Page
- Defined in:
- lib/spandex/page.rb
Instance Attribute Summary collapse
-
#extension ⇒ Object
readonly
Returns the value of attribute extension.
-
#mtime ⇒ Object
readonly
Returns the value of attribute mtime.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#render_options ⇒ Object
readonly
Returns the value of attribute render_options.
Class Method Summary collapse
- .from_filename(filename, base_path, render_options = {}) ⇒ Object
- .metadata?(text) ⇒ Boolean
- .path_from_file(pathname, base_path) ⇒ Object
- .registered?(pathname) ⇒ Boolean
Instance Method Summary collapse
- #body ⇒ Object
- #date ⇒ Object
- #draft? ⇒ Boolean
- #metadata(*keys) ⇒ Object
- #tags ⇒ Object
- #title ⇒ Object
- #to_atom_entry(root) ⇒ Object
Instance Attribute Details
#extension ⇒ Object (readonly)
Returns the value of attribute extension.
9 10 11 |
# File 'lib/spandex/page.rb', line 9 def extension @extension end |
#mtime ⇒ Object (readonly)
Returns the value of attribute mtime.
9 10 11 |
# File 'lib/spandex/page.rb', line 9 def mtime @mtime end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/spandex/page.rb', line 9 def path @path end |
#render_options ⇒ Object (readonly)
Returns the value of attribute render_options.
9 10 11 |
# File 'lib/spandex/page.rb', line 9 def @render_options end |
Class Method Details
.from_filename(filename, base_path, render_options = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/spandex/page.rb', line 11 def self.from_filename(filename, base_path, = {}) pathname = Pathname.new(filename) return nil unless pathname.exist? path = path_from_file(pathname, base_path) , content = parse_file(filename) Page.new(path, content, pathname.extname, , ) end |
.metadata?(text) ⇒ Boolean
89 90 91 |
# File 'lib/spandex/page.rb', line 89 def self.(text) text.split("\n").first =~ /^[\w ]+:/ end |
.path_from_file(pathname, base_path) ⇒ Object
21 22 23 24 |
# File 'lib/spandex/page.rb', line 21 def self.path_from_file(pathname, base_path) pathname = pathify pathname pathify pathname.relative_path_from(pathify(base_path)).sub_ext('') end |
.registered?(pathname) ⇒ Boolean
26 27 28 29 |
# File 'lib/spandex/page.rb', line 26 def self.registered?(pathname) pathname = pathify(pathname) Tilt.registered?(pathname.extname.sub(/^./, '')) end |
Instance Method Details
#body ⇒ Object
47 48 49 |
# File 'lib/spandex/page.rb', line 47 def body @rendered_body ||= Tilt[@extension].new(nil, 1, @render_options){@content}.render end |
#date ⇒ Object
43 44 45 |
# File 'lib/spandex/page.rb', line 43 def date @date ||= (:date) ? DateTime.parse((:date)) : nil end |
#draft? ⇒ Boolean
55 56 57 |
# File 'lib/spandex/page.rb', line 55 def draft? (:draft) ? true : false end |
#metadata(*keys) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/spandex/page.rb', line 31 def (*keys) keys.each do |key| key = key.to_s return @metadata[key] if @metadata.has_key? key end nil end |
#tags ⇒ Object
51 52 53 |
# File 'lib/spandex/page.rb', line 51 def @tags ||= (:tags, :categories) ? (:tags, :categories).split(",").map{|tag| tag.strip} : [] end |
#title ⇒ Object
39 40 41 |
# File 'lib/spandex/page.rb', line 39 def title (:title) || "(Unknown Title)" end |
#to_atom_entry(root) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/spandex/page.rb', line 59 def to_atom_entry(root) unless date raise "Must have a date" end Atom::Entry.new do |entry| entry.title = title entry.updated = date entry.id = "#{root},#{@path}" entry.links << Atom::Link.new(:href => "http://#{root}/#{@path}") entry.content = Atom::Content::Html.new(body) end end |