code_terminator 0.5.5 → 0.5.6

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
  SHA1:
3
- metadata.gz: 69aeb452b012e5dc968c16d8c681cbf4fecf7f66
4
- data.tar.gz: 46ee19a648f0e36810939a865a720e9c26398d68
3
+ metadata.gz: e8616d6be2d7e6877e6722e3cb0faf9b4be699fd
4
+ data.tar.gz: 261e03e5d01a646653eb7d3202202c66d272fc6c
5
5
  SHA512:
6
- metadata.gz: aff1e3b6f3dda1b7334d8cdc58eff28429f4c32b221a144113a8687c17c95f8d155cb112a7e81e2e9732934f070b2ebb048baabbcb58b346114620fe10007ef1
7
- data.tar.gz: 0cf2eb1b7efb088d79856de00f72d05133b5d8c0d6062f366e06c1910b1709aad9b3591b7067d468235ca71c722c54aa1490f51167b59b63a0f411571b0673b8
6
+ metadata.gz: f2d107298c0cf414e01edb594af73d21425c141be949d51439be1056cb899e489d798f3315133c7fd2dd07191614ca2df603e8416c8f4578bad428c1ec31335d
7
+ data.tar.gz: 0cb8ea6db083a884cd12bc9bba9d8df39afdb34dc6f1e7ef5115fbc004ead06b15209458662fe34ed61c6a9d59e9a82bc924454e60490e8bace2599d92ad744e
@@ -131,6 +131,13 @@ class CodeTerminator::Html
131
131
  node[:parent_pointer] = child.parent.pointer_id
132
132
  @elements << node
133
133
  else
134
+ node = Hash.new
135
+ node[:parent] = "body"
136
+ node[:tag] = child.name
137
+ node[:content] = child.text if child.text? or child.comment?
138
+ node[:pointer] = child.pointer_id
139
+ node[:parent_pointer] = child.parent.pointer_id
140
+ @elements << node
134
141
  child.attribute_nodes.each do |element_attribute|
135
142
  node = Hash.new
136
143
  node[:parent] = "body"
@@ -296,6 +303,7 @@ class CodeTerminator::Html
296
303
 
297
304
 
298
305
  exist_in_body = Array.new
306
+ exist_value = Array.new
299
307
 
300
308
  error_elements = Array.new
301
309
 
@@ -308,15 +316,25 @@ class CodeTerminator::Html
308
316
 
309
317
 
310
318
  elements.each do |e|
311
-
312
- if elements_count.select {|element| element[:parent_pointer].to_s == e[:parent_pointer].to_s && element[:tag].to_s == e[:tag]}.count < 1
313
- error_element = Hash.new
314
- error_element[:tag] = e[:tag]
315
- error_element[:pointer] = e[:pointer]
316
- error_element[:parent_pointer] = e[:parent_pointer]
317
- error_element[:count] = 0
318
- elements_count << error_element
319
- end
319
+ p "element " + e.to_s
320
+ p "select ---"
321
+ # p elements_count
322
+
323
+ if e[:attribute].nil?
324
+ #tag con el mismo parent pointer no se repite ni se cuenta
325
+ # p "element count"
326
+ # elements_count.select {|element| element[:parent_pointer].to_s == e[:parent_pointer].to_s && element[:tag].to_s == e[:tag]}
327
+
328
+
329
+ # if elements_count.select {|element| element[:parent_pointer].to_s == e[:parent_pointer].to_s && element[:tag].to_s == e[:tag]}.count < 1
330
+ the_element = Hash.new
331
+ the_element[:tag] = e[:tag]
332
+ the_element[:pointer] = e[:pointer]
333
+ the_element[:parent_pointer] = e[:parent_pointer]
334
+ the_element[:count] = 1
335
+ elements_count << the_element
336
+ # end
337
+ end
320
338
 
321
339
  item = e[:tag]
322
340
 
@@ -338,6 +356,7 @@ class CodeTerminator::Html
338
356
  #item class is different to text or comment
339
357
 
340
358
  code.css(e[:tag]).each do |tag|
359
+ p "tag " + tag.to_s
341
360
  tag_element = nil
342
361
  e_check = css_code_checked.select {|element| element[:original_pointer].to_s == e[:pointer].to_s }
343
362
  # p "echeck " + e_check.to_s
