Class: RhetButler::FilterResolver

Inherits:
SlideTraverser show all
Defined in:
lib/rhet-butler/filter-resolver.rb

Instance Attribute Summary collapse

Attributes inherited from SlideTraverser

#iter_stack, #target_stack

Instance Method Summary collapse

Methods inherited from SlideTraverser

#ascend, #descend, #initialize, #on_group, #traverse

Constructor Details

This class inherits a constructor from RhetButler::SlideTraverser

Instance Attribute Details

#default_content_filtersObject

Returns the value of attribute default_content_filters.



7
8
9
# File 'lib/rhet-butler/filter-resolver.rb', line 7

def default_content_filters
  @default_content_filters
end

#default_note_filtersObject

Returns the value of attribute default_note_filters.



7
8
9
# File 'lib/rhet-butler/filter-resolver.rb', line 7

def default_note_filters
  @default_note_filters
end

#named_filter_listsObject

Returns the value of attribute named_filter_lists.



7
8
9
# File 'lib/rhet-butler/filter-resolver.rb', line 7

def named_filter_lists
  @named_filter_lists
end

#root_groupObject

Returns the value of attribute root_group.



7
8
9
# File 'lib/rhet-butler/filter-resolver.rb', line 7

def root_group
  @root_group
end

Instance Method Details

#get_filters(filter, used_names = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rhet-butler/filter-resolver.rb', line 18

def get_filters(filter, used_names=nil)
  case filter
  when String
    if !used_names.nil? and used_names.include?(filter)
      raise "Recursive filter list definitions: #{filter} already referenced in #{used_names}"
    end
    get_filters(named_filter_lists.fetch(filter), (used_names||[])+[filter]) do
      raise "No filter named #{filter}"
    end
  when Array
    filter.map{|item| get_filters(item)}.flatten
  else
    filter
  end
end

#on_slide(slide) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rhet-butler/filter-resolver.rb', line 34

def on_slide(slide)
  slide.content_filters = get_filters(slide.content_filters || default_content_filters)
  slide.html_classes += slide.content_filters.map do |filter|
    filter.html_class
  end

  slide.note_filters    = get_filters(slide.note_filters || default_note_filters)
  slide.html_classes += slide.content_filters.map do |filter|
    "note-" + filter.html_class unless filter.html_class.nil?
  end

  [ *slide.raw_content ].each do |content| #XXX This is how all content filtering should work
    case content
    when SlideContents
      content.filters = get_filters(content.filters || default_content_filters)
    end
  end
rescue
  puts "While processing #{slide}:"
  raise
end

#setupObject



9
10
11
12
13
14
15
16
# File 'lib/rhet-butler/filter-resolver.rb', line 9

def setup
  named_filter_lists.each_key do |name|
    named_filter_lists[name] = get_filters(named_filter_lists[name])
  end
  self.default_content_filters = get_filters(default_content_filters)
  self.default_note_filters = get_filters(default_note_filters)
  descend(@root_group, @root_group)
end