asker-tool 2.2.2 → 2.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a0ce9d640d7af95956ae17f28a2acdffba7ca6f31437fbf7d18b6de30d5fd73a
4
- data.tar.gz: d62bc1fd0380f141dda9e17bd11beb24da62b99be7b4eed13e5206c265589f52
3
+ metadata.gz: 04d190919a7d7b95571b648c9c265903acdeae0ca4b698139218de32cfe0ee3c
4
+ data.tar.gz: fcb0b10af1a109958c8ff04dde61ff484ffbed75443a41898b97b9d633d915f3
5
5
  SHA512:
6
- metadata.gz: 3f35ecee5e80950d66c57b039e39d9be4eb1a06b87b9fc6ca19b0cc2fa8ca99769467fba7608c55e8d1a1e408e17088723c014d8b677fad506896669e65060f1
7
- data.tar.gz: 99b0da9a849a8d78802f70b03046d98df35f936086dd2f1eeca86a3655c5b8d5b1bbd5c221c291b19db5fafc802fd6202fb117ad8dd78f2f0fd57c907d98213d
6
+ metadata.gz: 022d75e6c3d4a2fedb183e60d86d64ab3b6494decd2ca5e1e8741824947bc2e3dadc902e6f7543978666d1833a29b7305794b33a84bfcfc07da6139c95f3009f
7
+ data.tar.gz: 713a78b38a4155700ad1e11cb562638b43bbbc479d2ffa2ef9726befa1b5e6b49283795cd141aee5871a8dbd37e04652c51cd98c1e0489b0c8cfa429b2002c42
@@ -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.2'
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, CONFIGFILE)
23
- filename = File.join(File.dirname(__FILE__), 'files', CONFIGFILE) unless File.exist? filename
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)
@@ -1,8 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'rainbow'
4
+ require 'colorize'
5
+ require_relative 'check_table'
4
6
 
5
- class InputData
7
+ class CheckHamlData
8
+ include CheckTable
6
9
  attr_reader :inputs, :outputs
7
10
 
8
11
  def initialize(filepath)
@@ -33,6 +36,7 @@ class InputData
33
36
  def show_errors
34
37
  errors = 0
35
38
  # puts "Line : Error description"
39
+ puts "\n"
36
40
  @outputs.each do |i|
37
41
  next if i[:state] == :ok
38
42
 
@@ -41,16 +45,16 @@ class InputData
41
45
  data = { id: i[:id], msg: i[:msg], source: i[:source][0, 40] }
42
46
  order = i[:id] + 1
43
47
  data = { order: order, msg: i[:msg], source: i[:source][0, 40] }
44
- puts format(' %<order>03d : %<msg>s. => %<source>s', data)
48
+ print format(' %<order>03d : %<msg>32s. => '.white, data)
49
+ puts format('%<source>s'.light_yellow, data)
45
50
  end
46
51
  puts '...' if errors == 11
47
52
  end
48
53
 
49
54
  if errors.positive?
50
- puts Rainbow("[ERROR] #{errors} errors " \
51
- "from #{@inputs.size} lines!").red.bright
55
+ puts "\n[ ASKER ] Please! Revise #{errors.to_s.light_red} error/s\n"
52
56
  end
53
- puts Rainbow('Syntax OK!').green if errors.zero?
57
+ puts 'Syntax OK!'.green if errors.zero?
54
58
  end
55
59
 
56
60
  def check
@@ -167,104 +171,6 @@ class InputData
167
171
  end
168
172
  end
169
173
 
