Sha256: cef9f8daf6123145073774ddad278d54f4bbc563e9d11fcf1ae41513af5a1289

Contents?: true

Size: 1.46 KB

Versions: 19

Compression:

Stored size: 1.46 KB

Contents

require 'rubygems'
require 'bundler'
Bundler.require

# Load the "model".
#
require File.expand_path 'book', File.dirname(__FILE__)

set :haml, { :format => :html5 }

# Sets up two query instances.
#
FullBooks = Picky::Client::Full.new :host => 'localhost', :port => 8080, :path => '/books/full'
LiveBooks = Picky::Client::Live.new :host => 'localhost', :port => 8080, :path => '/books/live'

set :static, true
set :public, File.dirname(__FILE__)
set :views,  File.expand_path('views', File.dirname(__FILE__))

# Root, the search interface.
#
get '/' do
  haml :'/search'
end

# Configure. The configuration info page.
#
get '/configure' do
  haml :'/configure'
end

# For full results, you get the ids from the picky server
# and then populate the result with models (rendered, even).
#
get '/search/full' do
  results = FullBooks.search :query => params[:query], :offset => params[:offset]
  results.extend Picky::Convenience
  results.populate_with Book do |book|
    book.to_s
  end
  
  #
  # Or use:
  #   results.populate_with Book
  #   
  # Then:
  #   rendered_entries = results.entries.map do |book| (render each book here) end
  #
  
  ActiveSupport::JSON.encode results
end

# For live results, you'd actually go directly to the search server without taking the detour.
#
get '/search/live' do
  LiveBooks.search :query => params[:query], :offset => params[:offset]
end

helpers do
  
  def js path
    "<script src='javascripts/#{path}.js' type='text/javascript'></script>"
  end
  
end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
picky-generators-1.1.7 prototypes/client/sinatra/app.rb
picky-generators-1.1.6 prototypes/client/sinatra/app.rb
picky-generators-1.1.5 prototypes/client/sinatra/app.rb
picky-generators-1.1.4 prototypes/client/sinatra/app.rb
picky-generators-1.1.3 prototypes/client/sinatra/app.rb
picky-generators-1.1.2 prototypes/client/sinatra/app.rb
picky-generators-1.1.1 prototypes/client/sinatra/app.rb
picky-generators-1.1.0 prototypes/client/sinatra/app.rb
picky-client-1.1.0 sinatra_prototype/app.rb
picky-client-1.0.0 sinatra_prototype/app.rb
picky-client-0.12.3 sinatra_prototype/app.rb
picky-client-0.12.2 sinatra_prototype/app.rb
picky-client-0.12.1 sinatra_prototype/app.rb
picky-client-0.12.0 sinatra_prototype/app.rb
picky-client-0.11.2 sinatra_prototype/app.rb
picky-client-0.11.1 sinatra_prototype/app.rb
picky-client-0.11.0 sinatra_prototype/app.rb
picky-client-0.10.5 sinatra_prototype/app.rb
picky-client-0.10.4 sinatra_prototype/app.rb