web_randomizer 0.1.0 → 0.2.0
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/.gitignore +2 -0
- data/README.md +0 -1
- data/lib/web_randomizer.rb +153 -123
- data/spec/web_randomizer_spec.rb +87 -0
- data/web_randomizer.gemspec +2 -2
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56a64c25d01f7b0fc4ae959f48ebc77eda2729cc862972df826dfe0992d25255
|
4
|
+
data.tar.gz: da22d32977061ddaa280a713e169cd61b736cd0099106f9b64af4ce5de1fe605
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e836dd9a165b10fb12cdd58a105d3c8fbcc9285f4096d49447a361b24a8d8bcc1e8fb524de43e7f3e055ea10daa14949eae32d61baca2c233ea4bf14b59101c7
|
7
|
+
data.tar.gz: 077ef13667b9dc2d5e53015f731e3f96517b15a9dfcff025eeac629003e72bebc3f796bd2275b24ee250e6fa2510f3fba9659ca39bd8a08c55a1c51c3dde333f
|
data/.gitignore
ADDED
data/README.md
CHANGED
data/lib/web_randomizer.rb
CHANGED
@@ -1,123 +1,153 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
#
|
55
|
-
|
56
|
-
output.
|
57
|
-
|
58
|
-
output.
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
end
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module WebRandomizer
|
6
|
+
class << self
|
7
|
+
def execute
|
8
|
+
initialize!
|
9
|
+
|
10
|
+
randomize_div!
|
11
|
+
|
12
|
+
@сss_files_array.each do |el|
|
13
|
+
puts "\n\nUpdating #{el[:filename]}\n"
|
14
|
+
|
15
|
+
File.open(el[:filename], 'w') do |file|
|
16
|
+
file.write(color_shift(el[:contents]))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def initialize!
|
24
|
+
if File.file?('randomize.yml')
|
25
|
+
config = YAML.load_file('randomize.yml')
|
26
|
+
|
27
|
+
@html_dir_list = config['html_dir']
|
28
|
+
@css_dir_list = config['css_dir']
|
29
|
+
|
30
|
+
else
|
31
|
+
@html_dir_list = %w[_layouts _includes]
|
32
|
+
@css_dir_list = %w[assets/css _sass]
|
33
|
+
end
|
34
|
+
|
35
|
+
@сss_files_array = []
|
36
|
+
|
37
|
+
@css_dir_list.each do |dir_item|
|
38
|
+
Dir.foreach(dir_item) do |css_filename|
|
39
|
+
next if css_filename == '.' || css_filename == '..'
|
40
|
+
|
41
|
+
@сss_files_array << ({ filename: "#{dir_item}/#{css_filename}",
|
42
|
+
contents: File.open("#{dir_item}/#{css_filename}").read })
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def randomize_div!
|
48
|
+
@html_dir_list.each do |dir_item|
|
49
|
+
Dir.foreach(dir_item) do |filename|
|
50
|
+
next if filename == '.' || filename == '..'
|
51
|
+
|
52
|
+
puts "Processing #{dir_item}/#{filename}"
|
53
|
+
|
54
|
+
output = File.open("#{dir_item}/#{filename}") { |f| f.read }
|
55
|
+
|
56
|
+
# puts 'DEBUG output:' + output.inspect + "\n\n"
|
57
|
+
|
58
|
+
output.gsub!(/<div>/, "<div class=\"#{rand_string}\">")
|
59
|
+
|
60
|
+
output.scan(/<div.*?class=(.*?)>/).uniq.each do |div|
|
61
|
+
div.first.slice(/\"(.*)\"/, 1).strip.split(/\s+/).each do |el|
|
62
|
+
puts "\n\nHTML Searching non-div classes: " + el + "\n\n"
|
63
|
+
|
64
|
+
if found_in_non_div(el)
|
65
|
+
puts "\n\nFound in non-div tags. Skipping: " + el + "\n\n"
|
66
|
+
next
|
67
|
+
end
|
68
|
+
|
69
|
+
new_value = rand_string.strip
|
70
|
+
@html_dir_list.each do |inner_dir_item|
|
71
|
+
Dir.foreach(inner_dir_item) do |inner_filename|
|
72
|
+
next if inner_filename == '.' || inner_filename == '..'
|
73
|
+
|
74
|
+
puts "\n\nHTML Processing inner file: #{inner_dir_item}/" + inner_filename + "\n\n"
|
75
|
+
|
76
|
+
contents = nil
|
77
|
+
|
78
|
+
File.open("#{inner_dir_item}/#{inner_filename}", 'r') { |f| contents = f.read }
|
79
|
+
|
80
|
+
File.open("#{inner_dir_item}/#{inner_filename}", 'w+') do |fw|
|
81
|
+
fw.write(contents.gsub(el, new_value))
|
82
|
+
end
|
83
|
+
|
84
|
+
# puts 'DEBUG contents:' + contents
|
85
|
+
# puts 'DEBUG contents.gsub(el, new_value):' + contents.gsub(el, new_value)
|
86
|
+
# raise ">>>>>>>>>>> DEBUG "
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
css_array_update!(el, new_value)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def found_in_non_div(el)
|
98
|
+
@html_dir_list.each do |dir_item|
|
99
|
+
Dir.foreach(dir_item) do |filename|
|
100
|
+
next if filename == '.' || filename == '..'
|
101
|
+
|
102
|
+
puts "Processing #{dir_item}/#{filename}"
|
103
|
+
|
104
|
+
output = File.open("#{dir_item}/#{filename}") { |f| f.read }
|
105
|
+
|
106
|
+
# puts 'DEBUG output:' + output.inspect + "\n\n"
|
107
|
+
|
108
|
+
# puts 'DEBUG output scan: ' + output.scan(/<(?!div).*?class.*?=.*?#{el}.*?>/).inspect
|
109
|
+
# puts 'DEBUG output scan: ' + output.scan(/<(?!div).*?class.*?=.*?#{el}.*?>/).empty?.inspect
|
110
|
+
|
111
|
+
return true unless output.scan(/<(?!div).*?class.*?=.*?#{el}.*?>/).empty?
|
112
|
+
|
113
|
+
# raise
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
false
|
118
|
+
end
|
119
|
+
|
120
|
+
def css_array_update!(old_value, new_value)
|
121
|
+
puts "\n\nCSS Processing div class from #{old_value} to #{new_value}\n\n"
|
122
|
+
|
123
|
+
@сss_files_array.each do |el|
|
124
|
+
puts "CSS Processing file: #{el[:filename]}\n"
|
125
|
+
el[:contents].gsub!(/.\b#{old_value}\b/, '.' + new_value) # .inspect
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def rand_string
|
130
|
+
o = [('a'..'z'), ('A'..'Z')].map(&:to_a).flatten
|
131
|
+
(0...16).map { o[rand(o.length)] }.join
|
132
|
+
end
|
133
|
+
|
134
|
+
def color_shift(contents)
|
135
|
+
contents.gsub!(/#[0-9a-fA-F]+/) do |pattern|
|
136
|
+
# puts "Color processing old_value: #{pattern}\n"
|
137
|
+
|
138
|
+
delta = pattern[1..2].downcase == 'ff' ? -1 : 1
|
139
|
+
|
140
|
+
pattern[1..2] = to_hex(pattern[1..2].hex + delta)
|
141
|
+
|
142
|
+
# puts "Color processing new value: #{pattern}\n"
|
143
|
+
|
144
|
+
pattern
|
145
|
+
end
|
146
|
+
contents
|
147
|
+
end
|
148
|
+
|
149
|
+
def to_hex(int)
|
150
|
+
int < 16 ? '0' + int.to_s(16) : int.to_s(16)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'web_randomizer'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
RSpec.describe 'WebRandomizer' do
|
7
|
+
before do
|
8
|
+
FileUtils.mkdir_p '_layouts'
|
9
|
+
FileUtils.mkdir_p '_includes'
|
10
|
+
FileUtils.mkdir_p 'assets/css'
|
11
|
+
FileUtils.mkdir_p '_sass'
|
12
|
+
end
|
13
|
+
|
14
|
+
after do
|
15
|
+
FileUtils.rm_rf('_layouts')
|
16
|
+
FileUtils.rm_rf('_includes')
|
17
|
+
FileUtils.rm_rf('assets')
|
18
|
+
FileUtils.rm_rf('_sass')
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'with valid tags' do
|
22
|
+
before do
|
23
|
+
html1_str =
|
24
|
+
<<-'_layouts'
|
25
|
+
<div class="div1">
|
26
|
+
<div class="div2">
|
27
|
+
<footer class="footer_class">
|
28
|
+
_layouts
|
29
|
+
|
30
|
+
html2_str =
|
31
|
+
<<-'_includes'
|
32
|
+
<div class="div2">
|
33
|
+
<div class="footer_class">
|
34
|
+
_includes
|
35
|
+
|
36
|
+
css_str =
|
37
|
+
<<-'css'
|
38
|
+
.div1
|
39
|
+
.div2
|
40
|
+
cite { color: #9B9b97; }
|
41
|
+
css
|
42
|
+
|
43
|
+
sass_str =
|
44
|
+
<<-'sass'
|
45
|
+
.div2
|
46
|
+
.div3
|
47
|
+
a:hover { color: #ff805E; }
|
48
|
+
sass
|
49
|
+
|
50
|
+
File.open('_layouts/test.html', 'w') { |file| file.write(html1_str) }
|
51
|
+
File.open('_includes/test.html', 'w') { |file| file.write(html2_str) }
|
52
|
+
File.open('assets/css/test.css', 'w') { |file| file.write(css_str) }
|
53
|
+
File.open('_sass/test.sass', 'w') { |file| file.write(sass_str) }
|
54
|
+
|
55
|
+
WebRandomizer.execute
|
56
|
+
|
57
|
+
puts "\n\nSPEC OUTPUT:\n\n"
|
58
|
+
puts "\n_layouts:\n" + File.open('_layouts/test.html', 'r', &:read)
|
59
|
+
puts "\n_includes:\n" + File.open('_includes/test.html', 'r', &:read)
|
60
|
+
puts "\nassets: \n" + File.open('assets/css/test.css', 'r', &:read)
|
61
|
+
puts "\n_sass:\n" + File.open('_sass/test.sass', 'r', &:read)
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should randomize div tags' do
|
65
|
+
scan_result = File.open('_layouts/test.html', 'r', &:read).scan(/.*?(?=div1|div2).*?/)
|
66
|
+
expect(scan_result.empty?).to be true
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should keep non-div tags' do
|
70
|
+
scan_result = File.open('_layouts/test.html', 'r', &:read).scan(/.*?footer_class.*?/)
|
71
|
+
expect(scan_result.empty?).to be false
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should process css classes' do
|
75
|
+
change_result = File.open('assets/css/test.css', 'r', &:read).scan(/.*?(?=div1|div2).*?/)
|
76
|
+
keep_result = File.open('_sass/test.sass', 'r', &:read).scan(/.*?(?=div3|div4).*?/)
|
77
|
+
|
78
|
+
expect(change_result.empty?).to be true
|
79
|
+
expect(keep_result.empty?).to be false
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should randomize colors' do
|
83
|
+
change_result = File.open('assets/css/test.css', 'r', &:read).scan(/.*?#9B9b97.*?/)
|
84
|
+
expect(change_result.empty?).to be true
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/web_randomizer.gemspec
CHANGED
@@ -4,8 +4,8 @@ $LOAD_PATH.push File.expand_path('lib', __dir__)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = 'web_randomizer'
|
7
|
-
s.version = '0.
|
8
|
-
s.date = '2020-10-
|
7
|
+
s.version = '0.2.0'
|
8
|
+
s.date = '2020-10-11'
|
9
9
|
s.summary = 'WebRandomizer - gem for randomizing div classes and color styles for static sites'
|
10
10
|
s.description = 'Gem for randomizing div classes and color styles for static sites.'
|
11
11
|
s.author = 'Timur Sobolev'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: web_randomizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Timur Sobolev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yaml
|
@@ -30,9 +30,11 @@ executables: []
|
|
30
30
|
extensions: []
|
31
31
|
extra_rdoc_files: []
|
32
32
|
files:
|
33
|
+
- ".gitignore"
|
33
34
|
- Gemfile
|
34
35
|
- README.md
|
35
36
|
- lib/web_randomizer.rb
|
37
|
+
- spec/web_randomizer_spec.rb
|
36
38
|
- web_randomizer.gemspec
|
37
39
|
homepage: https://github.com/sobolevtimur/web-randomizer
|
38
40
|
licenses:
|