picky-generators 1.5.4 → 2.0.0.pre1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  module Picky
2
2
 
3
3
  module Generators
4
-
4
+
5
5
  module Server
6
6
 
7
7
  # Generates a new empty Picky Unicorn Server.
@@ -10,11 +10,11 @@ module Picky
10
10
  # > picky-generate unicorn_server my_lovely_unicorn
11
11
  #
12
12
  class EmptyUnicorn < Picky::Generators::Base
13
-
13
+
14
14
  def initialize identifier, name, *args
15
15
  super identifier, name, 'server/empty_unicorn', *args
16
16
  end
17
-
17
+
18
18
  #
19
19
  #
20
20
  def generate
@@ -27,14 +27,14 @@ module Picky
27
27
  exclaim "Next steps:"
28
28
  exclaim "1. cd #{name}"
29
29
  exclaim "2. bundle install"
30
- exclaim "3. rake # (optional) shows you where Picky needs input from you"
30
+ exclaim "3. rake todo # (optional) shows you where Picky needs input from you"
31
31
  exclaim " # if you want to define your own search."
32
32
  end
33
-
33
+
34
34
  end
35
-
35
+
36
36
  end
37
-
37
+
38
38
  end
39
-
39
+
40
40
  end
@@ -1,7 +1,7 @@
1
1
  module Picky
2
2
 
3
3
  module Generators
4
-
4
+
5
5
  module Server
6
6
 
7
7
  # Generates a new Picky Unicorn Server Example.
@@ -10,11 +10,11 @@ module Picky
10
10
  # > picky-generate unicorn_server my_lovely_unicorn
11
11
  #
12
12
  class Unicorn < Picky::Generators::Base
13
-
13
+
14
14
  def initialize identifier, name, *args
15
15
  super identifier, name, 'server/unicorn', *args
16
16
  end
17
-
17
+
18
18
  #
19
19
  #
20
20
  def generate
@@ -29,14 +29,14 @@ module Picky
29
29
  exclaim "2. bundle install"
30
30
  exclaim "3. rake index"
31
31
  exclaim "4. rake start"
32
- exclaim "5. rake # (optional) shows you where Picky needs input from you"
32
+ exclaim "5. rake todo # (optional) shows you where Picky needs input from you"
33
33
  exclaim " # if you want to define your own search."
34
34
  end
35
-
35
+
36
36
  end
37
-
37
+
38
38
  end
39
-
39
+
40
40
  end
41
-
41
+
42
42
  end
@@ -2,7 +2,7 @@ source :gemcutter
2
2
 
3
3
  # Gems required by the Picky client.
4
4
  #
5
- gem 'picky-client'
5
+ gem 'picky-client', '2.0.0.pre1'
6
6
  gem 'i18n'
7
7
  gem 'activesupport', :require => 'active_support/core_ext'
8
8
  gem 'sinatra'
@@ -0,0 +1,5 @@
1
+ require 'picky-client/tasks'
2
+
3
+ # Pass in location of your javascript files, default is "javascripts".
4
+ #
5
+ Picky::Tasks::Javascripts.new
@@ -8,10 +8,9 @@ require File.expand_path 'book', File.dirname(__FILE__)
8
8
 
9
9
  set :haml, { :format => :html5 }
10
10
 
11
- # Sets up two query instances.
11
+ # Sets up a search instance to the server.
12
12
  #
13
- FullBooks = Picky::Client::Full.new :host => 'localhost', :port => 8080, :path => '/books/full'
14
- LiveBooks = Picky::Client::Live.new :host => 'localhost', :port => 8080, :path => '/books/live'
13
+ BookSearch = Picky::Client.new :host => 'localhost', :port => 8080, :path => '/books'
15
14
 
16
15
  set :static, true
17
16
  set :public, File.dirname(__FILE__)
@@ -31,11 +30,11 @@ get '/configure' do
31
30
  haml :'/configure'
32
31
  end
33
32
 
34
- # For full results, you get the ids from the picky server
35
- # and then populate the result with models (rendered, even).
33
+ # You get the ids from the picky server and then
34
+ # populate the result with rendered models.
36
35
  #
37
36
  get '/search/full' do
38
- results = FullBooks.search params[:query], :offset => params[:offset]
37
+ results = BookSearch.search params[:query], :ids => params[:ids], :offset => params[:offset]
39
38
  results.extend Picky::Convenience
40
39
  results.populate_with Book do |book|
41
40
  book.to_s
@@ -52,10 +51,12 @@ get '/search/full' do
52
51
  ActiveSupport::JSON.encode results
53
52
  end
54
53
 
55
- # For live results, you'd actually go directly to the search server without taking the detour.
54
+ # Normally, you'd actually go directly to the search server without taking the detour.
55
+ #
56
+ # We don't parse/reencode the returned json string using search_unparsed.
56
57
  #
