asker-tool 2.2.0 → 2.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -15
- data/lib/asker/ai/concept_ai.rb +1 -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 -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 +32 -47
- data/lib/asker/data/code.rb +1 -15
- data/lib/asker/data/concept.rb +8 -7
- data/lib/asker/{project.rb → data/project_data.rb} +5 -23
- data/lib/asker/data/world.rb +4 -15
- data/lib/asker/displayer/concept_ai_displayer.rb +1 -0
- 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/files/language/en/templates.yaml +1 -1
- data/lib/asker/files/language/es/templates.yaml +1 -1
- data/lib/asker/formatter/concept_doc_formatter.rb +0 -4
- data/lib/asker/loader/content_loader.rb +8 -10
- data/lib/asker/loader/directory_loader.rb +1 -8
- 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 +4 -6
- data/lib/asker/loader/input_loader.rb +5 -6
- data/lib/asker/loader/project_loader.rb +7 -8
- data/lib/asker/logger.rb +17 -15
- data/lib/asker/skeleton.rb +3 -3
- data/lib/asker/version.rb +9 -0
- data/lib/asker.rb +39 -38
- metadata +52 -7
- data/lib/asker/checker.rb +0 -453
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03472461b2c0fd2304386ed597031005721f01c704aa60faab99b877b2f1f391
|
4
|
+
data.tar.gz: 7ed5998cb07871d582458a05df781ba538b871135dd3a423d91939835a90c461
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3f9036a18868f4a7d38789770f2a63d27072c48831727af59b0c3ad6f0ef056427d0ab351f07e77c8e2323dbba820fe2cebc00d9b2d509209c1d99fe96719cc
|
7
|
+
data.tar.gz: '08f4c7f94bc0aec827a199cb4e641f02a96b470b53ac08270cbfdcef192084e2d8b61a94c11a3f267bfa932acbd51c0bd0b26d303b6fb7dabef8421dc468f818'
|
data/README.md
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
-
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/asker-tool.svg)](https://badge.fury.io/rb/asker-tool)
|
2
|
+
![GitHub](https://img.shields.io/github/license/dvarrui/asker)
|
3
|
+
![Gem](https://img.shields.io/gem/dv/asker-tool/2.2.4)
|
2
4
|
|
3
|
-
|
5
|
+
# ASKER
|
4
6
|
|
5
|
-
|
6
|
-
|
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.
|
8
|
+
|
9
|
+
![logo](./docs/images/logo.png)
|
7
10
|
|
8
11
|
ASKER helps trainers to create a huge amount of questions, from a definitions (_conceptual entities_) input file.
|
9
12
|
|
@@ -11,32 +14,29 @@ ASKER helps trainers to create a huge amount of questions, from a definitions (_
|
|
11
14
|
* Multiplatform.
|
12
15
|
* Ruby program.
|
13
16
|
|
14
|
-
|
15
|
-
# Installation
|
17
|
+
## Installation
|
16
18
|
|
17
19
|
1. Install Ruby on your system.
|
18
20
|
2. `gem install asker-tool`
|
19
21
|
|
20
|
-
|
21
|
-
# Usage
|
22
|
+
## Usage
|
22
23
|
|
23
24
|
Steps:
|
24
25
|
|
25
26
|
1. Create an input file with your definitions (_conceptual entities_).
|
26
27
|
1. Run _asker_ and get the results into `output` directory.
|
27
28
|
|
28
|
-
Example: Running `asker` with our example input file as argument (`
|
29
|
+
Example: Running `asker` with our example input file as argument (`acdc.haml`):
|
29
30
|
|
30
31
|
```
|
31
|
-
asker docs/examples/
|
32
|
+
asker docs/examples/bands/acdc.haml
|
32
33
|
```
|
33
34
|
|
34
35
|
* Output files created into the `output` folder.
|
35
|
-
* More [example input files](
|
36
|
+
* More [example input files](./docs/examples).
|
36
37
|
* More asker input files at `github/dvarrui/asker-inputs` repository.
|
37
38
|
|
38
|
-
|
39
|
-
# Documentation
|
39
|
+
## Documentation
|
40
40
|
|
41
41
|
* [Installation](https://github.com/dvarrui/asker/blob/devel/docs/install/README.md)
|
42
42
|
* [Inputs](https://github.com/dvarrui/asker/blob/devel/docs/inputs/README.md)
|
@@ -45,8 +45,7 @@ asker docs/examples/starwars/jedi.haml
|
|
45
45
|
* [Base idea](https://github.com/dvarrui/asker/blob/devel/docs/idea.md)
|
46
46
|
* [History](https://github.com/dvarrui/asker/blob/devel/docs/history.md)
|
47
47
|
|
48
|
-
|
49
|
-
# Contact
|
48
|
+
## Contact
|
50
49
|
|
51
50
|
* **Email**: `teuton.software@protonmail.com`
|
52
51
|
* **Twitter**: `@SoftwareTeuton`
|
data/lib/asker/ai/concept_ai.rb
CHANGED
@@ -46,7 +46,7 @@ class ConceptAI
|
|
46
46
|
##
|
47
47
|
# Generates random image URL
|
48
48
|
def random_image_for(_conceptname)
|
49
|
-
return '' if rand <=
|
49
|
+
return '' if rand <= ProjectData.instance.get(:threshold)
|
50
50
|
|
51
51
|
keys = @world.image_urls.keys
|
52
52
|
keys.shuffle!
|
@@ -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,31 +3,23 @@
|
|
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.0' # Application version
|
12
|
-
NAME = 'asker' # Application name
|
13
|
-
HOMEPAGE = "https://github.com/dvarrui/#{NAME}/tree/v2.2"
|
14
|
-
GEM = 'asker-tool' # Gem name
|
15
|
-
CONFIGFILE = 'asker.ini' # Config filename
|
16
11
|
attr_reader :config
|
17
12
|
|
18
|
-
##
|
19
|
-
# Initialize Application singleton
|
20
13
|
def initialize
|
21
14
|
reset
|
22
15
|
end
|
23
16
|
|
24
|
-
##
|
25
|
-
# Initialize config values from external "config.ini" file.
|
26
|
-
# rubocop:disable Metrics/AbcSize
|
27
|
-
# rubocop:disable Metrics/MethodLength
|
28
17
|
def reset
|
29
|
-
filename = File.join(Dir.pwd,
|
30
|
-
|
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
|
31
23
|
|
32
24
|
begin
|
33
25
|
@config = IniFile.load(filename)
|
@@ -42,6 +34,4 @@ class Application
|
|
42
34
|
Rainbow.enabled = false
|
43
35
|
Rainbow.enabled = true if @config['global']['color'].downcase == 'yes'
|
44
36
|
end
|
45
|
-
# rubocop:enable Metrics/MethodLength
|
46
|
-
# rubocop:enable Metrics/AbcSize
|
47
37
|
end
|
@@ -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
|