faqml 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/faqml.rb +2 -1
- data/lib/fml/details_filter.rb +14 -13
- data/lib/fml/engine.rb +1 -1
- data/lib/fml/markdown_filter.rb +46 -4
- data/lib/fml/version.rb +1 -1
- data/lib/fml/wrap_filter.rb +2 -0
- data/test/test0.fml +2 -4
- metadata +1 -1
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
|
data/lib/fml/details_filter.rb
CHANGED
@@ -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
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
data/lib/fml/markdown_filter.rb
CHANGED
@@ -1,5 +1,47 @@
|
|
1
|
-
|
1
|
+
require 'redcarpet'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
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
data/lib/fml/wrap_filter.rb
CHANGED
data/test/test0.fml
CHANGED