asker-tool 2.6.0 → 2.7.0

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.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -4
  3. data/lib/asker/ai/ai.rb +6 -6
  4. data/lib/asker/ai/ai_calculate.rb +3 -3
  5. data/lib/asker/ai/code/base_code_ai.rb +5 -30
  6. data/lib/asker/ai/code/code_ai_factory.rb +6 -12
  7. data/lib/asker/ai/code/javascript_code_ai.rb +33 -34
  8. data/lib/asker/ai/code/python_code_ai.rb +35 -36
  9. data/lib/asker/ai/code/ruby_code_ai.rb +33 -33
  10. data/lib/asker/ai/code/sql_code_ai.rb +20 -21
  11. data/lib/asker/ai/concept_ai.rb +12 -22
  12. data/lib/asker/ai/problem/problem_ai.rb +226 -0
  13. data/lib/asker/ai/question.rb +34 -45
  14. data/lib/asker/ai/stages/base_stage.rb +7 -7
  15. data/lib/asker/ai/stages/stage_b.rb +62 -28
  16. data/lib/asker/ai/stages/stage_d.rb +10 -10
  17. data/lib/asker/ai/stages/stage_f.rb +17 -17
  18. data/lib/asker/ai/stages/stage_i.rb +8 -18
  19. data/lib/asker/ai/stages/stage_s.rb +28 -26
  20. data/lib/asker/ai/stages/stage_t.rb +40 -51
  21. data/lib/asker/application.rb +15 -14
  22. data/lib/asker/check_input/check_haml_data.rb +52 -51
  23. data/lib/asker/check_input/check_table.rb +17 -20
  24. data/lib/asker/check_input.rb +10 -23
  25. data/lib/asker/cli.rb +43 -24
  26. data/lib/asker/data/code.rb +10 -9
  27. data/lib/asker/data/column.rb +21 -17
  28. data/lib/asker/data/concept.rb +24 -37
  29. data/lib/asker/data/data_field.rb +2 -2
  30. data/lib/asker/data/problem.rb +112 -0
  31. data/lib/asker/data/project_data.rb +11 -15
  32. data/lib/asker/data/row.rb +25 -23
  33. data/lib/asker/data/table.rb +25 -46
  34. data/lib/asker/data/template.rb +7 -7
  35. data/lib/asker/data/world.rb +3 -3
  36. data/lib/asker/{formatter → deprecated}/question_moodlexml_formatter.rb +19 -21
  37. data/lib/asker/displayer/code_displayer.rb +10 -10
  38. data/lib/asker/displayer/concept_ai_displayer.erb +1 -1
  39. data/lib/asker/displayer/concept_ai_displayer.rb +16 -16
  40. data/lib/asker/displayer/concept_displayer.rb +4 -2
  41. data/lib/asker/displayer/problem_displayer.rb +45 -0
  42. data/lib/asker/displayer/stats_displayer.rb +7 -12
  43. data/lib/asker/exporter/code_gift_exporter.rb +2 -2
  44. data/lib/asker/exporter/concept_ai_gift_exporter.rb +4 -4
  45. data/lib/asker/exporter/concept_ai_yaml_exporter.rb +7 -7
  46. data/lib/asker/exporter/concept_doc_exporter.rb +5 -5
  47. data/lib/asker/exporter/data_gift_exporter.rb +14 -15
  48. data/lib/asker/exporter/data_moodle_exporter.rb +51 -20
  49. data/lib/asker/exporter/output_file_exporter.rb +9 -8
  50. data/lib/asker/exporter/problem_gift_exporter.rb +30 -0
  51. data/lib/asker/files/language/ca/templates.yaml +6 -0
  52. data/lib/asker/files/language/du/templates.yaml +6 -0
  53. data/lib/asker/files/language/en/templates.yaml +7 -1
  54. data/lib/asker/files/language/es/templates.yaml +6 -0
  55. data/lib/asker/files/language/fr/templates.yaml +6 -0
  56. data/lib/asker/formatter/code_string_formatter.rb +5 -5
  57. data/lib/asker/formatter/concept_doc_formatter.rb +3 -3
  58. data/lib/asker/formatter/concept_string_formatter.rb +6 -6
  59. data/lib/asker/formatter/moodle/ddmatch.erb +40 -0
  60. data/lib/asker/formatter/moodle/gapfill.erb +57 -0
  61. data/lib/asker/formatter/moodle/ordering.erb +41 -0
  62. data/lib/asker/formatter/question_gift_formatter.rb +41 -14
  63. data/lib/asker/formatter/question_hash_formatter.rb +5 -6
  64. data/lib/asker/formatter/question_moodle_formatter.rb +14 -7
  65. data/lib/asker/formatter/rb2haml_formatter.rb +8 -7
  66. data/lib/asker/lang/lang.rb +16 -16
  67. data/lib/asker/lang/lang_factory.rb +13 -16
  68. data/lib/asker/lang/text_actions.rb +20 -18
  69. data/lib/asker/loader/code_loader.rb +10 -22
  70. data/lib/asker/loader/content_loader.rb +42 -49
  71. data/lib/asker/loader/directory_loader.rb +13 -16
  72. data/lib/asker/loader/embedded_file.rb +14 -14
  73. data/lib/asker/loader/file_loader.rb +5 -4
  74. data/lib/asker/loader/haml_loader.rb +4 -3
  75. data/lib/asker/loader/image_url_loader.rb +6 -5
  76. data/lib/asker/loader/input_loader.rb +24 -10
  77. data/lib/asker/loader/problem_loader.rb +88 -0
  78. data/lib/asker/loader/project_loader.rb +5 -12
  79. data/lib/asker/logger.rb +19 -10
  80. data/lib/asker/skeleton.rb +19 -35
  81. data/lib/asker/start.rb +44 -0
  82. data/lib/asker/version.rb +1 -1
  83. data/lib/asker.rb +7 -52
  84. metadata +12 -6
  85. data/lib/asker/ai/code/problem_code_ai.rb +0 -176
  86. data/lib/asker/exporter/code_moodle_exporter.rb +0 -15
  87. data/lib/asker/exporter/concept_ai_moodle_exporter.rb +0 -15
