Class: FAQML::WrapFilter

Inherits:
Temple::Filter
  • Object
show all
Defined in:
lib/fml/wrap_filter.rb

Overview

organizes the FAQs into a wrapped-block layout

Defined Under Namespace

Classes: SexpError

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ WrapFilter

Returns a new instance of WrapFilter.



7
8
9
# File 'lib/fml/wrap_filter.rb', line 7

def initialize(options = {})
  @options = options
end

Instance Method Details

#call(exp) ⇒ Object



11
12
13
# File 'lib/fml/wrap_filter.rb', line 11

def call(exp)
  compile(exp)
end

#on_multi(*exps) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fml/wrap_filter.rb', line 15

def on_multi(*exps)
  result = [:multi]

  current_block = nil

  exps.each do |exp|
    exp = compile(exp)

    if exp.length > 2 && exp[0] == :fml
      case exp[1]
      when :question
        # compile the details
        # exp[3] = compile(exp[3])
        current_block = [:fml, :qna, exp]
        result << current_block
      when :answer
        raise SexpError, "Cannot create an answer without a question" if current_block.nil?
        result.last << exp
        current_block = nil
      else
        result << exp
      end
      next
    end

    result << exp
  end

  result
end