Camping.goes :Pyropublish $: << "lib" require 'pyrosoma' class << Pyropublish attr_accessor :db attr_accessor :dispatcher end def Pyropublish.create self.db = Pyrosoma::Database.new(:path => ENV["DB"] || 'publish') self.dispatcher = Pyrosoma::Dispatcher.new db db.import < doc if plaintext? "Error: #{doc.message}" else raise doc end else if plaintext? "OK: Posted #{f[:id]}" else redirect R(Overview) end end end end class ListAll < R '/pyrosoma/list' def get if @input["query"] begin @ids = Pyropublish.db.search_each(@input["query"]) @heading = "All documents matching #{@input["query"]}" rescue Ferret::QueryParser::QueryParseException => ex return invalid_request!("Query parse error: " + ex.message) end else @ids = Pyropublish.db.ids.sort @heading = "All documents" end if plaintext? @ids.join("\n") + "\n" else render :listall end end end class Mapper < R '/.*' def get if frame = Pyropublish.dispatcher.dispatch(@env["REQUEST_PATH"]) @headers["Content-Type"] = frame["content-type".intern] || "text/html" if frame[:layout] frame[:template] = frame[:layout][:before] + frame[:template] + frame[:layout][:after] end frame.render else not_found! "could not dispatch `#{env["REQUEST_PATH"]}'" end end end end module Pyropublish::Views def layout if @heading heading = "Pyrosoma: #@heading" else heading = "Pyrosoma" end xhtml_strict { head { title heading } body { h1 heading self << yield } } end def overview ul { @ids.sort.each { |id| li { a id, :href => R(Inspect, id) } } } _searchbox form :method => "post" do textarea '', :name => 'frame', :rows => 25, :cols => 80 input :type => 'submit' end end def listall ul { @ids.sort.each { |id| li { a id, :href => R(Inspect, id) } } _searchbox } end def detail div { @frame.to_xoxo } form :method => "post", :action => R(Overview) do div { textarea @frame.to_s, :name => 'frame', :rows => 25, :cols => 80 } div { input :type => 'submit' } end end def _searchbox div.search { form :method => "get", :action => R(ListAll) do input :type => "text", :name => "query" input :type => "submit", :value => "Search" end } end end