@@ -37,12 +37,11 @@ class StageT < BaseStage
37
37
  a = s.to_a
38
38
 
39
39
  if s.count > 3
40
- q = Question.new
41
- q.set_choice
40
+ q = Question.new(:choice)
42
41
  q.name = "#{name}-#{num}-t1table-#{table.name}"
43
42
  q.text = random_image_for(name) \
44
- + lang.text_for(:t1table, name, table.fields[col1].capitalize, \
45
- table.fields[col2].capitalize, row[:data][col2])
43
+ + lang.text_for(:t1table, name, table.fields[col1].capitalize,
44
+ table.fields[col2].capitalize, row[:data][col2])
46
45
  q.good = row[:data][col1]
47
46
  q.bads << lang.text_for(:none)
48
47
  q.bads << a[2]
@@ -56,12 +55,11 @@ class StageT < BaseStage
56
55
  # a = s.to_a
57
56
 
58
57
  if s.count > 4
59
- q = Question.new
60
- q.set_choice
58
+ q = Question.new(:choice)
61
59
  q.name = "#{name}-#{num}-t2table-#{table.name}"
62
60
  q.text = random_image_for(name) \
63
- + lang.text_for(:t2table, name, table.fields[col1].capitalize, \
64
- table.fields[col2].capitalize, row[:data][col2])
61
+ + lang.text_for(:t2table, name, table.fields[col1].capitalize,
62
+ table.fields[col2].capitalize, row[:data][col2])
65
63
  q.good = lang.text_for(:none)
66
64
  q.bads << a[2]
67
65
  q.bads << a[3]
@@ -75,12 +73,11 @@ class StageT < BaseStage
75
73
  a = s.to_a
76
74
 
77
75
  if s.count > 3
78
- q = Question.new
79
- q.set_choice
76
+ q = Question.new(:choice)
80
77
  q.name = "#{name}-#{num}-t3table-#{table.name}"
81
78
  q.text = random_image_for(name) \
82
- + lang.text_for(:t3table, name, table.fields[col1].capitalize, \
83
- row[:data][col1], table.fields[col2].capitalize)
79
+ + lang.text_for(:t3table, name, table.fields[col1].capitalize,
80
+ row[:data][col1], table.fields[col2].capitalize)
84
81
  q.good = a[0]
85
82
  q.bads << lang.text_for(:none)
86
83
  q.bads << a[2]
@@ -94,12 +91,11 @@ class StageT < BaseStage
94
91
  # a = s.to_a
95
92
 
96
93
  if s.count > 4
97
- q = Question.new
98
- q.set_choice
94
+ q = Question.new(:choice)
99
95
  q.name = "#{name}-#{num}-t4table-#{table.name}"
100
96
  q.text = random_image_for(name) \
101
- + lang.text_for(:t4table, name, table.fields[col1].capitalize, \
102
- row[:data][col1], table.fields[col2].capitalize)
97
+ + lang.text_for(:t4table, name, table.fields[col1].capitalize,
98
+ row[:data][col1], table.fields[col2].capitalize)
103
99
  q.good = lang.text_for(:none)
