-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
madx
committed
Jun 17, 2009
1 parent
b6f521e
commit e1cf96f
Showing
5 changed files
with
218 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module Honk | ||
class Comment | ||
yaml_as "tag:honk.yapok.org,2009:Comment" | ||
|
||
attr_reader :author, :email, :website, :timestamp, :contents, :post | ||
|
||
def yaml_initialize(tag, values) | ||
raise FileFormatError, "not a valid comment" unless values.is_a? Hash | ||
initialize(values) | ||
end | ||
|
||
def initialize(params={}) | ||
params.each do |k,v| | ||
instance_variable_set "@#{k}", v | ||
end | ||
end | ||
|
||
def to_yaml_properties | ||
%w[@author @email @website @timestamp @contents] | ||
end | ||
|
||
def to_yaml(opts) | ||
YAML.quick_emit(object_id, opts) do |out| | ||
out.map(taguri, to_yaml_style) do |map| | ||
to_yaml_properties.each do |field| | ||
map.add(field[1..-1].to_sym, instance_variable_get(field)) | ||
end | ||
end | ||
end | ||
end | ||
|
||
def write(fileish) | ||
fileish << YAML.dump(self) | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
module Honk | ||
class Index | ||
yaml_as "tag:honk.yapok.org,2009:Index" | ||
|
||
def yaml_initialize(tag, array) | ||
@@tag = tag | ||
unless array.is_a?(Array) && array.inject(true) {|b,e| e.is_a?(Hash) } | ||
raise FileFormatError, "not a valid index" | ||
end | ||
@@list = [] | ||
@@map = {} | ||
for entry in array | ||
@@list << (key = entry.keys.first) | ||
if !entry[key] | ||
entry[key] = "#{key}.yml" | ||
elsif entry[key].index '~' | ||
entry[key].gsub! '~', key | ||
end | ||
@@map.update(entry) | ||
end | ||
raise IndexError if @@list.length != @@map.keys.length | ||
end | ||
|
||
|
||
class << self | ||
def dump | ||
YAML.quick_emit(object_id, {}) do |out| | ||
out.seq(@@tag, to_yaml_style) do |seq| | ||
@@list.each do |k| | ||
seq.add({k, @@map[k]}) | ||
end | ||
end | ||
end | ||
end | ||
|
||
def has?(name) | ||
@@list.member?(name) | ||
end | ||
|
||
def list | ||
@@list | ||
end | ||
|
||
def map | ||
@@map | ||
end | ||
|
||
def fetch(range) | ||
raise OutOfRangeError if range.first >= @@list.length | ||
@@list[range].collect do |slug| | ||
Post.open slug, resolve(slug) | ||
end | ||
end | ||
|
||
def page(num) | ||
return all if Honk.paginate == Infinity | ||
start = num * Honk.paginate | ||
fetch start...(start + Honk.paginate) | ||
end | ||
|
||
def all | ||
fetch 0...(@@list.length) | ||
end | ||
|
||
def pages(slug=nil) | ||
(@@list.index(slug) || @@list.length) / Honk.paginate | ||
end | ||
|
||
def resolve(slug) | ||
@@map[slug] | ||
end | ||
|
||
def push(map) | ||
key = map.keys.first | ||
unless @@list.member?(key) | ||
@@map.update(map) | ||
@@list.unshift(key) | ||
end | ||
end | ||
end # class methods | ||
end | ||
end |
Oops, something went wrong.