Class: Codex::Filters

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/codex/filter.rb

Overview

Filters contains a hash of all loaded filters. It does all parsing of the input file and send chunks to be filtered to the individual filters.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#filter_file_tagsObject

Returns the value of attribute filter_file_tags.



19
20
21
# File 'lib/codex/filter.rb', line 19

def filter_file_tags
  @filter_file_tags
end

#filter_inline_end_tagsObject

Returns the value of attribute filter_inline_end_tags.



19
20
21
# File 'lib/codex/filter.rb', line 19

def filter_inline_end_tags
  @filter_inline_end_tags
end

#filter_inline_tagsObject

Returns the value of attribute filter_inline_tags.



19
20
21
# File 'lib/codex/filter.rb', line 19

def filter_inline_tags
  @filter_inline_tags
end

#logObject

Returns the value of attribute log.



19
20
21
# File 'lib/codex/filter.rb', line 19

def log
  @log
end

Instance Method Details

#[](idx) ⇒ Object



25
26
27
# File 'lib/codex/filter.rb', line 25

def [](idx)
  @filters[idx]
end

#[]=(idx, val) ⇒ Object



21
22
23
# File 'lib/codex/filter.rb', line 21

def []=(idx,val)
  @filters[idx] = val
end

#filter_all(text) ⇒ Object

Parse the input text and parse chunks over to filters when encountering tags



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/codex/filter.rb', line 30

def filter_all(text)
  state = :copying
  result = []
  tagged_lines = []
  tag = args = nil
  text.split(/\n/).each do |line|
    case state
    when :copying
      if line =~ inline_tag
        tag = $1
        args = $2.strip
        state = :inside_tag
      elsif line =~ single_tag
        tag = $1
        args = $2.strip
        result << @filters[tag.to_sym].filter_single(args)
      else
        result << line
      end
    when :inside_tag
      # :endinlinewhatever, :endwhatever or just plain :end
      if line =~ /^:end(inline#{tag}|#{tag})?(\s.*)?$/
        result << @filters[tag.to_sym].filter_inline(tagged_lines.join("\n"),args)
        tagged_lines = []
        state = :copying
      else
        tagged_lines << line
      end
    end
  end

  result.join("\n")
end