104
100
  q.bads << a[2]
105
101
  q.bads << a[3]
@@ -108,12 +104,11 @@ class StageT < BaseStage
108
104
  end
109
105
 
110
106
  # Question Boolean: TRUE
111
- q = Question.new
112
- q.set_boolean
107
+ q = Question.new(:boolean)
113
108
  q.name = "#{name}-#{num}t5table-#{table.name}"
114
109
  q.text = random_image_for(name) \
115
- + lang.text_for(:t5table, name, table.fields[col1].capitalize, \
116
- row[:data][col1], table.fields[col2].capitalize, row[:data][col2])
110
+ + lang.text_for(:t5table, name, table.fields[col1].capitalize,
111
+ row[:data][col1], table.fields[col2].capitalize, row[:data][col2])
117
112
  q.good = "TRUE"
118
113
  questions << q
119
114
 
@@ -123,12 +118,11 @@ class StageT < BaseStage
123
118
  a = s.to_a
124
119
 
125
120
  if s.count > 1
126
- q = Question.new
127
- q.set_boolean
121
+ q = Question.new(:boolean)
128
122
  q.name = "#{name}-#{num}-t6table-#{table.name}"
129
123
  q.text = random_image_for(name) \
130
- + lang.text_for(:t6table, name, table.fields[col1].capitalize, \
131
- row[:data][col1], table.fields[col2].capitalize, a[1])
124
+ + lang.text_for(:t6table, name, table.fields[col1].capitalize,
125
+ row[:data][col1], table.fields[col2].capitalize, a[1])
132
126
  q.good = "FALSE"
133
127
  questions << q
134
128
  end
@@ -138,61 +132,56 @@ class StageT < BaseStage
138
132
  a = s.to_a
139
133
 
140
134
  if s.count > 1
141
- q = Question.new
142
- q.set_boolean
135
+ q = Question.new(:boolean)
143
136
  q.name = "#{name}-#{num}t7table-#{table.name}"
144
137
  q.text = random_image_for(name) \
145
- + lang.text_for(:t7table, name, table.fields[col1].capitalize, \
146
- a[1], table.fields[col2].capitalize, row[:data][col2])
147
- q.good = 'FALSE'
138
+ + lang.text_for(:t7table, name, table.fields[col1].capitalize,
139
+ a[1], table.fields[col2].capitalize, row[:data][col2])
140
+ q.good = "FALSE"
148
141
  questions << q
149
142
  end
150
143
 
151
144
  # Question Short: column #0, 1 word
152
145
  if lang.count_words(row[:data][col1]) == 1
153
- q = Question.new
154
- q.set_short
146
+ q = Question.new(:short)
155
147
  q.name = "#{name}-#{num}t8table-#{table.name}"
156
148
  q.text = random_image_for(name) \
157
- + lang.text_for(:t8table, name, table.fields[col2].capitalize, \
158
- row[:data][col2], table.fields[col1].capitalize)
149
+ + lang.text_for(:t8table, name, table.fields[col2].capitalize,
150
+ row[:data][col2], table.fields[col1].capitalize)
159
151
  q.shorts << row[:data][col1]
160
- q.shorts << row[:data][col1].gsub('-', ' ').gsub('_', ' ')
152
+ q.shorts << row[:data][col1].tr("-", " ").tr("_", " ")
161
153
  questions << q
162
154
  elsif lang.count_words(row[:data][col1]) == 2
163
- q = Question.new
164
- q.set_short
155
+ q = Question.new(:short)
165
156
  q.name = "#{name}-#{num}t9table-#{table.name}"
166
157
  q.text = random_image_for(name) \
167
- + lang.text_for(:t9table, name, table.fields[col2].capitalize, \
168
- row[:data][col2], table.fields[col1].capitalize, \
169
- "[#{lang.hide_text(row[:data][col1])}]", lang.count_words(row[:data][col1]))
158
+ + lang.text_for(:t9table, name, table.fields[col2].capitalize,
159
+ row[:data][col2], table.fields[col1].capitalize,
160
+ "[#{lang.hide_text(row[:data][col1])}]", lang.count_words(row[:data][col1]))
170
161
  q.shorts << row[:data][col1]
171
- q.shorts << row[:data][col1].gsub('-', ' ').gsub('_', ' ')
162
+ q.shorts << row[:data][col1].tr("-", " ").tr("_", " ")
172
163
  questions << q
173
164
  end
174
165
 
175
166
  # Question Short: column #1, 1 word
176
167
  if lang.count_words(row[:data][col2]) == 1
