Permalink
Browse files

+ preparations for 4.3.0, + completely overhauled JS, + gorgeous new …

…design (thanks @tvandervossen!)
  • Loading branch information...
floere committed Mar 9, 2012
1 parent 6c14477 commit 66abf229075a2c431db4d91b2566573b2cf72003
Showing with 1,268 additions and 1,050 deletions.
  1. BIN client/javascripts/picky.source.js.tar
  2. +0 −6 client/test_project/app.rb
  3. +0 −4 client/test_project/stylesheets/picky.css
  4. +0 −166 client/test_project/views/configure.haml
  5. +1 −7 generators/prototypes/all_in_one/sinatra/app.rb
  6. +10 −10 generators/prototypes/all_in_one/sinatra/book.rb
  7. BIN generators/prototypes/all_in_one/sinatra/images/picky.png
  8. +19 −17 generators/prototypes/all_in_one/sinatra/javascripts/picky.min.js
  9. +82 −18 generators/prototypes/all_in_one/sinatra/stylesheets/application.css
  10. BIN generators/prototypes/all_in_one/sinatra/stylesheets/images/background.png
  11. +10 −0 generators/prototypes/all_in_one/sinatra/stylesheets/images/cancel.svg
  12. +277 −135 generators/prototypes/all_in_one/sinatra/stylesheets/picky.css
  13. +0 −188 generators/prototypes/all_in_one/sinatra/views/configure.haml
  14. +232 −58 generators/prototypes/all_in_one/sinatra/views/search.haml
  15. +19 −30 generators/prototypes/client/sinatra/app.rb
  16. +9 −9 generators/prototypes/client/sinatra/book.rb
  17. BIN generators/prototypes/client/sinatra/images/picky.png
  18. +82 −18 generators/prototypes/client/sinatra/stylesheets/application.css
  19. BIN generators/prototypes/client/sinatra/stylesheets/images/background.png
  20. +10 −0 generators/prototypes/client/sinatra/stylesheets/images/cancel.svg
  21. +277 −135 generators/prototypes/client/sinatra/stylesheets/picky.css
  22. +0 −188 generators/prototypes/client/sinatra/views/configure.haml
  23. +232 −58 generators/prototypes/client/sinatra/views/search.haml
  24. +5 −0 history.textile
  25. +2 −2 integration
  26. +1 −1 version.rb
