Class: Yuzu::Filters::Filter
- Defined in:
- lib/yuzu/filters/base.rb
Overview
Filters are the primary means to derive information from a given source file and place new contents into it before it is placed in a layout.
There are 3 stages of filtering that happen to each file.
-
prefilter – replacing LINKROOT and CURRENTPATH, so the next phase has the proper paths
-
filter – transforming contents
-
postfilter – replacing LINKROOT and CURRENTPATH again
Direct Known Subclasses
CatalogFilter, CategoriesFilter, CurrentpathFilter, DescriptionFilter, ExtensionFilter, ImagesFilter, LinkrootFilter, PostDateFilter, PostTitleFilter, PostTitleRemovedFilter, SidebarFilter, TemplateFilter
Constant Summary collapse
- @@filters =
{}
Instance Attribute Summary collapse
-
#directive ⇒ Object
readonly
Returns the value of attribute directive.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #default(website_file = nil) ⇒ Object
- #filter_type ⇒ Object
- #get_match(contents) ⇒ Object
- #get_value(website_file) ⇒ Object
-
#initialize ⇒ Filter
constructor
A new instance of Filter.
- #match(contents) ⇒ Object
- #process(website_file, processing_contents) ⇒ Object
- #regex ⇒ Object
-
#replacement(website_file, processing_contents = nil) ⇒ String
Returns the contents to replace the directive with as written.
- #value(website_file) ⇒ Object
Constructor Details
#initialize ⇒ Filter
Returns a new instance of Filter.
25 26 27 28 |
# File 'lib/yuzu/filters/base.rb', line 25 def initialize @name = :directive @directive = "DIRECTIVE" end |
Instance Attribute Details
#directive ⇒ Object (readonly)
Returns the value of attribute directive.
23 24 25 |
# File 'lib/yuzu/filters/base.rb', line 23 def directive @directive end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
23 24 25 |
# File 'lib/yuzu/filters/base.rb', line 23 def name @name end |
Class Method Details
.filters ⇒ Object
19 20 21 |
# File 'lib/yuzu/filters/base.rb', line 19 def self.filters @@filters end |
.registry ⇒ Object
16 17 18 |
# File 'lib/yuzu/filters/base.rb', line 16 def self.registry :filters end |
Instance Method Details
#default(website_file = nil) ⇒ Object
34 35 36 |
# File 'lib/yuzu/filters/base.rb', line 34 def default(website_file=nil) nil end |
#filter_type ⇒ Object
30 31 32 |
# File 'lib/yuzu/filters/base.rb', line 30 def filter_type [:filter] end |
#get_match(contents) ⇒ Object
50 51 52 53 |
# File 'lib/yuzu/filters/base.rb', line 50 def get_match(contents) m = contents.match(regex) m.nil? ? nil : m[1] end |
#get_value(website_file) ⇒ Object
42 43 44 |
# File 'lib/yuzu/filters/base.rb', line 42 def get_value(website_file) match(website_file.raw_contents) end |
#match(contents) ⇒ Object
46 47 48 |
# File 'lib/yuzu/filters/base.rb', line 46 def match(contents) get_match(contents) end |
#process(website_file, processing_contents) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/yuzu/filters/base.rb', line 69 def process(website_file, processing_contents) m = processing_contents.match(regex) while not m.nil? repl = replacement(website_file, processing_contents) # Remove the next match. processing_contents = processing_contents.sub(regex, repl.to_s) # Find any others... m = processing_contents.match(regex) end processing_contents end |
#regex ⇒ Object
65 66 67 |
# File 'lib/yuzu/filters/base.rb', line 65 def regex Regexp.new('^\s*' + @directive.to_s + '\(([\w\s\.\,\'\"\/\-:]*?)\)') end |
#replacement(website_file, processing_contents = nil) ⇒ String
Returns the contents to replace the directive with as written.
61 62 63 |
# File 'lib/yuzu/filters/base.rb', line 61 def replacement(website_file, processing_contents=nil) "" end |
#value(website_file) ⇒ Object
38 39 40 |
# File 'lib/yuzu/filters/base.rb', line 38 def value(website_file) get_value(website_file) || default(website_file) end |