57
58
  get '/search/live' do
58
- LiveBooks.search params[:query], :offset => params[:offset]
59
+ BookSearch.search_unparsed params[:query], :ids => params[:ids], :offset => params[:offset]
59
60
  end
60
61
 
61
62
  helpers do
@@ -1,17 +1,17 @@
1
1
  Array.prototype.index=function(c){for(var i=0,g=this.length;i<g;i++)if(this[i]==c)return i;return null};Array.prototype.include=function(c){return this.index(c)!==null};Array.prototype.remove=function(c){this.splice(c,1);return this};var PickyI18n={};$(function(){PickyI18n.locale=$("html").attr("lang").split("-")[0]||"en"});
2
2
  var dictionary={common:{join:{de:"und",fr:"et",it:"e",en:"and",ch:"und"},"with":{de:"mit",fr:"avec",it:"con",en:"with",ch:"mit"},of:{de:"von",fr:"de",it:"di",en:"of",ch:"vo"},to:{de:"bis",fr:"\u00e0",it:"alla",en:"to",ch:"bis"}},results:{addination:{more:{de:"Weitere Resultate",fr:"Autres r\u00e9sultats",it:"Altri risultati",en:"More results",ch:"Mee Resultaat"}},header:{de:"Ergebnisse",fr:"R\u00e9sultats",it:"Risultati",en:"Results",ch:"Erg\u00e4bnis"}}},t=function(c){for(var i=PickyI18n.locale||
3
- "en",g=c.split(".").concat(i),d=dictionary,e=0,o=g.length;e<o;e++){d=d[g[e]];if(d==undefined){d="Translation missing: "+c+"."+i;break}}return d};function Allocation(c,i,g,d,e,o){var m=this;this.type=c;this.weight=i;this.count=g;this.combination=d;this.ids=e||[];this.entries=this.rendered=o||[];this.isType=function(s){return s==m.type}}function Allocations(c){this.allocations=[];for(var i=0,g=c.length;i<g;i++){var d=c[i];this.allocations.push(new Allocation(d[0],d[1],d[2],d[3],d[4],d[5]))}this.length=this.allocations.length;this.each=function(e){return $.each(this.allocations,e)}}
4
- function PickyData(c){var i=c.total,g=c.duration,d=c.offset;c=new Allocations(c.allocations||[]);this.total=i;this.duration=g;this.offset=d;this.allocations=c;this.isEmpty=function(){return i==0}};var PickyView=function(c,i){var g=i.showResultsLimit||10,d=$("#picky input.query"),e=$("#picky div.reset"),o=$("#picky input.search_button"),m=$("#picky div.status"),s=$("#picky .dashboard"),u=$("#picky .results"),j=$("#picky .no_results"),k=new PickyAddination(this,u),r=new PickyAllocationsCloud(this,i),p=new PickyResultsRenderer(k,i),a=function(){e.fadeTo(166,1)},b=function(){r.hide();u.empty();j.hide()},f=function(h){d.val(h);e.fadeTo(166,0);v("empty");m.empty();b()},n=function(){return d.val()};
5
- this.text=n;var q=function(h){m.text(h);h>0&&h<=5&&m.fadeTo("fast",0.5).fadeTo("fast",1)},w=function(h){if(h.isEmpty())return"none";if(h.total>g&&h.allocations.length>1)return"support";return"ok"},v=function(h){s.attr("class","dashboard "+h)};this.insert=function(h){d.val(h);d.select()};this.fullResultsCallback=function(h){v(w(h));if(h.isEmpty()){b();q(0);j.show();a()}else if(h.total>g&&h.allocations.length>1){b();a();r.show(h);q(h.total)}else if(h.offset==0){b();q(h.total);p.render(h);u.show();a();
6
- d.focus()}else{k.remove();p.render(h);$("body").animate({scrollTop:$("#picky div.results div.header:last").position().top-12},500)}};this.liveResultsCallback=function(h){v(w(h));q(h.total)};this.allocationChosen=function(h){h=h.data.query;d.val(h);c.allocationChosen(h)};this.addinationClicked=function(h){c.addinationClicked(n(),h)};(function(){d.keyup(function(h){if(n()==""){f();c.searchTextCleared()}else{c.searchTextEntered(n(),h);a()}});m.click(function(){n()==""||c.searchButtonClicked(n())});o.click(function(){n()==
7
- ""||c.searchButtonClicked(n())});e.click(function(){f("");c.clearButtonClicked();d.focus()})})();d.focus()};var PickyBackend=function(c){var i=function(g,d,e,o){var m=o||{};m=$.extend({query:g,offset:e},o);$.getJSON(c,m,function(s){d&&d(new PickyData(s))})};this.search=function(g,d,e,o,m){i(g,function(s){d&&d(m,s)},e,o)}},LiveBackend=function(c){var i=new PickyBackend(c);this.search=function(g,d,e,o,m){m=m||{};latestRequestTimestamp=new Date;m.live=latestRequestTimestamp;i.search(g,function(s,u){if(!s.live||s.live==latestRequestTimestamp)d&&d(u)},e,o,m)}},FullBackend=function(c){var i=new PickyBackend(c);
8
- this.search=function(g,d,e,o,m){m=m||{};latestRequestTimestamp=new Date;m.full=latestRequestTimestamp;i.search(g,function(s,u){if(!s.full||s.full==latestRequestTimestamp)d&&d(u)},e,o,m)}};var PickyController=function(c){var i=new PickyView(this,c),g=c.backends,d=c.before||function(){},e=c.success||function(){},o=c.after||function(){},m=function(a){return(a=a&&a.match(/q=([^&]+)/))&&unescape(a[1]||"")};this.extractQuery=m;var s=function(){var a=window.History&&window.History.getState();return m(a&&a.url)};this.lastQuery=s;var u=function(a,b){a=e(a,b)||a;i.liveResultsCallback(a);o(a,b)},j,k=function(){var a=i.text();d({});var b=g.live;b&&b.search(a,u,0,void 0);clearInterval(j)};j=setInterval(k,
9
- 180);clearInterval(j);var r=function(a,b){a=e(a,b)||a;i.fullResultsCallback(a);o(a,b)},p=function(a,b,f){f=f||{};b=b||0;clearInterval(j);if(a!=s()){var n="?q="+a;window.History&&window.History.getState()&&window.History.pushState&&window.History.pushState(null,null,n)}f=d(f,a,b)||f;(n=g.full)&&n.search(a,r,b,f)};this.insert=function(a,b){i.insert(a);b&&p(a)};this.clearButtonClicked=function(){clearInterval(j)};this.searchTextCleared=function(){clearInterval(j)};this.searchTextEntered=function(a,b){if($.inArray(b.keyCode,
3
+ "en",g=c.split(".").concat(i),d=dictionary,e=0,m=g.length;e<m;e++){d=d[g[e]];if(d==undefined){d="Translation missing: "+c+"."+i;break}}return d};function Allocation(c,i,g,d,e,m){var n=this;this.type=c;this.weight=i;this.count=g;this.combination=d;this.ids=e||[];this.entries=this.rendered=m||[];this.isType=function(s){return s==n.type}}function Allocations(c){this.allocations=[];for(var i=0,g=c.length;i<g;i++){var d=c[i];this.allocations.push(new Allocation(d[0],d[1],d[2],d[3],d[4],d[5]))}this.length=this.allocations.length;this.each=function(e){return $.each(this.allocations,e)}}
4
+ function PickyData(c){var i=c.total,g=c.duration,d=c.offset;c=new Allocations(c.allocations||[]);this.total=i;this.duration=g;this.offset=d;this.allocations=c;this.isEmpty=function(){return i==0}};var PickyView=function(c,i){var g=i.showResultsLimit||10,d=$("#picky input.query"),e=$("#picky div.reset"),m=$("#picky input.search_button"),n=$("#picky div.status"),s=$("#picky .dashboard"),u=$("#picky .results"),j=$("#picky .no_results"),k=new PickyAddination(this,u),r=new PickyAllocationsCloud(this,i),p=new PickyResultsRenderer(k,i),a=function(){e.fadeTo(166,1)},b=function(){r.hide();u.empty();j.hide()},f=function(h){d.val(h);e.fadeTo(166,0);v("empty");n.empty();b()},o=function(){return d.val()};
5
+ this.text=o;var q=function(h){n.text(h);h>0&&h<=5&&n.fadeTo("fast",0.5).fadeTo("fast",1)},w=function(h){if(h.isEmpty())return"none";if(h.total>g&&h.allocations.length>1)return"support";return"ok"},v=function(h){s.attr("class","dashboard "+h)};this.insert=function(h){d.val(h);d.select()};this.fullResultsCallback=function(h){v(w(h));if(h.isEmpty()){b();q(0);j.show();a()}else if(h.total>g&&h.allocations.length>1){b();a();r.show(h);q(h.total)}else if(h.offset==0){b();q(h.total);p.render(h);u.show();a();
6
+ d.focus()}else{k.remove();p.render(h);$("body").animate({scrollTop:$("#picky div.results div.header:last").position().top-12},500)}};this.liveResultsCallback=function(h){v(w(h));q(h.total)};this.allocationChosen=function(h){h=h.data.query;d.val(h);c.allocationChosen(h)};this.addinationClicked=function(h){c.addinationClicked(o(),h)};(function(){d.keyup(function(h){if(o()==""){f();c.searchTextCleared()}else{c.searchTextEntered(o(),h);a()}});n.click(function(){o()==""||c.searchButtonClicked(o())});m.click(function(){o()==
7
+ ""||c.searchButtonClicked(o())});e.click(function(){f("");c.clearButtonClicked();d.focus()})})();d.focus()};var PickyBackend=function(c){var i=function(g,d,e,m){var n=m||{};n=$.extend({query:g,offset:e},m);$.getJSON(c,n,function(s){d&&d(new PickyData(s))})};this.search=function(g,d,e,m,n){i(g,function(s){d&&d(n,s)},e,m)}},LiveBackend=function(c){var i=new PickyBackend(c);this.search=function(g,d,e,m,n){n=n||{};latestRequestTimestamp=new Date;n.live=latestRequestTimestamp;m=$.extend({ids:0},m);i.search(g,function(s,u){if(!s.live||s.live==latestRequestTimestamp)d&&d(u)},e,m,n)}},FullBackend=function(c){var i=
8
+ new PickyBackend(c);this.search=function(g,d,e,m,n){n=n||{};latestRequestTimestamp=new Date;n.full=latestRequestTimestamp;m=$.extend({ids:20},m);i.search(g,function(s,u){if(!s.full||s.full==latestRequestTimestamp)d&&d(u)},e,m,n)}};var PickyController=function(c){var i=new PickyView(this,c),g=c.backends,d=c.before||function(){},e=c.success||function(){},m=c.after||function(){},n=function(a){return(a=a&&a.match(/q=([^&]+)/))&&unescape(a[1]||"")};this.extractQuery=n;var s=function(){var a=window.History&&window.History.getState();return n(a&&a.url)};this.lastQuery=s;var u=function(a,b){a=e(a,b)||a;i.liveResultsCallback(a);m(a,b)},j,k=function(){var a=i.text();d({});var b=g.live;b&&b.search(a,u,0,void 0);clearInterval(j)};j=setInterval(k,
9
+ 180);clearInterval(j);var r=function(a,b){a=e(a,b)||a;i.fullResultsCallback(a);m(a,b)},p=function(a,b,f){f=f||{};b=b||0;clearInterval(j);if(a!=s()){var o="?q="+a;window.History&&window.History.getState()&&window.History.pushState&&window.History.pushState(null,null,o)}f=d(f,a,b)||f;(o=g.full)&&o.search(a,r,b,f)};this.insert=function(a,b){i.insert(a);b&&p(a)};this.clearButtonClicked=function(){clearInterval(j)};this.searchTextCleared=function(){clearInterval(j)};this.searchTextEntered=function(a,b){if($.inArray(b.keyCode,
10
10
  [0,8,13,32,46,48,49,50,51,52,53,54,55,56,57,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90])>-1)if(b.keyCode==13)p(a);else{clearInterval(j);j=setInterval(k,180)}};this.searchButtonClicked=function(a){p(a)};this.allocationChosen=function(a){p(a)};this.addinationClicked=function(a,b){p(a,b.data.offset)}};var Localization={},PickyClient=function(c){Localization.qualifiers=c.qualifiers||{};Localization.explanations=c.explanations||{};Localization.choices=c.choices||{};Localization.explanation_delimiters={de:"und",fr:"et",it:"e",en:"and",ch:"und"};var i=c.backends;if(i){i.live||alert("Both a full and live backend must be provided.");i.full||alert("Both a full and live backend must be provided.")}else c.backends={live:c.live&&new LiveBackend(c.live)||alert("A live backend path must be provided."),full:c.full&&
11
- new FullBackend(c.full)||alert("A live backend path must be provided.")};var g=c.controller&&new c.controller(c)||new PickyController(c);var d=this.insert=function(e,o){g.insert(e,o||true)};this.insertFromURL=function(e){if(e&&e!="")d(e);else(e=g.lastQuery())&&d(e)};window.History&&window.History.Adapter.bind(window,"statechange",function(){var e=window.History.getState();(e=g.extractQuery(e.url))&&d(e)})};var PickyAddination=function(c,i){this.remove=function(){i.find(".addination").remove()};this.render=function(g){var d=g.total,e;e=g.offset+20+0;var o=e+20;g=g.total;if(g<o)o=g;e={offset:e,start:e+1,end:o};if(e.offset<d){d=$("<div class='addination'>"+t("results.addination.more")+"</div>");d.bind("click",{offset:e.offset},c.addinationClicked);return d}else return""}};var PickyResultsRenderer=function(c,i){var g=i.wrapResults||'<ol class="results"></ol>',d=["street_number","zipcode"],e=function(j){var k=j[j.length-1];j=j.slice(0,j.length-1);if(j==[])j=[j];if(!d.include(k[0]))if(k[1].match(/[^\*~]$/))k[1]+="*";j.push(k);return j},o=function(j){for(var k=Localization.explanations&&Localization.explanations[PickyI18n.locale]||{},r=[],p,a=0,b=j.length;a<b;a++){p=j[a];var f=p[0];f=k[f]||f;r.push([f,p[1]])}return r},m=function(j,k){return[j.replace(/([\w\s\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00e9\u00e8\u00e0]+)/,
12
- "<strong>$1</strong>"),k].join(" ")},s=function(j,k){var r=Localization.explanation_delimiters[PickyI18n.locale],p=o(e(k)),a="",b=[];p=$.map(p,function(f){var n=f[0];f=f[1];if(a==""||n==a){b.push(f);a=n}else{var q=m(a,b.join(" "));b=[];b.push(f);a=n;return q}});p.push(m(a,b.join(" ")));p=p.join(" "+r+" ");return'<span class="explanation">'+j+" "+p+"</span>"},u=function(j,k){var r='<div class="header">';r+=s(k.type,k.combination);if(j.offset>0)r+='<div class="tothetop"><a href="#" onclick="javascript:$(\'body\').animate({scrollTop: 0}, 500);">&uarr;</a></div>';
13
- return r};this.render=function(j){var k=$("#picky div.results");j.allocations.each(function(r,p){k.append(u(j,p)).append(p.entries.join("")).append(c.render(j));k.children("li").wrapAll(g)})}};function AllocationRenderer(c,i){function g(a){var b={},f={},n=[],q;q=0;for(l=a.length;q<l;q++){var w=a[q][0];if(w in b){b[w]=b[w]+" "+a[q][1];n.push(q)}else{b[w]=a[q][1];f[q]=w}}for(q in f)a[q][1]=b[f[q]];for(q=n.length-1;q>=0;q--)a.remove(n[q]);return a}function d(a){return $.map(a,function(b,f){return"%"+(f+1)+"$s"}).join(" ")}function e(a){if(a.length==0)return"";var b=a=g(a);b.sort(function(x,y){return x[0]<y[0]?-1:1});for(var f=[],n=0,q=b.length;n<q;n++)f.push(b[n][0]);var w=f.length==1,v=r[f]||
14
- (r[f]=d(f));if($.type(v)==="string"){r[f]={format:v};v=r[f]}var h=1,z=v.format;$.each(a,function(x,y){var A=y[0],B=y[1];if(v.filter)B=v.filter(B);A=j[A]||A;if(w&&!(v&&v.ignoreSingle))return z=B+"&nbsp;("+A+")";z=z.replace(RegExp("%"+h+"\\$s","g"),B);h+=1;return h});return z}function o(a){for(var b=[],f=0,n=k.length;f<n;f++)b.push([]);b.push([]);f=0;for(n=a.length;f<n;f++){for(var q=a[f],w=q[0],v=false,h=0,z=k.length;h<z;h++)if(k[h].include(w)){b[h].push(q);v=true;break}v||b[b.length-1].push(q)}var x;
15
- for(a=b.length-1;a>=0;a--){x=b[a];if(x.length>0)break}x=x[x.length-1];p.include(x[0])||(x[1]+="...");return $.map(b,function(y){return e(y)})}function m(a){var b=[],f,n;for(n in a){f=a[n][0];f=u[f]||f;b[n]=f+":"+a[n][1]}return b.join(" ")}var s=PickyI18n.locale,u=Localization.qualifiers&&Localization.qualifiers[s]||{},j=Localization.explanations&&Localization.explanations[s]||{},k=i.groups||[],r=Localization.choices&&Localization.choices[s]||{};this.explanation=this.query=this.text="";var p=["street_number",
16
- "zipcode"];this.contract=g;this.rendered=e;this.groupify=o;this.querify=m;this.render=function(a){var b=a.combination,f=a.count;a=m(b);b=o(b).join(" ");b=$('<li><div class="text">'+b+'</div><div class="count">'+f+"</div></li>");b.bind("click",{query:a},c);return b}};var PickyAllocationsCloud=function(c,i){var g=$("#picky .allocations"),d=g.find(".shown"),e=g.find(".more"),o=g.find(".hidden"),m=function(){g.hide()},s=new AllocationRenderer(function(k){m();c.allocationChosen(k)},i),u=function(k){var r=[];k.each(function(p,a){r.push(s.render(a))});return r},j=function(k){if(k.length==0)return $("#search .allocations").hide();d.empty();e.hide();o.empty().hide();if(k.length>3){$.each(k.slice(0,2),function(r,p){d.append(p)});$.each(k.slice(2),function(r,p){o.append(p)});
17
- e.show()}else $.each(k,function(r,p){d.append(p)});return $("#search .allocations").show()};e.click(function(){e.hide();o.show()});this.hide=m;this.show=function(k){j(u(k.allocations));g.show()}};
11
+ new FullBackend(c.full)||alert("A live backend path must be provided.")};var g=c.controller&&new c.controller(c)||new PickyController(c);var d=this.insert=function(e,m){g.insert(e,m||true)};this.insertFromURL=function(e){if(e&&e!="")d(e);else(e=g.lastQuery())&&d(e)};window.History&&window.History.Adapter.bind(window,"statechange",function(){var e=window.History.getState();(e=g.extractQuery(e.url))&&d(e)})};var PickyAddination=function(c,i){this.remove=function(){i.find(".addination").remove()};this.render=function(g){var d=g.total,e;e=g.offset+20+0;var m=e+20;g=g.total;if(g<m)m=g;e={offset:e,start:e+1,end:m};if(e.offset<d){d=$("<div class='addination'>"+t("results.addination.more")+"</div>");d.bind("click",{offset:e.offset},c.addinationClicked);return d}else return""}};var PickyResultsRenderer=function(c,i){var g=i.wrapResults||'<ol class="results"></ol>',d=["street_number","zipcode"],e=function(j){var k=j[j.length-1];j=j.slice(0,j.length-1);if(j==[])j=[j];if(!d.include(k[0]))if(k[1].match(/[^\*~]$/))k[1]+="*";j.push(k);return j},m=function(j){for(var k=Localization.explanations&&Localization.explanations[PickyI18n.locale]||{},r=[],p,a=0,b=j.length;a<b;a++){p=j[a];var f=p[0];f=k[f]||f;r.push([f,p[1]])}return r},n=function(j,k){return[j.replace(/([\w\s\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00e9\u00e8\u00e0]+)/,
12
+ "<strong>$1</strong>"),k].join(" ")},s=function(j,k){var r=Localization.explanation_delimiters[PickyI18n.locale],p=m(e(k)),a="",b=[];p=$.map(p,function(f){var o=f[0];f=f[1];if(a==""||o==a){b.push(f);a=o}else{var q=n(a,b.join(" "));b=[];b.push(f);a=o;return q}});p.push(n(a,b.join(" ")));p=p.join(" "+r+" ");return'<span class="explanation">'+j+" "+p+"</span>"},u=function(j,k){var r='<div class="header">';r+=s(k.type,k.combination);if(j.offset>0)r+='<div class="tothetop"><a href="#" onclick="javascript:$(\'body\').animate({scrollTop: 0}, 500);">&uarr;</a></div>';
13
+ return r};this.render=function(j){var k=$("#picky div.results");j.allocations.each(function(r,p){k.append(u(j,p)).append(p.entries.join("")).append(c.render(j));k.children("li").wrapAll(g)})}};function AllocationRenderer(c,i){function g(a){var b={},f={},o=[],q;q=0;for(l=a.length;q<l;q++){var w=a[q][0];if(w in b){b[w]=b[w]+" "+a[q][1];o.push(q)}else{b[w]=a[q][1];f[q]=w}}for(q in f)a[q][1]=b[f[q]];for(q=o.length-1;q>=0;q--)a.remove(o[q]);return a}function d(a){return $.map(a,function(b,f){return"%"+(f+1)+"$s"}).join(" ")}function e(a){if(a.length==0)return"";var b=a=g(a);b.sort(function(x,y){return x[0]<y[0]?-1:1});for(var f=[],o=0,q=b.length;o<q;o++)f.push(b[o][0]);var w=f.length==1,v=r[f]||
14
+ (r[f]=d(f));if($.type(v)==="string"){r[f]={format:v};v=r[f]}var h=1,z=v.format;$.each(a,function(x,y){var A=y[0],B=y[1];if(v.filter)B=v.filter(B);A=j[A]||A;if(w&&!(v&&v.ignoreSingle))return z=B+"&nbsp;("+A+")";z=z.replace(RegExp("%"+h+"\\$s","g"),B);h+=1;return h});return z}function m(a){for(var b=[],f=0,o=k.length;f<o;f++)b.push([]);b.push([]);f=0;for(o=a.length;f<o;f++){for(var q=a[f],w=q[0],v=false,h=0,z=k.length;h<z;h++)if(k[h].include(w)){b[h].push(q);v=true;break}v||b[b.length-1].push(q)}var x;
15
+ for(a=b.length-1;a>=0;a--){x=b[a];if(x.length>0)break}x=x[x.length-1];p.include(x[0])||(x[1]+="...");return $.map(b,function(y){return e(y)})}function n(a){var b=[],f,o;for(o in a){f=a[o][0];f=u[f]||f;b[o]=f+":"+a[o][1]}return b.join(" ")}var s=PickyI18n.locale,u=Localization.qualifiers&&Localization.qualifiers[s]||{},j=Localization.explanations&&Localization.explanations[s]||{},k=i.groups||[],r=Localization.choices&&Localization.choices[s]||{};this.explanation=this.query=this.text="";var p=["street_number",
16
+ "zipcode"];this.contract=g;this.rendered=e;this.groupify=m;this.querify=n;this.render=function(a){var b=a.combination,f=a.count;a=n(b);b=m(b).join(" ");b=$('<li><div class="text">'+b+'</div><div class="count">'+f+"</div></li>");b.bind("click",{query:a},c);return b}};var PickyAllocationsCloud=function(c,i){var g=$("#picky .allocations"),d=g.find(".shown"),e=g.find(".more"),m=g.find(".hidden"),n=function(){g.hide()},s=new AllocationRenderer(function(k){n();c.allocationChosen(k)},i),u=function(k){var r=[];k.each(function(p,a){r.push(s.render(a))});return r},j=function(k){if(k.length==0)return $("#search .allocations").hide();d.empty();e.hide();m.empty().hide();if(k.length>3){$.each(k.slice(0,2),function(r,p){d.append(p)});$.each(k.slice(2),function(r,p){m.append(p)});
17
+ e.show()}else $.each(k,function(r,p){d.append(p)});return $("#search .allocations").show()};e.click(function(){e.hide();m.show()});this.hide=n;this.show=function(k){j(u(k.allocations));g.show()}};
@@ -27,22 +27,15 @@
27
27
  %strong app.rb
