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

Commit 0960865

Browse files
committedOct 29, 2013
Add initial router support for filters
1 parent ef04746 commit 0960865

File tree

3 files changed

+21
-24
lines changed

3 files changed

+21
-24
lines changed
 

‎Gemfile

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
source 'https://rubygems.org'
22

3-
gem 'opal', '>= 0.4.4'
4-
gem 'opal-sprockets'
5-
gem 'opal-jquery'
6-
gem 'vienna', :github => 'opal/vienna'
3+
gem 'opal', :github => 'opal/opal'
4+
gem 'opal-sprockets', :github => 'opal/opal-sprockets'
5+
gem 'opal-jquery', :github => 'opal/opal-jquery'
6+
gem 'vienna', :github => 'opal/vienna'

‎app/app.rb

+12-20
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,27 @@
1212

1313
require 'models/todo'
1414

15-
module Vienna
16-
class << self
17-
attr_accessor :application
18-
end
19-
20-
class Application
21-
class << self
22-
def inherited(base)
23-
Vienna.application ||= base.instance
24-
end
15+
class Application
16+
def run
17+
@app_view = AppView.new
2518

26-
def method_missing(sym, *args)
27-
instance.__send__(sym, *args)
28-
end
19+
router.update
20+
end
2921

30-
def instance
31-
@instance ||= self.new
22+
def router
23+
@router ||= Vienna::Router.new.tap do |router|
24+
router.route('/:filter') do |params|
25+
apply_filter params[:filter]
3226
end
3327
end
3428
end
35-
end
3629

37-
class Application < Vienna::Application
38-
def run
39-
@app_view = AppView.new
30+
def apply_filter(filter)
31+
Todo.all.each { |t| t.trigger :filter, filter }
4032
end
4133
end
4234

4335
# when document is ready, lets go!
4436
Document.ready? do
45-
Application.run
37+
Application.new.run
4638
end

‎app/views/todo_view.rb

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ def initialize(todo)
2828
@todo = todo
2929
@todo.on(:update) { render }
3030
@todo.on(:destroy) { remove }
31+
@todo.on(:filter) { |filter| apply_filter filter }
32+
end
33+
34+
def apply_filter(filter)
35+
puts "need to apply #{filter} for #{@todo}"
3136
end
3237

3338
def clear

0 commit comments

Comments
 (0)