Module: Ruty::Filters
- Defined in:
- lib/ruty/filters.rb
Overview
module used to lookup filters
Class Method Summary collapse
-
.[](name) ⇒ Object
return filter ‘name`.
-
.add(name, &block) ⇒ Object
add just one filter using a code block: Ruty::Filters::add(‘swapcase’) { |context, value| value.to_s.swap_case }.
-
.all ⇒ Object
return an array of symbols containing the names of all registered filters.
-
.register_collection(collection) ⇒ Object
register a new filter collection.
Class Method Details
.[](name) ⇒ Object
return filter ‘name`
154 155 156 |
# File 'lib/ruty/filters.rb', line 154 def [] name @filters[name] end |
.add(name, &block) ⇒ Object
add just one filter using a code block: Ruty::Filters::add(‘swapcase’) { |context, value|
value.to_s.swap_case
}
172 173 174 175 |
# File 'lib/ruty/filters.rb', line 172 def add name, &block raise AttributeError, 'block required' if !block @filters[name] = block end |
.all ⇒ Object
return an array of symbols containing the names of all registered filters.
179 180 181 |
# File 'lib/ruty/filters.rb', line 179 def all return @filters.keys end |
.register_collection(collection) ⇒ Object
register a new filter collection
159 160 161 162 163 164 165 166 |
# File 'lib/ruty/filters.rb', line 159 def register_collection collection return if @collections.include? collection collection.each_filter {|name, filter| @filters[name] = filter } @collections[collection] = true nil end |