28
28
  and take a peek inside.
29
29
  %p
30
- First you need both a client instance for a
31
- %strong full
32
- or a
33
- %strong live search
34
- depending on what you need (Full gets results with IDs, Live without and is used for updating the counter).
30
+ First you need a client instance.
35
31
  %p
36
32
  In the example, I called it
37
- %strong FullBooks
38
- and
39
- %strong LiveBooks
33
+ %strong BookSearch
40
34
  respectively.
41
35
  %code
42
36
  %pre
43
37
  :preserve
44
- FullBooks = Picky::Client::Full.new :host => 'localhost', :port => 8080, :path => '/books/full'
45
- LiveBooks = Picky::Client::Live.new :host => 'localhost', :port => 8080, :path => '/books/live'
38
+ BookSearch = Picky::Client.new :host => 'localhost', :port => 8080, :path => '/books'
46
39
  %p
47
40
  Both clients offer the options:
48
41
  %dl
@@ -61,7 +54,7 @@
61
54
  %pre
62
55
  :preserve
63
56
  get '/search/full' do
64
- results = FullBooks.search params[:query], :offset => params[:offset]
57
+ results = BookSearch.search params[:query], :ids => params[:ids], :offset => params[:offset]
65
58
  results.extend Picky::Convenience
66
59
  results.populate_with Book do |book|
