faqml 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/faqml.rb CHANGED
@@ -6,8 +6,9 @@ require 'fml/version'
6
6
  require 'fml/parser'
7
7
  require 'fml/wrap_filter'
8
8
  require 'fml/details_filter'
9
+ require 'fml/markdown_filter'
9
10
  require 'fml/engine'
10
11
  require 'fml/template'
11
12
 
12
- # module FAQML;end; require 'pp'; require 'temple'; %w{parser details_filter wrap_filter engine template}.each {|x| require "./lib/fml/#{x}"}
13
+ # module FAQML;end; require 'pp'; require 'temple'; %w{parser details_filter wrap_filter markdown_filter engine template}.each {|x| require "./lib/fml/#{x}"}
13
14
  # puts Tilt.new('test/test0.fml').render
@@ -8,8 +8,8 @@ class FAQML::DetailsFilter < Temple::Filter
8
8
  end
9
9
 
10
10
  def on_fml_qna(question, answer=nil)
11
- answer_sexp = !answer.nil? && answer.length >= 4 ? build_fml_details('answer', answer[2], answer[3]) : nil
12
- question_sexp = build_fml_details('question', question[2], question[3])
11
+ answer_sexp = !answer.nil? && answer.length >= 4 ? build_fml_details('answer', true, answer[2], answer[3]) : nil
12
+ question_sexp = build_fml_details('question', false, question[2], question[3])
13
13
  question_sexp.last << answer_sexp unless answer_sexp.nil?
14
14
  [:html, :tag, 'section', [:html, :attrs, [:html, :attr, 'class', [:static, 'qna']]],
15
15
  question_sexp
@@ -18,17 +18,18 @@ class FAQML::DetailsFilter < Temple::Filter
18
18
 
19
19
  private
20
20
 
21
- def build_fml_details(class_name, summary, details)
22
- sexp = [:html, :tag, 'details',
23
- [:html, :attrs,
24
- [:html, :attr, 'class', [:static, class_name]]],
25
- [:multi]]
26
- if !summary.last.first.nil? && summary.last.first != ''
27
- sexp.last << [:html, :tag, 'summary', [:multi], [:static, summary.last.first]]
28
- end
29
- if details.length > 0
30
- sexp.last << [:html, :tag, 'div', [:multi], [:multi, *details.last]]
31
- end
21
+ def build_fml_details(class_name, open, summary, details)
22
+ attrs = [:html, :attrs, [:html, :attr, 'class', [:static, class_name]] ]
23
+ # open if marked as open, or has no summary
24
+ attrs << [:html, :attr, 'open', [:static, 'open']] if open || !has_summary_text?(summary)
25
+
26
+ sexp = [:html, :tag, 'details', attrs, [:multi]]
27
+ sexp.last << [:html, :tag, 'summary', [:multi], [:static, summary.last.first]]
28
+ sexp.last << [:html, :tag, 'div', [:multi], [:multi, *details.last]] if details.length > 0
32
29
  sexp
33
30
  end
31
+
32
+ def has_summary_text?(summary)
33
+ !summary.last.first.nil? && summary.last.first != ''
34
+ end
34
35
  end
data/lib/fml/engine.rb CHANGED
@@ -11,7 +11,7 @@ class FAQML::Engine < Temple::Engine
11
11
  use FAQML::Parser, :strict
12
12
 
13
13
  # TODO: replace inline generation with a markdown filter
14
- # use FAQML::MarkdownFilter
14
+ use FAQML::MarkdownFilter
15
15
  use FAQML::WrapFilter
16
16
  use FAQML::DetailsFilter
17
17
 
@@ -1,5 +1,47 @@
1
- # require 'redcarpet'
1
+ require 'redcarpet'
2
2
 
3
- # renderer = Redcarpet::Render::HTML.new
4
- # extensions = {fenced_code_blocks: true}
5
- # @markdown = Redcarpet::Markdown.new(renderer, extensions)
3
+ class FAQML::MarkdownFilter < Temple::Filter
4
+ def initialize(options = {})
5
+ @options = options
6
+
7
+ renderer = Redcarpet::Render::HTML.new
8
+ extensions = {fenced_code_blocks: true}
9
+ @markdown = Redcarpet::Markdown.new(renderer, extensions)
10
+ end
11
+
12
+ def call(exp)
13
+ compile(exp)
14
+ end
15
+
16
+ def on_fml_answer(summary, details)
17
+ build_fml_type(:answer, summary, details)
18
+ end
19
+
20
+ def on_fml_question(summary, details)
21
+ build_fml_type(:question, summary, details)
22
+ end
23
+
24
+ def build_fml_type(type, summary, details)
25
+ [:fml, type,
26
+ [:fml, :summary, [build_markdown(summary.last)]],
27
+ [:fml, :details, [[:static, build_markdown(details.last)]]]
28
+ ]
29
+ end
30
+
31
+ def build_markdown(lines)
32
+ markdown_data = ""
33
+ lines.each do |line|
34
+ if line.is_a? String
35
+ markdown_data += line
36
+ next
37
+ end
38
+ case line.first
39
+ when :static
40
+ markdown_data += line.last
41
+ when :newline
42
+ markdown_data += "\n"
43
+ end
44
+ end
45
+ markdown_data = @markdown.render(markdown_data)
46
+ end
47
+ end
data/lib/fml/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module FAQML
2
2
  # @api public
3
- VERSION = '0.2.0'
3
+ VERSION = '0.2.1'
4
4
  end
@@ -23,6 +23,8 @@ class FAQML::WrapFilter < Temple::Filter
23
23
  if exp.length > 2 && exp[0] == :fml
24
24
  case exp[1]
25
25
  when :question
26
+ # compile the details
27
+ # exp[3] = compile(exp[3])
26
28
  current_block = [:fml, :qna, exp]
27
29
  result << current_block
28
30
  when :answer
data/test/test0.fml CHANGED
@@ -1,4 +1,2 @@
1
- question: What kind of bear is best?
2
- Well?
3
- answer: False
4
- Blackbear
1
+ question: What kind of bear is *best?*
2
+ answer: False. *Blackbear*
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faqml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: