code_terminator 0.3.0 → 0.3.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 87e6dca14dbac0d4b60af01602c73f19d2155cb1
4
- data.tar.gz: 690cd6aa18eeca2de64d86d5aadff6a081b87086
3
+ metadata.gz: 4082bd74f0e7d14d4a8d8c6292a389dbdd442729
4
+ data.tar.gz: 01c77d3f7559c715c350837b0b294466bbc27082
5
5
  SHA512:
6
- metadata.gz: 08c93b876778cd097b3de362176f257a3870e1991ad9f2eb73551c8f4d30ddeecef52b1504f6010d9204febaa2fd33896953f68dbabb2fcde299203b7d0f6825
7
- data.tar.gz: 11e944f39c5fd1fab19654fd4ad60289840662c4386d50e39e0b92bd117328b7b0ccdc8d8dc366d18b2fb321f438bbfd68b81b8e36d6524325de022846668b86
6
+ metadata.gz: 618000fcb3011b6cf2417468725e1037d172090bb860e1228ebb2bf9ab2aee35851597ecbc258080c5233167ea2be7d6520a54d67c480ac42df7f29e1846ff7f
7
+ data.tar.gz: f15697ff82365c2246f39ed2ea25645a34254782b68b81035dfc48293ddcfe931b147143801c8c4535ffd115adea3e2650c37daeb5ffe9816de0812b71ddb838
data/README.md CHANGED
@@ -50,7 +50,7 @@ You will know that the code and the source file have the same html elements when
50
50
  # <h1>Come with me if you want to live!</h1>
51
51
  #
52
52
  >> ct.match("hola_mundo.html","<h2>Come with me if you want to live!</h2>")
53
- # => ["h1 not exist"]
53
+ # => [{:element=>{:parent=>"body", :tag=>"p"}, :type=>404, :description=>"p not exist"}]
54
54
  ```
55
55
 
56
56
  ##### CSS
@@ -76,7 +76,7 @@ You will know that the code and the source file have the same css elements when
76
76
  # => h1{ margin: 100px; }
77
77
  #
78
78
  >> ct.match("test.html","h1{ margin: 50px; }")
79
- # => ["not the same property margin: 100px in selector h1"]
79
+ # => [{:element=>{:selector=>"body", :property=>"background-color", :value=>"yellow"}, :type=>111, :description=>"not the same property background-color: yellow in selector body"}]
80
80
  ```
81
81
 
82
82
  ##Cheat Sheet
@@ -92,7 +92,7 @@ Match if the code have the same elements than the exercise. Return an array with
92
92
  ```ruby
93
93
  >> ct = CodeTerminator::Html.new
94
94
  >> ct.match("hola_mundo.html","<h2>Come with me if you want to live!</h2>")
95
- # => ["h1 not exist"]
95
+ # => [{:element=>{:parent=>"body", :tag=>"p"}, :type=>404, :description=>"p not exist"}]
96
96
  #
97
97
  ```
98
98
 
@@ -104,10 +104,30 @@ Match if the code have the same elements than the exercise. Return an array with
104
104
  ```ruby
105
105
  >> ct = CodeTerminator::Css.new
106
106
  >> ct.match("hola_mundo.css","h1{ margin: 50px; }")
107
- # => ["not the same property margin: 100px in selector h1"]
107
+ # => [{:element=>{:selector=>"body", :property=>"background-color", :value=>"yellow"}, :type=>111, :description=>"not the same property background-color: yellow in selector body"}]
108
+
108
109
  #
109
110
  ```
110
111
 
112
+ ######Errors description
113
+ The errors that throw match() are in json format to help you to identify each error type as the following:
114
+ ```ruby
115
+ # [element, error_type, description]
116
+ [{:element=>{:selector=>"body", :property=>"background-color", :value=>"yellow"}, :type=>111, :description=>"not the same property background-color: yellow in selector body"}]
117
+ ```
118
+ Errors Types
119
+ <ul>
120
+ <li><b>101 : </b>Css property not found</li>
121
+ <li><b>111 : </b>Different css property in the selector</li>
122
+ <li><b>330 : </b>Different text in the html tag</li>
123
+ <li><b>333 : </b>Different value in the html attribute</li>
124
+ <li><b>334 : </b>Html attribute doesn't exist in the tag</li>
125
+ <li><b>404 : </b>Element not found</li>
126
+ <li><b>440 : </b>Tag not found in the parent tag</li>
127
+ </ul>
128
+
129
+ <br>
130
+
111
131
  ###new_file(source, code)
112
132
  Create a Html/Css file with the code of the editor. Return a boolean that indicate if the file was created or not.
113
133
  #####HTML
Binary file
Binary file
@@ -21,6 +21,6 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_development_dependency "bundler", "~> 1.10"
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
- spec.add_development_dependency "minitest"
24
+ spec.add_development_dependency 'minitest', '~> 0'
25
25
 
26
26
  end
data/exercises/test.html CHANGED
@@ -1 +1 @@
1
- <body><h2>hola test</h2><p></p></body>
1
+ <body><h2>hola test</h2><div><h2>html</h2></div><div><h2>css</h2></div></body>
@@ -189,7 +189,7 @@ class CodeTerminator::Css
189
189
  # => body { background-color: lightblue; }
190
190
  #
191
191
  # >> CodeTerminator::Css.match("test.css","body {background-color: blue; }")
192
- # => ["not the same property background-color in selector body "]
192
+ # => [{:element=>{:selector=>"body", :property=>"background-color", :value=>"yellow"}, :type=>111, :description=>"not the same property background-color: yellow in selector body"}]
193
193
  #
194
194
  # Arguments:
195
195
  # source: (String)
@@ -217,29 +217,18 @@ class CodeTerminator::Css
217
217
  if e[:value]==""
218
218
  property = e[:property] + ": "
219
219
  if parser_property.empty? { |s| s.include?(property) }
220
- node = Hash.new
221
- node[:element] = e
222
- node[:type] = 111
223
- node[:description] = "not the same property " + property + " in selector " + item
224
- css_errors << node
220
+ css_errors << new_error(element: e, type: 111, description: "not the same property " + property + " in selector " + item)
225
221
  end
226
222
  else
227
223
  property = e[:property] + ": " + e[:value]
228
224
  if !parser_property.include?(property)
229
- node = Hash.new
230
- node[:element] = e
231
- node[:type] = 111
232
- node[:description] = "not the same property " + property + " in selector " + item
233
- css_errors << node
225
+ css_errors << new_error(element: e, type: 111, description: "not the same property " + property + " in selector " + item)
234
226
  end
235
227
  end
236
228
 
237
229
  else
238
230
  node = Hash.new
239
- node[:element] = e
240
- node[:type] = 101
241
- node[:description] = "property "+ property + " not found in " + item
242
- css_errors << node
231
+ css_errors << new_error(element: e, type: 101, description: "property "+ property + " not found in " + item)
243
232
  end
244
233
  end
245
234
  end
@@ -248,7 +237,16 @@ class CodeTerminator::Css
248
237
 
249
238
  private
250
239
 
251
-
240
+ def new_error(args = {})
241
+ element = args[:element]
242
+ type = args[:type]
243
+ description = args[:description]
244
+ node = Hash.new
245
+ node[:element] = element
246
+ node[:type] = type
247
+ node[:description] = description
248
+ node
249
+ end
252
250
  #end
253
251
 
254
252
  end
@@ -220,15 +220,23 @@ class CodeTerminator::Html
220
220
  if item=="text"
221
221
 
222
222
  if !e[:content].nil?
223
- if code.css(e[:parent]).text != e[:content]
224
- node = Hash.new
225
- node[:element] = e
226
- node[:type] = 330
227
- node[:description] = e[:parent] + " haven't the same text " + e[:content]
228
- html_errors << node
223
+ if code.css(e[:parent]).count < 2
224
+ if code.css(e[:parent]).text != e[:content]
225
+ html_errors << new_error(element: e, type: 330, description: e[:parent] + " haven't the same text " + e[:content])
226
+ end
227
+ else
228
+ exist = false
229
+ code.css(e[:parent]).each do |code_css|
230
+ #if code_css.at_css(e[:tag]).parent.name == e[:parent]
231
+ if code_css.text == e[:content]
232
+ exist = true
233
+ end
234
+ #end
235
+ end
236
+ if !exist
237
+ html_errors << new_error(element: e, type: 330, description: e[:parent] + " haven't the same text " + e[:content])
238
+ end
229
239
  end
