From 98359f61e18e1b815d78e9a48534f060311e7be1 Mon Sep 17 00:00:00 2001 From: Florian Hanke Date: Sat, 2 Oct 2010 03:55:23 +0200 Subject: [PATCH] + helper extracted, documentation --- examples/simple_example/webapp/app.rb | 100 ++++------------------- examples/simple_example/webapp/helper.rb | 65 +++++++++++++++ 2 files changed, 83 insertions(+), 82 deletions(-) create mode 100644 examples/simple_example/webapp/helper.rb diff --git a/examples/simple_example/webapp/app.rb b/examples/simple_example/webapp/app.rb index 4353d95f..77a1e27a 100644 --- a/examples/simple_example/webapp/app.rb +++ b/examples/simple_example/webapp/app.rb @@ -3,30 +3,21 @@ require "sinatra/reloader" if development? require 'picky-client' +require 'helper' + PickyBackend = Picky::Client::Full.new :host => 'localhost', :port => 4000, :path => '/books/full' set :static, true -set :public, '.' - -get '/javascripts/:file_name' do - f = File.open("javascripts/#{params[:file_name]}") - result = f.read - f.close - result -end -get '/stylesheets/:file_name' do - f = File.open("stylesheets/#{params[:file_name]}") - result = f.read - f.close - result -end +set :public, File.dirname(__FILE__) +# Search Interface. +# get '/' do - PickyBackend.search :query => params[:query] - wrap_in_html Picky::Helper.interface end +# Normally, you'd access the picky server directly for the live data. +# get '/search/live' do # Return a fake result { @@ -40,7 +31,18 @@ }.to_json 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 + # What you would do: + # + # result = PickyBackend.search :query => params[:query], :offset => params[:offset] + # result.extend Picky::Convenience + # result.populate_with(SomeModelClass) { |model| render model } + # result.to_json + # + # Return a fake result { :allocations => [ @@ -53,70 +55,4 @@ :total => rand(20), :duration => rand(1) }.to_json -end - -def wrap_in_html interface - javascripts = [] - javascripts << 'jquery-1.3.2.js' - javascripts << 'jquery.timer.js' - javascripts << 'picky.extensions.js' - javascripts << 'picky.translations.js' - javascripts << 'picky.data.js' - javascripts << 'picky.view.js' - javascripts << 'picky.backend.js' - javascripts << 'picky.controller.js' - javascripts << 'picky.client.js' - javascripts << 'picky.results_renderer.js' - javascripts << 'picky.allocation_renderer.js' - javascripts << 'picky.allocations_cloud_renderer.js' - javascripts = javascripts.map { |js_file| "" }.join - <<-HTML - - - - #{javascripts} - - - -
-
- - -
-
    -
    Sorry!
    -
    -
      -
        More
      - -
      -
      - - - -HTML end \ No newline at end of file diff --git a/examples/simple_example/webapp/helper.rb b/examples/simple_example/webapp/helper.rb new file mode 100644 index 00000000..67106207 --- /dev/null +++ b/examples/simple_example/webapp/helper.rb @@ -0,0 +1,65 @@ +def wrap_in_html interface + javascripts = [] + javascripts << 'jquery-1.3.2.js' + javascripts << 'jquery.timer.js' + javascripts << 'picky.extensions.js' + javascripts << 'picky.translations.js' + javascripts << 'picky.data.js' + javascripts << 'picky.view.js' + javascripts << 'picky.backend.js' + javascripts << 'picky.controller.js' + javascripts << 'picky.client.js' + javascripts << 'picky.results_renderer.js' + javascripts << 'picky.allocation_renderer.js' + javascripts << 'picky.allocations_cloud_renderer.js' + javascripts = javascripts.map { |js_file| "" }.join + <<-HTML + + + + #{javascripts} + + + +
      +
      + + +
      +
        +
        Sorry!
        +
        +
          +
            More
          + +
          +
          + + + +HTML +end \ No newline at end of file