Module: RailsBlogEngine::Filters

Defined in:
lib/rails_blog_engine/filters.rb,
lib/rails_blog_engine/filters/base.rb,
lib/rails_blog_engine/filters/code.rb

Defined Under Namespace

Classes: Base, Code

Constant Summary collapse

FILTERS =

:nodoc: All registered filters.

{}

Class Method Summary collapse

Class Method Details

.apply_all_to(text) ⇒ Object

Apply all registered filters to the specified text.



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rails_blog_engine/filters.rb', line 18

def self.apply_all_to(text)
  text.gsub(/<(filter|macro|typo):([_a-zA-z0-9]+)([^>]*)\/>/m) do
    trap_filter_errors do
      find($2.to_sym).process(nil, parse_arguments($3))
    end
  end.gsub(/<(filter|macro|typo):([_a-zA-z0-9]+)([^>]*)>(.*?)<\/\1:\2>/m) do
    trap_filter_errors do
      find($2.to_sym).process($4, parse_arguments($3))
    end
  end
end

.find(name) ⇒ Object

Look up a registered filter class. Raises an error if the filter can’t be found.



13
14
15
# File 'lib/rails_blog_engine/filters.rb', line 13

def self.find(name)
  FILTERS[name] or raise "Text filter not installed: #{name}"
end

.register_filter(name, filter_class) ⇒ Object

Register a filter class to be used by #apply_all_to.



7
8
9
# File 'lib/rails_blog_engine/filters.rb', line 7

def self.register_filter(name, filter_class)
  FILTERS[name] = filter_class.new
end