67
60
  book.to_s
@@ -73,7 +66,7 @@
73
66
  %strong hash
74
67
  with the results:
75
68
  %code
76
- %pre results = FullBooks.search params[:query], :offset => params[:offset]
69
+ %pre results = BookSearch.search params[:query], :ids => params[:ids], :offset => params[:offset]
77
70
  %p
78
71
  This part takes the
79
72
  %strong hash
@@ -121,11 +114,10 @@
121
114
  %code
122
115
  %pre
123
116
  :preserve
124
- FullBooks = Picky::Client::Full.new :host => 'localhost', :port => 8080, :path => '/books/full'
125
- LiveBooks = Picky::Client::Live.new :host => 'localhost', :port => 8080, :path => '/books/live'
117
+ BookSearch = Picky::Client.new :host => 'localhost', :port => 8080, :path => '/books/full'
126
118
 
127
119
  get '/search/full' do
128
- results = FullBooks.search params[:query], :offset => params[:offset]
120
+ results = BookSearch.search params[:query], :ids => params[:ids], :offset => params[:offset]
129
121
 
130
122
  results.extend Picky::Convenience
131
123
  results.populate_with Book do |book|
@@ -2,17 +2,17 @@ source :gemcutter
2
2
 
3
3
  # Gems required by Picky.
