web_randomizer 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 87005117f31f22bf286e0e4a7cbbe73722dba4f281532cb95e64f3cad57d2e60
4
+ data.tar.gz: 85190000e6ba3d5297cb5dd918cf5184f45348dc32d34a77239efe7041057596
5
+ SHA512:
6
+ metadata.gz: f8b279533300cc4def8c412ef21952115258396c9a533b61c3b2da133b2a32d16c9ef10268025292d6c4b84a8564218d063e352374fd8f3c08c7790c4b35d0ba
7
+ data.tar.gz: 2f7b3e44dd1151b446045d27bfc7985bc68f119fd8e2d16417e5694fa13bc259656da896ce8390b44fae44b8791ce73fb23c0609037dc55740623b1da75e92ed
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Gemfile
4
+ source 'https://rubygems.org'
5
+ ruby '2.5.5'
6
+
7
+ gem 'rspec'
8
+ gem 'yaml'
@@ -0,0 +1,38 @@
1
+ # Web Randomizer
2
+
3
+ ## Features
4
+ * Randomize classes for div tags for all files in specified folders
5
+ * Set random class value for div tags without class
6
+ * Replace style classes for css files in specified folders according to randomized div classes values
7
+ * Randomize css colors in specified folders
8
+
9
+ ## Installation
10
+
11
+ Add this line to your Gemfile:
12
+
13
+ gem 'web_randomizer'
14
+
15
+ Then run bundle install or install it manually:
16
+
17
+ gem install web_randomizer
18
+
19
+
20
+ ## Settings
21
+ If you want to specify your own parsing folders, you can add them to randomize.yml file located at the root of your project
22
+
23
+ Settings example:
24
+
25
+ # randomize.yml
26
+ html_dir: ["_includes", "_layouts"]
27
+ css_dir: ["assets/css","_sass"]
28
+
29
+ ## Usage
30
+
31
+ Usage example:
32
+
33
+ require 'web_randomizer'
34
+ WebRandomizer.execute
35
+
36
+ ## License
37
+ MIT License.
38
+ `
@@ -0,0 +1,123 @@
1
+ require 'yaml'
2
+
3
+ module WebRandomizer
4
+ class << self
5
+ def execute
6
+ initialize!
7
+
8
+ randomize_div!
9
+
10
+ @сss_files_array.each do |el|
11
+ puts "\n\nUpdating #{el[:filename]}\n"
12
+
13
+ File.open(el[:filename], 'w') do |file|
14
+ file.write(color_shift(el[:contents]))
15
+ end
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def initialize!
22
+ if File.file?('randomize.yml')
23
+ config = YAML.load_file('randomize.yml')
24
+
25
+ @html_dir_list = config['html_dir']
26
+ @css_dir_list = config['css_dir']
27
+
28
+ else
29
+ @html_dir_list = %w[_layouts _includes]
30
+ @css_dir_list = %w[assets/css _sass]
31
+ end
32
+
33
+ @сss_files_array = []
34
+
35
+ @css_dir_list.each do |dir_item|
36
+ Dir.foreach(dir_item) do |css_filename|
37
+ next if css_filename == '.' || css_filename == '..'
38
+
39
+ @сss_files_array << ({ filename: "#{dir_item}/#{css_filename}",
40
+ contents: File.open("#{dir_item}/#{css_filename}").read })
41
+ end
42
+ end
43
+ end
44
+
45
+ def randomize_div!
46
+ @html_dir_list.each do |dir_item|
47
+ Dir.foreach(dir_item) do |filename|
48
+ next if filename == '.' || filename == '..'
49
+
50
+ puts "Processing #{dir_item}/#{filename}"
51
+
52
+ output = File.open("#{dir_item}/#{filename}") { |f| f.read }
53
+
54
+ # puts 'DEBUG output:' + output.inspect + "\n\n"
55
+
56
+ output.gsub!(/<div>/, "<div class=\"#{rand_string}\">")
57
+
58
+ output.scan(/<div.*?class=(.*?)>/).uniq.each do |div|
59
+ div.first.slice(/\"(.*)\"/, 1).strip.split(/\s+/).each do |el|
60
+ puts "\n\nHTML Processing div: " + el + "\n\n"
61
+
62
+ new_value = rand_string.strip
63
+ @html_dir_list.each do |inner_dir_item|
64
+ Dir.foreach(inner_dir_item) do |inner_filename|
65
+ next if inner_filename == '.' || inner_filename == '..'
66
+
67
+ puts "\n\nHTML Processing inner file: #{inner_dir_item}/" + inner_filename + "\n\n"
68
+
69
+ contents = nil
70
+
71
+ File.open("#{inner_dir_item}/#{inner_filename}", 'r') { |f| contents = f.read }
72
+
73
+ File.open("#{inner_dir_item}/#{inner_filename}", 'w+') do |fw|
74
+ fw.write(contents.gsub(el, new_value))
75
+ end
76
+
77
+ # puts 'DEBUG contents:' + contents
78
+ # puts 'DEBUG contents.gsub(el, new_value):' + contents.gsub(el, new_value)
79
+ # raise ">>>>>>>>>>> DEBUG "
80
+ end
81
+ end
82
+
83
+ css_array_update!(el, new_value)
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
89
+
90
+ def css_array_update!(old_value, new_value)
91
+ puts "\n\nCSS Processing div class from #{old_value} to #{new_value}\n\n"
92
+
93
+ @сss_files_array.each do |el|
94
+ puts "CSS Processing file: #{el[:filename]}\n"
95
+ el[:contents].gsub!(/.\b#{old_value}\b/, '.' + new_value) # .inspect
96
+ end
97
+ end
98
+
99
+ def rand_string
100
+ o = [('a'..'z'), ('A'..'Z')].map(&:to_a).flatten
101
+ (0...16).map { o[rand(o.length)] }.join
102
+ end
103
+
104
+ def color_shift(contents)
105
+ contents.gsub!(/#[0-9a-fA-F]+/) do |pattern|
106
+ # puts "Color processing old_value: #{pattern}\n"
107
+
108
+ delta = pattern[1..2].downcase == 'ff' ? -1 : 1
109
+
110
+ pattern[1..2] = to_hex(pattern[1..2].hex + delta)
111
+
112
+ # puts "Color processing new value: #{pattern}\n"
113
+
114
+ pattern
115
+ end
116
+ contents
117
+ end
118
+
119
+ def to_hex(int)
120
+ int < 16 ? '0' + int.to_s(16) : int.to_s(16)
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.push File.expand_path('lib', __dir__)
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'web_randomizer'
7
+ s.version = '0.1.0'
8
+ s.date = '2020-10-10'
9
+ s.summary = 'WebRandomizer - gem for randomizing div classes and color styles for static sites'
10
+ s.description = 'Gem for randomizing div classes and color styles for static sites.'
11
+ s.author = 'Timur Sobolev'
12
+ s.email = 'timur.sobolev@gmail.com'
13
+ s.homepage = 'https://github.com/sobolevtimur/web-randomizer'
14
+ s.license = 'MIT'
15
+ s.files = `git ls-files`.split("\n")
16
+ s.add_dependency('yaml')
17
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: web_randomizer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Timur Sobolev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-10-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: yaml
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
+ description: Gem for randomizing div classes and color styles for static sites.
28
+ email: timur.sobolev@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - Gemfile
34
+ - README.md
35
+ - lib/web_randomizer.rb
36
+ - web_randomizer.gemspec
37
+ homepage: https://github.com/sobolevtimur/web-randomizer
38
+ licenses:
39
+ - MIT
40
+ metadata: {}
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 2.7.6.2
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: WebRandomizer - gem for randomizing div classes and color styles for static
61
+ sites
62
+ test_files: []