177
- q = Question.new
178
- q.set_short
168
+ q = Question.new(:short)
179
169
  q.name = "#{name}-#{num}t8table-#{table.name}"
180
170
  q.text = random_image_for(name) \
181
- + lang.text_for(:t8table, name, table.fields[col1].capitalize, \
182
- row[:data][col1], table.fields[col2].capitalize)
171
+ + lang.text_for(:t8table, name, table.fields[col1].capitalize,
172
+ row[:data][col1], table.fields[col2].capitalize)
183
173
  q.shorts << row[:data][col2]
184
- q.shorts << row[:data][col2].gsub('-', ' ').gsub('_', ' ')
174
+ q.shorts << row[:data][col2].tr("-", " ").tr("_", " ")
185
175
  questions << q
186
176
  elsif lang.count_words(row[:data][col2]) == 2
187
- q = Question.new
188
- q.set_short
177
+ q = Question.new(:short)
189
178
  q.name = "#{name}-#{num}t9table-#{table.name}"
190
179
  q.text = random_image_for(name) \
191
- + lang.text_for(:t9table, name, table.fields[col1].capitalize, \
192
- row[:data][col1], table.fields[col2].capitalize, \
193
- "[#{lang.hide_text(row[:data][col2])}]", lang.count_words(row[:data][col2]))
180
+ + lang.text_for(:t9table, name, table.fields[col1].capitalize,
181
+ row[:data][col1], table.fields[col2].capitalize,
182
+ "[#{lang.hide_text(row[:data][col2])}]", lang.count_words(row[:data][col2]))
194
183
  q.shorts << row[:data][col2]
195
- q.shorts << row[:data][col2].gsub('-', ' ').gsub('_', ' ')
184
+ q.shorts << row[:data][col2].tr("-", " ").tr("_", " ")
196
185
  questions << q
197
186
  end
198
187
  questions
@@ -1,6 +1,6 @@
1
1
  require "singleton"
2
2
  require "inifile"
3
- require "rainbow"
3
+ require_relative "logger"
4
4
  require_relative "version"
5
5
 
6
6
  # Global parameters
@@ -14,26 +14,27 @@ class Application
14
14
 
15
15
  def reset
16
16
  filename = File.join(Dir.pwd,
17
- Asker::CONFIGFILE)
18
- filename = File.join(File.dirname(__FILE__),
19
- 'files',
20
- Asker::CONFIGFILE) unless File.exist? filename
17
+ Asker::CONFIGFILE)
18
+ unless File.exist? filename
19
+ filename = File.join(File.dirname(__FILE__),
20
+ "files",
21
+ Asker::CONFIGFILE)
22
+ end
21
23
 
22
24
  begin
23
25
  @config = IniFile.load(filename)
24
- rescue StandardError => e
25
- puts e.display
26
- puts Rainbow('[ERROR] Revise configuration file:').red.bright
27
- puts Rainbow(" #{filename}").red.bright
26
+ rescue => e
27
+ Logger.error e.display
28
+ Logger.error "Application: Revise configuration file (#{filename})"
28
29
  exit 1
29
30
  end
30
- stages = @config['questions']['stages'].split(',')
31
- @config['questions']['stages'] = stages.map(&:to_sym)
31
+ stages = @config["questions"]["stages"].split(",")
32
+ @config["questions"]["stages"] = stages.map(&:to_sym)
32
33
 
33
- fractions = @config['questions']['fractions'].split(',')
34
- @config['questions']['fractions'] = fractions + Array.new(5, '0')
34
+ fractions = @config["questions"]["fractions"].split(",")
35
+ @config["questions"]["fractions"] = fractions + Array.new(5, "0")
35
36
 
36
37
  Rainbow.enabled = false
37
- Rainbow.enabled = true if @config['global']['color'].downcase == 'yes'
38
+ Rainbow.enabled = true if @config["global"]["color"].downcase == "yes"
38
39
  end
39
40
  end
@@ -8,19 +8,19 @@ class CheckHamlData
8
8
  @inputs = File.read(filepath).split("\n")
9
9
  @outputs = []
10
10
  @inputs.each_with_index do |line, index|
11
- output = { id: index,
12
- level: 0,
13
- state: :none,
14
- type: :none,
15
- source: line,
16
- msg: '' }
11
+ output = {id: index,
12
+ level: 0,
13
+ state: :none,
14
+ type: :none,
15
+ source: line,
16
+ msg: ""}
17
17
  @outputs << output
18
18
  end
19
19
  @ok = false
20
20
  end
21
21
 
22
22
  def ok?
23
- @ok
23
+ @ok
24
24
  end
