cells-filters 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +5 -0
- data/README.markdown +35 -0
- data/Rakefile +12 -0
- data/cells-filters.gemspec +25 -0
- data/lib/cell/filters.rb +20 -0
- data/lib/cells-filters.rb +8 -0
- data/lib/cells-filters/version.rb +5 -0
- data/test/filters_test.rb +31 -0
- data/test/test_helper.rb +25 -0
- metadata +88 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Filters for Cells.
|
2
|
+
|
3
|
+
## Introduction
|
4
|
+
|
5
|
+
`cells-filters` allows you having before and after filters in your cell while having access to state-args.
|
6
|
+
|
7
|
+
## Example
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
class BassistCell < Cell::Base
|
11
|
+
include Cell::Filters
|
12
|
+
|
13
|
+
before_filter :prepare
|
14
|
+
after_filter :cleanup
|
15
|
+
|
16
|
+
def prepare(state, tone, timing)
|
17
|
+
@before = "In #{tone} and #{timing}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def cleanup(state, tone, timing)
|
21
|
+
@later = "After #{tone} and #{timing}"
|
22
|
+
end
|
23
|
+
```
|
24
|
+
|
25
|
+
It gives you `before_filter` and `after_filter` just like in ActionControllers. You can pass a method name or a block. The difference to the filters found in Rails itself is that Cells' filters receive the arguments passed in `render_cell` as parameters.
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
render_cell(:bassist, :play, "C-sharp", "4/4")
|
29
|
+
```
|
30
|
+
|
31
|
+
The three parameters will be forwarded to the filter methods.
|
32
|
+
|
33
|
+
## Limitations
|
34
|
+
|
35
|
+
We'd love to use the Callbacks module found in Rails directly, but they don't support passing arguments to the filters. Sorry for that.
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "cells-filters/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "cells-filters"
|
7
|
+
s.version = Cells::Filters::VERSION
|
8
|
+
s.authors = ["Nick Sutterer"]
|
9
|
+
s.email = ["apotonick@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Before and after filters for your cell.}
|
12
|
+
s.description = %q{Before and after filters for your cell.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "cells-filters"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
|
22
|
+
s.add_runtime_dependency "cells"
|
23
|
+
s.add_runtime_dependency "hooks"
|
24
|
+
s.add_development_dependency "minitest", ">= 2.8.1"
|
25
|
+
end
|
data/lib/cell/filters.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "hooks"
|
2
|
+
|
3
|
+
module Cell
|
4
|
+
module Filters
|
5
|
+
def self.included(base)
|
6
|
+
base.class_eval do
|
7
|
+
include Hooks
|
8
|
+
define_hook :before_filter
|
9
|
+
define_hook :after_filter
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def process(*args)
|
14
|
+
run_hook(:before_filter, *args)
|
15
|
+
content = super
|
16
|
+
run_hook(:after_filter, *args)
|
17
|
+
content
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'test_helper.rb'
|
2
|
+
|
3
|
+
class FiltersTest < MiniTest::Spec
|
4
|
+
class BassistCell < Cell::Base
|
5
|
+
attr_reader :later
|
6
|
+
include Cell::Filters
|
7
|
+
|
8
|
+
before_filter :before
|
9
|
+
after_filter :after
|
10
|
+
|
11
|
+
def before(state, tone, timing)
|
12
|
+
@before = "In #{tone} and #{timing}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def after(state, tone, timing)
|
16
|
+
@later = "After #{tone} and #{timing}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def play(*)
|
20
|
+
render :text => "#{@before}. Doo."
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "Filters" do
|
25
|
+
it "is run properly" do
|
26
|
+
cell = BassistCell.new
|
27
|
+
assert_equal "In C and 4/4. Doo.", cell.render_state(:play, "C", "4/4")
|
28
|
+
assert_equal "After C and 4/4", cell.later
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
# wycats says...
|
4
|
+
require 'bundler'
|
5
|
+
Bundler.setup
|
6
|
+
require 'test/unit'
|
7
|
+
require 'minitest/spec'
|
8
|
+
|
9
|
+
require 'rails' # FIXME: make cells not depend on Rails.
|
10
|
+
|
11
|
+
require 'cells'
|
12
|
+
module ActionController::RequestForgeryProtection # FIXME: make that optional in cell/rails, man!
|
13
|
+
end
|
14
|
+
|
15
|
+
require 'cell/rails'
|
16
|
+
require 'cells-filters'
|
17
|
+
|
18
|
+
# FIXME: make caching not depend on AC.
|
19
|
+
class ActionController::Base
|
20
|
+
def self.cache_configured?
|
21
|
+
false
|
22
|
+
end
|
23
|
+
def self.logger(*)
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cells-filters
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Nick Sutterer
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: cells
|
16
|
+
requirement: &72791950 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *72791950
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: hooks
|
27
|
+
requirement: &72595000 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *72595000
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: minitest
|
38
|
+
requirement: &72593830 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2.8.1
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *72593830
|
47
|
+
description: Before and after filters for your cell.
|
48
|
+
email:
|
49
|
+
- apotonick@gmail.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- README.markdown
|
57
|
+
- Rakefile
|
58
|
+
- cells-filters.gemspec
|
59
|
+
- lib/cell/filters.rb
|
60
|
+
- lib/cells-filters.rb
|
61
|
+
- lib/cells-filters/version.rb
|
62
|
+
- test/filters_test.rb
|
63
|
+
- test/test_helper.rb
|
64
|
+
homepage: ''
|
65
|
+
licenses: []
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project: cells-filters
|
84
|
+
rubygems_version: 1.8.10
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: Before and after filters for your cell.
|
88
|
+
test_files: []
|