Class: FAQML::MarkdownFilter

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ MarkdownFilter

Returns a new instance of MarkdownFilter.



4
5
6
7
8
9
10
# File 'lib/fml/markdown_filter.rb', line 4

def initialize(options = {})
  @options = options
  
  renderer = Redcarpet::Render::HTML.new
  extensions = {:fenced_code_blocks => true}
  @markdown = Redcarpet::Markdown.new(renderer, extensions)
end

Instance Method Details

#build_fml_type(type, summary, details) ⇒ Object



24
25
26
27
28
29
# File 'lib/fml/markdown_filter.rb', line 24

def build_fml_type(type, summary, details)
  [:fml, type,
    [:fml, :summary, [build_markdown(summary.last)]],
    [:fml, :details, [[:static, build_markdown(details.last)]]]
  ]
end

#build_markdown(lines) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/fml/markdown_filter.rb', line 31

def build_markdown(lines)
  markdown_data = ""
  lines.each do |line|
    if line.is_a? String
      markdown_data += line
      next
    end
    case line.first
    when :static
    	markdown_data += line.last
    when :newline
    	markdown_data += "\n"
    end
  end
  markdown_data = @markdown.render(markdown_data)
end

#call(exp) ⇒ Object



12
13
14
# File 'lib/fml/markdown_filter.rb', line 12

def call(exp)
  compile(exp)
end

#on_fml_answer(summary, details) ⇒ Object



16
17
18
# File 'lib/fml/markdown_filter.rb', line 16

def on_fml_answer(summary, details)
  build_fml_type(:answer, summary, details)
end

#on_fml_question(summary, details) ⇒ Object



20
21
22
# File 'lib/fml/markdown_filter.rb', line 20

def on_fml_question(summary, details)
  build_fml_type(:question, summary, details)
end