code_terminator 0.5.2 → 0.5.3

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.
@@ -0,0 +1,657 @@
1
+ require 'active_support/core_ext/string/filters'
2
+
3
+ class CodeTerminator::Html
4
+
5
+ def initialize(args = {})
6
+ @code = args[:code]
7
+ @source = args[:source]
8
+ @tags = Array.new
9
+ @elements = Array.new
10
+
11
+ args[:source_type] ||= "file"
12
+ @source_type = args[:source_type]
13
+ end
14
+
15
+ # Create a Html file with the code of the editor. Return a boolean that indicate if the file was created or not.
16
+ #
17
+ # Example:
18
+ # >> CodeTerminator::Html.new_file("hola_mundo.html", "<h1>Hola Mundo!</h1>")
19
+ # => true
20
+ #
21
+ # Arguments:
22
+ # source: (String)
23
+ # code: (String)
24
+
25
+ def new_file(source,code)
26
+ fileHtml = File.new(source, "w+")
27
+ result = true
28
+ begin
29
+ fileHtml.puts code
30
+ rescue
31
+ result = false
32
+ ensure
33
+ fileHtml.close unless fileHtml.nil?
34
+ end
35
+ #return true if file was succesfully created
36
+ result
37
+ end
38
+
39
+
40
+ # Get html elements of a html file. Return a list of Nokogiri XML objects.
41
+ #
42
+ # Example:
43
+ # >> CodeTerminator::Html.get_elements("hola_mundo.html")
44
+ # => [#<Nokogiri::XML::Element:0x3fe3391547d8 name="h1" children=[#<Nokogiri::XML::Text:0x3fe33915474c "Hola Mundo!">]>, #<Nokogiri::XML::Text:0x3fe33915474c "Hola Mundo!">]
45
+ #
46
+ # Arguments:
47
+ # source: (String)
48
+
49
+ def get_elements(source)
50
+ @elements = Array.new
51
+ #How to read if is an url
52
+ if @source_type == "url"
53
+ reader = Nokogiri::HTML(open(source).read)
54
+ else
55
+ reader = Nokogiri::HTML(File.open(source))
56
+ end
57
+ #remove empty spaces from reader
58
+ reader = remove_empty_text(reader)
59
+ node = Hash.new
60
+ node[:parent] = ""
61
+ node[:tag] = "html"
62
+ @elements << node
63
+
64
+ #search elements from body section
65
+ if reader.at('body')
66
+ node = Hash.new
67
+ node[:parent] = "html"
68
+ node[:tag] = "body"
69
+ @elements << node
70
+
71
+ reader.at('body').attribute_nodes.each do |element_attribute|
72
+ node = Hash.new
73
+ node[:parent] = "html"
74
+ node[:tag] = "body"
75
+ node[:attribute] = element_attribute.name if element_attribute.name
76
+ node[:value] = element_attribute.value if element_attribute.value
77
+ node[:pointer] = element_attribute.pointer_id
78
+ @elements << node
79
+ end
80
+ end
81
+ #end search
82
+
83
+ #search elements from head section
84
+ if reader.at('head')
85
+ node = Hash.new
86
+ node[:parent] = "html"
87
+ node[:tag] = "head"
88
+ @elements << node
89
+ reader.at('head').children.each do |child|
90
+ if child.attribute_nodes.empty?
91
+ node = Hash.new
92
+ node[:parent] = "head"
93
+ node[:tag] = child.name
94
+ node[:content] = child.text if child.text or child.comment?
95
+ node[:pointer] = child.pointer_id
96
+ node[:parent_pointer] = child.parent.pointer_id
97
+
98
+ @elements << node
99
+ else
100
+ child.attribute_nodes.each do |element_attribute|
101
+ node = Hash.new
102
+ node[:parent] = "head"
103
+ if child.name == "#cdata-section"
104
+ node[:tag] = "text"
105
+ else
106
+ node[:tag] = child.name
107
+ end
108
+ # node[:tag] = ( ? "text", child.name)
109
+ node[:content] = child.text if !child.text.nil?
110
+ node[:attribute] = element_attribute.name if element_attribute.name
111
+ node[:value] = element_attribute.value if element_attribute.value
112
+ node[:pointer] = element_attribute.pointer_id
113
+ node[:parent_pointer] = child.pointer_id
114
+ @elements << node
115
+ end
116
+ end
117
+ add_children(child) if child.children.any?
118
+ end
119
+ end
120
+ #end search elements
121
+
122
+ #search elements inside body (children)
123
+ if reader.at('body')
124
+ reader.at('body').children.each do |child|
125
+ if child.attribute_nodes.empty?
126
+ node = Hash.new
127
+ node[:parent] = "body"
128
+ node[:tag] = child.name
129
+ node[:content] = child.text if child.text? or child.comment?
130
+ node[:pointer] = child.pointer_id
131
+ node[:parent_pointer] = child.parent.pointer_id
132
+ @elements << node
133
+ else
134
+ child.attribute_nodes.each do |element_attribute|
135
+ node = Hash.new
136
+ node[:parent] = "body"
137
+ node[:tag] = child.name
138
+ node[:attribute] = element_attribute.name if element_attribute.name
139
+ node[:value] = element_attribute.value if element_attribute.value
140
+ node[:pointer] = element_attribute.pointer_id
141
+ node[:parent_pointer] = child.pointer_id
142
+ @elements << node
143
+ end
144
+ end
145
+ add_children(child) if child.children.any?
146
+ end
147
+ end
148
+ #end search elements
149
+
150
+ @elements
151
+ end
152
+
153
+ # Validate if the syntax is correct. Return an array with Nokogiri errors.
154
+ #
155
+ # Example:
156
+ # >> CodeTerminator::Html.validate_syntax("<h1>Hola Mundo!</h1")
157
+ # => [#<Nokogiri::XML::SyntaxError: expected '>'>]
158
+ #
159
+ # Arguments:
160
+ # code: (String)
161
+
162
+ def validate_syntax(code)
163
+ errors = Array.new
164
+
165
+ begin
166
+ Nokogiri::XML(code) { |config| config.strict }
167
+
168
+ #validate if html follow w3, uncomment when check all the page
169
+ #"<!DOCTYPE html>
170
+ # <html>
171
+ # <head>
172
+ # <h1>asdasd</h1>
173
+ # <title>asdasd</title>
174
+ # </head>
175
+ # <body>
176
+ # <h1>hola</h1>
177
+ # </body>
178
+ # </html>"
179
+ # @validator = Html5Validator::Validator.new
180
+ # @validator.validate_text(@html)
181
+
182
+ rescue Nokogiri::XML::SyntaxError => e
183
+ #errors[0] = "Check if you close your tags"
184
+ errors[0] = e
185
+ end
186
+
187
+ errors
188
+ end
189
+
190
+ # Read a html file. Return the text of the file.
191
+ #
192
+ # Example:
193
+ # >> CodeTerminator::Html.read_file("hola_mundo.html")
194
+ # => "<h1>Hola Mundo!</h1>\n"
195
+ #
196
+ # Arguments:
197
+ # source: (String)
198
+
199
+ def read_file(source)
200
+ if @source_type == "url"
201
+ fileHtml = open(source).read
202
+ else
203
+ fileHtml = File.open(source, "r")
204
+ end
205
+
206
+ text = ""
207
+ begin
208
+ fileHtml.each_line do |line|
209
+ text << line
210
+ end
211
+ fileHtml.close
212
+ rescue
213
+ text = false
214
+ ensure
215
+ #fileHtml.close unless fileHtml.nil?
216
+ end
217
+
218
+ text
219
+ end
220
+
221
+ # Get the elements of the code in html format. Return a string with elements in html.
222
+ #
223
+ # Example:
224
+ # >> CodeTerminator::Html.print_elements("exercises/hola_mundo.html" )
225
+ # => "name = h1<br><hr>name = text<br>content = hola mundo<br><hr>"
226
+ #
227
+ # Arguments:
228
+ # elements: (Array)
229
+
230
+ def print_elements(elements)
231
+ text = ""
232
+ elements.each do |child|
233
+ text << "parent = " + child[:parent] + "<br>" if child[:parent]
234
+ text << "tag = " + child[:tag] + "<br>" if child[:tag]
235
+ text << "attribute = " + child[:attribute] + "<br>" if child[:attribute]
236
+ text << "value = " + child[:value] + "<br>" if child[:value]
237
+ text << "content = " + child[:content] + "<br>" if child[:content]
238
+ text << "<hr>"
239
+ end
240
+ text
241
+ end
242
+
243
+ # Get the instructions to recreate the html code. Return an array with strings .
244
+ #
245
+ # Example:
246
+ # >> CodeTerminator::Html.get_instructions(file.get_elements("exercises/test.html"))
247
+ # => ["Add the tag h2 in body", "Add the tag text in h2 with content 'hola test' ", "Add the tag p in body"]
248
+ #
249
+ # Arguments:
250
+ # instructions: (Array)
251
+
252
+ def get_instructions(source)
253
+ elements = get_elements(source)
254
+ text = ""
255
+ instructions = Array.new
256
+ elements.each do |child|
257
+ if child[:tag]!="text"
258
+ text << "Add the tag " + child[:tag]
259
+ text << " in " + child[:parent] if !child[:parent].nil?
260
+ text << " with an attribute '" + child[:attribute] + "' " if !child[:attribute].nil?
261
+ text << " with value '" + child[:value] + "' " if !child[:value].nil?
262
+ elsif child[:tag] == "comment"
263
+ text << " In " + child[:tag]+ " add the text '" + child[:content] + "' " if !child[:content].nil?
264
+ else
265
+ text << " In " + child[:parent]+ " add the text '" + child[:content] + "' " if !child[:content].nil?
266
+ end
267
+ instructions.push(text)
268
+ text = ""
269
+ end
270
+ instructions
271
+ end
272
+
273
+
274
+
275
+ # Match if the code have the same elements than the exercise. Return an array with the mismatches.
276
+ #
277
+ # Example:
278
+ #
279
+ # hola_mundo.html
280
+ # => <h1>Hola Mundo!</h1>
281
+ #
282
+ # >> CodeTerminator::Html.match("hola_mundo.html","<h2>Hola Mundo!</h2>")
283
+ # => ["h1 not exist"]
284
+ #
285
+ # Arguments:
286
+ # source: (String)
287
+ # code: (String)
288
+
289
+ def match(source, code)
290
+ @html_errors = Array.new
291
+ html_errors = @html_errors
292
+
293
+ code = Nokogiri::HTML(code)
294
+
295
+ elements = get_elements(source)
296
+
297
+ css_code_checked = Array.new
298
+
299
+ exist_in_body = Array.new
300
+
301
+ error_elements = Array.new
302
+
303
+
304
+ error333 = nil
305
+
306
+ elements.each do |e|
307
+ error_count = 0
308
+
309
+ item = e[:tag]
310
+
311
+ if item == "text" or item == "comment"
312
+ # Check the text
313
+ if e[:content]
314
+ if code.css(e[:parent]).count < 2
315
+ if code.css(e[:parent]).class == Nokogiri::XML::NodeSet
316
+ #look for children elements with texts or comments
317
+ look_comment_or_text(code,e)
318
+ end
319
+ else
320
+ #check if parent tag of the user code has text apart from the children tags
321
+ look_parent_text(code,e)
322
+ end
323
+ end
324
+ #end if content is null
325
+
326
+ else
327
+ #item class is different to text or comment
328
+
329
+ if code.css(e[:tag]).length > 0
330
+
331
+ # error_elements = Array.new
332
+
333
+ code.css(e[:tag]).each do |tag|
334
+
335
+ p "code original css + " + e[:tag].to_s
336
+ p "pointer original element " + e[:pointer].to_s
337
+ p "pointer element code " + tag.pointer_id.to_s
338
+
339
+ e_check = css_code_checked.select {|element| element[:target_pointer].to_s == e[:pointer].to_s }
340
+ p "echeck " + e_check.to_s
341
+ e_check2 = css_code_checked.select {|element| element[:pointer].to_s == tag.pointer_id.to_s }
342
+ #e_check3 = css_code_checked.select {|element| element[:target_parent_pointer].to_s == e[:parent_pointer].to_s }
343
+
344
+ # e_check_exist = css_code_checked.select {|element| element[:pointer].to_s == tag.pointer_id.to_s && element[:target_pointer].to_s == e[:pointer]}
345
+ # e_check_2_exist = css_code_checked.select {|element| element[:pointer].to_s == tag.pointer_id.to_s && element[:target_pointer].to_s != e[:pointer]}
346
+ # e_check_3_exist = css_code_checked.select {|element| element[:pointer].to_s == tag.pointer_id.to_s && element[:target_pointer].to_s != e[:pointer]}
347
+
348
+ # p "check1 " + e_check_exist.to_s
349
+ # p "check2 " + e_check_2_exist.to_s
350
+ #si el target pointer- pointer no esta en la lista de check agregar,
351
+ #si es target-pointer que ya existe + otro pointer da error,
352
+ #si es target-pointer y si esta, hacer nada.
353
+ #si pointer ya esta en la lista hacer nada
354
+ #look for same tags in code
355
+ # p elements.select {|x| x[:tag].to_s == e[:tag].to_s }
356
+ if css_code_checked.select {|element| element[:target_pointer].to_s == e[:pointer].to_s }.count == 0
357
+ if elements.select {|x| x[:tag].to_s == e[:tag].to_s }.count > 1
358
+ if e_check.count == 0 && e_check2.count == 0
359
+ element_checked = Hash.new
360
+ element_checked[:pointer] = tag.pointer_id
361
+ element_checked[:tag] = e[:tag]
362
+ element_checked[:target_pointer] = e[:pointer]
363
+ element_checked[:target_parent_pointer] = e[:parent_pointer]
364
+ css_code_checked << element_checked
365
+ p "code_checked " + css_code_checked
366
+ elsif (e_check.count == 1) || (e_check2.count == 1 && e_check.count == 0)
367
+ error_count += 1
368
+
369
+ # html_errors << new_error(element: e, type: 440, description: "Remember to add the `<#{e[:tag]}>` tag inside `<#{e[:parent]}>`")
370
+ # p "css code list " + css_code_checked.to_s
371
+ # if css_code_checked.select {|element| element[:pointer].to_s == tag.pointer_id.to_s }
372
+ #
373
+ # end
374
+ # elsif e_check_exist.count == 1
375
+ # html_errors << new_error(element: e, type: 440, description: "Remember to add the `<#{e[:tag]}>` tag inside `<#{e[:parent]}>`")
376
+ end
377
+ end
378
+ # e_check_exist = nil
379
+ end
380
+ # if tag
381
+ # if tag.respond_to? :parent
382
+ # p "check if exists in parent tags"
383
+ # p e_check4 = css_code_checked.select {|element| element[:pointer].to_s == e[:pointer].to_s }
384
+ # p e_check5 = css_code_checked.select {|element| element[:target_parent_pointer].to_s == e[:parent_pointer].to_s }
385
+ # if (tag.count < 2 && tag.first) or (e_check4.count < 1 && e_check5.count < 1)
386
+ # if tag.parent.name != e[:parent]
387
+ # html_errors << new_error(element: e, type: 440, description: "Remember to add the `<#{e[:tag]}>` tag inside `<#{e[:parent]}>`")
388
+ # end
389
+ # else
390
+ # exist_in_parent = false
391
+ # tag.each do |code_css|
392
+ # exist_in_parent = true if code_css.parent.name == e[:parent]
393
+ # end
394
+ # html_errors << new_error(element: e, type: 440, description: "Remember to add the `<#{e[:tag]}>` tag inside `<#{e[:parent]}>`") if !exist_in_parent
395
+ # end
396
+ # end
397
+ # end
398
+
399
+
400
+ if e_check.count < 1 and e_check2.count < 1
401
+
402
+ element_checked = Hash.new
403
+ element_checked[:pointer] = tag.pointer_id
404
+ element_checked[:tag] = e[:tag]
405
+ element_checked[:target_pointer] = e[:pointer]
406
+ element_checked[:target_parent_pointer] = e[:parent_pointer]
407
+
408
+
409
+ if e[:attribute]
410
+ # Check the tag's attributes
411
+ if tag.attribute(e[:attribute]).nil?
412
+ html_errors << new_error(element: e, type: 334, description: "`<#{e[:tag]}>` should have an attribute named #{e[:attribute]}")
413
+ else
414
+ if tag.attribute(e[:attribute]).value != e[:value]
415
+ exist_in_body << false
416
+ # p "type " + e[:tag] + " with attribute " + e[:attribute] + " value " + e[:value]
417
+ # Check if the img have attribute src and value is null, the user can write whatever image he wants
418
+ if !(e[:tag] == "img" && e[:attribute] == "src" && e[:value] == "")
419
+ error333 = new_error(element: e, type: 333, description: "Make sure that the attribute #{e[:attribute]} in `<#{e[:tag]}>` has the value #{e[:value]}")
420
+ end
421
+ else
422
+ p "add code_checked"
423
+ css_code_checked << element_checked
424
+ exist_in_body << true
425
+ end
426
+
427
+ end
428
+
429
+ end #if element checked
430
+
431
+ end
432
+
433
+
434
+ # p "respond" + tag.parent.to_s
435
+ # Check that tags exist within parent tags
436
+ if tag.first.respond_to? :parent
437
+
438
+ p "check if exists in parent tags"
439
+
440
+ e_check4 = css_code_checked.select {|element| element[:pointer].to_s == e[:pointer].to_s }
441
+ e_check5 = css_code_checked.select {|element| element[:target_parent_pointer].to_s == e[:parent_pointer].to_s }
442
+
443
+ if (tag.count < 2 && tag.first) or (e_check4.count < 1 && e_check5.count < 1)
444
+ if tag.first.parent.name != e[:parent]
445
+ html_errors << new_error(element: e, type: 440, description: "Remember to add the `<#{e[:tag]}>` tag inside `<#{e[:parent]}>`")
446
+ end
447
+ else
448
+ exist_in_parent = false
449
+ tag.each do |code_css|
450
+ exist_in_parent = true if code_css.parent.name == e[:parent]
451
+ end
452
+ html_errors << new_error(element: e, type: 440, description: "Remember to add the `<#{e[:tag]}>` tag inside `<#{e[:parent]}>`") if !exist_in_parent
453
+ end
454
+ end
455
+
456
+
457
+ end
458
+
459
+
460
+ else
461
+ "pasa else"
462
+ # Check that the tag is present
463
+ # p "check if exists in parent"
464
+ e_check4 = css_code_checked.select {|element| element[:pointer].to_s == e[:pointer].to_s }
465
+ e_check5 = css_code_checked.select {|element| element[:target_parent_pointer].to_s == e[:parent_pointer].to_s }
466
+ if code.at_css(e[:tag]).nil? or e_check4.count < 1 and e_check5.count < 1
467
+ html_errors << new_error(element: e, type: 404, description: "Remember to add the `<#{e[:tag]}>` tag")
468
+ end
469
+ end
470
+
471
+ if exist_in_body && !exist_in_body.include?(true) && error333
472
+ html_errors << error333
473
+ end
474
+ exist_in_body = []
475
+
476
+ end
477
+ # p "code checked" + css_code_checked.to_s
478
+ # p "errors = " + error_elements.to_s
479
+ # # errors_x = error_elements.group_by{|k,v| v}
480
+ # error_elements.each do |error|
481
+ # p error.to_s
482
+ # e_check_errors = css_code_checked.select {|element| element[:pointer].to_s == error[:pointer].to_s}
483
+ # # p e_check_errors = css_code_checked.select {|element| element[:pointer].to_s == error[:pointer].to_s && element[:target_pointer].to_s == error[:e][:pointer].to_s}
484
+ #
485
+ # # e_check2_errors = css_code_checked.select {|element| element[:target_pointer].to_s == error[:e][:pointer].to_s }
486
+ # if e_check_errors.count < 1
487
+ # html_errors << new_error(element: error[:e], type: 404, description: "Remember to add the `<#{error[:e][:tag]}>` tag")
488
+ # end
489
+ # end
490
+
491
+ p "count " + error_count.to_s
492
+ end
493
+ html_errors
494
+
495
+ end
496
+
497
+ private
498
+
499
+ def add_children(parent)
500
+ parent.children.each do |child|
501
+ if child.attribute_nodes.empty?
502
+ node = Hash.new
503
+ node[:parent] = parent.name
504
+ # node[:tag] = child.name
505
+ if child.name == "#cdata-section"
506
+ node[:tag] = "text"
507
+ else
508
+ node[:tag] = child.name
509
+ end
510
+ node[:content] = child.text if !child.text.nil? and child.class!=Nokogiri::XML::Element
511
+ node[:pointer] = child.pointer_id
512
+ node[:parent_pointer] = child.parent.pointer_id
513
+ @elements << node
514
+ else
515
+ child.attribute_nodes.each do |element_attribute|
516
+ node = Hash.new
517
+ node[:parent] = parent.name
518
+ # node[:tag] = child.namecode
519
+ if element_attribute.name == "#cdata-section"
520
+ node[:tag] = "text"
521
+ elsif element_attribute.name == "href"
522
+ node[:tag] = child.name
523
+ else
524
+ node[:tag] = element_attribute.name
525
+ end
526
+ node[:attribute] = element_attribute.name if !element_attribute.name.nil?
527
+ node[:value] = element_attribute.value if !element_attribute.value.nil?
528
+ node[:pointer] = element_attribute.pointer_id
529
+ node[:parent_pointer] = child.pointer_id
530
+ @elements << node
531
+ end
532
+ end
533
+
534
+ add_children(child) if child.children.any?
535
+ end
536
+ end
537
+
538
+ def remove_empty_text (reader)
539
+ if reader.at('head')
540
+ reader.at('head').children.each do |child|
541
+ if child.text
542
+ child.remove if child.content.to_s.squish.empty? && child.class == Nokogiri::XML::Text
543
+ end
544
+ check_children(child) if child.children.any?
545
+ end
546
+ end
547
+ if reader.at('body')
548
+ reader.at('body').children.each do |child|
549
+ if child.text
550
+ child.remove if child.content.to_s.squish.empty? && child.class == Nokogiri::XML::Text
551
+ end
552
+ check_children(child) if child.children.any?
553
+ end
554
+ end
555
+ reader
556
+ end
557
+
558
+ def check_children(parent)
559
+ parent.children.each do |child|
560
+ if child.text
561
+ child.remove if child.content.to_s.squish.empty? && child.class == Nokogiri::XML::Text
562
+ end
563
+ check_children(child) if child.children.any?
564
+ end
565
+ end
566
+
567
+ def new_error(args = {})
568
+ element = args[:element]
569
+ type = args[:type]
570
+ description = args[:description]
571
+ node = Hash.new
572
+ node[:element] = element
573
+ node[:type] = type
574
+ node[:description] = description
575
+ node
576
+ end
577
+
578
+
579
+ #methods of match
580
+ def look_comment_or_text(code,e)
581
+ error330 = nil
582
+ text_found = false
583
+ @comment_found = false if e[:tag] == "comment"
584
+
585
+ #look for comments or text in code
586
+ #code, e
587
+ if code.css(e[:parent]).children.any?
588
+ #look for comments and text in children of body
589
+ # code, e
590
+ #save
591
+ #return
592
+ code.css(e[:parent]).children.each do |node_child|
593
+ #if class of the node is a comment, look in the code
594
+ # @e, node_child
595
+ #save error330
596
+ #return true (flag)
597
+ if node_child.class == Nokogiri::XML::Comment
598
+ error330 = new_error(element: e, type: 330, description: "The text inside the comment should be #{e[:content]}") if e[:content].strip != "" && node_child.text.strip! != e[:content].strip!
599
+ @comment_found = true
600
+ end
601
+
602
+ #if class of node is text and element is not a comment
603
+ #@e, node_child
604
+ #save a error330, text_found
605
+ #return true (flag)
606
+ if node_child.class == Nokogiri::XML::Text && e[:content] != "comment"
607
+ node_child.text.strip != e[:content].strip ? error330 = new_error(element: e, type: 330, description: "The text inside `<#{e[:parent]}>` should be #{e[:content]}") : text_found = true
608
+ end
609
+ end #each
610
+
611
+ else
612
+ #validate if comment exist and has the expected content in body
613
+ #code, @e
614
+ #save @comment_found, text_found
615
+ if code.css(e[:parent]).text.strip != e[:content].strip
616
+ if e[:tag] == "comment"
617
+ error330 = new_error(element: e, type: 330, description: "The text inside the comment should be #{e[:content]}")
618
+ @comment_found = true
619
+ else
620
+ error330 = new_error(element: e, type: 330, description: "The text inside `<#{e[:parent]}>` should be #{e[:content]}")
621
+ end
622
+ else
623
+ text_found = true
624
+ end
625
+ end #end if parent has children
626
+
627
+ #throw errors of comment or text
628
+ #if comment not found, throw error
629
+ if (defined? @comment_found) && !@comment_found
630
+ @html_errors << new_error(element: e, type: 404, description: "Remember to add the comment tag")
631
+ remove_instance_variable(:@comment_found) if !@comment_found
632
+ end
633
+
634
+ if !text_found && error330
635
+ @html_errors << error330
636
+ error330 = nil
637
+ end
638
+ #end throw errors
639
+ end #end look_comment_or_text
640
+
641
+ def look_parent_text(code,e)
642
+ exist = false
643
+ #look for text in parent, if found check flag true
644
+ code.css(e[:parent]).each do |code_css|
645
+ if code_css.text == e[:content]
646
+ exist = true
647
+ end
648
+ end
649
+ if !exist
650
+ @html_errors << new_error(element: e, type: 330, description: "The text inside `<#{e[:parent]}>` should be #{e[:content]}")
651
+ end
652
+ end
653
+
654
+
655
+ #end
656
+
657
+ end
@@ -1,3 +1,3 @@
1
1
  module CodeTerminator
2
- VERSION = "0.5.2"
2
+ VERSION = "0.5.3"
3
3
  end