Skip to content

Commit

Permalink
Initialize app, start sketching out the classifier
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-c committed Sep 25, 2012
0 parents commit aca9680
Show file tree
Hide file tree
Showing 27 changed files with 3,055 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: serveup ./public
Empty file added README.md
Empty file.
Empty file added app/controllers/.gitkeep
Empty file.
19 changes: 19 additions & 0 deletions app/controllers/classifier.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{Controller} = require 'spine'
animals = require 'lib/animals'
template = require 'views/classifier'
FilteringCombobox = require './filtering_combobox'

class Classifier extends Controller
elements:
'.filtering-select': 'filteringComboboxNode'

constructor: ->
super

@html template

@filteringCombobox = new FilteringCombobox
el: @filteringComboboxNode
set: animals

module.exports = Classifier
19 changes: 19 additions & 0 deletions app/controllers/filtering_combobox.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{Controller} = require 'spine'
template = require 'views/filtering_select'

class FilteringSelect extends Controller
set: null
itemTemplate: (item) -> "<span>#{item.id}</span>"

className: 'filtering-select'

elements:
'.filtering-select-menu': 'menu'

constructor: ->
super
throw new Error 'FilteringSelect needs a FilteringSet' unless @set?

@el.html template @

module.exports = FilteringSelect
11 changes: 11 additions & 0 deletions app/controllers/image_switcher.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{Controller} = require 'spine'
$ = require 'jqueryify'

class ImageSwitcher extends Controller
events:
'click button[name="toggle"]': onClickToggle

onClickToggle: ({currentTarget}) =>
imgIndex = $(currentTarget).val()

module.exports = ImageSwitcher
8 changes: 8 additions & 0 deletions app/index.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'lib/setup'

Classifier = require 'controllers/classifier'

classifier = new Classifier
classifier.el.appendTo 'body'

module.exports = {classifier}
48 changes: 48 additions & 0 deletions app/lib/animals.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
FilteringSet = require 'models/filtering_set'

animals = []

animals.push
id: 'aardvark'
face: ['long', 'snout']
back: ['round']
coat: ['short']
frontLimbs: ['short']
backLimbs: ['short']
build: ['stocky']
horns: ['none']
ears: ['large']
tail: ['thin']
color: ['red', 'brown', 'gray']

animals.push
id: 'batEaredFox'
face: ['short']
back: ['round']
frontChest: ['light']
ears: ['large']
tail: ['bushy']
color: ['red', 'gray']

animals.push
id: 'cheetah'
face: ['short']
back: ['flat']
frontLimbs: ['thin']
backLimbs: ['thin']
feet: ['small']
pattern: ['spots']
build: ['lean']

animals.push
id: 'dikDik'
face: ['long', 'snout']
frontChest: ['light']
build: ['small']
horns: ['small', 'backward']
ears: ['large']
eyes: ['large']
tail: ['short']
color: ['gray', 'brown']

module.exports = new FilteringSet items: animals
4 changes: 4 additions & 0 deletions app/lib/setup.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require 'json2ify'
require 'es5-shimify'
require 'jqueryify'
require 'spine'
Empty file added app/models/.gitkeep
Empty file.
24 changes: 24 additions & 0 deletions app/models/filtering_set.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class FilteringSet
items: null
matches: null

constructor: (params = {}) ->
@[property] = value for own property, value of params
@items ?= []

@filter()

filter: (given = {}) ->
@matches = for item in @items
mismatch = false
for feature, value of given
if value instanceof RegExp and typeof item[feature] is 'string'
mismatch = true unless value.test item[feature]
else if item[feature] instanceof Array
mismatch = true unless value in item[feature]
else
mismatch = true unless item[feature] is value
continue if mismatch
item

module.exports = FilteringSet
8 changes: 8 additions & 0 deletions app/translations/en_us.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports =
navigation:
home: 'Home'
about: 'About'
classify: 'Classify'
profile: 'Profile'
discuss: 'Discuss'
blog: 'Blog'
Empty file added app/views/.gitkeep
Empty file.
3 changes: 3 additions & 0 deletions app/views/classifier.eco
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="image-switcher"></div>
<div class="filtering-select"></div>
<div class="select interface"></div>
13 changes: 13 additions & 0 deletions app/views/filtering_select.eco
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<input type="text" value="" />
<button>
<span class="possible-values"></span>
<span class="arrow">&darr;</span>
</button>

<div class="filtering-select-menu">
<% for item in @set.items: %>
<div data-item="<%= item.id %>">
<%- @itemTemplate item %>
</div>
<% end %>
</div>
Empty file added css/index.styl
Empty file.
13 changes: 13 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "serengeti",
"version": "0.0.1",
"dependencies": {
"serveup": "~0.0.5",
"hem": "~0.1.8",
"es5-shimify": "~0.0.1",
"json2ify": "~0.0.1",
"jqueryify": "~0.0.1",
"spine": "~1.0.7",
"nib": "~0.8.2"
}
}
Empty file added public/favicon.ico
Empty file.
17 changes: 17 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>

<html>
<head>
<meta charset="utf-8" />
<title>Serengeti</title>
<link rel="stylesheet" href="/application.css" />
</head>

<body>
<p>Serengeti</p>
<script src="/application.js"></script>
<script type="text/javascript">
window.app = require('index');
</script>
</body>
</html>
10 changes: 10 additions & 0 deletions slug.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"dependencies": [
"es5-shimify",
"json2ify",
"jqueryify",
"spine"
],

"libs": []
}
23 changes: 23 additions & 0 deletions test/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<title>Jasmine Test Runner</title>
<link rel="stylesheet" type="text/css" href="/test/lib/jasmine.css">
<script type="text/javascript" src="/test/lib/jasmine.js"></script>
<script type="text/javascript" src="/test/lib/jasmine.html.js"></script>

<script src="/application.js" type="text/javascript" charset="utf-8"></script>
<script src="/test/specs.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
for(var key in specs.modules) specs(key);
</script>
</head>
<body>
<script type="text/javascript">
jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
window.onload = function(){
jasmine.getEnv().execute();
};
</script>
</body>
</html>
Loading

0 comments on commit aca9680

Please sign in to comment.