25
25
 
26
26
  def show
@@ -36,22 +36,23 @@ class CheckHamlData
36
36
 
37
37
  errors += 1
38
38
  if errors < 11
39
- data = { id: i[:id], msg: i[:msg], source: i[:source][0, 40] }
39
+ data = {id: i[:id], msg: i[:msg], source: i[:source][0, 40]}
40
40
  order = i[:id] + 1
41
- data = { order: order, msg: i[:msg], source: i[:source][0, 40] }
42
- message = Rainbow(" %<order>03d : %<msg>32s. => ").white
43
- print format(message, data)
44
- message = Rainbow("%<source>s").yellow.bright
45
- puts format(message, data)
41
+ data = {order: order, msg: i[:msg], source: i[:source][0, 40]}
42
+ message1 = Rainbow(" %<order>03d : %<msg>32s. => ").white
43
+ message2 = Rainbow("%<source>s").yellow.bright
44
+ output = format(message1, data) + format(message2, data)
45
+ warn output
46
46
  end
47
- puts "..." if errors == 11
47
+ warn "..." if errors == 11
48
48
  end
49
49
 
50
50
  if errors.zero?
51
51
  puts Rainbow("Syntax OK!").green.bright
52
52
  else
53
- message = "\nRevise #{errors.to_s} syntax error/s\n"
54
- puts Rainbow(message).yellow.bright
53
+ message = "\nRevise #{errors} syntax warning or error/s\n"
54
+ warn Rainbow(message).yellow.bright
55
+ exit 1
55
56
  end
56
57
  end
57
58
 
@@ -82,7 +83,7 @@ class CheckHamlData
82
83
  private
83
84
 
84
85
  def check_empty_lines(line, index)
85
- return unless line.strip.size.zero? || line.start_with?('#')
86
+ return unless line.strip.size.zero? || line.start_with?("#")
86
87
 
87
88
  @outputs[index][:type] = :empty
88
89
  @outputs[index][:level] = -1
@@ -92,155 +93,155 @@ class CheckHamlData
92
93
  def check_map(line, index)
93
94
  if index.zero?
94
95
  @outputs[index][:type] = :map
95
- if line.start_with?('%map{')
96
+ if line.start_with?("%map{")
96
97
  @outputs[index][:state] = :ok
97
98
  else
98
99
  @outputs[index][:state] = :err
99
- @outputs[index][:msg] = 'Start with %map{'
100
+ @outputs[index][:msg] = "Start with %map{"
100
101
  end
101
- elsif index.positive? && line.include?('%map{')
102
+ elsif index.positive? && line.include?("%map{")
102
103
  @outputs[index][:state] = :err
103
104
  @outputs[index][:type] = :map
104
- @outputs[index][:msg] = 'Write %map on line 0'
105
+ @outputs[index][:msg] = "Write %map on line 0"
105
106
  end
106
107
  end
107
108
 
108
109
  def check_concept(line, index)
109
110
  return unless @outputs[index][:state] == :none
110
- return unless line.include? '%concept'
111
+ return unless line.include? "%concept"
111
112
 
112
113
  @outputs[index][:type] = :concept
113
114
  @outputs[index][:level] = 1
114
115
  @outputs[index][:state] = :ok
115
116
  if find_parent(index) != :map
116
117
  @outputs[index][:state] = :err
117
- @outputs[index][:msg] = 'Parent(map) not found!'
118
+ @outputs[index][:msg] = "Parent(map) not found!"
118
119
  elsif !line.match(/^\s\s%concept\s*$/)
119
120
  binding.break
120
121
  @outputs[index][:state] = :err
121
- @outputs[index][:msg] = 'Write 2 spaces before %concept, and no text after'
122
+ @outputs[index][:msg] = "Write 2 spaces before %concept, and no text after"
122
123
  end
123
124
  end
124
125
 
125
126
  def check_names(line, index)
126
127
  return unless @outputs[index][:state] == :none
127
- return unless line.include? '%names'
128
+ return unless line.include? "%names"
128
129
 
129
130
  @outputs[index][:type] = :names
130
131
  @outputs[index][:level] = 2
131
132
  @outputs[index][:state] = :ok
132
133
  if find_parent(index) != :concept
133
134
  @outputs[index][:state] = :err
134
- @outputs[index][:msg] = 'Parent(concept) not found!'
135
- elsif !line.start_with? ' %names'
135
+ @outputs[index][:msg] = "Parent(concept) not found!"
136
+ elsif !line.start_with? " %names"
136
137
  elsif !line.match(/^\s\s\s\s%names\s/)