170
- def check_table(line, index)
171
- return unless @outputs[index][:state] == :none
172
- return unless line.include? '%table'
173
-
174
- @outputs[index][:type] = :table
175
- @outputs[index][:level] = 2
176
- @outputs[index][:state] = :ok
177
- if find_parent(index) != :concept
178
- @outputs[index][:state] = :err
179
- @outputs[index][:msg] = 'Parent(concept) not found!'
180
- elsif !line.start_with? ' %table'
181
- @outputs[index][:state] = :err
182
- @outputs[index][:msg] = 'Write 4 spaces before %table'
183
- end
184
- end
185
-
186
- def check_row(line, index)
187
- return unless @outputs[index][:state] == :none
188
- return unless line.include? '%row'
189
-
190
- @outputs[index][:type] = :row
191
- @outputs[index][:state] = :ok
192
-
193
- case count_spaces(line)
194
- when 6
195
- @outputs[index][:level] = 3
196
- parent = find_parent(index)
197
- unless %i[table features].include? parent
198
- @outputs[index][:state] = :err
199
- @outputs[index][:msg] = 'Parent(table/features) not found!'
200
- end
201
- when 8
202
- @outputs[index][:level] = 4
203
- if find_parent(index) != :template
204
- @outputs[index][:state] = :err
205
- @outputs[index][:msg] = 'Parent(template) not found!'
206
- end
207
- else
208
- @outputs[index][:state] = :err
209
- @outputs[index][:msg] = 'Write 6 or 8 spaces before %row'
210
- end
211
- end
212
-
213
- def check_col(line, index)
214
- return unless @outputs[index][:state] == :none
215
- return unless line.include? '%col'
216
-
217
- @outputs[index][:type] = :col
218
- @outputs[index][:state] = :ok
219
- case count_spaces(line)
220
- when 8
221
- @outputs[index][:level] = 4
222
- if find_parent(index) != :row
223
- @outputs[index][:state] = :err
224
- @outputs[index][:msg] = 'Parent(row) not found!'
225
- end
226
- when 10
227
- @outputs[index][:level] = 5
228
- if find_parent(index) != :row
229
- @outputs[index][:state] = :err
230
- @outputs[index][:msg] = 'Parent(row) not found!'
231
- end
232
- else
233
- @outputs[index][:state] = :err
234
- @outputs[index][:msg] = 'Write 8 or 10 spaces before %col'
235
- end
236
- check_text(line, index)
237
- end
238
-
239
- def check_text(line, index)
240
- return unless @outputs[index][:state] == :ok
241
-
242
- ok = ''
243
- %w[< >].each do |char|
244
- ok = char if line.include? char
245
- end
246
- return if ok == ''
247
-
248
- @outputs[index][:state] = :err
249
- @outputs[index][:msg] = "Char #{ok} not allow!"
250
- end
251
-
252
- def check_template(line, index)
253
- return unless @outputs[index][:state] == :none
254
- return unless line.include? '%template'
255
-
256
- @outputs[index][:type] = :template
257
- @outputs[index][:level] = 3
258
- @outputs[index][:state] = :ok
259
- if find_parent(index) != :table
260
- @outputs[index][:state] = :err
261
- @outputs[index][:msg] = 'Parent(concept) not found!'
262
- elsif !line.start_with? ' %template'
263
- @outputs[index][:state] = :err
264
- @outputs[index][:msg] = 'Write 6 spaces before %template'
265
- end
266
- end
267
-
268
174
  def check_code(line, index)
269
175
  return unless @outputs[index][:state] == :none
270
176
  return unless line.include? '%code'
@@ -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
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'rainbow'
4
- require_relative 'check_input/input_data'
4
+ require_relative 'check_input/check_haml_data'
5
5
 
6
6
  class CheckInput
7
7
  def initialize(verbose = true)
@@ -43,7 +43,7 @@ class CheckInput
43
43
  end
44
44
 
45
45
  def check_file_content
46
- data = InputData.new(@filepath)
46
+ data = CheckHamlData.new(@filepath)
47
47
  data.check
48
48
  data.show_errors if @verbose
49
49
  data.ok?
data/lib/asker/cli.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'rainbow'
4
4
  require 'thor'