@@ -351,9 +370,22 @@ class CodeTerminator::Html
351
370
  check_original_pointer = css_code_checked.select {|element| element[:original_pointer].to_s == e[:pointer].to_s }
352
371
 
353
372
  check_add_pointer = css_code_checked.select {|element| element[:pointer].to_s == tag.pointer_id.to_s }
354
-
373
+ # p "check_add " + check_add_pointer.to_s
355
374
  #look for same tags in code
375
+ # p "elements_count"
376
+ # p elements_count
377
+
356
378
  if check_original_pointer.count == 0
379
+ # p "pasa"
380
+ # # if tag.attributes.nil?
381
+ # # p "CON ATRIBUTOS"
382
+ # # else
383
+ # # p elements_count.to_s
384
+ # p "element " +e[:tag].to_s
385
+ # p "e pointer "+e[:pointer].to_s
386
+ # p "e parent pointer "+e[:parent_pointer].to_s
387
+
388
+ # end
357
389
  if check_add_pointer.count < 1
358
390
  element_checked = Hash.new
359
391
  element_checked[:pointer] = tag.pointer_id
@@ -362,8 +394,11 @@ class CodeTerminator::Html
362
394
  element_checked[:original_parent_pointer] = e[:parent_pointer]
363
395
  css_code_checked << element_checked
364
396
 
365
- error_element = elements_count.select {|element| element[:tag].to_s == e[:tag].to_s && element[:parent_pointer].to_s == e[:parent_pointer].to_s}.first
366
- error_element[:count] += 1
397
+ # the_element = elements_count.select {|element| element[:tag].to_s == e[:tag].to_s && element[:parent_pointer].to_s == e[:parent_pointer].to_s}.first
398
+ the_element = elements_count.select {|element| element[:tag].to_s == e[:tag].to_s && element[:pointer].to_s == e[:parent_pointer].to_s}.first
399
+
400
+ # p "the element " + the_element.to_s
401
+ the_element[:count] += 1 if the_element
367
402
  end
368
403
  end
369
404
  # end
@@ -409,13 +444,24 @@ class CodeTerminator::Html
409
444
  else
410
445
  if tag.attribute(e[:attribute]).value != e[:value]
411
446
  exist_in_body << false
412
- # p "type " + e[:tag] + " with attribute " + e[:attribute] + " value " + e[:value]
447
+ # p "value " + e[:value]
448
+ tag_attribute = tag.attribute(e[:attribute]).name
449
+ tag_attribute_value = tag.attribute(e[:attribute]).value
450
+ # p "type " + e[:tag] + " with attribute " + e[:attribute] + " value " + e[:value]
413
451
  # Check if the img have attribute src and value is null, the user can write whatever image he wants
414
- if !(e[:tag] == "img" && e[:attribute] == "src" && e[:value] == "")
415
- error333 = new_error(element: e, type: 333, description: "Make sure that the attribute #{e[:attribute]} in `<#{e[:tag]}>` has the value #{e[:value]}")
452
+ # p exist_value
453
+ if !(e[:tag] == "img" && (e[:attribute] == tag_attribute) && e[:value] == "")
454
+ if (!exist_value.include? tag_attribute_value and !exist_value.include? e[:value])
455
+ exist_in_body << false
456
+ error333 = new_error(element: e, type: 333, description: "Make sure that the attribute #{e[:attribute]} in `<#{e[:tag]}>` has the value #{e[:value]}")
457
+ end
458
+ # html_errors << error333 if error333
459
+ else
460
+
416
461
  end
417
462
  else
418
463
  # p "add code_checked"
464
+ exist_value << e[:value]
419
465
  # css_code_checked << element_checked
420
466
  exist_in_body << true
421
467
  end
@@ -427,7 +473,7 @@ class CodeTerminator::Html
427
473
  # Check that tags exist within parent tags
428
474
  if tag.first.respond_to? :parent
429
475
 
430
- p "check if exists in parent tags"
476
+ # p "check if exists in parent tags"
431
477
 
432
478
  # e_check4 = css_code_checked.select {|element| element[:pointer].to_s == e[:pointer].to_s }
433
479
  # e_check5 = css_code_checked.select {|element| element[:target_parent_pointer].to_s == e[:parent_pointer].to_s }
@@ -453,31 +499,66 @@ class CodeTerminator::Html
453
499
 