137
138
  @outputs[index][:state] = :err
138
- @outputs[index][:msg] = 'Write 4 spaces before %names'
139
+ @outputs[index][:msg] = "Write 4 spaces before %names"
139
140
  end
140
141
  end
141
142
 
142
143
  def check_tags(line, index)
143
144
  return unless @outputs[index][:state] == :none
144
- return unless line.include? '%tags'
145
+ return unless line.include? "%tags"
145
146
 
146
147
  @outputs[index][:type] = :tags
147
148
  @outputs[index][:level] = 2
148
149
  @outputs[index][:state] = :ok
149
- if line.strip == '%tags'
150
+ if line.strip == "%tags"
150
151
  @outputs[index][:state] = :err
151
- @outputs[index][:msg] = 'Please, fill with concept tags!'
152
+ @outputs[index][:msg] = "Please, fill with concept tags!"
152
153
  elsif find_parent(index) != :concept
153
154
  @outputs[index][:state] = :err
154
- @outputs[index][:msg] = 'Parent(concept) not found!'
155
+ @outputs[index][:msg] = "Parent(concept) not found!"
155
156
  elsif !line.match(/^\s\s\s\s%tags\s/)
156
157
  @outputs[index][:state] = :err
157
- @outputs[index][:msg] = 'Write 4 spaces before %tags'
158
+ @outputs[index][:msg] = "Write 4 spaces before %tags"
158
159
  end
159
160
  end
160
161
 
161
162
  def check_def(line, index)
162
163
  return unless @outputs[index][:state] == :none
163
- return unless line.include? '%def'
164
+ return unless line.include? "%def"
164
165
 
165
166
  @outputs[index][:type] = :def
166
167
  @outputs[index][:level] = 2
167
168
  @outputs[index][:state] = :ok
168
169
  if find_parent(index) != :concept
169
170
  @outputs[index][:state] = :err
