asker-tool 2.2.1 → 2.2.5
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.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/lib/asker/ai/stages/stage_b.rb +1 -10
- data/lib/asker/ai/stages/stage_d.rb +4 -10
- data/lib/asker/ai/stages/stage_f.rb +1 -20
- data/lib/asker/application.rb +6 -7
- data/lib/asker/check_input/check_haml_data.rb +264 -0
- data/lib/asker/check_input/check_table.rb +117 -0
- data/lib/asker/check_input.rb +51 -0
- data/lib/asker/cli.rb +29 -26
- data/lib/asker/exporter/concept_ai_moodle_exporter.rb +3 -2
- data/lib/asker/exporter/concept_doc_exporter.rb +3 -6
- data/lib/asker/exporter/data_gift_exporter.rb +4 -2
- data/lib/asker/loader/content_loader.rb +3 -3
- data/lib/asker/loader/file_loader.rb +0 -3
- data/lib/asker/loader/haml_loader.rb +9 -5
- data/lib/asker/logger.rb +3 -3
- data/lib/asker/skeleton.rb +3 -3
- data/lib/asker/version.rb +10 -0
- data/lib/asker.rb +2 -3
- metadata +52 -6
- data/lib/asker/input_checker.rb +0 -450
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d29f94512a3e39c8bca78635cf2dd2e8fe17af08a0051e06891d2215b53156c1
|
4
|
+
data.tar.gz: c7171059dff700353dbdcf95b7156ace478c8636c66fff6710980d1f057c3522
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f03b51754a35ef5db35b7b6d90431dd6e274ca5944d15e9ea80bf1ac65968576e7e2569758c936f71b56da7c69c0239ae8e48157788b5fe944960213f283fecb
|
7
|
+
data.tar.gz: 813968477e5f6346fc21a28670dc3a151bc390dc97b62f9945954a5b902ec275cef2460a3b1df3fda9ae989dce4663d8afe0def00adc54b2f73d799ce6482bca
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
[](https://badge.fury.io/rb/asker-tool)
|
2
|
+

|
3
|
+

|
2
4
|
|
3
|
-
# ASKER
|
5
|
+
# ASKER
|
4
6
|
|
5
7
|
Generate a lot of questions from an _input_ text file with on your own _definitions_. In a way, this _input file_ is a concept map.
|
6
8
|
|
@@ -5,16 +5,13 @@ require 'set'
|
|
5
5
|
require_relative 'base_stage'
|
6
6
|
require_relative '../question'
|
7
7
|
|
8
|
-
##
|
9
|
-
# range b1
|
10
8
|
class StageB < BaseStage
|
11
9
|
##
|
10
|
+
# range b1
|
12
11
|
# Process table data to generate match questions
|
13
12
|
# @param table (Table)
|
14
13
|
# @param list1 (Array) Rows that belong to this table
|
15
14
|
# @param list2 (Array) List with similar rows (same table name) from the neighbours tables
|
16
|
-
# rubocop:disable Metrics/AbcSize
|
17
|
-
# rubocop:disable Metrics/MethodLength
|
18
15
|
def run(table, list1, list2)
|
19
16
|
questions = []
|
20
17
|
return questions if table.fields.count < 2
|
@@ -44,12 +41,6 @@ class StageB < BaseStage
|
|
44
41
|
# @param list2 (Array) List with similar rows (same table name) from the neighbours tables
|
45
42
|
# @param index1 (Integer) Use this field number
|
46
43
|
# @param index2 (Integer) Use this field number
|
47
|
-
# rubocop:disable Metrics/AbcSize
|
48
|
-
# rubocop:disable Metrics/MethodLength
|
49
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
50
|
-
# rubocop:disable Style/ConditionalAssignment
|
51
|
-
# rubocop:disable Metrics/BlockLength
|
52
|
-
# rubocop:disable Metrics/PerceivedComplexity
|
53
44
|
def process_table_match2fields(p_table, list1, list2, index1, index2)
|
54
45
|
questions = []
|
55
46
|
lang = concept.lang
|
@@ -7,12 +7,6 @@ require_relative '../question'
|
|
7
7
|
|
8
8
|
# range d1-d4
|
9
9
|
class StageD < BaseStage
|
10
|
-
# rubocop:disable Lint/BooleanSymbol
|
11
|
-
# rubocop:disable Metrics/MethodLength
|
12
|
-
# rubocop:disable Metrics/AbcSize
|
13
|
-
# rubocop:disable Metrics/BlockLength
|
14
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
15
|
-
# rubocop:disable Metrics/PerceivedComplexity
|
16
10
|
def run
|
17
11
|
# Stage D: process every definition, I mean every <def> tag
|
18
12
|
questions = []
|
@@ -67,22 +61,22 @@ class StageD < BaseStage
|
|
67
61
|
|
68
62
|
# Question choice => mispelled
|
69
63
|
q = Question.new(:choice)
|
70
|
-
q.name = "#{name(:id)}-#{num}-d2def-
|
64
|
+
q.name = "#{name(:id)}-#{num}-d2def-misspelled"
|
71
65
|
q.text = random_image_for(name(:raw)) + lang.text_for(:d2, name(:decorated), lang.do_mistake_to(t))
|
72
66
|
q.good = lang.text_for(:misspelling)
|
73
67
|
q.bads << lang.text_for(:true)
|
74
68
|
q.bads << lang.text_for(:false)
|
75
|
-
q.feedback = "Definition text
|
69
|
+
q.feedback = "Definition text misspelled!: #{t}"
|
76
70
|
questions << q
|
77
71
|
|
78
72
|
# Question choice => name mispelled
|
79
73
|
q = Question.new(:choice)
|
80
|
-
q.name = "#{name(:id)}-#{num}-d2name-
|
74
|
+
q.name = "#{name(:id)}-#{num}-d2name-misspelled"
|
81
75
|
q.text = random_image_for(name(:raw)) + lang.text_for(:d2, lang.do_mistake_to(name(:raw)), t)
|
82
76
|
q.good = lang.text_for(:misspelling)
|
83
77
|
q.bads << lang.text_for(:true)
|
84
78
|
q.bads << lang.text_for(:false)
|
85
|
-
q.feedback = "Concept name
|
79
|
+
q.feedback = "Concept name misspelled!: #{name(:raw)}"
|
86
80
|
questions << q
|
87
81
|
|
88
82
|
# Question choice => true
|
@@ -3,8 +3,6 @@
|
|
3
3
|
require_relative 'base_stage'
|
4
4
|
require_relative '../question'
|
5
5
|
|
6
|
-
# StageF: process tables with 1 field
|
7
|
-
# rubocop:disable Metrics/ClassLength
|
8
6
|
class StageF < BaseStage
|
9
7
|
##
|
10
8
|
# run stage_f: generate guqestion for tables with 1 field
|
@@ -24,8 +22,6 @@ class StageF < BaseStage
|
|
24
22
|
|
25
23
|
private
|
26
24
|
|
27
|
-
# rubocop:disable Metrics/AbcSize
|
28
|
-
# rubocop:disable Metrics/MethodLength
|
29
25
|
def run_only_this_concept(table, list1)
|
30
26
|
questions = []
|
31
27
|
lang = concept.lang
|
@@ -69,12 +65,7 @@ class StageF < BaseStage
|
|
69
65
|
end
|
70
66
|
questions
|
71
67
|
end
|
72
|
-
# rubocop:enable Metrics/AbcSize
|
73
|
-
# rubocop:enable Metrics/MethodLength
|
74
68
|
|
75
|
-
# rubocop:disable Lint/BooleanSymbol
|
76
|
-
# rubocop:disable Metrics/MethodLength
|
77
|
-
# rubocop:disable Metrics/AbcSize
|
78
69
|
def make_questions_with(values, table)
|
79
70
|
questions = []
|
80
71
|
lang = concept.lang
|
@@ -124,17 +115,11 @@ class StageF < BaseStage
|
|
124
115
|
q.good = lang.text_for(:misspelling)
|
125
116
|
q.bads << lang.text_for(:true)
|
126
117
|
q.bads << lang.text_for(:false)
|
127
|
-
q.feedback = "Text #{save}
|
118
|
+
q.feedback = "Text #{save} misspelled!"
|
128
119
|
values[0] = save
|
129
120
|
questions << q
|
130
121
|
end
|
131
|
-
# rubocop:enable Lint/BooleanSymbol
|
132
|
-
# rubocop:enable Metrics/MethodLength
|
133
|
-
# rubocop:enable Metrics/AbcSize
|
134
122
|
|
135
|
-
# rubocop:disable Lint/BooleanSymbol
|
136
|
-
# rubocop:disable Metrics/MethodLength
|
137
|
-
# rubocop:disable Metrics/AbcSize
|
138
123
|
def run_with_other_concepts(table, list1, list2)
|
139
124
|
questions = []
|
140
125
|
|
@@ -177,8 +162,4 @@ class StageF < BaseStage
|
|
177
162
|
|
178
163
|
questions
|
179
164
|
end
|
180
|
-
# rubocop:enable Lint/BooleanSymbol
|
181
|
-
# rubocop:enable Metrics/MethodLength
|
182
|
-
# rubocop:enable Metrics/AbcSize
|
183
165
|
end
|
184
|
-
# rubocop:enable Metrics/ClassLength
|
data/lib/asker/application.rb
CHANGED
@@ -3,15 +3,11 @@
|
|
3
3
|
require 'singleton'
|
4
4
|
require 'inifile'
|
5
5
|
require 'rainbow'
|
6
|
+
require_relative 'version'
|
6
7
|
|
7
8
|
# Global parameters
|
8
9
|
class Application
|
9
10
|
include Singleton
|
10
|
-
|
11
|
-
VERSION = '2.2.1'
|
12
|
-
NAME = 'asker'
|
13
|
-
GEM = 'asker-tool'
|
14
|
-
CONFIGFILE = 'asker.ini'
|
15
11
|
attr_reader :config
|
16
12
|
|
17
13
|
def initialize
|
@@ -19,8 +15,11 @@ class Application
|
|
19
15
|
end
|
20
16
|
|
21
17
|
def reset
|
22
|
-
filename = File.join(Dir.pwd,
|
23
|
-
|
18
|
+
filename = File.join(Dir.pwd,
|
19
|
+
Version::CONFIGFILE)
|
20
|
+
filename = File.join(File.dirname(__FILE__),
|
21
|
+
'files',
|
22
|
+
Version::CONFIGFILE) unless File.exist? filename
|
24
23
|
|
25
24
|
begin
|
26
25
|
@config = IniFile.load(filename)
|
@@ -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,117 @@
|
|
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
|
+
end
|
18
|
+
|
19
|
+
unless line.include? "%table{"
|
20
|
+
@outputs[index][:state] = :err
|
21
|
+
@outputs[index][:msg] = "table must be next to { (Without spaces)"
|
22
|
+
end
|
23
|
+
|
24
|
+
unless line.include? "fields:"
|
25
|
+
@outputs[index][:state] = :err
|
26
|
+
@outputs[index][:msg] = "fields must be next to : (Without spaces)"
|
27
|
+
end
|
28
|
+
|
29
|
+
# TODO
|
30
|
+
#else not /\s+%table{\s?fields:\s?'[A-Za-z,áéíóú]*'\s?}/.match(line)
|
31
|
+
# @outputs[index][:state] = :err
|
32
|
+
# @outputs[index][:msg] = 'Table#fields malformed!'
|
33
|
+
#end
|
34
|
+
end
|
35
|
+
|
36
|
+
def check_row(line, index)
|
37
|
+
return unless @outputs[index][:state] == :none
|
38
|
+
return unless line.include? '%row'
|
39
|
+
|
40
|
+
@outputs[index][:type] = :row
|
41
|
+
@outputs[index][:state] = :ok
|
42
|
+
|
43
|
+
case count_spaces(line)
|
44
|
+
when 6
|
45
|
+
@outputs[index][:level] = 3
|
46
|
+
parent = find_parent(index)
|
47
|
+
unless %i[table features].include? parent
|
48
|
+
@outputs[index][:state] = :err
|
49
|
+
@outputs[index][:msg] = 'Parent(table/features) not found!'
|
50
|
+
end
|
51
|
+
when 8
|
52
|
+
@outputs[index][:level] = 4
|
53
|
+
if find_parent(index) != :template
|
54
|
+
@outputs[index][:state] = :err
|
55
|
+
@outputs[index][:msg] = 'Parent(template) not found!'
|
56
|
+
end
|
57
|
+
else
|
58
|
+
@outputs[index][:state] = :err
|
59
|
+
@outputs[index][:msg] = 'Write 6 or 8 spaces before %row'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def check_col(line, index)
|
64
|
+
return unless @outputs[index][:state] == :none
|
65
|
+
return unless line.include? '%col'
|
66
|
+
|
67
|
+
@outputs[index][:type] = :col
|
68
|
+
@outputs[index][:state] = :ok
|
69
|
+
case count_spaces(line)
|
70
|
+
when 8
|
71
|
+
@outputs[index][:level] = 4
|
72
|
+
if find_parent(index) != :row
|
73
|
+
@outputs[index][:state] = :err
|
74
|
+
@outputs[index][:msg] = 'Parent(row) not found!'
|
75
|
+
end
|
76
|
+
when 10
|
77
|
+
@outputs[index][:level] = 5
|
78
|
+
if find_parent(index) != :row
|
79
|
+
@outputs[index][:state] = :err
|
80
|
+
@outputs[index][:msg] = 'Parent(row) not found!'
|
81
|
+
end
|
82
|
+
else
|
83
|
+
@outputs[index][:state] = :err
|
84
|
+
@outputs[index][:msg] = 'Write 8 or 10 spaces before %col'
|
85
|
+
end
|
86
|
+
check_text(line, index)
|
87
|
+
end
|
88
|
+
|
89
|
+
def check_text(line, index)
|
90
|
+
return unless @outputs[index][:state] == :ok
|
91
|
+
|
92
|
+
ok = ''
|
93
|
+
%w[< >].each do |char|
|
94
|
+
ok = char if line.include? char
|
95
|
+
end
|
96
|
+
return if ok == ''
|
97
|
+
|
98
|
+
@outputs[index][:state] = :err
|
99
|
+
@outputs[index][:msg] = "Char #{ok} not allow!"
|
100
|
+
end
|
101
|
+
|
102
|
+
def check_template(line, index)
|
103
|
+
return unless @outputs[index][:state] == :none
|
104
|
+
return unless line.include? '%template'
|
105
|
+
|
106
|
+
@outputs[index][:type] = :template
|
107
|
+
@outputs[index][:level] = 3
|
108
|
+
@outputs[index][:state] = :ok
|
109
|
+
if find_parent(index) != :table
|
110
|
+
@outputs[index][:state] = :err
|
111
|
+
@outputs[index][:msg] = 'Parent(concept) not found!'
|
112
|
+
elsif !line.start_with? ' %template'
|
113
|
+
@outputs[index][:state] = :err
|
114
|
+
@outputs[index][:msg] = 'Write 6 spaces before %template'
|
115
|
+
end
|
116
|
+
end
|
117
|
+
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,7 +2,7 @@
|
|
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
|
##
|
@@ -13,7 +13,34 @@ class CLI < Thor
|
|
13
13
|
map ['--version'] => 'version'
|
14
14
|
desc 'version', 'Show the program version'
|
15
15
|
def version
|
16
|
-
puts "#{
|
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)
|
17
44
|
end
|
18
45
|
|
19
46
|
map ['f', '-f', '--file'] => 'file'
|
@@ -38,30 +65,6 @@ class CLI < Thor
|
|
38
65
|
Asker.start(filename)
|
39
66
|
end
|
40
67
|
|
41
|
-
map ['--check'] => 'check'
|
42
|
-
desc 'check FILEPATH', 'Check input HAML file syntax'
|
43
|
-
def check(filename)
|
44
|
-
# Enable/disable color output
|
45
|
-
Rainbow.enabled = false if options['color'] == false
|
46
|
-
# Asker start processing input file
|
47
|
-
Asker.check(filename)
|
48
|
-
end
|
49
|
-
|
50
|
-
map ['--init'] => 'init'
|
51
|
-
desc 'init', 'Create default INI config file'
|
52
|
-
def init
|
53
|
-
Asker.init
|
54
|
-
end
|
55
|
-
|
56
|
-
map ['new','--new'] => 'new_input'
|
57
|
-
desc 'new DIRPATH', 'Create Asker demo input files'
|
58
|
-
##
|
59
|
-
# Create Asker demo input files
|
60
|
-
# @param dirname (String) Path to folder
|
61
|
-
def new_input(dirname)
|
62
|
-
Asker.new_input(dirname)
|
63
|
-
end
|
64
|
-
|
65
68
|
##
|
66
69
|
# This actions are equals:
|
67
70
|
# * asker demo/foo.haml
|