5
- require_relative 'application'
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 "#{Application::NAME} version #{Application::VERSION}"
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
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative '../formatter/question_moodle_formatter'
4
+ require_relative '../version'
4
5
 
5
6
  # Export ConceptIA data to gift to moodlefile
6
7
  module ConceptAIMoodleExporter
@@ -13,8 +14,8 @@ module ConceptAIMoodleExporter
13
14
  file.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
14
15
  file.write("<quiz>\n")
15
16
  file.write("<!--\n#{('=' * 50)}\n")
16
- file.write(" Created by : #{Application::NAME}")
17
- file.write(" (version #{Application::VERSION})\n")
17
+ file.write(" Created by : #{Version::NAME}")
18
+ file.write(" (version #{Version::VERSION})\n")
18
19
  file.write(" File : #{project.get(:moodlename)}\n")
19
20
  file.write(" Time : #{Time.new}\n")
20
21
  file.write(" Author : David Vargas Ruiz\n")
@@ -1,18 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative '../formatter/concept_doc_formatter'
4
+ require_relative '../version'
4
5
 
5
6
  ##
6
7
  # Export Concept to Doc file
7
8
  module ConceptDocExporter
8
9
  ##
9
- # Export arrya of concepts to doc
10
- # rubocop:disable Metrics/AbcSize
11
- # rubocop:disable Metrics/MethodLength
10
+ # Export array of concepts to doc
12
11
  def self.export_all(concepts, project)
13
12
  file = File.new(project.get(:lessonpath), 'w')
14
13
  file.write('=' * 50 + "\n")
15
- file.write("Created by : #{Application::NAME} (version #{Application::VERSION})\n")
14
+ file.write("Created by : #{Version::NAME} (version #{Version::VERSION})\n")
16
15
  file.write("File : #{project.get(:lessonname)}\n")
17
16
  file.write("Time : #{Time.new}\n")
18
17
  file.write("Author : David Vargas Ruiz\n")
@@ -23,6 +22,4 @@ module ConceptDocExporter
23
22
  end
24
23
  file.close
25
24
  end
26
- # rubocop:enable Metrics/AbcSize
27
- # rubocop:enable Metrics/MethodLength
28
25
  end
@@ -2,6 +2,8 @@
2
2
 
3
3
  require_relative 'concept_ai_gift_exporter'
4
4
  require_relative 'code_gift_exporter'
5
+ require_relative '../version'
6
+ require_relative '../application'
5
7
 
6
8
  # Export Data (ConceptIA and Code) to gift to outputfile
7
9
  module DataGiftExporter
@@ -12,8 +14,8 @@ module DataGiftExporter
12
14
  def self.export_all(data, project)
13
15
  file = File.open(project.get(:outputpath), 'w')
14
16
  file.write('// ' + ('=' * 50) + "\n")
15
- file.write("// Created by : #{Application::NAME}")
16
- file.write(" (version #{Application::VERSION})\n")
17
+ file.write("// Created by : #{Version::NAME}")
18
+ file.write(" (version #{Version::VERSION})\n")
17
19
  file.write("// File : #{project.get(:outputname)}\n")
18
20
  file.write("// Time : #{Time.new}\n")
19
21
  file.write("// Author : David Vargas Ruiz\n")
@@ -5,9 +5,6 @@ require_relative 'haml_loader'
5
5
 
6
6
  # Methods that load a filename and return list of concepts
7
7
  module FileLoader
8
- ##
9
- # Load asker data from file
10
- # @param filename (String) File name to be load
11
8
  def self.load(filename)
12
9
  if File.extname(filename).casecmp('.haml').zero?
13
10
  file_content = HamlLoader.load filename
@@ -4,12 +4,16 @@ require 'haml'
4
4
 
5
5
  # HAML file loader
6
6
  module HamlLoader
7
- ##
8
- # Load HAML file name
9
- # @param filename (String) HAML file name
10
7
  def self.load(filename)
11
8
  template = File.read(filename)
