Module: Braai::Matchers

Included in:
Template, Template
Defined in:
lib/braai/matchers.rb

Constant Summary collapse

IterationMatcher =
/({{\s*for (\w+) in (\w+)\s*}}(.+?){{\s*\/for\s*}})/im
ConditionalMatcher =
/({{\s*if\s*([\w\.]+)\s*}}(.*){{\s*\/if\s*}})/mi
DefaultMatcher =
/({{\s*([\w\.]+)\s*}})/i
RegionMatcher =
/({{\s*([\w]+)\s*}}(.*){{\s*\/([\w]+)\s*}})/mi

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fallbackObject

Returns the value of attribute fallback.



3
4
5
# File 'lib/braai/matchers.rb', line 3

def fallback
  @fallback
end

Instance Method Details

#add_fallback(regex, handler = nil, &block) ⇒ Object



18
19
20
# File 'lib/braai/matchers.rb', line 18

def add_fallback(regex, handler=nil, &block)
  @fallback = { :regex => regex.to_s, :handler => handler || block }
end

#clear!Object



26
27
28
29
# File 'lib/braai/matchers.rb', line 26

def clear!
  self.matchers.clear
  self.fallback = nil
end

#map(regex, handler = nil, &block) ⇒ Object



14
15
16
# File 'lib/braai/matchers.rb', line 14

def map(regex, handler = nil, &block)
  @matchers = {regex.to_s => handler || block}.merge(self.matchers)
end

#matchersObject



10
11
12
# File 'lib/braai/matchers.rb', line 10

def matchers
  @matchers ||= reset!
end

#reset!Object



31
32
33
34
# File 'lib/braai/matchers.rb', line 31

def reset!
  @matchers = {}
  set_defaults
end

#set_defaultsObject



36
37
38
39
40
# File 'lib/braai/matchers.rb', line 36

def set_defaults
  map(IterationMatcher, Braai::Handlers::Iteration)
  map(ConditionalMatcher, Braai::Handlers::Conditional)
  map(DefaultMatcher, Braai::Handlers::Default)
end

#unmap(regex) ⇒ Object



22
23
24
# File 'lib/braai/matchers.rb', line 22

def unmap(regex)
  self.matchers.delete(regex.to_s)
end