4
4
  #
5
- gem 'picky', '~> 1.0'
5
+ gem 'picky', '2.0.0.pre1'
6
6
  gem 'rake'
7
7
  gem 'bundler'
8
- gem 'rack', '~> 1.2.1'
9
- gem 'rack-mount', '~> 0.6.9'
10
- gem 'text', '~> 0.2.0'
11
- gem 'yajl-ruby', '~> 0.7.8', :require => 'yajl'
8
+ gem 'rack', '~> 1.2.2'
9
+ gem 'rack-mount', '~> 0.6.13'
10
+ gem 'text', '~> 0.2.0'
11
+ gem 'yajl-ruby', '~> 0.8.1', :require => 'yajl'
12
12
 
13
13
  # Should be optional, but isn't yet. Sorry.
14
14
  #
15
- gem 'activerecord', '~> 2.3.8', :require => 'active_record'
15
+ gem 'activerecord', '~> 2.3.8', :require => 'active_record'
16
16
 
17
17
  # Optional. Makes rack faster.
18
18
  #
@@ -1,11 +1 @@
1
- require 'picky-tasks'
2
-
3
- desc "Finds where Picky still needs input from you."
4
- task :todo do
5
- if system "grep -e 'TO#{}DO.*' -n --color=always -R *"
6
- puts "Picky needs a bit of input from you there. Thanks."
7
- else
8
- puts "Picky seems to be fine (no TO#{}DOs found)."
9
- end
10
- end
11
- task :default => :todo
1
+ require 'picky-tasks'
@@ -28,7 +28,7 @@ puts "Copy the following line to do just that:"
28
28
  puts "\x1b[1;30mLoader.load_application; Indexes.load_from_cache; nil\x1b[m"