12
- haml_engine = Haml::Engine.new(template)
13
- haml_engine.render
9
+ begin
10
+ haml_engine = Haml::Engine.new(template)
11
+ return haml_engine.render
12
+ rescue StandardError => e
13
+ puts "[ERROR] HamlLoader: Can't load <#{filename}> file!"
14
+ puts " => #{e}"
15
+ exit 0
16
+ end
14
17
  end
18
+
15
19
  end
data/lib/asker/logger.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'singleton'
4
- require_relative 'application'
4
+ require_relative 'version'
5
5
 
6
6
  # Display and log project messages
7
7
  class Logger
@@ -33,8 +33,8 @@ class Logger
33
33
  def self.create(logpath, logname)
34
34
  @logfile = File.open(logpath, 'w')
35
35
  @logfile.write('=' * 50 + "\n")
36
- @logfile.write("Created by : #{Application::NAME}")
37
- @logfile.write(" (version #{Application::VERSION})\n")
36
+ @logfile.write("Created by : #{Version::NAME}")
37
+ @logfile.write(" (version #{Version::VERSION})\n")
38
38
  @logfile.write("File : #{logname}\n")
39
39
  @logfile.write("Time : #{Time.new}\n")
40
40
  @logfile.write("Author : David Vargas Ruiz\n")
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'fileutils'
4
4
  require 'rainbow'
5
- require_relative 'application'
5
+ require_relative 'version'
6
6
 
7
7
  # Skeleton: create skeleton for asker input files
8
8
  # * create
@@ -34,8 +34,8 @@ module Skeleton
34
34
  # Create default configuration files
35
35
  def self.create_configuration
36
36
  puts "\n[INFO] Creating configuration files"
37
- src = File.join(File.dirname(__FILE__), 'files', Application::CONFIGFILE)
38
- dst = File.join(Application::CONFIGFILE)
37
+ src = File.join(File.dirname(__FILE__), 'files', Version::CONFIGFILE)
38
+ dst = File.join(Version::CONFIGFILE)
39
39
  copyfile(src, dst)
40
40
  end
41
41
 
@@ -0,0 +1,9 @@
1
+
2
+ # Global parameters
3
+ module Version
4
+ VERSION = '2.2.3'
5
+ NAME = 'asker'
6
+ GEM = 'asker-tool'
7
+ CONFIGFILE = 'asker.ini'
8
+ HOMEPAGE = "https://github.com/teuton-software/#{NAME}/tree/v2.2"
9
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asker-tool
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 2.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Vargas Ruiz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-04 00:00:00.000000000 Z
11
+ date: 2022-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: haml
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: colorize
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.8'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.8'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rexml
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -171,7 +185,8 @@ files:
171
185
  - lib/asker/ai/stages/stage_t.rb
172
186
  - lib/asker/application.rb
173
187
  - lib/asker/check_input.rb
174
- - lib/asker/check_input/input_data.rb
188
+ - lib/asker/check_input/check_haml_data.rb
189
+ - lib/asker/check_input/check_table.rb
175
190
  - lib/asker/cli.rb
176
191
  - lib/asker/data/code.rb
177
192
  - lib/asker/data/column.rb
@@ -250,6 +265,7 @@ files:
250
265
  - lib/asker/loader/project_loader.rb
251
266
  - lib/asker/logger.rb
252
267
  - lib/asker/skeleton.rb
268
+ - lib/asker/version.rb
253
269
  homepage: https://github.com/teuton-software/asker/tree/v2.2
254
270
  licenses:
255
271
  - GPL-3.0
@@ -269,7 +285,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
269
285
  - !ruby/object:Gem::Version
270
286
  version: '0'
271
287
  requirements: []
272
- rubygems_version: 3.1.2
288
+ rubygems_version: 3.1.6
273
289
  signing_key:
274
290
  specification_version: 4
275
291
  summary: Asker generates questions from input definitions file.