asker-tool 2.7.1 → 2.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/asker/ai/problem/customizer.rb +36 -0
- data/lib/asker/ai/problem/problem_ai.rb +9 -213
- data/lib/asker/ai/problem/stage_answers.rb +104 -0
- data/lib/asker/ai/problem/stage_base.rb +34 -0
- data/lib/asker/ai/problem/stage_steps.rb +121 -0
- data/lib/asker/application.rb +1 -0
- data/lib/asker/check_input/check_haml_data.rb +136 -0
- data/lib/asker/check_input.rb +15 -10
- data/lib/asker/cli.rb +2 -0
- data/lib/asker/data/concept.rb +3 -3
- data/lib/asker/data/problem.rb +10 -2
- data/lib/asker/data/project_data.rb +2 -1
- data/lib/asker/displayer/code_displayer.rb +2 -2
- data/lib/asker/displayer/concept_ai_displayer.rb +5 -3
- data/lib/asker/displayer/concept_displayer.rb +2 -2
- data/lib/asker/displayer/problem_displayer.rb +14 -7
- data/lib/asker/displayer/stats_displayer.rb +3 -3
- data/lib/asker/files/language/ca/templates.yaml +1 -0
- data/lib/asker/files/language/du/templates.yaml +1 -0
- data/lib/asker/files/language/en/templates.yaml +1 -0
- data/lib/asker/files/language/es/templates.yaml +1 -0
- data/lib/asker/files/language/fr/templates.yaml +1 -0
- data/lib/asker/formatter/concept_string_formatter.rb +0 -1
- data/lib/asker/loader/content_loader.rb +10 -8
- data/lib/asker/loader/embedded_file/loader.rb +103 -0
- data/lib/asker/loader/embedded_file/type.rb +51 -0
- data/lib/asker/loader/file_loader.rb +2 -1
- data/lib/asker/loader/problem_loader.rb +2 -0
- data/lib/asker/logger.rb +7 -3
- data/lib/asker/start.rb +2 -2
- data/lib/asker/version.rb +1 -1
- metadata +8 -3
- data/lib/asker/loader/embedded_file.rb +0 -133
@@ -1,133 +0,0 @@
|
|
1
|
-
require "base64"
|
2
|
-
require_relative "../logger"
|
3
|
-
|
4
|
-
# Methods to load embedded files defined into asker input data file
|
5
|
-
# Example:
|
6
|
-
# * def line with :type = :image_url used to link external file as https://..."
|
7
|
-
# * def line with :type = :file used to load local file as image.png or file.txt"
|
8
|
-
module EmbeddedFile
|
9
|
-
##
|
10
|
-
# @param value (String)
|
11
|
-
# @param localdir (String) Input file base folder
|
12
|
-
# @return Hash
|
13
|
-
def self.load(value, localdir)
|
14
|
-
return load_image(value, localdir) if is_image? value
|
15
|
-
return load_audio(value, localdir) if is_audio? value
|
16
|
-
return load_video(value, localdir) if is_video? value
|
17
|
-
|
18
|
-
if is_url? value
|
19
|
-
Logger.error "EmbebbedFile: Unknown URL type (#{value})"
|
20
|
-
exit 1
|
21
|
-
end
|
22
|
-
|
23
|
-
filepath = File.join(localdir, value)
|
24
|
-
unless File.exist?(filepath)
|
25
|
-
Logger.error "EmbeddedFile: File does not exist (#{filepath})"
|
26
|
-
exit 1
|
27
|
-
end
|
28
|
-
|
29
|
-
# Suposse that filename is TEXT file
|
30
|
-
{text: "<pre>#{File.read(filepath)}</pre>", file: :none, type: :text}
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.is_audio?(filename)
|
34
|
-
extens = [".mp3", ".ogg", ".wav"]
|
35
|
-
extens.each { |ext| return true if filename.downcase.end_with?(ext) }
|
36
|
-
false
|
37
|
-
end
|
38
|
-
|
39
|
-
def self.is_image?(filename)
|
40
|
-
extens = [".jpg", ".jpeg", ".png"]
|
41
|
-
extens.each { |ext| return true if filename.downcase.end_with?(ext) }
|
42
|
-
false
|
43
|
-
end
|
44
|
-
|
45
|
-
def self.is_video?(filename)
|
46
|
-
extens = [".mp4", ".ogv"]
|
47
|
-
extens.each { |ext| return true if filename.downcase.end_with?(ext) }
|
48
|
-
false
|
49
|
-
end
|
50
|
-
|
51
|
-
def self.is_url?(value)
|
52
|
-
return true if value.start_with?("https://", "http://")
|
53
|
-
|
54
|
-
false
|
55
|
-
end
|
56
|
-
|
57
|
-
def self.load_audio(value, localdir)
|
58
|
-
output = {text: :error, file: :none, type: :audio}
|
59
|
-
|
60
|
-
if is_url? value
|
61
|
-
output[:text] = "<audio src=\"#{value}\" controls></audio>"
|
62
|
-
output[:file] = :none
|
63
|
-
output[:type] = :url
|
64
|
-
return output
|
65
|
-
end
|
66
|
-
|
67
|
-
filepath = File.join(localdir, value)
|
68
|
-
unless File.exist?(filepath)
|
69
|
-
Logger.error "EmbebbedFile: Audio file no exists (#{filepath})"
|
70
|
-
exit 1
|
71
|
-
end
|
72
|
-
output[:text] = '<audio controls><source src="@@PLUGINFILE@@/' + File.basename(filepath) \
|
73
|
-
+ '">Your browser does not support the audio tag.</audio>'
|
74
|
-
output[:file] = '<file name="' + File.basename(filepath) \
|
75
|
-
+ '" path="/" encoding="base64">' \
|
76
|
-
+ Base64.strict_encode64(File.open(filepath, "rb").read) \
|
77
|
-
+ "</file>"
|
78
|
-
output[:type] = :audio
|
79
|
-
output
|
80
|
-
end
|
81
|
-
|
82
|
-
def self.load_image(value, localdir)
|
83
|
-
output = {text: :error, file: :none, type: :image}
|
84
|
-
|
85
|
-
if is_url? value
|
86
|
-
output[:text] = "<img src=\"#{value}\" alt=\"image\" width=\"400\" height=\"300\">"
|
87
|
-
output[:file] = :none
|
88
|
-
output[:type] = :url
|
89
|
-
return output
|
90
|
-
end
|
91
|
-
|
92
|
-
filepath = File.join(localdir, value)
|
93
|
-
unless File.exist?(filepath)
|
94
|
-
Logger.error "EmbeddedFile: Unknown file (#{filepath})"
|
95
|
-
exit 1
|
96
|
-
end
|
97
|
-
output[:text] = '<img src="@@PLUGINFILE@@/' + File.basename(filepath) \
|
98
|
-
+ '" alt="imagen" class="img-responsive atto_image_button_text-bottom">'
|
99
|
-
output[:file] = '<file name="' + File.basename(filepath) \
|
100
|
-
+ '" path="/" encoding="base64">' \
|
101
|
-
+ Base64.strict_encode64(File.open(filepath, "rb").read) \
|
102
|
-
+ "</file>"
|
103
|
-
output[:type] = :image
|
104
|
-
output
|
105
|
-
end
|
106
|
-
|
107
|
-
def self.load_video(value, localdir)
|
108
|
-
output = {text: :error, file: :none, type: :video}
|
109
|
-
if is_url? value
|
110
|
-
output[:text] = "<video controls width=\"400\" height=\"300\">" \
|
111
|
-
+ "<source src=\"#{value}\"/></video>"
|
112
|
-
output[:file] = :none
|
113
|
-
output[:type] = :url
|
114
|
-
return output
|
115
|
-
end
|
116
|
-
|
117
|
-
filepath = File.join(localdir, value)
|
118
|
-
unless File.exist?(filepath)
|
119
|
-
Logger.error "Unknown file (#{filepath})"
|
120
|
-
exit 1
|
121
|
-
end
|
122
|
-
output[:text] = '<video controls><source src="@@PLUGINFILE@@/' \
|
123
|
-
+ File.basename(filepath) \
|
124
|
-
+ '"/>Your browser does not support the video tag.</video>'
|
125
|
-
output[:file] = '<file name="' \
|
126
|
-
+ File.basename(filepath) \
|
127
|
-
+ '" path="/" encoding="base64">' \
|
128
|
-
+ Base64.strict_encode64(File.open(filepath, "rb").read) \
|
129
|
-
+ "</file>"
|
130
|
-
output[:type] = :video
|
131
|
-
output
|
132
|
-
end
|
133
|
-
end
|