170
- @outputs[index][:msg] = 'Parent(concept) not found!'
171
+ @outputs[index][:msg] = "Parent(concept) not found!"
171
172
  elsif !line.match(/^\s\s\s\s%def[\s{]/)
172
173
  @outputs[index][:state] = :err
173
- @outputs[index][:msg] = 'Write 4 spaces before %def'
174
+ @outputs[index][:msg] = "Write 4 spaces before %def"
174
175
  else
175
176
  items = line.strip.split
176
177
  if items.size < 2
177
178
  @outputs[index][:state] = :err
178
- @outputs[index][:msg] = '%def has no definition'
179
+ @outputs[index][:msg] = "%def has no definition"
179
180
  end
180
181
  end
181
182
  end
182
183
 
183
184
  def check_code(line, index)
184
185
  return unless @outputs[index][:state] == :none
185
- return unless line.include? '%code'
186
+ return unless line.include? "%code"
186
187
 
187
188
  @outputs[index][:type] = :code
188
189
  @outputs[index][:level] = 1
189
190
  @outputs[index][:state] = :ok
190
191
  if find_parent(index) != :map
191
192
  @outputs[index][:state] = :err
192
- @outputs[index][:msg] = 'Parent(map) not found!'
193
+ @outputs[index][:msg] = "Parent(map) not found!"
193
194
  elsif !line.match(/^\s\s%code\s*$/)
194
195
  @outputs[index][:state] = :err
195
- @outputs[index][:msg] = 'Write 2 spaces before %code, and no text after'
196
+ @outputs[index][:msg] = "Write 2 spaces before %code, and no text after"
196
197
  end
197
198
  end
198
199
 
199
200
  def check_type(line, index)
200
201
  return unless @outputs[index][:state] == :none
201
- return unless line.include? '%type'
202
+ return unless line.include? "%type"
202
203
 
203
204
  @outputs[index][:type] = :type
204
205
  @outputs[index][:level] = 2
205
206
  @outputs[index][:state] = :ok
206
207
  if find_parent(index) != :code
207
208
  @outputs[index][:state] = :err
208
- @outputs[index][:msg] = 'Parent(code) not found!'
209
+ @outputs[index][:msg] = "Parent(code) not found!"
209
210
  elsif !line.match(/^\s\s\s\s%type\s/)
210
211
  @outputs[index][:state] = :err
211
- @outputs[index][:msg] = 'Write 4 spaces before %type'
212
+ @outputs[index][:msg] = "Write 4 spaces before %type"
212
213
  end
213
214
  end
214
215
 
215
216
  def check_path(line, index)
216
217
  return unless @outputs[index][:state] == :none
217
- return unless line.include? '%path'
218
+ return unless line.include? "%path"
218
219
 
219
220
  @outputs[index][:type] = :path
220
221
  @outputs[index][:level] = 2
221
222
  @outputs[index][:state] = :ok
222
223
  if find_parent(index) != :code
223
224
  @outputs[index][:state] = :err
224
- @outputs[index][:msg] = 'Parent(code) not found!'
225
+ @outputs[index][:msg] = "Parent(code) not found!"
225
226
  elsif !line.match(/^\s\s\s\s%path\s/)
226
227
  @outputs[index][:state] = :err
227
- @outputs[index][:msg] = 'Write 4 spaces before %type'
228
+ @outputs[index][:msg] = "Write 4 spaces before %type"
228
229
  end
229
230
  end
230
231
 
231
232
  def check_features(line, index)
232
233
  return unless @outputs[index][:state] == :none
233
- return unless line.include? '%features'
234
+ return unless line.include? "%features"
234
235
 
235
236
  @outputs[index][:type] = :features
236
237
  @outputs[index][:level] = 2
237
238
  @outputs[index][:state] = :ok
238
239
  if find_parent(index) != :code
239
240
  @outputs[index][:state] = :err
240
- @outputs[index][:msg] = 'Parent(code) not found!'
241
+ @outputs[index][:msg] = "Parent(code) not found!"
241
242
  elsif !line.match(/^\s\s\s\s%features\s*$/)
242
243
  @outputs[index][:state] = :err
243
- @outputs[index][:msg] = 'Write 4 spaces before %features, and no text after'
244
+ @outputs[index][:msg] = "Write 4 spaces before %features, and no text after"
244
245
  end
245
246
  end
246
247
 
@@ -267,7 +268,7 @@ class CheckHamlData
267
268
  end
268
269
 
269
270
  def count_spaces(line)
270
- a = line.split('%')
271
- a[0].count(' ')
271
+ a = line.split("%")
272
+ a[0].count(" ")
272
273
  end
273
274
  end
@@ -1,19 +1,17 @@
1
-
2
1
  module CheckTable
3
-
4
2
  def check_table(line, index)
5
3
  return unless @outputs[index][:state] == :none
6
- return unless line.include? '%table'
4
+ return unless line.include? "%table"
7
5
 
8
6
  @outputs[index][:type] = :table
9
7
  @outputs[index][:level] = 2
10
8
  @outputs[index][:state] = :ok
11
9
  if find_parent(index) != :concept
12
10
  @outputs[index][:state] = :err
13
- @outputs[index][:msg] = 'Parent(concept) not found!'
11
+ @outputs[index][:msg] = "Parent(concept) not found!"
14
12
  elsif !line.match(/^\s\s\s\s%table\s*/)
15
13
  @outputs[index][:state] = :err
16
- @outputs[index][:msg] = 'Write 4 spaces before %table'
14
+ @outputs[index][:msg] = "Write 4 spaces before %table"
17
15
  end
18
16
 
19
17
  unless line.include? "%table{"
@@ -29,7 +27,7 @@ module CheckTable
29
27
 
30
28
  def check_row(line, index)
31
29
  return unless @outputs[index][:state] == :none
32
- return unless line.include? '%row'
30
+ return unless line.include? "%row"
33
31
 
34
32
  @outputs[index][:type] = :row
35
33
  @outputs[index][:state] = :ok
@@ -40,23 +38,23 @@ module CheckTable
40
38
  parent = find_parent(index)
41
39
  unless %i[table template features].include? parent
42
40
  @outputs[index][:state] = :err
43
- @outputs[index][:msg] = 'Parent(table/template/features) not found!'
41
+ @outputs[index][:msg] = "Parent(table/template/features) not found!"
44
42
  end
45
43
  when 8
46
44
  @outputs[index][:level] = 4
47
45
  if find_parent(index) != :template
48
46
  @outputs[index][:state] = :err
49
- @outputs[index][:msg] = 'Parent(template) not found!'
47
+ @outputs[index][:msg] = "Parent(template) not found!"
50
48
  end
51
49
  else
52
50
  @outputs[index][:state] = :err
53
- @outputs[index][:msg] = 'Write 6 or 8 spaces before %row'
51
+ @outputs[index][:msg] = "Write 6 or 8 spaces before %row"
54
52
  end
55
53
  end
56
54
 
57
55
  def check_col(line, index)
58
56
  return unless @outputs[index][:state] == :none
59
- return unless line.include? '%col'
57
+ return unless line.include? "%col"
60
58
 
61
59
  @outputs[index][:type] = :col
62
60
  @outputs[index][:state] = :ok
@@ -64,9 +62,8 @@ module CheckTable
64
62
  # row parent requires empty msg
65
63
  if @outputs[index - 1][:type] == :row
66
64
  if @outputs[index - 1][:source].strip != "%row"
67
- require "debug"; binding.break
68
65
  @outputs[index - 1][:state] = :err
69
- @outputs[index - 1 ][:msg] = 'Row with cols requires empty text!'
66
+ @outputs[index - 1][:msg] = "Row with cols requires empty text!"
70
67
  end
71
68
  end
72
69
 
@@ -75,17 +72,17 @@ module CheckTable
75
72
  @outputs[index][:level] = 4
76
73
  if find_parent(index) != :row
77
74
  @outputs[index][:state] = :err
78
- @outputs[index][:msg] = 'Parent(row) not found!'
75
+ @outputs[index][:msg] = "Parent(row) not found!"
79
76
  end
80
77
  when 10
81
78
  @outputs[index][:level] = 5
82
79
  if find_parent(index) != :row
83
80
  @outputs[index][:state] = :err
84
- @outputs[index][:msg] = 'Parent(row) not found!'
81
+ @outputs[index][:msg] = "Parent(row) not found!"
85
82
  end
86
83
  else
87
84
  @outputs[index][:state] = :err
88
- @outputs[index][:msg] = 'Write 8 or 10 spaces before %col'
85
+ @outputs[index][:msg] = "Write 8 or 10 spaces before %col"
89
86
  end
90
87
  check_text(line, index)
91
88
  end
@@ -93,11 +90,11 @@ module CheckTable
93
90
  def check_text(line, index)
94
91
  return unless @outputs[index][:state] == :ok
95
92
 
96
- ok = ''
93
+ ok = ""
97
94
  %w[< >].each do |char|
98
95
  ok = char if line.include? char
99
96
  end
100
- return if ok == ''
97
+ return if ok == ""
101
98
 
102
99
  @outputs[index][:state] = :err
103
100
  @outputs[index][:msg] = "Char #{ok} not allow!"
@@ -105,17 +102,17 @@ module CheckTable
105
102
 
106
103
  def check_template(line, index)
107
104
  return unless @outputs[index][:state] == :none
108
- return unless line.include? '%template'
105
+ return unless line.include? "%template"
109
106
 
110
107
  @outputs[index][:type] = :template
111
108
  @outputs[index][:level] = 3
112
109
  @outputs[index][:state] = :ok
113
110
  if find_parent(index) != :table
114
111
  @outputs[index][:state] = :err
115
- @outputs[index][:msg] = 'Parent(concept) not found!'
112
+ @outputs[index][:msg] = "Parent(concept) not found!"
116
113
  elsif !line.match(/^\s\s\s\s\s\s%template\s*/)
117
114
  @outputs[index][:state] = :err
118
- @outputs[index][:msg] = 'Write 6 spaces before %template'
115
+ @outputs[index][:msg] = "Write 6 spaces before %template"
119
116
  end
120
117
  end
121
118
  end
@@ -1,22 +1,9 @@
1
- require 'rainbow'
2
- require_relative 'check_input/check_haml_data'
1
+ require_relative "check_input/check_haml_data"
2
+ require_relative "logger"
3
3
 
4
4
  class CheckInput
5
- def initialize(verbose = true)
6
- @verbose = verbose
7
- end
8
-
9
- def file(filepath)
5
+ def check(filepath)
10
6
  @filepath = filepath
11
- self
12
- end
13
-
14
- def verbose(verbose)
15
- @verbose = verbose
16
- self
17
- end
18
-
19
- def check
20
7
  # Check HAML file syntax
21
8
  exist = check_file_exist
22
9
  return false unless exist
@@ -27,16 +14,16 @@ class CheckInput
27
14
 
28
15
  def check_file_exist
29
16
  if @filepath.nil?
30
- puts Rainbow("[ERROR] Can't check nil filename").red.bright
31
- return false
17
+ Logger.error "CheckInput: Unkown filename"
18
+ exit 1
32
19
  end
33
20
  unless File.exist? @filepath
34
- puts Rainbow("[ERROR] File not found!: #{@filepath}").red.bright if @verbose
35
- return false
21
+ Logger.error "CheckInput: File not found! (#{@filepath})"
22
+ exit 1
36
23
  end
37
- unless File.extname(@filepath) == '.haml'
38
- puts Rainbow("[ERROR] Check require's HAML file!").red.bright if @verbose
39
- return false
24
+ unless File.extname(@filepath) == ".haml"
25
+ Logger.error "CheckInput: Check works with HAML files!"
26
+ exit 1
40
27
  end
41
28
  true
42
29
  end