quotifier 0.0.2 → 0.0.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/lib/quotifier.rb +52 -21
- metadata +34 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7beb980438956fc78ab8538fb84ddcae844b038
|
4
|
+
data.tar.gz: 1632feea4e5f6180ed2f06db44c466f72e020673
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60947d7901115d0de07dff4a75931604371c4d2bc099177249fbaf9b73dc214792f2895f0915361f981a2ed5a62bbd9e5b57622d9abf55f7f4c15cfeaa95afba
|
7
|
+
data.tar.gz: 8957ba76e2e0835cfa54d471f2d85a7508fcb53cd5e46f4c3da0c6c7087d1ff2a0c9ffb84c2d731da64b8594ef596d416cd5171e80a5206af60556584d065d3f
|
data/lib/quotifier.rb
CHANGED
@@ -1,50 +1,81 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'net/http'
|
3
|
+
require 'quotify'
|
3
4
|
|
4
5
|
class Quotifier
|
5
6
|
|
6
7
|
def initialize(app)
|
7
8
|
@app = app
|
8
|
-
url = "https://raw.githubusercontent.com/jusleg/quotifier/master/db.json"
|
9
|
-
@dictionnary = JSON.parse(Net::HTTP.get(URI.parse(url)))
|
10
9
|
end
|
11
10
|
|
12
11
|
def call(env)
|
13
|
-
status, headers, body = @app.call(env)
|
12
|
+
status, @headers, body = @app.call(env)
|
14
13
|
|
15
|
-
if headers['Content-Type'].include?'text/html'
|
16
|
-
[status, headers, quotify(body
|
14
|
+
if @headers['Content-Type'].include?'text/html'
|
15
|
+
[status, @headers, quotify(body)]
|
17
16
|
else
|
18
|
-
[status, headers, body]
|
17
|
+
[status, @headers, body]
|
19
18
|
end
|
20
19
|
|
21
20
|
end
|
22
21
|
|
23
|
-
def quotify(html
|
24
|
-
|
22
|
+
def quotify(html)
|
25
23
|
string_html = html[0]
|
26
24
|
counter = 0
|
27
|
-
fresh_output =
|
25
|
+
fresh_output = ''
|
26
|
+
js_flag = false
|
27
|
+
css_flag = false
|
28
|
+
regex = {
|
29
|
+
js_open: /[<]{1}script[>]{1}/,
|
30
|
+
js_closed: /[<]{1}\/script[>]{1}/,
|
31
|
+
style_open: /[<]{1}style[>]{1}/,
|
32
|
+
style_closed: /[<]{1}\/style[>]{1}/
|
33
|
+
}
|
34
|
+
|
35
|
+
string_html.split(/[\n\r]+/).each do |line|
|
36
|
+
if regex[:js_open].match(line)
|
37
|
+
js_flag = true
|
38
|
+
elsif regex[:js_closed].match(line)
|
39
|
+
js_flag = false
|
40
|
+
elsif regex[:style_open].match(line)
|
41
|
+
css_flag = true
|
42
|
+
elsif regex[:style_closed].match(line)
|
43
|
+
css_flag = false
|
44
|
+
end
|
28
45
|
|
29
|
-
string_html.each_line do |line|
|
30
46
|
random_mod = rand(1..10)
|
31
47
|
if counter % random_mod == 0
|
32
|
-
|
48
|
+
if js_flag
|
49
|
+
line = line + "\n\t \\\\" + Quotify.generate
|
50
|
+
elsif css_flag
|
51
|
+
line = line + "\n\t #" + Quotify.generate
|
52
|
+
elsif !js_flag
|
53
|
+
line = line + "\n\t" + Quotify.generate
|
54
|
+
elsif !css_flag
|
55
|
+
line = line + "\n\t" + Quotify.generate
|
56
|
+
end
|
33
57
|
end
|
34
|
-
fresh_output << line
|
35
|
-
counter
|
58
|
+
fresh_output << line + "\n"
|
59
|
+
counter += 1
|
36
60
|
end
|
37
|
-
html[0] = fresh_output
|
38
|
-
headers['Content-Length'] = fresh_output.length.to_s
|
39
|
-
return html
|
40
|
-
end
|
41
61
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
62
|
+
|
63
|
+
html[0] = fresh_output
|
64
|
+
@headers['Content-Length'] = fresh_output.length.to_s
|
65
|
+
html
|
46
66
|
end
|
47
67
|
|
68
|
+
#This will be used for the next release
|
69
|
+
def single_line_js_or_css? (line)
|
70
|
+
single_line_js = /[<]{1}script[>]{1} .* [<]{1}\/script[>]{1}/
|
71
|
+
single_line_css = /[<]{1}script[>]{1} .* [<]{1}\/script[>]{1}/
|
72
|
+
|
73
|
+
if single_line_css.match(line) || single_line_js.match(line)
|
74
|
+
return true
|
75
|
+
else
|
76
|
+
return false
|
77
|
+
end
|
48
78
|
|
79
|
+
end
|
49
80
|
|
50
81
|
end
|
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quotifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michel Chatmajian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
11
|
+
date: 2018-01-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: quotify
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
13
41
|
description: 'Rack Middleware that inserts random quotes into outbound html being
|
14
42
|
served from any Rack webserver '
|
15
43
|
email: chamich196@hotmail.com
|
@@ -21,7 +49,9 @@ files:
|
|
21
49
|
homepage: http://rubygems.org/gems/quotifier
|
22
50
|
licenses:
|
23
51
|
- MIT
|
24
|
-
metadata:
|
52
|
+
metadata:
|
53
|
+
source_code_uri: https://github.com/almiche/quotifier_as_middleware
|
54
|
+
changelog_uri: https://github.com/almiche/quotifier_as_middleware/blob/master/CHANGELOG.md
|
25
55
|
post_install_message:
|
26
56
|
rdoc_options: []
|
27
57
|
require_paths:
|