29
29
  puts ""
30
30
  puts "Now you can for example create a query instance."
31
- puts "\x1b[1;30mfull_books = Query::Full.new(Indexes[:books]); nil\x1b[m"
31
+ puts "\x1b[1;30mbooks = Search.new(Indexes[:books]); nil\x1b[m"
32
32
  puts "and search on it"
33
- puts "\x1b[1;30mfull_books.search_with_text 'bla'\x1b[m"
33
+ puts "\x1b[1;30mbooks.search_with_text 'bla'\x1b[m"
34
34
  exec "#{options[:irb]} #{libs} --simple-prompt"
@@ -37,13 +37,9 @@ class PickySearch < Application
37
37
  partial: Partial::None.new # Partial substring searching on the year does not make
38
38
  # much sense, neither does similarity.
39
39
 
40
- query_options = { :weights => { [:title, :author] => +3, [:title] => +1 } } # +/- points for ordered combinations.
40
+ options = { :weights => { [:title, :author] => +3, [:title] => +1 } } # +/- points for combinations.
41
41
 
42
- # A Full query returns ids, combinations, and counts.
43
- # A Live query does return all that Full returns, except ids.
44
- #
45
- route %r{\A/books/full\Z} => Query::Full.new(books_index, query_options) # Routing is simple:
46
- route %r{\A/books/live\Z} => Query::Live.new(books_index, query_options) # url_path_regexp => query
42
+ route %r{\A/books\Z} => Search.new(books_index, options)
47
43
 
