code_terminator 0.2.3 → 0.2.4
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 +4 -4
- data/README.md +16 -16
- data/code_terminator-0.2.3.gem +0 -0
- data/exercises/test.html +5 -1
- data/lib/code_terminator/html.rb +83 -22
- data/lib/code_terminator/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8aceb132c1e05ea755d7692ecf035f0918db62da
|
4
|
+
data.tar.gz: c9fdcf92ebcd55ef592fb2b5904fa0c3ef0278f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70a295a63d6099ea31f0ac1392931d1264b383010416f2499ab200a20eed6b3ce60ecf342ac00f7ab221b2a298674c40ae4f0a04e57b3ce03c47f3e61a930ff0
|
7
|
+
data.tar.gz: f810a42cc618a59021f28effa1fea7061c18dfe43105e134b00ece5ae347a220d3438d5f51823815629770e436c2c470edbdd2417289244fe7ec85b9507f240a
|
data/README.md
CHANGED
@@ -26,7 +26,7 @@ Or install it yourself as:
|
|
26
26
|
|
27
27
|
## Quick Start
|
28
28
|
|
29
|
-
|
29
|
+
#####HTML
|
30
30
|
To parse HTML and match the file with html code you just need to do:
|
31
31
|
```ruby
|
32
32
|
# code = code get from an editor
|
@@ -53,7 +53,7 @@ You will know that the code and the source file have the same html elements when
|
|
53
53
|
# => ["h1 not exist"]
|
54
54
|
```
|
55
55
|
|
56
|
-
|
56
|
+
##### CSS
|
57
57
|
To parse CSS and match the file with css code you just need to do:
|
58
58
|
```ruby
|
59
59
|
# code = code get from an editor
|
@@ -84,7 +84,7 @@ You will know that the code and the source file have the same css elements when
|
|
84
84
|
###match(source, code)
|
85
85
|
Match if the code have the same elements than the exercise. Return an array with the mismatches.
|
86
86
|
|
87
|
-
|
87
|
+
####HTML
|
88
88
|
```ruby
|
89
89
|
# hola_mundo.html
|
90
90
|
# => <h1>Come with me if you want to live!</h1>
|
@@ -96,7 +96,7 @@ Match if the code have the same elements than the exercise. Return an array with
|
|
96
96
|
#
|
97
97
|
```
|
98
98
|
|
99
|
-
|
99
|
+
#####CSS
|
100
100
|
```ruby
|
101
101
|
# test.css
|
102
102
|
# => h1{ margin: 100px; }
|
@@ -110,13 +110,13 @@ Match if the code have the same elements than the exercise. Return an array with
|
|
110
110
|
|
111
111
|
###new_file(source, code)
|
112
112
|
Create a Html/Css file with the code of the editor. Return a boolean that indicate if the file was created or not.
|
113
|
-
|
113
|
+
#####HTML
|
114
114
|
```ruby
|
115
115
|
>> ct = CodeTerminator::Html.new
|
116
116
|
>> ct.new_file("hola_mundo.html", "<h1>Come with me if you want to live!</h1>")
|
117
117
|
# => true
|
118
118
|
```
|
119
|
-
|
119
|
+
#####CSS
|
120
120
|
```ruby
|
121
121
|
>> ct = CodeTerminator::Css.new
|
122
122
|
>> ct.new_file("hola_mundo.css", "h1{ margin: 50px; }")
|
@@ -125,13 +125,13 @@ Create a Html/Css file with the code of the editor. Return a boolean that indica
|
|
125
125
|
|
126
126
|
###read_file(source)
|
127
127
|
Read a html file. Return the text of the file.
|
128
|
-
|
128
|
+
#####HTML
|
129
129
|
```ruby
|
130
130
|
>> ct = CodeTerminator::Html.new
|
131
131
|
>> ct.read_file("hola_mundo.html")
|
132
132
|
# => "<h1>Come with me if you want to live!</h1>"
|
133
133
|
```
|
134
|
-
|
134
|
+
#####CSS
|
135
135
|
```ruby
|
136
136
|
>> ct = CodeTerminator::Css.new
|
137
137
|
>> ct.read_file("hola_mundo.css")
|
@@ -140,13 +140,13 @@ Read a html file. Return the text of the file.
|
|
140
140
|
|
141
141
|
###validate_syntax(code)
|
142
142
|
Validate if the syntax is correct. Return an array with errors.
|
143
|
-
|
143
|
+
#####HTML
|
144
144
|
```ruby
|
145
145
|
>> ct = CodeTerminator::Html.new
|
146
146
|
>> ct.validate_syntax("<h1>Come with me if you want to live!</h1")
|
147
147
|
# => [#<Nokogiri::XML::SyntaxError: expected '>'>]
|
148
148
|
```
|
149
|
-
|
149
|
+
#####CSS
|
150
150
|
```ruby
|
151
151
|
>> ct = CodeTerminator::Css.new
|
152
152
|
>> ct.validate_syntax("h1{ margi")
|
@@ -155,13 +155,13 @@ Validate if the syntax is correct. Return an array with errors.
|
|
155
155
|
|
156
156
|
###get_elements(source)
|
157
157
|
Get html elements of a html file. Return a list of Nokogiri XML objects.
|
158
|
-
|
158
|
+
#####HTML
|
159
159
|
```ruby
|
160
160
|
>> ct = CodeTerminator::Html.new
|
161
161
|
>> ct.get_elements("hola_mundo.html")
|
162
|
-
# => [
|
162
|
+
# => [{:parent=>"body", :tag=>"div", :attribute=>"class", :value=>"col-md-12"}, {:parent=>"div", :tag=>"h1"}, {:parent=>"h1", :tag=>"text", :content=>"Come with me if you want to live!"}]
|
163
163
|
```
|
164
|
-
|
164
|
+
#####CSS
|
165
165
|
```ruby
|
166
166
|
>> ct = CodeTerminator::Css.new
|
167
167
|
>> ct.get_elements("hola_mundo.css")
|
@@ -172,13 +172,13 @@ Get html elements of a html file. Return a list of Nokogiri XML objects.
|
|
172
172
|
Get the elements of the code in html format. Return a string with elements in html.
|
173
173
|
<br>
|
174
174
|
**Get 'Elements Array' calling 'get_elements()'
|
175
|
-
|
175
|
+
#####HTML
|
176
176
|
```ruby
|
177
|
-
CodeTerminator::Html.print_elements([
|
177
|
+
CodeTerminator::Html.print_elements(=> [{:parent=>"body", :tag=>"div", :attribute=>"class", :value=>"col-md-12"}, {:parent=>"div", :tag=>"h1"}, {:parent=>"h1", :tag=>"text", :content=>"Come with me if you want to live!"}] )
|
178
178
|
# => "name = h1<br><hr>name = text<br>content = Come with me if you want to live!<br><hr>"
|
179
179
|
#
|
180
180
|
```
|
181
|
-
|
181
|
+
#####CSS
|
182
182
|
```ruby
|
183
183
|
CodeTerminator::Css.print_elements([{:selector=>"h1"}, {:selector=>"h1", :property=>"margin", :value=>"50px"}])
|
184
184
|
# => "selector = h1<br><hr>property = margin<br>value = 50px<br><hr>"
|
Binary file
|
data/exercises/test.html
CHANGED
data/lib/code_terminator/html.rb
CHANGED
@@ -7,6 +7,7 @@ class CodeTerminator::Html
|
|
7
7
|
@code = args[:code]
|
8
8
|
@source = args[:source]
|
9
9
|
@tags = Array.new
|
10
|
+
@elements = Array.new
|
10
11
|
end
|
11
12
|
|
12
13
|
# Create a Html file with the code of the editor. Return a boolean that indicate if the file was created or not.
|
@@ -44,13 +45,37 @@ class CodeTerminator::Html
|
|
44
45
|
# source: (String)
|
45
46
|
|
46
47
|
def get_elements(source)
|
48
|
+
@elements = Array.new
|
47
49
|
reader = Nokogiri::HTML(File.open(source))
|
48
50
|
reader = remove_empty_text(reader)
|
51
|
+
reader.at('body').attribute_nodes.each do |element_attribute|
|
52
|
+
node[:parent] = "html"
|
53
|
+
node[:tag] = "body"
|
54
|
+
node[:attribute] = element_attribute.name if !element_attribute.name.nil?
|
55
|
+
node[:value] = element_attribute.value if !element_attribute.value.nil?
|
56
|
+
@elements << node
|
57
|
+
end
|
49
58
|
reader.at('body').children.each do |child|
|
50
|
-
|
51
|
-
|
59
|
+
if child.attribute_nodes.empty?
|
60
|
+
node = Hash.new
|
61
|
+
node[:parent] = "body"
|
62
|
+
node[:tag] = child.name
|
63
|
+
node[:content] = child.text if child.text?
|
64
|
+
@elements << node
|
65
|
+
else
|
66
|
+
child.attribute_nodes.each do |element_attribute|
|
67
|
+
node = Hash.new
|
68
|
+
node[:parent] = "body"
|
69
|
+
node[:tag] = child.name
|
70
|
+
node[:attribute] = element_attribute.name if !element_attribute.name.nil?
|
71
|
+
node[:value] = element_attribute.value if !element_attribute.value.nil?
|
72
|
+
@elements << node
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
add_children(child) if child.children.any?
|
52
77
|
end
|
53
|
-
@
|
78
|
+
@elements
|
54
79
|
end
|
55
80
|
|
56
81
|
# Validate if the syntax is correct. Return an array with Nokogiri errors.
|
@@ -128,11 +153,11 @@ class CodeTerminator::Html
|
|
128
153
|
def print_elements(elements)
|
129
154
|
text = ""
|
130
155
|
elements.each do |child|
|
131
|
-
text << "
|
132
|
-
text << "
|
133
|
-
child
|
134
|
-
|
135
|
-
|
156
|
+
text << "parent = " + child[:parent] + "<br>" if !child[:parent].nil?
|
157
|
+
text << "tag = " + child[:tag] + "<br>" if !child[:tag].nil?
|
158
|
+
text << "attribute = " + child[:attribute] + "<br>" if !child[:attribute].nil?
|
159
|
+
text << "value = " + child[:value] + "<br>" if !child[:value].nil?
|
160
|
+
text << "content = " + child[:content] + "<br>" if !child[:content].nil?
|
136
161
|
text << "<hr>"
|
137
162
|
end
|
138
163
|
text
|
@@ -160,26 +185,47 @@ class CodeTerminator::Html
|
|
160
185
|
|
161
186
|
elements = get_elements(source)
|
162
187
|
#@elements = Html::PrintElements.call(elements)
|
188
|
+
# '[{:parent=>"body", :tag=>"div"}, {:parent=>"body", :tag=>"div", :attribute=>"class", :value=>"col-md-12"}, {:parent=>"div", :tag=>"h2"}, {:parent=>"h2", :tag=>"text", :content=>"hola test"}, {:parent=>"div", :tag=>"h1"}] '
|
163
189
|
|
164
|
-
elements.each do |
|
165
|
-
|
166
|
-
|
190
|
+
elements.each do |e|
|
191
|
+
item = e[:tag]
|
192
|
+
if item=="text"
|
193
|
+
if !e[:content].nil?
|
194
|
+
if code.css(e[:parent]).text != e[:content]
|
195
|
+
html_errors << e[:parent] + " haven't the same text " + e[:content]
|
196
|
+
end
|
197
|
+
e[:content] == code.css()
|
198
|
+
end
|
199
|
+
#manage text
|
167
200
|
else
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
else
|
177
|
-
html_errors << element_attribute.name + " not exist"
|
201
|
+
if code.css(e[:tag]).length > 0
|
202
|
+
|
203
|
+
if !e[:attribute].nil?
|
204
|
+
if code.css(e[:tag]).attribute(e[:attribute]).nil?
|
205
|
+
html_errors << e[:attribute] + " not exist in " + e[:tag]
|
206
|
+
else
|
207
|
+
if code.css(e[:tag]).attribute(e[:attribute]).value != e[:value]
|
208
|
+
html_errors << e[:attribute] + " not is the same value " + e[:value]
|
178
209
|
end
|
179
210
|
end
|
180
211
|
end
|
212
|
+
|
213
|
+
if code.at_css(e[:tag]).parent.name != e[:parent]
|
214
|
+
html_errors << e[:tag] + " not exist in " + e[:parent]
|
215
|
+
end
|
216
|
+
|
217
|
+
else
|
218
|
+
|
219
|
+
#if code.css(e[:tag]).parent.name != e[:parent]
|
220
|
+
#html_errors << e[:tag] + " not exist in " + e[:parent]
|
221
|
+
#end
|
222
|
+
|
181
223
|
end
|
224
|
+
|
225
|
+
end
|
182
226
|
end
|
227
|
+
|
228
|
+
|
183
229
|
html_errors
|
184
230
|
end
|
185
231
|
|
@@ -187,7 +233,22 @@ class CodeTerminator::Html
|
|
187
233
|
|
188
234
|
def add_children(parent)
|
189
235
|
parent.children.each do |child|
|
190
|
-
|
236
|
+
if child.attribute_nodes.empty?
|
237
|
+
node = Hash.new
|
238
|
+
node[:parent] = parent.name
|
239
|
+
node[:tag] = child.name
|
240
|
+
node[:content] = child.text if child.text?
|
241
|
+
@elements << node
|
242
|
+
else
|
243
|
+
child.attribute_nodes.each do |element_attribute|
|
244
|
+
node = Hash.new
|
245
|
+
node[:parent] = parent.name
|
246
|
+
node[:tag] = child.name
|
247
|
+
node[:attribute] = element_attribute.name if !element_attribute.name.nil?
|
248
|
+
node[:value] = element_attribute.value if !element_attribute.value.nil?
|
249
|
+
@elements << node
|
250
|
+
end
|
251
|
+
end
|
191
252
|
add_children(child) if child.children.any?
|
192
253
|
end
|
193
254
|
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.2.
|
4
|
+
version: 0.2.4
|
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-
|
11
|
+
date: 2016-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- code_terminator-0.2.0.gem
|
78
78
|
- code_terminator-0.2.1.gem
|
79
79
|
- code_terminator-0.2.2.gem
|
80
|
+
- code_terminator-0.2.3.gem
|
80
81
|
- code_terminator.gemspec
|
81
82
|
- exe/code_terminator
|
82
83
|
- exercises/new.html
|