code_terminator 0.2.7 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -5
- data/lib/code_terminator/css.rb +29 -1
- data/lib/code_terminator/html.rb +30 -1
- data/lib/code_terminator/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87e6dca14dbac0d4b60af01602c73f19d2155cb1
|
4
|
+
data.tar.gz: 690cd6aa18eeca2de64d86d5aadff6a081b87086
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 08c93b876778cd097b3de362176f257a3870e1991ad9f2eb73551c8f4d30ddeecef52b1504f6010d9204febaa2fd33896953f68dbabb2fcde299203b7d0f6825
|
7
|
+
data.tar.gz: 11e944f39c5fd1fab19654fd4ad60289840662c4386d50e39e0b92bd117328b7b0ccdc8d8dc366d18b2fb321f438bbfd68b81b8e36d6524325de022846668b86
|
data/README.md
CHANGED
@@ -154,7 +154,7 @@ Validate if the syntax is correct. Return an array with errors.
|
|
154
154
|
```
|
155
155
|
|
156
156
|
###get_elements(source)
|
157
|
-
Get html elements of a html file. Return a list of
|
157
|
+
Get html elements of a html file. Return a list of elements with their properties.
|
158
158
|
#####HTML
|
159
159
|
```ruby
|
160
160
|
>> ct = CodeTerminator::Html.new
|
@@ -168,19 +168,33 @@ Get html elements of a html file. Return a list of Nokogiri XML objects.
|
|
168
168
|
# => [{:selector=>"h1"}, {:selector=>"h1", :property=>"margin", :value=>"50px"}]
|
169
169
|
```
|
170
170
|
|
171
|
-
###
|
171
|
+
###get_instructions(source)
|
172
|
+
Get the instructions to recreate the html code. Return an array with strings .
|
173
|
+
#####HTML
|
174
|
+
```ruby
|
175
|
+
>> ct = CodeTerminator::Html.new
|
176
|
+
>> ct.get_instructions("hola_mundo.html")
|
177
|
+
# => ["Add the tag h2 in body", " In h2 add the text 'hola test' ", "Add the tag p in body"]
|
178
|
+
```
|
179
|
+
#####CSS
|
180
|
+
```ruby
|
181
|
+
>> ct = CodeTerminator::Css.new
|
182
|
+
>> ct.get_instructions("hola_mundo.css")
|
183
|
+
# => ["Create the selector body", "In the selector body add the property ' background-color' with value 'yellow' "]
|
184
|
+
```
|
185
|
+
|
186
|
+
###print_elements(source)
|
172
187
|
Get the elements of the code in html format. Return a string with elements in html.
|
173
188
|
<br>
|
174
|
-
**Get 'Elements Array' calling 'get_elements()'
|
175
189
|
#####HTML
|
176
190
|
```ruby
|
177
|
-
CodeTerminator::Html.print_elements(
|
191
|
+
CodeTerminator::Html.print_elements("exercises/hola_mundo.html" )
|
178
192
|
# => "name = h1<br><hr>name = text<br>content = Come with me if you want to live!<br><hr>"
|
179
193
|
#
|
180
194
|
```
|
181
195
|
#####CSS
|
182
196
|
```ruby
|
183
|
-
CodeTerminator::Css.print_elements(
|
197
|
+
CodeTerminator::Css.print_elements("exercises/hola_mundo.css" )
|
184
198
|
# => "selector = h1<br><hr>property = margin<br>value = 50px<br><hr>"
|
185
199
|
#
|
186
200
|
```
|
data/lib/code_terminator/css.rb
CHANGED
@@ -134,7 +134,7 @@ class CodeTerminator::Css
|
|
134
134
|
# Get the elements of the code in css format. Return a string with elements in css.
|
135
135
|
#
|
136
136
|
# Example:
|
137
|
-
# >> CodeTerminator::Css.print_elements(
|
137
|
+
# >> CodeTerminator::Css.print_elements("exercises/hola_mundo.css" )
|
138
138
|
# => "selector = body<br><hr>selector = body<br>property = background-color<br>value = lightblue<br><hr>"
|
139
139
|
#
|
140
140
|
# Arguments:
|
@@ -142,6 +142,7 @@ class CodeTerminator::Css
|
|
142
142
|
|
143
143
|
|
144
144
|
def print_elements(elements)
|
145
|
+
elements = get_elements(source)
|
145
146
|
text = ""
|
146
147
|
elements.each do |child|
|
147
148
|
text << "selector = " + child[:selector] + "<br>"
|
@@ -152,6 +153,33 @@ class CodeTerminator::Css
|
|
152
153
|
text
|
153
154
|
end
|
154
155
|
|
156
|
+
# Get the instructions to recreate the html code. Return an array with strings .
|
157
|
+
#
|
158
|
+
# Example:
|
159
|
+
# >> CodeTerminator::Css.get_instructions(file.get_elements("exercises/test.css"))
|
160
|
+
# => [["Create the selector body", "In the selector body add the property 'background-color' with value 'yellow' "]
|
161
|
+
#
|
162
|
+
# Arguments:
|
163
|
+
# instructions: (Array)
|
164
|
+
|
165
|
+
def get_instructions(source)
|
166
|
+
elements = get_elements(source)
|
167
|
+
text = ""
|
168
|
+
instructions = Array.new
|
169
|
+
elements.each do |child|
|
170
|
+
if child[:property].nil?
|
171
|
+
text << "Create the selector " + child[:selector]
|
172
|
+
else
|
173
|
+
text << "In the selector " + child[:selector] + " add the property '" + child[:property] + "'" if !child[:property].nil?
|
174
|
+
text << " with value '" + child[:value] + "' " if !child[:value].nil?
|
175
|
+
end
|
176
|
+
instructions.push(text)
|
177
|
+
text = ""
|
178
|
+
end
|
179
|
+
instructions
|
180
|
+
end
|
181
|
+
|
182
|
+
|
155
183
|
|
156
184
|
# Match if the code have the same elements than the exercise. Return an array with the mismatches.
|
157
185
|
|
data/lib/code_terminator/html.rb
CHANGED
@@ -144,7 +144,7 @@ class CodeTerminator::Html
|
|
144
144
|
# Get the elements of the code in html format. Return a string with elements in html.
|
145
145
|
#
|
146
146
|
# Example:
|
147
|
-
# >> CodeTerminator::Html.print_elements(
|
147
|
+
# >> CodeTerminator::Html.print_elements("exercises/hola_mundo.html" )
|
148
148
|
# => "name = h1<br><hr>name = text<br>content = hola mundo<br><hr>"
|
149
149
|
#
|
150
150
|
# Arguments:
|
@@ -163,6 +163,35 @@ class CodeTerminator::Html
|
|
163
163
|
text
|
164
164
|
end
|
165
165
|
|
166
|
+
# Get the instructions to recreate the html code. Return an array with strings .
|
167
|
+
#
|
168
|
+
# Example:
|
169
|
+
# >> CodeTerminator::Html.get_instructions(file.get_elements("exercises/test.html"))
|
170
|
+
# => ["Add the tag h2 in body", "Add the tag text in h2 with content 'hola test' ", "Add the tag p in body"]
|
171
|
+
#
|
172
|
+
# Arguments:
|
173
|
+
# instructions: (Array)
|
174
|
+
|
175
|
+
def get_instructions(source)
|
176
|
+
elements = get_elements(source)
|
177
|
+
text = ""
|
178
|
+
instructions = Array.new
|
179
|
+
elements.each do |child|
|
180
|
+
if child[:tag]!="text"
|
181
|
+
text << "Add the tag " + child[:tag]
|
182
|
+
text << " in " + child[:parent] if !child[:parent].nil?
|
183
|
+
text << " with an attribute '" + child[:attribute] + "' " if !child[:attribute].nil?
|
184
|
+
text << " with value '" + child[:value] + "' " if !child[:value].nil?
|
185
|
+
else
|
186
|
+
text << " In " + child[:parent]+ " add the text '" + child[:content] + "' " if !child[:content].nil?
|
187
|
+
end
|
188
|
+
instructions.push(text)
|
189
|
+
text = ""
|
190
|
+
end
|
191
|
+
instructions
|
192
|
+
end
|
193
|
+
|
194
|
+
|
166
195
|
|
167
196
|
# Match if the code have the same elements than the exercise. Return an array with the mismatches.
|
168
197
|
#
|