230
- #e[:content] == code.css()
231
-
232
240
  end
233
241
 
234
242
  else
@@ -236,38 +244,34 @@ class CodeTerminator::Html
236
244
 
237
245
  if !e[:attribute].nil?
238
246
  if code.css(e[:tag]).attribute(e[:attribute]).nil?
239
- node = Hash.new
240
- node[:element] = e
241
- node[:type] = 334
242
- node[:description] = e[:attribute] + " not exist in " + e[:tag]
243
- html_errors << node
247
+ html_errors << new_error(element: e, type: 334, description: e[:attribute] + " not exist in " + e[:tag])
244
248
  else
245
249
  if code.css(e[:tag]).attribute(e[:attribute]).value != e[:value]
246
- node = Hash.new
247
- node[:element] = e
248
- node[:type] = 333
249
- node[:description] = e[:attribute] + " not is the same value " + e[:value]
250
- html_errors << node
250
+ html_errors << new_error(element: e, type: 333, description: e[:attribute] + " not is the same value " + e[:value])
251
251
  end
252
252
  end
253
253
  end
254
254
 
255
- if code.at_css(e[:tag]).parent.name != e[:parent]
256
- node = Hash.new
257
- node[:element] = e
258
- node[:type] = 440
259
- node[:description] = e[:tag] + " not exist in " + e[:parent]
260
- html_errors << node
255
+ if code.css(e[:tag]).count < 2
256
+ if code.css(e[:tag]).first.parent.name != e[:parent]
257
+ html_errors << new_error(element: e, type: 440, description: e[:tag] + " not exist in " + e[:parent])
258
+ end
259
+ else
260
+ exist_in_parent = false
261
+ code.css(e[:tag]).each do |code_css|
262
+ if code_css.parent.name == e[:parent]
263
+ exist_in_parent = true
264
+ end
265
+ end
266
+ if !exist_in_parent
267
+ html_errors << new_error(element: e, type: 440, description: e[:tag] + " not exist in " + e[:parent])
268
+ end
261
269
  end
262
270
 
263
271
  else
264
272
 
265
273
  if code.at_css(e[:tag]).nil?
266
- node = Hash.new
267
- node[:element] = e
268
- node[:type] = 404
269
- node[:description] = e[:tag] + " not exist"
270
- html_errors << node
274
+ html_errors << new_error(element: e, type: 404, description: e[:tag] + " not exist")
271
275
  end
272
276
 
273
277
  end
@@ -275,7 +279,6 @@ class CodeTerminator::Html
275
279
  end
276
280
  end
277
281
 
278
-
279
282
  html_errors
280
283
  end
281
284
 
@@ -322,6 +325,17 @@ class CodeTerminator::Html
322
325
  end
323
326
  end
324
327
 
328
+ def new_error(args = {})
329
+ element = args[:element]
330
+ type = args[:type]
331
+ description = args[:description]
332
+ node = Hash.new
333
+ node[:element] = element
334
+ node[:type] = type
335
+ node[:description] = description
336
+ node
337
+ end
338
+
325
339
  #end
326
340
 
327
341
  end
@@ -1,3 +1,3 @@
1
1
  module CodeTerminator
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.2"
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.3.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evelin Ponce
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-29 00:00:00.000000000 Z
11
+ date: 2016-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -42,14 +42,14 @@ dependencies:
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: Helps to evaluate and parse html and css code.
@@ -81,6 +81,8 @@ files:
81
81
  - code_terminator-0.2.4.gem
82
82
  - code_terminator-0.2.5.gem
83
83
  - code_terminator-0.2.6.gem
84
+ - code_terminator-0.2.7.gem
85
+ - code_terminator-0.3.0.gem
84
86
  - code_terminator.gemspec
85
87
  - exe/code_terminator
86
88
  - exercises/new.html