lib/spontaneous/site/selectors.rb in spontaneous-0.2.0.beta1 vs lib/spontaneous/site/selectors.rb in spontaneous-0.2.0.beta2

- old
+ new

@@ -7,24 +7,43 @@ module ClassMethods def root(content_model = Spontaneous::Content) content_model.root end + # roots returns the list of top-level pages + # Only one of these is publicly visible and this is mapped to the + # configured site domain. + # + # The rest are "hidden" roots. + def roots(user = nil, content_model = Spontaneous::Content) + domain = config.site_domain + roots = pages_dataset(content_model).where(depth: 0).all + pub, hidden = roots.partition { |p| p.root? } + map = {} + map[domain] = pub.first.id unless pub.empty? + hidden.each { |p| map[p.path] = p.id } + { "public" => domain, "roots" => map } + end + def pages(content_model = Spontaneous::Content) pages_dataset(content_model).all end def pages_dataset(content_model = Spontaneous::Content) content_model::Page.order(:depth) end + ID_PATH = /\A\d+\z/o + PATH_PATH = /^[\/#]/o + UID_PATH = /^\$/o + def [](path_or_uid) case path_or_uid - when Fixnum, /\A\d+\z/o + when Fixnum, ID_PATH by_id(path_or_uid) - when /^\//o + when PATH_PATH by_path(path_or_uid) - when /^#/o + when UID_PATH by_uid(path_or_uid[1..-1]) else by_uid(path_or_uid) end end