TriviaMD 0.1.8 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 11a573c7c5f9f468ec7b5516223b03c82e969a8422a1e05618955e27c2362cc1
4
- data.tar.gz: 23bf44e763e2d73d21a88027a2f6e5453d0bcc5a9077d1fdf8f8549dd28e1a67
3
+ metadata.gz: 9c9d294431e5bbcee588459e604abd0a7c92d2215ef5299c6b67fcee87975ef8
4
+ data.tar.gz: 4ea3c51bc2d91522aa2654606a08821e0289a732ffb67edac6c046d32367687e
5
5
  SHA512:
6
- metadata.gz: 231c1b0a2cdbae0012d3634f429c1e2c273666d092483ad701808d9ab092eb6ea5a6eb621cefde207282b7129cdad53b5ae03603992022352934c0f955c16d91
7
- data.tar.gz: 5082698b8f7d736fecd6402b17768587d0e15e53a891b5fbf90f6285b4eac732bf1bb11f5683938c00b792cb21a66d3ae0a8d17869b09d88aa45e1b88e618437
6
+ metadata.gz: cd57a640a346fba946b62fc02fd5d9a50c8c92189b93e5e28ab5c7b354dc141f9afa396ead8ceaca01e011d2deaa35228a5831e7dd5c318bac4a8e4b856a9bed
7
+ data.tar.gz: b72de6ecb4fd805f2d035fbc263ec41a46cf6de0e89c03d3a034b39735a03cea801ff48279f1b6dcbd67936475b3685402413e21a2c869dbd68d527231632916
data/lib/quizzes_v1.rb CHANGED
@@ -39,7 +39,6 @@ class QuizzesV1
39
39
  question_text: question["question"],
40
40
  question_type: "multiple_answers_question",
41
41
  neutral_comments_html: question["reason"],
42
- neutral_comments: question["reason"],
43
42
  points_possible: 1
44
43
  }
45
44
  }
data/lib/trivia_md.rb CHANGED
@@ -24,7 +24,7 @@ module App
24
24
  desc "parse", "parses trivias"
25
25
  option :file_path
26
26
  def parse(file_path)
27
- puts TriviaParser.new(File.read(file_path)).parse.to_json
27
+ puts TriviaParser.new().parse.to_json
28
28
  end
29
29
  end
30
30
 
data/lib/trivia_parser.rb CHANGED
@@ -2,8 +2,9 @@ require 'kramdown'
2
2
 
3
3
  class TriviaParser
4
4
  include Kramdown::Utils::Html
5
- def initialize(file, debug = false)
6
- @file = file
5
+ def initialize(file_path, debug = false)
6
+ @file_path = file_path
7
+ @file = File.read(@file_path)
7
8
  @debug = debug
8
9
  end
9
10
 
@@ -11,17 +12,22 @@ class TriviaParser
11
12
  def get_event(c)
12
13
  return { type: :event_trivia_header } if c.type == :header && c.options[:level] == 2 && c.options[:raw_text] == "Trivia"
13
14
  return { type: :event_header } if c.type == :header
14
- return { type: :event_reason, payload: { reason: parse_reason(c.children.first) } } if c.type == :p && (c.children.first.type == :codespan || c.children.first.type == :codeblock)
15
+ return { type: :event_reason, payload: { reason: parse_reason(c) } } if c.type == :codeblock
15
16
  return { type: :event_answers, payload: { answers: parse_answers(c) } } if c.type == :ul
16
17
  return { type: :event_question, payload: { question: c.children.first.children.first.value } } if c.type == :blockquote
17
18
  return { type: :no_event }
18
19
  end
19
20
 
21
+
22
+ def markdown_gitlies_url
23
+ "#{ENV.fetch('GITLIES_PROJECT_URL', 'https://gitlies.com/')}#{@file_path}"
24
+ end
25
+
20
26
  def parse_reason(c)
21
- if c.value.start_with?("html\n")
22
- c.value.split("html\n")[1].strip
27
+ if c.options[:lang] == "html"
28
+ c.value.strip.gsub(/{GITLIES_MD}/,markdown_gitlies_url)
23
29
  else
24
- escape_html(c.value)
30
+ escape_html(c.value.strip)
25
31
  end
26
32
  end
27
33
 
@@ -51,7 +57,7 @@ class TriviaParser
51
57
 
52
58
  @doc.root.children.each do |c|
53
59
  event = get_event(c)
54
- puts [state, c.type, event] if @debug
60
+ p [state, c.type, event, c.children] if @debug
55
61
 
56
62
  case event[:type]
57
63
  when :event_trivia_header
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: TriviaMD
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bence Pjatacsuk