454
500
  # end #end tag
455
501
 
456
-
457
502
  if exist_in_body && !exist_in_body.include?(true) && error333
458
503
  html_errors << error333
459
504
  end
505
+
506
+ # if exist_in_body && !exist_in_body.include?(true) && error333
507
+ # html_errors << error333
508
+ # end
509
+
460
510
  exist_in_body = []
511
+ error333 = nil
512
+ # exist_value = []
461
513
 
462
514
  end
463
515
 
464
516
  end
465
517
 
466
- # p elements_count.to_s
518
+ # p "elements_count = " + elements_count.group_by{|h| h[:parent_pointer]}.to_s
519
+
520
+ # p "elements_count2 = "
521
+ grouped_elements = elements_count.select {|element| element[:count] > 0}.group_by { |s| [s[:parent_pointer], s[:tag]] }
467
522
 
468
- elements_count.each do |x|
523
+ grouped_elements.each do |x|
469
524
  #filtrar por parent
470
- # tag_count = code.css(x[:tag]).length
471
- tag_count = elements.select {|element| element[:parent_pointer].to_s == x[:parent_pointer].to_s && element[:tag].to_s == x[:tag]}.count
525
+ #tag_count = code.css(x[:tag]).length
526
+ tag_count = elements.select {|element| element[:parent_pointer].to_s == x[0][0].to_s && element[:tag].to_s == x[0][1]}
527
+ # p "group="+tag_count.group_by{|h| h[:parent_pointer]}.values.to_s
528
+ # p result=Hash[tag_count.group_by{|x|x}.map{|k,v| [k,v.size]}]
529
+ p "tag" + x.to_s
530
+ p "tag count " + tag_count.count.to_s
531
+ p "grouped" + x.to_s
532
+ p "grouped count " + x[1].first[:count].to_s
533
+ (p "div count " + x[1][0].count.to_s) if x[0][1]=="div"
534
+
535
+ # p tag_count = elements.select {|element| element[:pointer].to_s == x[:pointer].to_s && element[:tag].to_s == x[:tag]}.count
472
536
  # p x[:tag]!="body"
473
- if tag_count >= 1 && !(x[:tag]=="body" || x[:tag]=="head" || x[:tag]=="text" || x[:tag]=="comment" || x[:tag]=="img")
537
+ if tag_count.count >= 1 && !(x[0][1]=="body" || x[0][1]=="head" || x[0][1]=="text" || x[0][1]=="comment")
474
538
  # if tag_count >= 1 && !(x[:tag]!="div")
475
- if x[:count] < tag_count
476
- html_errors << new_error(element: x[:tag], type: 404, description: "Remember to add the `<#{x[:tag]}>` tag")
539
+ if x[0][1]=="div"
540
+ if x[1][0].count.to_i < tag_count.count
541
+ html_errors << new_error(element: x[0][1], type: 404, description: "Remember to add the `<#{x[0][1]}>` tag")
542
+ end
543
+ else
544
+ if x[1].first[:count] < tag_count.count
545
+ html_errors << new_error(element: x[0][1], type: 404, description: "Remember to add the `<#{x[0][1]}>` tag")
477
546
  end
547
+ end
478
548
  end
479
549
  end
480
550
 
551
+ # grouped_elements_null = elements_count.select {|element| element[:count] == 0}.group_by { |s| [s[:parent_pointer], s[:tag]] }
552
+ #
553
+ # grouped_elements_null.each do |nulls|
554
+ # if !(nulls[0][1]=="body" || nulls[0][1]=="head" || nulls[0][1]=="text" || nulls[0][1]=="comment")
555
+ # # if tag_count >= 1 && !(x[:tag]!="div")
556
+ # # if x[1].count < tag_count.count
557
+ # html_errors << new_error(element: nulls[0][1], type: 404, description: "Remember to add the `<#{nulls[0][1]}>` tag")
558
+ # # end
559
+ # end
560
+ # end
561
+ p elements_count
481
562
  html_errors
482
563
 
483
564
  end
@@ -1,3 +1,3 @@
1
1
  module CodeTerminator
2
- VERSION = "0.5.5"
2
+ VERSION = "0.5.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code_terminator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evelin Ponce
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-25 00:00:00.000000000 Z
11
+ date: 2017-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler