asker-tool 2.1.7 → 2.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{LICENSE.txt → LICENSE} +0 -0
- data/README.md +14 -15
- data/bin/asker +1 -1
- data/lib/asker/ai/ai.rb +6 -3
- data/lib/asker/ai/ai_calculate.rb +20 -6
- data/lib/asker/ai/concept_ai.rb +12 -3
- data/lib/asker/ai/question.rb +28 -6
- data/lib/asker/ai/stages/base_stage.rb +45 -6
- data/lib/asker/ai/stages/stage_b.rb +90 -49
- data/lib/asker/ai/stages/stage_d.rb +69 -90
- data/lib/asker/ai/stages/stage_f.rb +47 -38
- data/lib/asker/ai/stages/stage_i.rb +79 -92
- data/lib/asker/ai/stages/stage_s.rb +41 -36
- data/lib/asker/ai/stages/stage_t.rb +114 -73
- data/lib/asker/application.rb +7 -16
- data/lib/asker/check_input/check_haml_data.rb +264 -0
- data/lib/asker/check_input/check_table.rb +104 -0
- data/lib/asker/check_input.rb +51 -0
- data/lib/asker/cli.rb +47 -44
- data/lib/asker/data/code.rb +5 -16
- data/lib/asker/data/concept.rb +71 -24
- data/lib/asker/data/project_data.rb +63 -0
- data/lib/asker/data/table.rb +2 -0
- data/lib/asker/data/template.rb +3 -1
- data/lib/asker/data/world.rb +8 -16
- data/lib/asker/displayer/code_displayer.rb +7 -0
- data/lib/asker/displayer/concept_ai_displayer.erb +10 -0
- data/lib/asker/displayer/concept_ai_displayer.rb +24 -22
- data/lib/asker/displayer/concept_displayer.rb +9 -4
- data/lib/asker/displayer/stats_displayer.rb +8 -0
- data/lib/asker/exporter/concept_ai_gift_exporter.rb +7 -11
- data/lib/asker/exporter/concept_ai_moodle_exporter.rb +45 -0
- data/lib/asker/exporter/concept_ai_yaml_exporter.rb +6 -3
- data/lib/asker/exporter/concept_doc_exporter.rb +12 -2
- data/lib/asker/exporter/data_gift_exporter.rb +31 -0
- data/lib/asker/exporter/output_file_exporter.rb +9 -6
- data/lib/asker/files/{config.ini → asker.ini} +14 -4
- data/lib/asker/files/language/du/connectors.yaml +81 -0
- data/lib/asker/files/language/du/mistakes.yaml +82 -0
- data/lib/asker/files/language/du/templates.yaml +28 -49
- data/lib/asker/files/language/en/templates.yaml +19 -19
- data/lib/asker/files/language/es/mistakes.yaml +9 -7
- data/lib/asker/files/language/es/templates.yaml +19 -19
- data/lib/asker/files/language/fr/connectors.yaml +68 -84
- data/lib/asker/files/language/fr/templates.yaml +22 -22
- data/lib/asker/formatter/concept_doc_formatter.rb +0 -4
- data/lib/asker/formatter/concept_string_formatter.rb +7 -4
- data/lib/asker/formatter/moodle/matching.erb +38 -0
- data/lib/asker/formatter/moodle/multichoice.erb +49 -0
- data/lib/asker/formatter/moodle/shortanswer.erb +30 -0
- data/lib/asker/formatter/moodle/truefalse.erb +47 -0
- data/lib/asker/formatter/question_gift_formatter.rb +21 -19
- data/lib/asker/formatter/question_moodle_formatter.rb +27 -0
- data/lib/asker/lang/lang_factory.rb +7 -1
- data/lib/asker/loader/code_loader.rb +1 -1
- data/lib/asker/loader/content_loader.rb +12 -14
- data/lib/asker/loader/directory_loader.rb +1 -8
- data/lib/asker/loader/embedded_file.rb +42 -0
- data/lib/asker/loader/file_loader.rb +1 -6
- data/lib/asker/loader/haml_loader.rb +9 -5
- data/lib/asker/loader/image_url_loader.rb +8 -9
- data/lib/asker/loader/input_loader.rb +5 -6
- data/lib/asker/loader/project_loader.rb +18 -10
- data/lib/asker/logger.rb +36 -9
- data/lib/asker/skeleton.rb +3 -2
- data/lib/asker/version.rb +9 -0
- data/lib/asker.rb +72 -43
- metadata +60 -18
- data/lib/asker/checker.rb +0 -455
- data/lib/asker/project.rb +0 -146
@@ -0,0 +1,264 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rainbow'
|
4
|
+
require 'colorize'
|
5
|
+
require_relative 'check_table'
|
6
|
+
|
7
|
+
class CheckHamlData
|
8
|
+
include CheckTable
|
9
|
+
attr_reader :inputs, :outputs
|
10
|
+
|
11
|
+
def initialize(filepath)
|
12
|
+
@inputs = File.read(filepath).split("\n")
|
13
|
+
@outputs = []
|
14
|
+
@inputs.each_with_index do |line, index|
|
15
|
+
output = { id: index,
|
16
|
+
level: 0,
|
17
|
+
state: :none,
|
18
|
+
type: :none,
|
19
|
+
source: line,
|
20
|
+
msg: '' }
|
21
|
+
@outputs << output
|
22
|
+
end
|
23
|
+
@ok = false
|
24
|
+
end
|
25
|
+
|
26
|
+
def ok?
|
27
|
+
@ok
|
28
|
+
end
|
29
|
+
|
30
|
+
def show
|
31
|
+
@outputs.each do |i|
|
32
|
+
puts "#{i[:id]}: #{i[:state]} [#{i[:type]}] #{i[:msg]}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def show_errors
|
37
|
+
errors = 0
|
38
|
+
# puts "Line : Error description"
|
39
|
+
puts "\n"
|
40
|
+
@outputs.each do |i|
|
41
|
+
next if i[:state] == :ok
|
42
|
+
|
43
|
+
errors += 1
|
44
|
+
if errors < 11
|
45
|
+
data = { id: i[:id], msg: i[:msg], source: i[:source][0, 40] }
|
46
|
+
order = i[:id] + 1
|
47
|
+
data = { order: order, msg: i[:msg], source: i[:source][0, 40] }
|
48
|
+
print format(' %<order>03d : %<msg>32s. => '.white, data)
|
49
|
+
puts format('%<source>s'.light_yellow, data)
|
50
|
+
end
|
51
|
+
puts '...' if errors == 11
|
52
|
+
end
|
53
|
+
|
54
|
+
if errors.positive?
|
55
|
+
puts "\n[ ASKER ] Please! Revise #{errors.to_s.light_red} error/s\n"
|
56
|
+
end
|
57
|
+
puts 'Syntax OK!'.green if errors.zero?
|
58
|
+
end
|
59
|
+
|
60
|
+
def check
|
61
|
+
@ok = true
|
62
|
+
@inputs.each_with_index do |line, index|
|
63
|
+
check_empty_lines(line, index)
|
64
|
+
check_map(line, index)
|
65
|
+
check_concept(line, index)
|
66
|
+
check_names(line, index)
|
67
|
+
check_tags(line, index)
|
68
|
+
check_def(line, index)
|
69
|
+
check_table(line, index)
|
70
|
+
check_row(line, index)
|
71
|
+
check_col(line, index)
|
72
|
+
check_template(line, index)
|
73
|
+
check_code(line, index)
|
74
|
+
check_type(line, index)
|
75
|
+
check_path(line, index)
|
76
|
+
check_features(line, index)
|
77
|
+
check_unknown(line, index)
|
78
|
+
@ok = false unless @outputs[index][:state] == :ok
|
79
|
+
@ok = false if @outputs[index][:type] == :unkown
|
80
|
+
end
|
81
|
+
@ok
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def check_empty_lines(line, index)
|
87
|
+
return unless line.strip.size.zero? || line.start_with?('#')
|
88
|
+
|
89
|
+
@outputs[index][:type] = :empty
|
90
|
+
@outputs[index][:level] = -1
|
91
|
+
@outputs[index][:state] = :ok
|
92
|
+
end
|
93
|
+
|
94
|
+
def check_map(line, index)
|
95
|
+
if index.zero?
|
96
|
+
@outputs[index][:type] = :map
|
97
|
+
if line.start_with?('%map{')
|
98
|
+
@outputs[index][:state] = :ok
|
99
|
+
else
|
100
|
+
@outputs[index][:state] = :err
|
101
|
+
@outputs[index][:msg] = 'Start with %map{'
|
102
|
+
end
|
103
|
+
elsif index.positive? && line.include?('%map{')
|
104
|
+
@outputs[index][:state] = :err
|
105
|
+
@outputs[index][:type] = :map
|
106
|
+
@outputs[index][:msg] = 'Write %map on line 0'
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def check_concept(line, index)
|
111
|
+
return unless @outputs[index][:state] == :none
|
112
|
+
return unless line.include? '%concept'
|
113
|
+
|
114
|
+
@outputs[index][:type] = :concept
|
115
|
+
@outputs[index][:level] = 1
|
116
|
+
@outputs[index][:state] = :ok
|
117
|
+
if find_parent(index) != :map
|
118
|
+
@outputs[index][:state] = :err
|
119
|
+
@outputs[index][:msg] = 'Parent(map) not found!'
|
120
|
+
elsif line != ' %concept'
|
121
|
+
@outputs[index][:state] = :err
|
122
|
+
@outputs[index][:msg] = 'Write 2 spaces before %concept'
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def check_names(line, index)
|
127
|
+
return unless @outputs[index][:state] == :none
|
128
|
+
return unless line.include? '%names'
|
129
|
+
|
130
|
+
@outputs[index][:type] = :names
|
131
|
+
@outputs[index][:level] = 2
|
132
|
+
@outputs[index][:state] = :ok
|
133
|
+
if find_parent(index) != :concept
|
134
|
+
@outputs[index][:state] = :err
|
135
|
+
@outputs[index][:msg] = 'Parent(concept) not found!'
|
136
|
+
elsif !line.start_with? ' %names'
|
137
|
+
@outputs[index][:state] = :err
|
138
|
+
@outputs[index][:msg] = 'Write 4 spaces before %names'
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def check_tags(line, index)
|
143
|
+
return unless @outputs[index][:state] == :none
|
144
|
+
return unless line.include? '%tags'
|
145
|
+
|
146
|
+
@outputs[index][:type] = :tags
|
147
|
+
@outputs[index][:level] = 2
|
148
|
+
@outputs[index][:state] = :ok
|
149
|
+
if find_parent(index) != :concept
|
150
|
+
@outputs[index][:state] = :err
|
151
|
+
@outputs[index][:msg] = 'Parent(concept) not found!'
|
152
|
+
elsif !line.start_with? ' %tags'
|
153
|
+
@outputs[index][:state] = :err
|
154
|
+
@outputs[index][:msg] = 'Write 4 spaces before %tags'
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def check_def(line, index)
|
159
|
+
return unless @outputs[index][:state] == :none
|
160
|
+
return unless line.include? '%def'
|
161
|
+
|
162
|
+
@outputs[index][:type] = :def
|
163
|
+
@outputs[index][:level] = 2
|
164
|
+
@outputs[index][:state] = :ok
|
165
|
+
if find_parent(index) != :concept
|
166
|
+
@outputs[index][:state] = :err
|
167
|
+
@outputs[index][:msg] = 'Parent(concept) not found!'
|
168
|
+
elsif !line.start_with? ' %def'
|
169
|
+
@outputs[index][:state] = :err
|
170
|
+
@outputs[index][:msg] = 'Write 4 spaces before %def'
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def check_code(line, index)
|
175
|
+
return unless @outputs[index][:state] == :none
|
176
|
+
return unless line.include? '%code'
|
177
|
+
|
178
|
+
@outputs[index][:type] = :code
|
179
|
+
@outputs[index][:level] = 1
|
180
|
+
@outputs[index][:state] = :ok
|
181
|
+
if find_parent(index) != :map
|
182
|
+
@outputs[index][:state] = :err
|
183
|
+
@outputs[index][:msg] = 'Parent(map) not found!'
|
184
|
+
elsif line != ' %code'
|
185
|
+
@outputs[index][:state] = :err
|
186
|
+
@outputs[index][:msg] = 'Write 2 spaces before %code'
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
def check_type(line, index)
|
191
|
+
return unless @outputs[index][:state] == :none
|
192
|
+
return unless line.include? '%type'
|
193
|
+
|
194
|
+
@outputs[index][:type] = :type
|
195
|
+
@outputs[index][:level] = 2
|
196
|
+
@outputs[index][:state] = :ok
|
197
|
+
if find_parent(index) != :code
|
198
|
+
@outputs[index][:state] = :err
|
199
|
+
@outputs[index][:msg] = 'Parent(code) not found!'
|
200
|
+
elsif !line.start_with? ' %type'
|
201
|
+
@outputs[index][:state] = :err
|
202
|
+
@outputs[index][:msg] = 'Write 4 spaces before %type'
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
def check_path(line, index)
|
207
|
+
return unless @outputs[index][:state] == :none
|
208
|
+
return unless line.include? '%path'
|
209
|
+
|
210
|
+
@outputs[index][:type] = :path
|
211
|
+
@outputs[index][:level] = 2
|
212
|
+
@outputs[index][:state] = :ok
|
213
|
+
if find_parent(index) != :code
|
214
|
+
@outputs[index][:state] = :err
|
215
|
+
@outputs[index][:msg] = 'Parent(code) not found!'
|
216
|
+
elsif !line.start_with? ' %path'
|
217
|
+
@outputs[index][:state] = :err
|
218
|
+
@outputs[index][:msg] = 'Write 4 spaces before %type'
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
def check_features(line, index)
|
223
|
+
return unless @outputs[index][:state] == :none
|
224
|
+
return unless line.include? '%features'
|
225
|
+
|
226
|
+
@outputs[index][:type] = :features
|
227
|
+
@outputs[index][:level] = 2
|
228
|
+
@outputs[index][:state] = :ok
|
229
|
+
if find_parent(index) != :code
|
230
|
+
@outputs[index][:state] = :err
|
231
|
+
@outputs[index][:msg] = 'Parent(code) not found!'
|
232
|
+
elsif !line.start_with? ' %features'
|
233
|
+
@outputs[index][:state] = :err
|
234
|
+
@outputs[index][:msg] = 'Write 4 spaces before %features'
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
def check_unknown(line, index)
|
239
|
+
return unless @outputs[index][:state] == :none
|
240
|
+
|
241
|
+
@outputs[index][:type] = :unknown
|
242
|
+
@outputs[index][:level] = count_spaces(line) / 2
|
243
|
+
@outputs[index][:state] = :err
|
244
|
+
@outputs[index][:msg] = "Unknown tag with parent(#{find_parent(index)})!"
|
245
|
+
end
|
246
|
+
|
247
|
+
def find_parent(index)
|
248
|
+
current_level = @outputs[index][:level]
|
249
|
+
return :noparent if current_level.zero?
|
250
|
+
|
251
|
+
i = index - 1
|
252
|
+
while i >= 0
|
253
|
+
return @outputs[i][:type] if @outputs[i][:level] == current_level - 1
|
254
|
+
|
255
|
+
i -= 1
|
256
|
+
end
|
257
|
+
:noparent
|
258
|
+
end
|
259
|
+
|
260
|
+
def count_spaces(line)
|
261
|
+
a = line.split('%')
|
262
|
+
a[0].count(' ')
|
263
|
+
end
|
264
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
|
2
|
+
module CheckTable
|
3
|
+
|
4
|
+
def check_table(line, index)
|
5
|
+
return unless @outputs[index][:state] == :none
|
6
|
+
return unless line.include? '%table'
|
7
|
+
|
8
|
+
@outputs[index][:type] = :table
|
9
|
+
@outputs[index][:level] = 2
|
10
|
+
@outputs[index][:state] = :ok
|
11
|
+
if find_parent(index) != :concept
|
12
|
+
@outputs[index][:state] = :err
|
13
|
+
@outputs[index][:msg] = 'Parent(concept) not found!'
|
14
|
+
elsif !line.start_with? ' %table'
|
15
|
+
@outputs[index][:state] = :err
|
16
|
+
@outputs[index][:msg] = 'Write 4 spaces before %table'
|
17
|
+
#else not /\s+%table{\s?fields:\s?'[A-Za-z,áéíóú]*'\s?}/.match(line)
|
18
|
+
# @outputs[index][:state] = :err
|
19
|
+
# @outputs[index][:msg] = 'Table#fields malformed!'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def check_row(line, index)
|
24
|
+
return unless @outputs[index][:state] == :none
|
25
|
+
return unless line.include? '%row'
|
26
|
+
|
27
|
+
@outputs[index][:type] = :row
|
28
|
+
@outputs[index][:state] = :ok
|
29
|
+
|
30
|
+
case count_spaces(line)
|
31
|
+
when 6
|
32
|
+
@outputs[index][:level] = 3
|
33
|
+
parent = find_parent(index)
|
34
|
+
unless %i[table features].include? parent
|
35
|
+
@outputs[index][:state] = :err
|
36
|
+
@outputs[index][:msg] = 'Parent(table/features) not found!'
|
37
|
+
end
|
38
|
+
when 8
|
39
|
+
@outputs[index][:level] = 4
|
40
|
+
if find_parent(index) != :template
|
41
|
+
@outputs[index][:state] = :err
|
42
|
+
@outputs[index][:msg] = 'Parent(template) not found!'
|
43
|
+
end
|
44
|
+
else
|
45
|
+
@outputs[index][:state] = :err
|
46
|
+
@outputs[index][:msg] = 'Write 6 or 8 spaces before %row'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def check_col(line, index)
|
51
|
+
return unless @outputs[index][:state] == :none
|
52
|
+
return unless line.include? '%col'
|
53
|
+
|
54
|
+
@outputs[index][:type] = :col
|
55
|
+
@outputs[index][:state] = :ok
|
56
|
+
case count_spaces(line)
|
57
|
+
when 8
|
58
|
+
@outputs[index][:level] = 4
|
59
|
+
if find_parent(index) != :row
|
60
|
+
@outputs[index][:state] = :err
|
61
|
+
@outputs[index][:msg] = 'Parent(row) not found!'
|
62
|
+
end
|
63
|
+
when 10
|
64
|
+
@outputs[index][:level] = 5
|
65
|
+
if find_parent(index) != :row
|
66
|
+
@outputs[index][:state] = :err
|
67
|
+
@outputs[index][:msg] = 'Parent(row) not found!'
|
68
|
+
end
|
69
|
+
else
|
70
|
+
@outputs[index][:state] = :err
|
71
|
+
@outputs[index][:msg] = 'Write 8 or 10 spaces before %col'
|
72
|
+
end
|
73
|
+
check_text(line, index)
|
74
|
+
end
|
75
|
+
|
76
|
+
def check_text(line, index)
|
77
|
+
return unless @outputs[index][:state] == :ok
|
78
|
+
|
79
|
+
ok = ''
|
80
|
+
%w[< >].each do |char|
|
81
|
+
ok = char if line.include? char
|
82
|
+
end
|
83
|
+
return if ok == ''
|
84
|
+
|
85
|
+
@outputs[index][:state] = :err
|
86
|
+
@outputs[index][:msg] = "Char #{ok} not allow!"
|
87
|
+
end
|
88
|
+
|
89
|
+
def check_template(line, index)
|
90
|
+
return unless @outputs[index][:state] == :none
|
91
|
+
return unless line.include? '%template'
|
92
|
+
|
93
|
+
@outputs[index][:type] = :template
|
94
|
+
@outputs[index][:level] = 3
|
95
|
+
@outputs[index][:state] = :ok
|
96
|
+
if find_parent(index) != :table
|
97
|
+
@outputs[index][:state] = :err
|
98
|
+
@outputs[index][:msg] = 'Parent(concept) not found!'
|
99
|
+
elsif !line.start_with? ' %template'
|
100
|
+
@outputs[index][:state] = :err
|
101
|
+
@outputs[index][:msg] = 'Write 6 spaces before %template'
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rainbow'
|
4
|
+
require_relative 'check_input/check_haml_data'
|
5
|
+
|
6
|
+
class CheckInput
|
7
|
+
def initialize(verbose = true)
|
8
|
+
@verbose = verbose
|
9
|
+
end
|
10
|
+
|
11
|
+
def file(filepath)
|
12
|
+
@filepath = filepath
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
def verbose(verbose)
|
17
|
+
@verbose = verbose
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
def check
|
22
|
+
# Check HAML file syntax
|
23
|
+
exist = check_file_exist
|
24
|
+
return false unless exist
|
25
|
+
check_file_content
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def check_file_exist
|
31
|
+
if @filepath.nil?
|
32
|
+
raise Rainbow("Can't check nil filename")
|
33
|
+
end
|
34
|
+
unless File.exist? @filepath
|
35
|
+
puts Rainbow('File not found!').red.bright if @verbose
|
36
|
+
return false
|
37
|
+
end
|
38
|
+
unless File.extname(@filepath) == '.haml'
|
39
|
+
puts Rainbow('Only check HAML files!').yellow.bright if @verbose
|
40
|
+
return false
|
41
|
+
end
|
42
|
+
true
|
43
|
+
end
|
44
|
+
|
45
|
+
def check_file_content
|
46
|
+
data = CheckHamlData.new(@filepath)
|
47
|
+
data.check
|
48
|
+
data.show_errors if @verbose
|
49
|
+
data.ok?
|
50
|
+
end
|
51
|
+
end
|
data/lib/asker/cli.rb
CHANGED
@@ -2,76 +2,69 @@
|
|
2
2
|
|
3
3
|
require 'rainbow'
|
4
4
|
require 'thor'
|
5
|
-
require_relative '
|
5
|
+
require_relative 'version'
|
6
6
|
require_relative '../asker'
|
7
7
|
|
8
8
|
##
|
9
9
|
# Command Line User Interface
|
10
10
|
class CLI < Thor
|
11
|
-
map ['
|
11
|
+
map ['--help'] => 'help'
|
12
12
|
|
13
|
-
map ['
|
13
|
+
map ['--version'] => 'version'
|
14
14
|
desc 'version', 'Show the program version'
|
15
|
-
##
|
16
|
-
# Show current version
|
17
15
|
def version
|
18
|
-
|
19
|
-
|
16
|
+
puts "#{Version::NAME} version #{Version::VERSION}"
|
17
|
+
exit 0
|
18
|
+
end
|
19
|
+
|
20
|
+
map ['--init'] => 'init'
|
21
|
+
desc 'init', 'Create default INI config file'
|
22
|
+
def init
|
23
|
+
Asker.init
|
24
|
+
exit 0
|
25
|
+
end
|
26
|
+
|
27
|
+
map ['new','--new'] => 'new_input'
|
28
|
+
desc 'new DIRPATH', 'Create Asker demo input files'
|
29
|
+
##
|
30
|
+
# Create Asker demo input files
|
31
|
+
# @param dirname (String) Path to folder
|
32
|
+
def new_input(dirname)
|
33
|
+
Asker.new_input(dirname)
|
34
|
+
exit 0
|
35
|
+
end
|
36
|
+
|
37
|
+
map ['--check'] => 'check'
|
38
|
+
desc 'check FILEPATH', 'Check input HAML file syntax'
|
39
|
+
def check(filename)
|
40
|
+
# Enable/disable color output
|
41
|
+
Rainbow.enabled = false if options['color'] == false
|
42
|
+
# Asker start processing input file
|
43
|
+
Asker.check(filename)
|
20
44
|
end
|
21
45
|
|
22
46
|
map ['f', '-f', '--file'] => 'file'
|
23
|
-
desc 'file
|
47
|
+
desc '[file] FILEPATH', 'Build output files, from HAML/XML input file.'
|
24
48
|
long_desc <<-LONGDESC
|
25
|
-
Create output files, from input file (HAML/XML format).
|
26
49
|
|
27
50
|
Build questions about contents defined into input file specified.
|
28
51
|
|
52
|
+
Create output files, from input file (HAML/XML format).
|
53
|
+
|
29
54
|
Examples:
|
30
55
|
|
31
|
-
(1) #{Rainbow('asker input/foo/foo.haml').
|
56
|
+
(1) #{Rainbow('asker input/foo/foo.haml').aqua}, Build questions from HAML file.
|
32
57
|
|
33
|
-
(2) #{Rainbow('asker input/foo/foo.xml').
|
58
|
+
(2) #{Rainbow('asker input/foo/foo.xml').aqua}, Build questions from XML file.
|
34
59
|
|
35
|
-
(3) #{Rainbow('asker projects/foo/foo.yaml').
|
60
|
+
(3) #{Rainbow('asker projects/foo/foo.yaml').aqua}, Build questions from YAML project file.
|
36
61
|
|
37
62
|
LONGDESC
|
38
|
-
##
|
39
|
-
# Create questions from input file
|
40
|
-
# @param filename (String) Path to input file
|
41
63
|
def file(filename)
|
42
64
|
# Asker start processing input file
|
43
65
|
Asker.start(filename)
|
44
66
|
end
|
45
67
|
|
46
|
-
map ['c', '-c', '--check'] => 'check'
|
47
|
-
desc 'check', 'Check input HAML file syntax'
|
48
|
-
##
|
49
|
-
# Check input file syntax
|
50
|
-
# @param filename (String) Path to input file
|
51
|
-
def check(filename)
|
52
|
-
# Enable/disable color output
|
53
|
-
Rainbow.enabled = false if options['color'] == false
|
54
|
-
# Asker start processing input file
|
55
|
-
Asker.check(filename)
|
56
|
-
end
|
57
|
-
|
58
|
-
map ['i', '-i', '--init'] => 'init'
|
59
|
-
desc 'init', 'Create default INI config fie'
|
60
|
-
##
|
61
|
-
# Create default INI config file
|
62
|
-
def init
|
63
|
-
Asker.create_configuration
|
64
|
-
end
|
65
|
-
|
66
|
-
map ['n', '-b', '--new', 'new'] => 'create_input'
|
67
|
-
desc 'new', 'Create Asker demo input files'
|
68
|
-
##
|
69
|
-
# Create Asker demo input files
|
70
|
-
# @param dirname (String) Path to folder
|
71
|
-
def create_input(dirname)
|
72
|
-
Asker.create_input(dirname)
|
73
|
-
end
|
74
|
-
|
75
68
|
##
|
76
69
|
# This actions are equals:
|
77
70
|
# * asker demo/foo.haml
|
@@ -79,4 +72,14 @@ class CLI < Thor
|
|
79
72
|
def method_missing(method, *_args, &_block)
|
80
73
|
file(method.to_s)
|
81
74
|
end
|
75
|
+
|
76
|
+
def respond_to_missing?(_method_name)
|
77
|
+
true
|
78
|
+
end
|
79
|
+
|
80
|
+
##
|
81
|
+
# Thor stop and show messages on screen on failure
|
82
|
+
def self.exit_on_failure?
|
83
|
+
true
|
84
|
+
end
|
82
85
|
end
|
data/lib/asker/data/code.rb
CHANGED
@@ -1,20 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative '../ai/code/code_ai_factory'
|
2
|
-
require_relative '../project'
|
3
|
-
require_relative '../logger'
|
4
|
-
require_relative '../formatter/code_string_formatter'
|
5
4
|
|
6
|
-
##
|
7
|
-
# Code data object
|
8
5
|
class Code
|
9
6
|
attr_reader :dirname, :filename, :type
|
10
7
|
attr_accessor :process, :features
|
11
8
|
attr_reader :lines, :questions
|
12
9
|
|
13
|
-
##
|
14
|
-
# Initialize Code object
|
15
|
-
# @param dirname (String)
|
16
|
-
# @param filename (String)
|
17
|
-
# @param type (String)
|
18
10
|
def initialize(dirname, filename, type)
|
19
11
|
@dirname = dirname
|
20
12
|
@filename = filename
|
@@ -38,16 +30,13 @@ class Code
|
|
38
30
|
out
|
39
31
|
end
|
40
32
|
|
41
|
-
def debug
|
42
|
-
Logger.verbose CodeStringFormatter.to_s(self)
|
43
|
-
end
|
44
|
-
|
45
33
|
private
|
46
34
|
|
47
35
|
def load(filepath)
|
48
36
|
return if filepath.nil?
|
37
|
+
|
49
38
|
unless File.exist? filepath
|
50
|
-
|
39
|
+
puts Rainbow("[ERROR] Unkown file #{filepath}").red.bright
|
51
40
|
return
|
52
41
|
end
|
53
42
|
content = File.read(filepath)
|
@@ -56,7 +45,7 @@ class Code
|
|
56
45
|
|
57
46
|
def encode_and_split(text, encoding = :default)
|
58
47
|
# Convert text to UTF-8 deleting unknown chars
|
59
|
-
text
|
48
|
+
text ||= '' # Ensure text is not nil
|
60
49
|
flag = [:default, 'UTF-8'].include? encoding
|
61
50
|
return text.encode('UTF-8', invalid: :replace).split("\n") if flag
|
62
51
|
|