Binary file not shown.
@@ -28,12 +28,6 @@
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).
#
@@ -1,7 +1,3 @@
-/* Headers */
-.picky .header {
- display: none; }
-
/* Form */
form
{
@@ -1,166 +0,0 @@
-!!!
-%html{ :lang => 'en' }
- %head
- %link{:href => "stylesheets/stylesheet.css", :media => "screen", :rel => "stylesheet", :type => "text/css"}/
- %body
- %img{:src => "images/picky.png"}/
- %p
- %a{:href => "http://floere.github.com/picky"} To the Picky Homepage
- \/
- %a{:href => '/' } Back to the example
- .content
- %h1 Already made it this far? You're good!
- %p I think you're ready for configuring me for your own purposes.
- %h2 Configuring the Picky client.
- %p
- There are two places where you configure the Picky client:
- %ol
- %li
- %a{ :href => '#controller' } In the controller.
- (client to Picky server)
- %li
- %a{ :href => '#view' } In the view.
- (javascript client interface)
- %h2#controller Controller
- %p
- Open the file
- %strong app.rb
- and take a peek inside.
- %p
- First you need both a client instance for a
- %strong full
- or a
- %strong live search
- depending on what you need (Full gets results with IDs, Live without and is used for updating the counter).
- %p
- In the example, I called it
- %strong BookSearch
- \.
- %code
- %pre
- :preserve
- BookSearch = Picky::Client.new :host => 'localhost', :port => 8080, :path => '/books'
- %p
- Both clients offer the options:
- %dl
- %dt
- %strong host
- %dd The Picky search server host.
- %dt
- %strong port
- %dd The Picky search server port (see unicorn.rb in the server).
- %dt
- %strong path
- %dd The Picky search path (see app/application.rb in the server for the mapping path => query).
- %p
- Then, use these Client instances in your actions. For example like this:
- %code
- %pre
- :preserve
- get '/search/full' do
- results = BookSearch.search params[:query], :ids => params[:ids], :offset => params[:offset]
- results.extend Picky::Convenience
- results.populate_with Book do |book|
- book.to_s
- end
- ActiveSupport::JSON.encode results
- end
- %p
- This part gets a
- %strong hash
- with the results:
- %code
- %pre results = BookSearch.search params[:query], :ids => params[:ids], :offset => params[:offset]
- %p
- This part takes the
- %strong hash
- and extends it with a few useful and convenient methods:
- %code
- %pre results.extend Picky::Convenience
- %p
- One of these methods is the
- %strong populate_with
- method which takes a
- %strong model
- as parameter, and then gets the corresponding
- %strong model instances
- for each id in the result.
- %code
- %pre
- :preserve
- results.populate_with Book do |book|
- book.to_s
- end
- The
- %strong book.to_s
- simulates rendering a book.
- You can do whatever with the book instance if you just return a rendered thing that's supposed to be shown in the front end.
- %p
- If you don't want to render in the controller, you can do so in a view. In the controller just call
- %code
- %pre
- results.populate_with Book
- and then render the books in a view using:
- %code
- %pre
- :preserve
- results.entries do |book|
- render book # or book.to_s, or however you like to render the book.
- end
- %p
- At the end, encode the hash in JSON:
- %code
- %pre
- ActiveSupport::JSON.encode results
- That's it for the controller.
- %p
- All the steps in one:
- %code
- %pre
- :preserve
- BookSearch = Picky::Client.new :host => 'localhost', :port => 8080, :path => '/books'
-
- get '/search/full' do
- results = BookSearch.search params[:query], :ids => params[:ids], :offset => params[:offset]
-
- results.extend Picky::Convenience
- results.populate_with Book do |book|
- book.to_s
- end
-
- ActiveSupport::JSON.encode results
- end
- %h2#view View
- %p
- The view is even easier. Just add the line
- %code
- %pre
- \= Picky::Helper.cached_interface
- if you use just one language, or
- %code
- %pre
- \= Picky::Helper.interface :button => 'search', :no_results => 'No results!', :more => 'more'
- if you use multiple languages.
- (You'd use the options
- %pre :button => t(:'search.button'), :no_results => t(:'search.no_results'), :more => t(:'search.more')
- of course, with proper i18n)
- The same options can be used for
- %strong #cached_interface
- but they will be cached, so you can only set them once and then reused.
- %p
- You're almost finished. Take a look at the file
- %strong views/search.haml
- where you'll find javascript at the end. It looks something like this:
- %code
- %pre
- :preserve
- :javascript
- pickyClient = new PickyClient({
- // A full query displays the rendered results.
- //
- full: '/search/full',
-
- // etc.
- Just take a look at the possible javascript client options in that file.
- %p
- %strong Good luck my friend! *waves several stubby pink tentacles*
@@ -89,12 +89,6 @@ def each
haml :'/search'
end
- # Configure. The configuration info page.
- #
- get '/configure' do
- haml :'/configure'
- end
-
# Renders the results into the json.
#
# You get the results from the (local) picky server and then
@@ -106,7 +100,7 @@ def each
results = results.to_hash
results.extend Picky::Convenience
results.populate_with Book do |book|
- book.render
+ book.to_s
end
#
@@ -9,34 +9,34 @@
# * a number of subjects
#
class Book
-
+
@@books_mapping = {}
-
+
# Load the books on startup.
#
- file_name = File.expand_path "../data/#{PICKY_ENVIRONMENT}/library.csv", __FILE__
+ file_name = File.expand_path "data/#{PICKY_ENVIRONMENT}/library.csv", File.dirname(__FILE__)
CSV.open(file_name, 'r').each do |row|
@@books_mapping[row.shift.to_i] = row
end
-
+
# Find uses a lookup table.
#
def self.find ids, _ = {}
ids.map { |id| new(id, *@@books_mapping[id]) }
end
-
+
attr_reader :id
-
+
def initialize id, title, author, year, publisher, subjects
@id, @title, @author, @year, @publisher, @subjects = id, title, author, year, publisher, subjects
end
-
+
# "Rendering" ;)
#
# Note: This is just an example. Please do not render in the model.
#
- def render
- "<li class='book'><p>\"#{@title}\", by #{@author}</p><p>#{@year}, #{@publisher}</p><p>#{@subjects}</p></li>"
+ def to_s
+ "<li class='book'><h3><a href='http://google.com?q=#{@title}'>#{@title}</a></h3><em>#{@author}</em><p>#{@year}, #{@publisher}</p><p>#{@subjects}</p></li>"
end
-
+
end
Binary file not shown.
Oops, something went wrong.

0 comments on commit 66abf22

Please sign in to comment.