Skip to content

Instantly share code, notes, and snippets.

@mattly
Created April 28, 2009 04:23
Show Gist options
  • Save mattly/102935 to your computer and use it in GitHub Desktop.
Save mattly/102935 to your computer and use it in GitHub Desktop.
class Site
include Exegesis::Database
design :pages do
docs :by_state
docs :for_path
def at_path(path='')
for_path([path, ''..'ZZZZ'])[path]
end
end
design :users do
view :by_email
def authenticate email, pass
row = by_email(email).rows.first
if row && Flowerpress::User.verify(pass, row['value'])
database.get(row['id'])
else
raise RestClient::ResourceNotFound
end
end
end
named_document :settings do
expose :primary_theme, :as => :reference
timestamps!
end
end
# for working with collations
# where the "for_path" view above returns key/value pairs like:
# ["projects", "child", "2009-04-03"], 1
# ["projects", "child", "2009-04-04"], 1
# ["projects", "comment", "ham", "2009-04-05"], 1
# ["projects", "comment", "ham", "2009-04-06"], 1
# ["projects", "comment", "spam", "2009-04-15"], 1
# ["projects", "primary", "2009-04-01"], 1
@pages = @site.pages.at_path("projects")
#first we want the primary content
@pages['primary'].map {|key, value, doc| Page.render(doc) }
# then we want a listing of child pages (f.e., "projects/exegesis") that output their parent page to the view
@pages['children'].map {|key, value, doc| Page.list_view(doc) }
# then we want only the ham comments
@paegs['comments']['ham'].map {|key, value, doc| Comment.render(doc) }
# beacuse a document collection's [] method returns another document collection; a jquery-ish, monad-ish kinda thing if you will
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment