Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'livelist-rails'

  • Loading branch information...
commit daeb4a8603a5eb5a9893ba91e4fc7cc75253c1a0 2 parents 5d36ca1 + 623e576
@pklingem authored
View
1  Gemfile
@@ -20,6 +20,7 @@ group :assets do
end
gem 'jquery-rails'
+gem 'livelist-rails', '0.0.2'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
View
2  Gemfile.lock
@@ -54,6 +54,7 @@ GEM
json (1.6.3)
linecache19 (0.5.12)
ruby_core_source (>= 0.1.4)
+ livelist-rails (0.0.2)
mail (2.3.0)
i18n (>= 0.4.0)
mime-types (~> 1.16)
@@ -132,6 +133,7 @@ DEPENDENCIES
coffee-rails (~> 3.1.1)
faker
jquery-rails
+ livelist-rails (= 0.0.2)
mysql2
rabl
rails (= 3.1.1)
View
1  app/assets/javascripts/application.js
@@ -6,4 +6,5 @@
//
//= require jquery
//= require jquery_ujs
+//= require livelist-rails
//= require_tree .
View
199 app/assets/javascripts/livelist.coffee
@@ -1,199 +0,0 @@
-class window.Utilities
- setOptions: (options, context=@) =>
- _.each( options, (value, option) => context[option] = value )
-
-class window.LiveList extends Utilities
- constructor: (options) ->
- @globalOptions.listSelector = options.list.renderTo
- @globalOptions.eventName = "livelist:#{options.global.resourceName}"
- @globalOptions.urlPrefix = "/#{options.global.resourceName}"
-
- @setOptions(options.global, @globalOptions)
-
- @search = new Search(@globalOptions, options.search)
- @filters = new Filters(@globalOptions, options.filters)
- @pagination = new Pagination(@globalOptions, options.pagination)
- @list = new List(@search, @filters, @pagination, @globalOptions, options.list)
-
- globalOptions:
- data: null
- resourceName: 'items'
- resourceNameSingular: 'item'
-
-class window.List extends Utilities
- constructor: (search, filters, pagination, globalOptions, options = {}) ->
- @data = globalOptions.data
- @fetchRequest = null
- @search = search
- @filters = filters
- @pagination = pagination
-
- @setOptions(globalOptions)
- @listTemplate = "{{##{@resourceName}}}{{>#{@resourceNameSingular}}}{{/#{@resourceName}}}"
- @listItemTemplate = '<li>{{id}}</li>'
- @fetchingIndicationClass = 'updating'
- @setOptions(options)
-
- $(@renderTo).bind(@eventName, (event, params) => @fetch(filterPresets: null, page: params?.page))
- @fetch(filterPresets: @filters.presets)
-
- displayFetchingIndication: => $(@renderTo).addClass(@fetchingIndicationClass)
- removeFetchingIndication: => $(@renderTo).removeClass(@fetchingIndicationClass)
-
- renderIndex: (data, textStatus, jqXHR) =>
- @data = data
- @render()
- @pagination.render(@data)
- @filters.filters = _.pluck( @data.filters, 'filter_slug' )
- @filters.render(@data)
-
- fetch: (options) ->
- @fetchRequest.abort() if @fetchRequest
- searchTerm = @search.searchTerm()
- params = { filters: {} }
- if options.filterPresets?.length > 0
- params.filters = options.filterPresets
- else
- _.each( @filters.filters, (filter) => params.filters[filter] = @filters.filterSelections( filter ) )
- if searchTerm then params.q = searchTerm
- if options.page then params.page = options.page
- @fetchRequest = $.ajax(
- url: @urlPrefix
- dataType: 'json'
- data: params
- type: @httpMethod
- beforeSend: @displayFetchingIndication
- success: @renderIndex
- )
-
- render: ->
- partials = {}
- partials[@resourceNameSingular] = @listItemTemplate
- $(@renderTo).html( Mustache.to_html(@listTemplate, @data, partials) )
- @removeFetchingIndication()
-
-class window.Filters extends Utilities
- constructor: (globalOptions, options = {}) ->
- @setOptions(globalOptions)
- @filters = if options.presets then _.keys(options.presets) else []
- @setOptions(options)
- $('input.filter_option', @renderTo).live( 'change', => $(@listSelector).trigger(@eventName) )
- $(@advancedOptionsToggleSelector).click(@handleAdvancedOptionsClick)
-
- filtersTemplate: '''
- {{#filters}}
- <div class='filter'>
- <h3>
- {{name}}
- </h3>
- <ul id='{{filter_slug}}_filter_options'>
- {{#options}}
- <label>
- <li>
- <input {{#selected}}checked='checked'{{/selected}}
- class='left filter_option'
- id='filter_{{slug}}'
- name='filters[]'
- type='checkbox'
- value='{{value}}' />
- <div class='left filter_name'>{{name}}</div>
- <div class='right filter_count'>{{count}}</div>
- <div class='clear'></div>
- </li>
- </label>
- {{/options}}
- </ul>
- </div>
- {{/filters}}
- '''
-
- filterValues: (filter) -> _.pluck( $(".#{filter}_filter_input"), 'value' )
- filterSelections: (filter) -> _.pluck( $("##{filter}_filter_options input.filter_option:checked"), 'value' )
-
- render: (data) -> $(@renderTo).html( Mustache.to_html(@filtersTemplate, data) )
-
- handleAdvancedOptionsClick: (event) =>
- event.preventDefault()
- $(@renderTo).slideToggle()
-
-class window.Pagination extends Utilities
- constructor: (globalOptions, options = {}) ->
- @pagination = null
- @maxPages = 30
-
- @setOptions(globalOptions)
- @emptyListMessage = "<p>No #{@resourceName} matched your filter criteria</p>"
- @setOptions(options)
-
- $("#{@renderTo} a").live('click', @handlePaginationLinkClick)
-
- paginationTemplate: '''
- {{#isEmpty}}
- {{{emptyListMessage}}}
- {{/isEmpty}}
- {{^isEmpty}}
- {{#previousPage}}
- <a href='{{urlPrefix}}?page={{previousPage}}' data-page='{{previousPage}}'>← Previous</a>
- {{/previousPage}}
- {{^previousPage}}
- <span>← Previous</span>
- {{/previousPage}}
- {{#pages}}
- {{#currentPage}}
- <span>{{page}}</span>
- {{/currentPage}}
- {{^currentPage}}
- <a href='{{urlPrefix}}?page={{page}}' data-page='{{page}}'>{{page}}</a>
- {{/currentPage}}
- {{/pages}}
- {{#nextPage}}
- <a href='{{urlPrefix}}?page={{nextPage}}' data-page='{{nextPage}}'>Next →</a>
- {{/nextPage}}
- {{^nextPage}}
- <span>Next →</span>
- {{/nextPage}}
- {{/isEmpty}}
- '''
-
- pagesJSON: (currentPage, totalPages) ->
- groupSize = @maxPages / 2
- firstPage = if currentPage < groupSize then 1 else currentPage - groupSize
- previousPage = firstPage + groupSize * 2 - 1
- lastPage = if previousPage >= totalPages then totalPages else previousPage
- _.map([firstPage..lastPage], (page) ->
- page: page
- currentPage: -> currentPage is page
- )
-
- paginationJSON: (pagination) ->
- {
- isEmpty : pagination.total_pages == 0
- emptyListMessage : @emptyListMessage
- currentPage : pagination.current_page
- nextPage : pagination.next_page
- previousPage : pagination.previous_page
- urlPrefix : @urlPrefix
- pages : @pagesJSON(pagination.current_page, pagination.total_pages)
- }
-
- render: (data) ->
- @pagination = @paginationJSON(data.pagination)
- $(@renderTo).html( Mustache.to_html(@paginationTemplate, @pagination) )
-
- handlePaginationLinkClick: (event) =>
- event.preventDefault()
- $(@listSelector).trigger(@eventName, {page: $(event.target).data('page')})
-
-class window.Search extends Utilities
- constructor: (globalOptions, options = {}) ->
- @setOptions(globalOptions)
- @setOptions(options)
- $(@formSelector).submit( (event) => @handleSearchFormSubmit(event) )
-
- searchTerm: ->
- q = $(@searchTextInputSelector).val()
- if !q or (q is '') then null else q
-
- handleSearchFormSubmit: (event) =>
- event.preventDefault()
- $(@listSelector).trigger(@eventName)
View
422 app/assets/javascripts/mustache.js
@@ -1,422 +0,0 @@
-/*
- mustache.js — Logic-less templates in JavaScript
-
- See http://mustache.github.com/ for more info.
-*/
-
-var Mustache = function() {
- var regexCache = {};
- var Renderer = function() {};
-
- Renderer.prototype = {
- otag: "{{",
- ctag: "}}",
- pragmas: {},
- buffer: [],
- pragmas_implemented: {
- "IMPLICIT-ITERATOR": true
- },
- context: {},
-
- render: function(template, context, partials, in_recursion) {
- // reset buffer & set context
- if(!in_recursion) {
- this.context = context;
- this.buffer = []; // TODO: make this non-lazy
- }
-
- // fail fast
- if(!this.includes("", template)) {
- if(in_recursion) {
- return template;
- } else {
- this.send(template);
- return;
- }
- }
-
- // get the pragmas together
- template = this.render_pragmas(template);
-
- // render the template
- var html = this.render_section(template, context, partials);
-
- // render_section did not find any sections, we still need to render the tags
- if (html === false) {
- html = this.render_tags(template, context, partials, in_recursion);
- }
-
- if (in_recursion) {
- return html;
- } else {
- this.sendLines(html);
- }
- },
-
- /*
- Sends parsed lines
- */
- send: function(line) {
- if(line !== "") {
- this.buffer.push(line);
- }
- },
-
- sendLines: function(text) {
- if (text) {
- var lines = text.split("\n");
- for (var i = 0; i < lines.length; i++) {
- this.send(lines[i]);
- }
- }
- },
-
- /*
- Looks for %PRAGMAS
- */
- render_pragmas: function(template) {
- // no pragmas
- if(!this.includes("%", template)) {
- return template;
- }
-
- var that = this;
- var regex = this.getCachedRegex("render_pragmas", function(otag, ctag) {
- return new RegExp(otag + "%([\\w-]+) ?([\\w]+=[\\w]+)?" + ctag, "g");
- });
-
- return template.replace(regex, function(match, pragma, options) {
- if(!that.pragmas_implemented[pragma]) {
- throw({message:
- "This implementation of mustache doesn't understand the '" +
- pragma + "' pragma"});
- }
- that.pragmas[pragma] = {};
- if(options) {
- var opts = options.split("=");
- that.pragmas[pragma][opts[0]] = opts[1];
- }
- return "";
- // ignore unknown pragmas silently
- });
- },
-
- /*
- Tries to find a partial in the curent scope and render it
- */
- render_partial: function(name, context, partials) {
- name = this.trim(name);
- if(!partials || partials[name] === undefined) {
- throw({message: "unknown_partial '" + name + "'"});
- }
- if(typeof(context[name]) != "object") {
- return this.render(partials[name], context, partials, true);
- }
- return this.render(partials[name], context[name], partials, true);
- },
-
- /*
- Renders inverted (^) and normal (#) sections
- */
- render_section: function(template, context, partials) {
- if(!this.includes("#", template) && !this.includes("^", template)) {
- // did not render anything, there were no sections
- return false;
- }
-
- var that = this;
-
- var regex = this.getCachedRegex("render_section", function(otag, ctag) {
- // This regex matches _the first_ section ({{#foo}}{{/foo}}), and captures the remainder
- return new RegExp(
- "^([\\s\\S]*?)" + // all the crap at the beginning that is not {{*}} ($1)
-
- otag + // {{
- "(\\^|\\#)\\s*(.+)\\s*" + // #foo (# == $2, foo == $3)
- ctag + // }}
-
- "\n*([\\s\\S]*?)" + // between the tag ($2). leading newlines are dropped
-
- otag + // {{
- "\\/\\s*\\3\\s*" + // /foo (backreference to the opening tag).
- ctag + // }}
-
- "\\s*([\\s\\S]*)$", // everything else in the string ($4). leading whitespace is dropped.
-
- "g");
- });
-
-
- // for each {{#foo}}{{/foo}} section do...
- return template.replace(regex, function(match, before, type, name, content, after) {
- // before contains only tags, no sections
- var renderedBefore = before ? that.render_tags(before, context, partials, true) : "",
-
- // after may contain both sections and tags, so use full rendering function
- renderedAfter = after ? that.render(after, context, partials, true) : "",
-
- // will be computed below
- renderedContent,
-
- value = that.find(name, context);
-
- if (type === "^") { // inverted section
- if (!value || that.is_array(value) && value.length === 0) {
- // false or empty list, render it
- renderedContent = that.render(content, context, partials, true);
- } else {
- renderedContent = "";
- }
- } else if (type === "#") { // normal section
- if (that.is_array(value)) { // Enumerable, Let's loop!
- renderedContent = that.map(value, function(row) {
- return that.render(content, that.create_context(row), partials, true);
- }).join("");
- } else if (that.is_object(value)) { // Object, Use it as subcontext!
- renderedContent = that.render(content, that.create_context(value),
- partials, true);
- } else if (typeof value === "function") {
- // higher order section
- renderedContent = value.call(context, content, function(text) {
- return that.render(text, context, partials, true);
- });
- } else if (value) { // boolean section
- renderedContent = that.render(content, context, partials, true);
- } else {
- renderedContent = "";
- }
- }
-
- return renderedBefore + renderedContent + renderedAfter;
- });
- },
-
- /*
- Replace {{foo}} and friends with values from our view
- */
- render_tags: function(template, context, partials, in_recursion) {
- // tit for tat
- var that = this;
-
-
-
- var new_regex = function() {
- return that.getCachedRegex("render_tags", function(otag, ctag) {
- return new RegExp(otag + "(=|!|>|\\{|%)?([^\\/#\\^]+?)\\1?" + ctag + "+", "g");
- });
- };
-
- var regex = new_regex();
- var tag_replace_callback = function(match, operator, name) {
- switch(operator) {
- case "!": // ignore comments
- return "";
- case "=": // set new delimiters, rebuild the replace regexp
- that.set_delimiters(name);
- regex = new_regex();
- return "";
- case ">": // render partial
- return that.render_partial(name, context, partials);
- case "{": // the triple mustache is unescaped
- return that.find(name, context);
- default: // escape the value
- return that.escape(that.find(name, context));
- }
- };
- var lines = template.split("\n");
- for(var i = 0; i < lines.length; i++) {
- lines[i] = lines[i].replace(regex, tag_replace_callback, this);
- if(!in_recursion) {
- this.send(lines[i]);
- }
- }
-
- if(in_recursion) {
- return lines.join("\n");
- }
- },
-
- set_delimiters: function(delimiters) {
- var dels = delimiters.split(" ");
- this.otag = this.escape_regex(dels[0]);
- this.ctag = this.escape_regex(dels[1]);
- },
-
- escape_regex: function(text) {
- // thank you Simon Willison
- if(!arguments.callee.sRE) {
- var specials = [
- '/', '.', '*', '+', '?', '|',
- '(', ')', '[', ']', '{', '}', '\\'
- ];
- arguments.callee.sRE = new RegExp(
- '(\\' + specials.join('|\\') + ')', 'g'
- );
- }
- return text.replace(arguments.callee.sRE, '\\$1');
- },
-
- /*
- find `name` in current `context`. That is find me a value
- from the view object
- */
- find: function(name, context) {
- name = this.trim(name);
-
- // Checks whether a value is thruthy or false or 0
- function is_kinda_truthy(bool) {
- return bool === false || bool === 0 || bool;
- }
-
- var value;
-
- // check for dot notation eg. foo.bar
- if(name.match(/([a-z_]+)\./ig)){
- var childValue = this.walk_context(name, context);
- if(is_kinda_truthy(childValue)) {
- value = childValue;
- }
- }
- else{
- if(is_kinda_truthy(context[name])) {
- value = context[name];
- } else if(is_kinda_truthy(this.context[name])) {
- value = this.context[name];
- }
- }
-
- if(typeof value === "function") {
- return value.apply(context);
- }
- if(value !== undefined) {
- return value;
- }
- // silently ignore unkown variables
- return "";
- },
-
- walk_context: function(name, context){
- var path = name.split('.');
- // if the var doesn't exist in current context, check the top level context
- var value_context = (context[path[0]] != undefined) ? context : this.context;
- var value = value_context[path.shift()];
- while(value != undefined && path.length > 0){
- value_context = value;
- value = value[path.shift()];
- }
- // if the value is a function, call it, binding the correct context
- if(typeof value === "function") {
- return value.apply(value_context);
- }
- return value;
- },
-
- // Utility methods
-
- /* includes tag */
- includes: function(needle, haystack) {
- return haystack.indexOf(this.otag + needle) != -1;
- },
-
- /*
- Does away with nasty characters
- */
- escape: function(s) {
- s = String(s === null ? "" : s);
- return s.replace(/&(?!\w+;)|["'<>\\]/g, function(s) {
- switch(s) {
- case "&": return "&amp;";
- case '"': return '&quot;';
- case "'": return '&#39;';
- case "<": return "&lt;";
- case ">": return "&gt;";
- default: return s;
- }
- });
- },
-
- // by @langalex, support for arrays of strings
- create_context: function(_context) {
- if(this.is_object(_context)) {
- return _context;
- } else {
- var iterator = ".";
- if(this.pragmas["IMPLICIT-ITERATOR"]) {
- iterator = this.pragmas["IMPLICIT-ITERATOR"].iterator;
- }
- var ctx = {};
- ctx[iterator] = _context;
- return ctx;
- }
- },
-
- is_object: function(a) {
- return a && typeof a == "object";
- },
-
- is_array: function(a) {
- return Object.prototype.toString.call(a) === '[object Array]';
- },
-
- /*
- Gets rid of leading and trailing whitespace
- */
- trim: function(s) {
- return s.replace(/^\s*|\s*$/g, "");
- },
-
- /*
- Why, why, why? Because IE. Cry, cry cry.
- */
- map: function(array, fn) {
- if (typeof array.map == "function") {
- return array.map(fn);
- } else {
- var r = [];
- var l = array.length;
- for(var i = 0; i < l; i++) {
- r.push(fn(array[i]));
- }
- return r;
- }
- },
-
- getCachedRegex: function(name, generator) {
- var byOtag = regexCache[this.otag];
- if (!byOtag) {
- byOtag = regexCache[this.otag] = {};
- }
-
- var byCtag = byOtag[this.ctag];
- if (!byCtag) {
- byCtag = byOtag[this.ctag] = {};
- }
-
- var regex = byCtag[name];
- if (!regex) {
- regex = byCtag[name] = generator(this.otag, this.ctag);
- }
-
- return regex;
- }
- };
-
- return({
- name: "mustache.js",
- version: "0.4.0-dev",
-
- /*
- Turns a template and view into HTML
- */
- to_html: function(template, view, partials, send_fun) {
- var renderer = new Renderer();
- if(send_fun) {
- renderer.send = send_fun;
- }
- renderer.render(template, view || {}, partials);
- if(!send_fun) {
- return renderer.buffer.join("\n");
- }
- }
- });
-}();
View
30 app/assets/javascripts/underscore-min.js
@@ -1,30 +0,0 @@
-// Underscore.js 1.2.2
-// (c) 2011 Jeremy Ashkenas, DocumentCloud Inc.
-// Underscore is freely distributable under the MIT license.
-// Portions of Underscore are inspired or borrowed from Prototype,
-// Oliver Steele's Functional, and John Resig's Micro-Templating.
-// For all details and documentation:
-// http://documentcloud.github.com/underscore
-(function(){function r(a,c,d){if(a===c)return a!==0||1/a==1/c;if(a==null||c==null)return a===c;if(a._chain)a=a._wrapped;if(c._chain)c=c._wrapped;if(b.isFunction(a.isEqual))return a.isEqual(c);if(b.isFunction(c.isEqual))return c.isEqual(a);var e=l.call(a);if(e!=l.call(c))return false;switch(e){case "[object String]":return String(a)==String(c);case "[object Number]":return a=+a,c=+c,a!=a?c!=c:a==0?1/a==1/c:a==c;case "[object Date]":case "[object Boolean]":return+a==+c;case "[object RegExp]":return a.source==
-c.source&&a.global==c.global&&a.multiline==c.multiline&&a.ignoreCase==c.ignoreCase}if(typeof a!="object"||typeof c!="object")return false;for(var f=d.length;f--;)if(d[f]==a)return true;d.push(a);var f=0,g=true;if(e=="[object Array]"){if(f=a.length,g=f==c.length)for(;f--;)if(!(g=f in a==f in c&&r(a[f],c[f],d)))break}else{if("constructor"in a!="constructor"in c||a.constructor!=c.constructor)return false;for(var h in a)if(m.call(a,h)&&(f++,!(g=m.call(c,h)&&r(a[h],c[h],d))))break;if(g){for(h in c)if(m.call(c,
-h)&&!f--)break;g=!f}}d.pop();return g}var s=this,F=s._,o={},k=Array.prototype,p=Object.prototype,i=k.slice,G=k.unshift,l=p.toString,m=p.hasOwnProperty,v=k.forEach,w=k.map,x=k.reduce,y=k.reduceRight,z=k.filter,A=k.every,B=k.some,q=k.indexOf,C=k.lastIndexOf,p=Array.isArray,H=Object.keys,t=Function.prototype.bind,b=function(a){return new n(a)};if(typeof exports!=="undefined"){if(typeof module!=="undefined"&&module.exports)exports=module.exports=b;exports._=b}else typeof define==="function"&&define.amd?
-define("underscore",function(){return b}):s._=b;b.VERSION="1.2.2";var j=b.each=b.forEach=function(a,c,b){if(a!=null)if(v&&a.forEach===v)a.forEach(c,b);else if(a.length===+a.length)for(var e=0,f=a.length;e<f;e++){if(e in a&&c.call(b,a[e],e,a)===o)break}else for(e in a)if(m.call(a,e)&&c.call(b,a[e],e,a)===o)break};b.map=function(a,c,b){var e=[];if(a==null)return e;if(w&&a.map===w)return a.map(c,b);j(a,function(a,g,h){e[e.length]=c.call(b,a,g,h)});return e};b.reduce=b.foldl=b.inject=function(a,c,d,e){var f=
-d!==void 0;a==null&&(a=[]);if(x&&a.reduce===x)return e&&(c=b.bind(c,e)),f?a.reduce(c,d):a.reduce(c);j(a,function(a,b,i){f?d=c.call(e,d,a,b,i):(d=a,f=true)});if(!f)throw new TypeError("Reduce of empty array with no initial value");return d};b.reduceRight=b.foldr=function(a,c,d,e){a==null&&(a=[]);if(y&&a.reduceRight===y)return e&&(c=b.bind(c,e)),d!==void 0?a.reduceRight(c,d):a.reduceRight(c);a=(b.isArray(a)?a.slice():b.toArray(a)).reverse();return b.reduce(a,c,d,e)};b.find=b.detect=function(a,c,b){var e;
-D(a,function(a,g,h){if(c.call(b,a,g,h))return e=a,true});return e};b.filter=b.select=function(a,c,b){var e=[];if(a==null)return e;if(z&&a.filter===z)return a.filter(c,b);j(a,function(a,g,h){c.call(b,a,g,h)&&(e[e.length]=a)});return e};b.reject=function(a,c,b){var e=[];if(a==null)return e;j(a,function(a,g,h){c.call(b,a,g,h)||(e[e.length]=a)});return e};b.every=b.all=function(a,c,b){var e=true;if(a==null)return e;if(A&&a.every===A)return a.every(c,b);j(a,function(a,g,h){if(!(e=e&&c.call(b,a,g,h)))return o});
-return e};var D=b.some=b.any=function(a,c,d){var c=c||b.identity,e=false;if(a==null)return e;if(B&&a.some===B)return a.some(c,d);j(a,function(a,b,h){if(e||(e=c.call(d,a,b,h)))return o});return!!e};b.include=b.contains=function(a,c){var b=false;if(a==null)return b;return q&&a.indexOf===q?a.indexOf(c)!=-1:b=D(a,function(a){return a===c})};b.invoke=function(a,c){var d=i.call(arguments,2);return b.map(a,function(a){return(c.call?c||a:a[c]).apply(a,d)})};b.pluck=function(a,c){return b.map(a,function(a){return a[c]})};
-b.max=function(a,c,d){if(!c&&b.isArray(a))return Math.max.apply(Math,a);if(!c&&b.isEmpty(a))return-Infinity;var e={computed:-Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;b>=e.computed&&(e={value:a,computed:b})});return e.value};b.min=function(a,c,d){if(!c&&b.isArray(a))return Math.min.apply(Math,a);if(!c&&b.isEmpty(a))return Infinity;var e={computed:Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;b<e.computed&&(e={value:a,computed:b})});return e.value};b.shuffle=function(a){var c=[],b;
-j(a,function(a,f){f==0?c[0]=a:(b=Math.floor(Math.random()*(f+1)),c[f]=c[b],c[b]=a)});return c};b.sortBy=function(a,c,d){return b.pluck(b.map(a,function(a,b,g){return{value:a,criteria:c.call(d,a,b,g)}}).sort(function(a,c){var b=a.criteria,d=c.criteria;return b<d?-1:b>d?1:0}),"value")};b.groupBy=function(a,c){var d={},e=b.isFunction(c)?c:function(a){return a[c]};j(a,function(a,c){var b=e(a,c);(d[b]||(d[b]=[])).push(a)});return d};b.sortedIndex=function(a,c,d){d||(d=b.identity);for(var e=0,f=a.length;e<
-f;){var g=e+f>>1;d(a[g])<d(c)?e=g+1:f=g}return e};b.toArray=function(a){return!a?[]:a.toArray?a.toArray():b.isArray(a)?i.call(a):b.isArguments(a)?i.call(a):b.values(a)};b.size=function(a){return b.toArray(a).length};b.first=b.head=function(a,b,d){return b!=null&&!d?i.call(a,0,b):a[0]};b.initial=function(a,b,d){return i.call(a,0,a.length-(b==null||d?1:b))};b.last=function(a,b,d){return b!=null&&!d?i.call(a,Math.max(a.length-b,0)):a[a.length-1]};b.rest=b.tail=function(a,b,d){return i.call(a,b==null||
-d?1:b)};b.compact=function(a){return b.filter(a,function(a){return!!a})};b.flatten=function(a,c){return b.reduce(a,function(a,e){if(b.isArray(e))return a.concat(c?e:b.flatten(e));a[a.length]=e;return a},[])};b.without=function(a){return b.difference(a,i.call(arguments,1))};b.uniq=b.unique=function(a,c,d){var d=d?b.map(a,d):a,e=[];b.reduce(d,function(d,g,h){if(0==h||(c===true?b.last(d)!=g:!b.include(d,g)))d[d.length]=g,e[e.length]=a[h];return d},[]);return e};b.union=function(){return b.uniq(b.flatten(arguments,
-true))};b.intersection=b.intersect=function(a){var c=i.call(arguments,1);return b.filter(b.uniq(a),function(a){return b.every(c,function(c){return b.indexOf(c,a)>=0})})};b.difference=function(a,c){return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a=i.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e<c;e++)d[e]=b.pluck(a,""+e);return d};b.indexOf=function(a,c,d){if(a==null)return-1;var e;if(d)return d=b.sortedIndex(a,c),a[d]===c?d:-1;if(q&&a.indexOf===q)return a.indexOf(c);
-for(d=0,e=a.length;d<e;d++)if(a[d]===c)return d;return-1};b.lastIndexOf=function(a,b){if(a==null)return-1;if(C&&a.lastIndexOf===C)return a.lastIndexOf(b);for(var d=a.length;d--;)if(a[d]===b)return d;return-1};b.range=function(a,b,d){arguments.length<=1&&(b=a||0,a=0);for(var d=arguments[2]||1,e=Math.max(Math.ceil((b-a)/d),0),f=0,g=Array(e);f<e;)g[f++]=a,a+=d;return g};var E=function(){};b.bind=function(a,c){var d,e;if(a.bind===t&&t)return t.apply(a,i.call(arguments,1));if(!b.isFunction(a))throw new TypeError;
-e=i.call(arguments,2);return d=function(){if(!(this instanceof d))return a.apply(c,e.concat(i.call(arguments)));E.prototype=a.prototype;var b=new E,g=a.apply(b,e.concat(i.call(arguments)));return Object(g)===g?g:b}};b.bindAll=function(a){var c=i.call(arguments,1);c.length==0&&(c=b.functions(a));j(c,function(c){a[c]=b.bind(a[c],a)});return a};b.memoize=function(a,c){var d={};c||(c=b.identity);return function(){var b=c.apply(this,arguments);return m.call(d,b)?d[b]:d[b]=a.apply(this,arguments)}};b.delay=
-function(a,b){var d=i.call(arguments,2);return setTimeout(function(){return a.apply(a,d)},b)};b.defer=function(a){return b.delay.apply(b,[a,1].concat(i.call(arguments,1)))};b.throttle=function(a,c){var d,e,f,g,h,i=b.debounce(function(){h=g=false},c);return function(){d=this;e=arguments;var b;f||(f=setTimeout(function(){f=null;h&&a.apply(d,e);i()},c));g?h=true:a.apply(d,e);i();g=true}};b.debounce=function(a,b){var d;return function(){var e=this,f=arguments;clearTimeout(d);d=setTimeout(function(){d=
-null;a.apply(e,f)},b)}};b.once=function(a){var b=false,d;return function(){if(b)return d;b=true;return d=a.apply(this,arguments)}};b.wrap=function(a,b){return function(){var d=[a].concat(i.call(arguments));return b.apply(this,d)}};b.compose=function(){var a=i.call(arguments);return function(){for(var b=i.call(arguments),d=a.length-1;d>=0;d--)b=[a[d].apply(this,b)];return b[0]}};b.after=function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}};b.keys=H||function(a){if(a!==
-Object(a))throw new TypeError("Invalid object");var b=[],d;for(d in a)m.call(a,d)&&(b[b.length]=d);return b};b.values=function(a){return b.map(a,b.identity)};b.functions=b.methods=function(a){var c=[],d;for(d in a)b.isFunction(a[d])&&c.push(d);return c.sort()};b.extend=function(a){j(i.call(arguments,1),function(b){for(var d in b)b[d]!==void 0&&(a[d]=b[d])});return a};b.defaults=function(a){j(i.call(arguments,1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a};b.clone=function(a){return!b.isObject(a)?
-a:b.isArray(a)?a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};b.isEqual=function(a,b){return r(a,b,[])};b.isEmpty=function(a){if(b.isArray(a)||b.isString(a))return a.length===0;for(var c in a)if(m.call(a,c))return false;return true};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=p||function(a){return l.call(a)=="[object Array]"};b.isObject=function(a){return a===Object(a)};b.isArguments=l.call(arguments)=="[object Arguments]"?function(a){return l.call(a)=="[object Arguments]"}:
-function(a){return!(!a||!m.call(a,"callee"))};b.isFunction=function(a){return l.call(a)=="[object Function]"};b.isString=function(a){return l.call(a)=="[object String]"};b.isNumber=function(a){return l.call(a)=="[object Number]"};b.isNaN=function(a){return a!==a};b.isBoolean=function(a){return a===true||a===false||l.call(a)=="[object Boolean]"};b.isDate=function(a){return l.call(a)=="[object Date]"};b.isRegExp=function(a){return l.call(a)=="[object RegExp]"};b.isNull=function(a){return a===null};
-b.isUndefined=function(a){return a===void 0};b.noConflict=function(){s._=F;return this};b.identity=function(a){return a};b.times=function(a,b,d){for(var e=0;e<a;e++)b.call(d,e)};b.escape=function(a){return(""+a).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#x27;").replace(/\//g,"&#x2F;")};b.mixin=function(a){j(b.functions(a),function(c){I(c,b[c]=a[c])})};var J=0;b.uniqueId=function(a){var b=J++;return a?a+b:b};b.templateSettings={evaluate:/<%([\s\S]+?)%>/g,
-interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};b.template=function(a,c){var d=b.templateSettings,d="var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('"+a.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(d.escape,function(a,b){return"',_.escape("+b.replace(/\\'/g,"'")+"),'"}).replace(d.interpolate,function(a,b){return"',"+b.replace(/\\'/g,"'")+",'"}).replace(d.evaluate||null,function(a,b){return"');"+b.replace(/\\'/g,"'").replace(/[\r\n\t]/g," ")+";__p.push('"}).replace(/\r/g,
-"\\r").replace(/\n/g,"\\n").replace(/\t/g,"\\t")+"');}return __p.join('');",e=new Function("obj","_",d);return c?e(c,b):function(a){return e(a,b)}};var n=function(a){this._wrapped=a};b.prototype=n.prototype;var u=function(a,c){return c?b(a).chain():a},I=function(a,c){n.prototype[a]=function(){var a=i.call(arguments);G.call(a,this._wrapped);return u(c.apply(b,a),this._chain)}};b.mixin(b);j("pop,push,reverse,shift,sort,splice,unshift".split(","),function(a){var b=k[a];n.prototype[a]=function(){b.apply(this._wrapped,
-arguments);return u(this._wrapped,this._chain)}});j(["concat","join","slice"],function(a){var b=k[a];n.prototype[a]=function(){return u(b.apply(this._wrapped,arguments),this._chain)}});n.prototype.chain=function(){this._chain=true;return this};n.prototype.value=function(){return this._wrapped}}).call(this);
View
79 app/concerns/live_list.rb
@@ -1,79 +0,0 @@
-module LiveList
- def self.included(base)
- base.extend(ClassMethods)
- end
-
- module ClassMethods
- def filters(*filter_slugs)
- @@filter_slugs = filter_slugs
- @@filter_slugs.each do |filter_slug|
- metaclass = class << self; self; end
-
- metaclass.instance_eval do
- define_method "#{filter_slug}_filter_name" do
- filter_slug.capitalize
- end
-
- define_method "#{filter_slug}_filter_slug" do
- filter_slug
- end
-
-
- define_method "#{filter_slug}_filter" do |options|
- {
- :filter_slug => send("#{filter_slug}_filter_slug"),
- :name => send("#{filter_slug}_filter_name"),
- :options => options
- }
- end
-
- define_method "#{filter_slug}_filter_options" do
- select("distinct #{filter_slug}").map(&filter_slug)
- end
-
- define_method "#{filter_slug}_filter_counts" do
- group(filter_slug).count
- end
-
- define_method "#{filter_slug}_filter_option" do |state, selected|
- {
- :slug => state,
- :name => state.capitalize,
- :value => state,
- :count => @counts[state],
- :selected => selected
- }
- end
-
- define_method "#{filter_slug}_filters" do |filter_params|
- @counts = send("#{filter_slug}_filter_counts")
- send("#{filter_slug}_filter_options").map do |option|
- selected = filter_params.nil? ? true : filter_params.include?(option)
- send("#{filter_slug}_filter_option", option, selected)
- end
- end
-
- define_method "#{filter_slug}_relation" do |values|
- where(filter_slug => values)
- end
- end
- end
-
- def self.filters_as_json(filter_params)
- filter_params ||= {}
- @@filter_slugs.map do |filter|
- send("#{filter}_filter", send("#{filter}_filters", filter_params[filter]))
- end
- end
-
- def self.filter(filter_params)
- filter_params ||= {}
- query = scoped
- filter_params.each do |filter, values|
- query = query.send("#{filter}_relation", values)
- end
- query
- end
- end
- end
-end
View
1  app/models/user.rb
@@ -1,4 +1,3 @@
class User < ActiveRecord::Base
- include LiveList
filters :state
end
View
2  config/application.rb
@@ -16,7 +16,7 @@ class Application < Rails::Application
# -- all .rb files in that directory are automatically loaded.
# Custom directories with classes and modules you want to be autoloadable.
- config.autoload_paths += %W(#{config.root}/app/concerns)
+ # config.autoload_paths += %W(#{config.root}/app/concerns)
# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.
Please sign in to comment.
Something went wrong with that request. Please try again.