Skip to content
This repository has been archived by the owner on Jul 31, 2019. It is now read-only.

Commit

Permalink
Add initial router support for filters
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Oct 29, 2013
1 parent ef04746 commit 0960865
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
8 changes: 4 additions & 4 deletions Gemfile
@@ -1,6 +1,6 @@
source 'https://rubygems.org'

gem 'opal', '>= 0.4.4'
gem 'opal-sprockets'
gem 'opal-jquery'
gem 'vienna', :github => 'opal/vienna'
gem 'opal', :github => 'opal/opal'
gem 'opal-sprockets', :github => 'opal/opal-sprockets'
gem 'opal-jquery', :github => 'opal/opal-jquery'
gem 'vienna', :github => 'opal/vienna'
32 changes: 12 additions & 20 deletions app/app.rb
Expand Up @@ -12,35 +12,27 @@

require 'models/todo'

module Vienna
class << self
attr_accessor :application
end

class Application
class << self
def inherited(base)
Vienna.application ||= base.instance
end
class Application
def run
@app_view = AppView.new

def method_missing(sym, *args)
instance.__send__(sym, *args)
end
router.update
end

def instance
@instance ||= self.new
def router
@router ||= Vienna::Router.new.tap do |router|
router.route('/:filter') do |params|
apply_filter params[:filter]
end
end
end
end

class Application < Vienna::Application
def run
@app_view = AppView.new
def apply_filter(filter)
Todo.all.each { |t| t.trigger :filter, filter }
end
end

# when document is ready, lets go!
Document.ready? do
Application.run
Application.new.run
end
5 changes: 5 additions & 0 deletions app/views/todo_view.rb
Expand Up @@ -28,6 +28,11 @@ def initialize(todo)
@todo = todo
@todo.on(:update) { render }
@todo.on(:destroy) { remove }
@todo.on(:filter) { |filter| apply_filter filter }
end

def apply_filter(filter)
puts "need to apply #{filter} for #{@todo}"
end

def clear
Expand Down

0 comments on commit 0960865

Please sign in to comment.