Class: Content::Pipeline::Filter
- Inherits:
-
Object
- Object
- Content::Pipeline::Filter
- Extended by:
- Forwardable
- Defined in:
- lib/content/pipeline/filters.rb
Direct Known Subclasses
Content::Pipeline::Filters::CodeHighlight, Content::Pipeline::Filters::Gemoji, Content::Pipeline::Filters::Markdown
Class Attribute Summary collapse
-
.filters ⇒ Object
readonly
Returns the value of attribute filters.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(str, opts = nil) ⇒ Filter
constructor
A new instance of Filter.
- #run(next_filter = nil) ⇒ Object
Constructor Details
#initialize(str, opts = nil) ⇒ Filter
Returns a new instance of Filter.
13 14 15 |
# File 'lib/content/pipeline/filters.rb', line 13 def initialize(str, opts = nil) @opts, @str = (opts || {}), str end |
Class Attribute Details
.filters ⇒ Object (readonly)
Returns the value of attribute filters.
39 40 41 |
# File 'lib/content/pipeline/filters.rb', line 39 def filters @filters end |
Class Method Details
.add_filter(*filters) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/content/pipeline/filters.rb', line 41 def add_filter(*filters) @filters ||= [] filters.each do |f| if f.is_a?(Hash) f.each do |k, v| @filters.push([ k, v ]) end else @filters.push([ f, :str ]) end end end |
Instance Method Details
#run(next_filter = nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/content/pipeline/filters.rb', line 17 def run(next_filter = nil) return @str unless size > 0 each_with_index do |f, i| send(f.first) unless size == i + 1 || @str.is_a?(String) || \ self[i + 1].last == :nokogiri @str = @str.to_s end end next_filter = next_filter.filters.first if next_filter if ! next_filter || next_filter.last != :nokogiri return @str.to_s end @str end |