48
44
  # Note: You can pass a query multiple indexes and it will query in all of them.
49
45
 
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: picky-generators
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 1.5.4
4
+ prerelease: 6
5
+ version: 2.0.0.pre1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Florian Hanke
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-15 00:00:00 +01:00
13
+ date: 2011-03-18 00:00:00 +01:00
14
14
  default_executable: picky-generate
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -32,7 +32,7 @@ dependencies:
32
32
  requirements:
33
33
  - - ~>
34
34
  - !ruby/object:Gem::Version
35
- version: 1.5.4
35
+ version: 2.0.0.pre1
36
36
  type: :runtime
37
37
  version_requirements: *id002
38
38
  - !ruby/object:Gem::Dependency
@@ -43,7 +43,7 @@ dependencies:
43
43
  requirements:
44
44
  - - ~>
45
45
  - !ruby/object:Gem::Version
46
- version: 1.5.4
46
+ version: 2.0.0.pre1
47
47
  type: :runtime
48
48
  version_requirements: *id003
49
49
  description: Generators for Picky.
@@ -72,6 +72,7 @@ files:
72
72
  - prototypes/client/sinatra/javascripts/jquery-1.5.0.min.js
73
73
  - prototypes/client/sinatra/javascripts/picky.min.js
74
74
  - prototypes/client/sinatra/library.csv
75
+ - prototypes/client/sinatra/Rakefile
75
76
  - prototypes/client/sinatra/stylesheets/application.css
76
77
  - prototypes/client/sinatra/stylesheets/picky.css
77
78
  - prototypes/client/sinatra/views/configure.haml
@@ -113,9 +114,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
113
114
  required_rubygems_version: !ruby/object:Gem::Requirement
114
115
  none: false
115
116
  requirements:
116
- - - ">="
117
+ - - ">"
117
118
  - !ruby/object:Gem::Version
118
- version: "0"
119
+ version: 1.3.1
119
120
  requirements: []
120
121
 
121
122
  rubyforge_project: http://rubyforge.org/projects/picky