code_terminator 0.2.2 → 0.2.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.
- checksums.yaml +4 -4
- data/README.md +102 -21
- data/code_terminator-0.2.1.gem +0 -0
- data/code_terminator-0.2.2.gem +0 -0
- data/lib/code_terminator/css.rb +4 -5
- data/lib/code_terminator/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b9dd80f0480385f782d16f013ea23b3e5da72d0
|
4
|
+
data.tar.gz: 82e5bba3270ec1abca8d1d827f0bf14c41f82993
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d26de5396d0d3fb12c5c1e667fe43633bd893ebccd21103236ed13366714ae456a9052d7c3d0f54f224e9e4b2cb7b4757cdb024681b6d23d56388dc07c30853
|
7
|
+
data.tar.gz: d93ddd7ba64c42beb2e3ba276ff2c4c7dcc0e98e61c7174737a6dd3e4cdff4525f3196da5f4d33426fcb819bd393c71a5b1e73e89d2ec6577f7e48cdb56c0f00
|
data/README.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# CodeTerminator
|
2
2
|
|
3
|
-
CodeTerminator is a gem that helps to <strike>exterminate Sarah Connor</strike> parse, evaluate and compare html code. Also is useful when you need to check html code syntaxis.
|
3
|
+
CodeTerminator is a gem that helps to <strike>exterminate Sarah Connor</strike> parse, evaluate and compare html and css code. Also is useful when you need to check html and css code syntaxis.
|
4
4
|
|
5
5
|
##Features
|
6
6
|
<ul>
|
7
7
|
<li>HTML parser </li>
|
8
|
-
<li>CSS parser
|
8
|
+
<li>CSS parser </li>
|
9
9
|
</ul>
|
10
10
|
|
11
11
|
## Installation
|
@@ -26,17 +26,18 @@ Or install it yourself as:
|
|
26
26
|
|
27
27
|
## Quick Start
|
28
28
|
|
29
|
+
#HTML
|
29
30
|
To parse HTML and match the file with html code you just need to do:
|
30
31
|
```ruby
|
31
32
|
# code = code get from an editor
|
32
33
|
# source = Source of the file you want to compare with
|
33
|
-
|
34
|
+
|
34
35
|
# First, validate syntasis of the code
|
35
36
|
ct = CodeTerminator::Html.new
|
36
37
|
errors = ct.validate_syntax(code)
|
37
38
|
result << errors[0]
|
38
|
-
|
39
|
-
# If code
|
39
|
+
|
40
|
+
# If code don't have errors, match the code with your html file
|
40
41
|
if errors.empty?
|
41
42
|
result = ct.match(source, code)
|
42
43
|
end
|
@@ -46,60 +47,141 @@ You will know that the code and the source file have the same html elements when
|
|
46
47
|
|
47
48
|
```ruby
|
48
49
|
# hola_mundo.html
|
49
|
-
# <h1>
|
50
|
+
# <h1>Come with me if you want to live!</h1>
|
50
51
|
#
|
51
|
-
>>
|
52
|
+
>> ct.match("hola_mundo.html","<h2>Come with me if you want to live!</h2>")
|
52
53
|
# => ["h1 not exist"]
|
53
54
|
```
|
54
55
|
|
56
|
+
# CSS
|
57
|
+
To parse CSS and match the file with css code you just need to do:
|
58
|
+
```ruby
|
59
|
+
# code = code get from an editor
|
60
|
+
# source = Source of the file you want to compare with
|
61
|
+
|
62
|
+
# First, validate syntasis of the code
|
63
|
+
ct = CodeTerminator::Css.new
|
64
|
+
errors = ct.validate_syntax(code)
|
65
|
+
|
66
|
+
# If code do't have errors, match the code with your html file
|
67
|
+
if errors.empty?
|
68
|
+
result = ct.match(source, code)
|
69
|
+
end
|
70
|
+
```
|
71
|
+
If the code and the source mismatch, `ct.match()` will return an array with the differences between code and source file.
|
72
|
+
You will know that the code and the source file have the same css elements when the `ct.match()` return a nil array.
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
# test.css
|
76
|
+
# => h1{ margin: 100px; }
|
77
|
+
#
|
78
|
+
>> ct.match("test.html","h1{ margin: 50px; }")
|
79
|
+
# => ["not the same property margin: 100px in selector h1"]
|
80
|
+
```
|
81
|
+
|
55
82
|
##Cheat Sheet
|
56
83
|
|
57
84
|
###match(source, code)
|
58
85
|
Match if the code have the same elements than the exercise. Return an array with the mismatches.
|
59
86
|
|
87
|
+
#HTML
|
60
88
|
```ruby
|
61
89
|
# hola_mundo.html
|
62
|
-
# => <h1>
|
90
|
+
# => <h1>Come with me if you want to live!</h1>
|
63
91
|
```
|
64
92
|
```ruby
|
65
|
-
CodeTerminator::Html.
|
93
|
+
>> ct = CodeTerminator::Html.new
|
94
|
+
>> ct.match("hola_mundo.html","<h2>Come with me if you want to live!</h2>")
|
66
95
|
# => ["h1 not exist"]
|
67
96
|
#
|
68
97
|
```
|
98
|
+
|
99
|
+
#CSS
|
100
|
+
```ruby
|
101
|
+
# test.css
|
102
|
+
# => h1{ margin: 100px; }
|
103
|
+
```
|
104
|
+
```ruby
|
105
|
+
>> ct = CodeTerminator::Css.new
|
106
|
+
>> ct.match("hola_mundo.css","h1{ margin: 50px; }")
|
107
|
+
# => ["not the same property margin: 100px in selector h1"]
|
108
|
+
#
|
109
|
+
```
|
110
|
+
|
69
111
|
###new_file(source, code)
|
70
|
-
Create a Html file with the code of the editor. Return a boolean that indicate if the file was created or not.
|
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
|
+
#HTML
|
71
114
|
```ruby
|
72
|
-
CodeTerminator::Html.
|
115
|
+
>> ct = CodeTerminator::Html.new
|
116
|
+
>> ct.new_file("hola_mundo.html", "<h1>Come with me if you want to live!</h1>")
|
73
117
|
# => true
|
74
118
|
```
|
119
|
+
#CSS
|
120
|
+
```ruby
|
121
|
+
>> ct = CodeTerminator::Css.new
|
122
|
+
>> ct.new_file("hola_mundo.css", "h1{ margin: 50px; }")
|
123
|
+
# => true
|
124
|
+
```
|
125
|
+
|
75
126
|
###read_file(source)
|
76
127
|
Read a html file. Return the text of the file.
|
128
|
+
#HTML
|
77
129
|
```ruby
|
78
|
-
CodeTerminator::Html.
|
79
|
-
|
130
|
+
>> ct = CodeTerminator::Html.new
|
131
|
+
>> ct.read_file("hola_mundo.html")
|
132
|
+
# => "<h1>Come with me if you want to live!</h1>"
|
133
|
+
```
|
134
|
+
#CSS
|
135
|
+
```ruby
|
136
|
+
>> ct = CodeTerminator::Css.new
|
137
|
+
>> ct.read_file("hola_mundo.css")
|
138
|
+
# => "h1{ margin: 50px; }"
|
80
139
|
```
|
81
140
|
|
82
141
|
###validate_syntax(code)
|
83
|
-
Validate if the syntax is correct. Return an array with
|
142
|
+
Validate if the syntax is correct. Return an array with errors.
|
143
|
+
#HTML
|
84
144
|
```ruby
|
85
|
-
|
145
|
+
>> ct = CodeTerminator::Html.new
|
146
|
+
>> ct.validate_syntax("<h1>Come with me if you want to live!</h1")
|
86
147
|
# => [#<Nokogiri::XML::SyntaxError: expected '>'>]
|
87
148
|
```
|
88
|
-
|
149
|
+
#CSS
|
150
|
+
```ruby
|
151
|
+
>> ct = CodeTerminator::Css.new
|
152
|
+
>> ct.validate_syntax("h1{ margi")
|
153
|
+
# => ["error"]
|
154
|
+
```
|
155
|
+
|
89
156
|
###get_elements(source)
|
90
157
|
Get html elements of a html file. Return a list of Nokogiri XML objects.
|
158
|
+
#HTML
|
159
|
+
```ruby
|
160
|
+
>> ct = CodeTerminator::Html.new
|
161
|
+
>> ct.get_elements("hola_mundo.html")
|
162
|
+
# => [#<Nokogiri::XML::Element:0x3fe3391547d8 name="h1" children=[#<Nokogiri::XML::Text:0x3fe33915474c "Come with me if you want to live!">]>, #<Nokogiri::XML::Text:0x3fe33915474c "Come with me if you want to live!">]
|
163
|
+
```
|
164
|
+
#CSS
|
91
165
|
```ruby
|
92
|
-
CodeTerminator::
|
93
|
-
|
166
|
+
>> ct = CodeTerminator::Css.new
|
167
|
+
>> ct.get_elements("hola_mundo.css")
|
168
|
+
# => [{:selector=>"h1"}, {:selector=>"h1", :property=>"margin", :value=>"50px"}]
|
94
169
|
```
|
95
170
|
|
96
171
|
###print_elements(Elements Array)
|
97
172
|
Get the elements of the code in html format. Return a string with elements in html.
|
98
173
|
<br>
|
99
174
|
**Get 'Elements Array' calling 'get_elements()'
|
175
|
+
#HTML
|
100
176
|
```ruby
|
101
|
-
CodeTerminator::Html.print_elements([#<Nokogiri::XML::Element:0x3fe31dc42bfc name="h1" children=[#<Nokogiri::XML::Text:0x3fe31dc42b70 "
|
102
|
-
# => "name = h1<br><hr>name = text<br>content =
|
177
|
+
CodeTerminator::Html.print_elements([#<Nokogiri::XML::Element:0x3fe31dc42bfc name="h1" children=[#<Nokogiri::XML::Text:0x3fe31dc42b70 "Come with me if you want to live!">]>, #<Nokogiri::XML::Text:0x3fe31dc42b70 "hola mundo">])
|
178
|
+
# => "name = h1<br><hr>name = text<br>content = Come with me if you want to live!<br><hr>"
|
179
|
+
#
|
180
|
+
```
|
181
|
+
#CSS
|
182
|
+
```ruby
|
183
|
+
CodeTerminator::Css.print_elements([{:selector=>"h1"}, {:selector=>"h1", :property=>"margin", :value=>"50px"}])
|
184
|
+
# => "selector = h1<br><hr>property = margin<br>value = 50px<br><hr>"
|
103
185
|
#
|
104
186
|
```
|
105
187
|
|
@@ -121,4 +203,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/eponce
|
|
121
203
|
## License
|
122
204
|
|
123
205
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
124
|
-
|
Binary file
|
Binary file
|
data/lib/code_terminator/css.rb
CHANGED
@@ -53,7 +53,6 @@ class CodeTerminator::Css
|
|
53
53
|
reader = read_file(source)
|
54
54
|
parser = Crass.parse(reader)
|
55
55
|
errors = parser.pop
|
56
|
-
p errors
|
57
56
|
elements = Array.new
|
58
57
|
selector = ""
|
59
58
|
|
@@ -86,7 +85,7 @@ class CodeTerminator::Css
|
|
86
85
|
# IMPORTANT Method not validate <STYLE> tag from the code
|
87
86
|
|
88
87
|
def validate_syntax(code)
|
89
|
-
|
88
|
+
errors = Array.new
|
90
89
|
tree = Crass.parse(code)
|
91
90
|
last = tree.length
|
92
91
|
if !tree[last-1].nil?
|
@@ -94,16 +93,16 @@ class CodeTerminator::Css
|
|
94
93
|
if !nodes.nil?
|
95
94
|
nodes.each do |children|
|
96
95
|
if children[:node].to_s == "error"
|
97
|
-
|
96
|
+
errors[0] = "error"
|
98
97
|
end
|
99
98
|
end
|
100
99
|
#else
|
101
100
|
#valid = false
|
102
101
|
end
|
103
102
|
else
|
104
|
-
|
103
|
+
errors[0] = "error"
|
105
104
|
end
|
106
|
-
|
105
|
+
errors
|
107
106
|
end
|
108
107
|
|
109
108
|
# Read a css file. Return a string with the text of the file.
|
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.3
|
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-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -75,6 +75,8 @@ files:
|
|
75
75
|
- code_terminator-0.1.2.gem
|
76
76
|
- code_terminator-0.1.3.gem
|
77
77
|
- code_terminator-0.2.0.gem
|
78
|
+
- code_terminator-0.2.1.gem
|
79
|
+
- code_terminator-0.2.2.gem
|
78
80
|
- code_terminator.gemspec
|
79
81
|
- exe/code_terminator
|
80
82
|
- exercises/new.html
|