lbenicio-minimal-v1 1.0.2 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +471 -0
  3. data/_includes/analytics.html +10 -0
  4. data/_includes/anchor_headings.html +172 -0
  5. data/_includes/blog-navigation.html +18 -0
  6. data/_includes/conclusion.html +4 -0
  7. data/_includes/footer.html +13 -0
  8. data/_includes/fork.html +6 -0
  9. data/_includes/head.html +45 -0
  10. data/_includes/navigation.html +42 -0
  11. data/_includes/pagination.html +23 -0
  12. data/_includes/postList.html +20 -0
  13. data/_layouts/autopage_category.html +9 -0
  14. data/_layouts/autopage_collection.html +7 -0
  15. data/_layouts/autopage_tags.html +9 -0
  16. data/_layouts/default.html +28 -0
  17. data/_layouts/home.html +19 -0
  18. data/_layouts/posts.html +7 -0
  19. data/assets/favicon.ico +0 -0
  20. data/assets/monokai.scss +354 -0
  21. data/assets/postStyle.scss +26 -0
  22. data/assets/profile.jpg +0 -0
  23. data/assets/style.scss +143 -0
  24. data/assets/vendor/all.min.css +5 -0
  25. data/assets/webfonts/fa-brands-400.eot +0 -0
  26. data/assets/webfonts/fa-brands-400.svg +3717 -0
  27. data/assets/webfonts/fa-brands-400.ttf +0 -0
  28. data/assets/webfonts/fa-brands-400.woff +0 -0
  29. data/assets/webfonts/fa-brands-400.woff2 +0 -0
  30. data/assets/webfonts/fa-regular-400.eot +0 -0
  31. data/assets/webfonts/fa-regular-400.svg +801 -0
  32. data/assets/webfonts/fa-regular-400.ttf +0 -0
  33. data/assets/webfonts/fa-regular-400.woff +0 -0
  34. data/assets/webfonts/fa-regular-400.woff2 +0 -0
  35. data/assets/webfonts/fa-solid-900.eot +0 -0
  36. data/assets/webfonts/fa-solid-900.svg +5034 -0
  37. data/assets/webfonts/fa-solid-900.ttf +0 -0
  38. data/assets/webfonts/fa-solid-900.woff +0 -0
  39. data/assets/webfonts/fa-solid-900.woff2 +0 -0
  40. data/benchmark/capture-assign.rb +23 -0
  41. data/benchmark/conditional_liquid.rb +102 -0
  42. data/benchmark/end-with-vs-regexp +18 -0
  43. data/benchmark/file-dir-ensure-trailing-slash +56 -0
  44. data/benchmark/find-filter-vs-where-first-filters.rb +49 -0
  45. data/benchmark/flat-map +19 -0
  46. data/benchmark/hash-fetch +12 -0
  47. data/benchmark/jekyll-sanitize-path +47 -0
  48. data/benchmark/local-require +29 -0
  49. data/benchmark/native-vs-pathutil-relative +33 -0
  50. data/benchmark/parse-date +26 -0
  51. data/benchmark/parse-include-tag-params.rb +85 -0
  52. data/benchmark/path-manager.rb +65 -0
  53. data/benchmark/proc-call-vs-yield +17 -0
  54. data/benchmark/regexp-vs-include.rb +53 -0
  55. data/benchmark/sanitize-url.rb +27 -0
  56. data/benchmark/schwartzian_transform.rb +110 -0
  57. data/benchmark/sequential-assignment +15 -0
  58. data/benchmark/static-drop-vs-forwarded.rb +83 -0
  59. data/benchmark/string-concat +11 -0
  60. data/benchmark/string-replacement +16 -0
  61. data/benchmark/symbol-to-proc +9 -0
  62. data/rubocop/jekyll/assert_equal_literal_actual.rb +149 -0
  63. data/rubocop/jekyll/no_p_allowed.rb +23 -0
  64. data/rubocop/jekyll/no_puts_allowed.rb +23 -0
  65. data/rubocop/jekyll.rb +5 -0
  66. metadata +68 -4
@@ -0,0 +1,110 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # The Ruby documentation for #sort_by describes what's called a Schwartzian transform:
6
+ #
7
+ # > A more efficient technique is to cache the sort keys (modification times in this case)
8
+ # > before the sort. Perl users often call this approach a Schwartzian transform, after
9
+ # > Randal Schwartz. We construct a temporary array, where each element is an array
10
+ # > containing our sort key along with the filename. We sort this array, and then extract
11
+ # > the filename from the result.
12
+ # > This is exactly what sort_by does internally.
13
+ #
14
+ # The well-documented efficiency of sort_by is a good reason to use it. However, when a property
15
+ # does not exist on an item being sorted, it can cause issues (no nil's allowed!)
16
+ # In Jekyll::Filters#sort_input, we extract the property in each iteration of #sort,
17
+ # which is quite inefficient! How inefficient? This benchmark will tell you just how, and how much
18
+ # it can be improved by using the Schwartzian transform. Thanks, Randall!
19
+
20
+ require 'benchmark/ips'
21
+ require 'minitest'
22
+ require File.expand_path('../lib/jekyll', __dir__)
23
+
24
+ def site
25
+ @site ||= Jekyll::Site.new(
26
+ Jekyll.configuration('source' => File.expand_path('../docs', __dir__))
27
+ ).tap(&:reset).tap(&:read)
28
+ end
29
+
30
+ def site_docs
31
+ site.collections['docs'].docs.dup
32
+ end
33
+
34
+ def sort_by_property_directly(docs, meta_key)
35
+ docs.sort! do |apple, orange|
36
+ apple_property = apple[meta_key]
37
+ orange_property = orange[meta_key]
38
+
39
+ if !apple_property.nil? && !orange_property.nil?
40
+ apple_property <=> orange_property
41
+ elsif !apple_property.nil? && orange_property.nil?
42
+ -1
43
+ elsif apple_property.nil? && !orange_property.nil?
44
+ 1
45
+ else
46
+ apple <=> orange
47
+ end
48
+ end
49
+ end
50
+
51
+ def schwartzian_transform(docs, meta_key)
52
+ docs.collect! do |d|
53
+ [d[meta_key], d]
54
+ end.sort! do |apple, orange|
55
+ if !apple[0].nil? && !orange[0].nil?
56
+ apple.first <=> orange.first
57
+ elsif !apple[0].nil? && orange[0].nil?
58
+ -1
59
+ elsif apple[0].nil? && !orange[0].nil?
60
+ 1
61
+ else
62
+ apple[-1] <=> orange[-1]
63
+ end
64
+ end.collect! { |d| d[-1] }
65
+ end
66
+
67
+ # Before we test efficiency, do they produce the same output?
68
+ class Correctness
69
+ include Minitest::Assertions
70
+
71
+ define_method :mu_pp, &:pretty_inspect
72
+
73
+ attr_accessor :assertions
74
+
75
+ def initialize(docs, property)
76
+ @assertions = 0
77
+ @docs = docs
78
+ @property = property
79
+ end
80
+
81
+ def assert!
82
+ assert sort_by_property_directly(@docs, @property).is_a?(Array), 'sort_by_property_directly must return an array'
83
+ assert schwartzian_transform(@docs, @property).is_a?(Array), 'schwartzian_transform must return an array'
84
+ assert_equal sort_by_property_directly(@docs, @property),
85
+ schwartzian_transform(@docs, @property)
86
+ puts "Yeah, ok, correctness all checks out for property #{@property.inspect}"
87
+ end
88
+ end
89
+
90
+ Correctness.new(site_docs, 'redirect_from').assert!
91
+ Correctness.new(site_docs, 'title').assert!
92
+
93
+ def property(property, meta_key)
94
+ Benchmark.ips do |x|
95
+ x.config(time: 10, warmup: 5)
96
+ x.report("sort_by_property_directly with #{property} property") do
97
+ sort_by_property_directly(site_docs, meta_key)
98
+ end
99
+ x.report("schwartzian_transform with #{property} property") do
100
+ schwartzian_transform(site_docs, meta_key)
101
+ end
102
+ x.compare!
103
+ end
104
+ end
105
+
106
+ # First, test with a property only a handful of documents have.
107
+ test_property('sparse', 'redirect_from')
108
+
109
+ # Next, test with a property they all have.
110
+ test_property('non-sparse', 'title')
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'benchmark/ips'
5
+
6
+ Benchmark.ips do |x|
7
+ x.report('parallel assignment') do
8
+ a = 1
9
+ b = 2
10
+ end
11
+ x.report('multi-line assignment') do
12
+ a = 1
13
+ b = 2
14
+ end
15
+ end
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'forwardable'
5
+ require 'colorator'
6
+ require 'liquid'
7
+ require 'benchmark/ips'
8
+ require 'memory_profiler'
9
+
10
+ # Set up (memory) profiler
11
+
12
+ class Profiler
13
+ def self.run
14
+ yield new(ARGV[0] || 10_000)
15
+ end
16
+
17
+ def initialize(count)
18
+ @count = count.to_i
19
+ end
20
+
21
+ def report(label, color, &block)
22
+ prof_report = MemoryProfiler.report { @count.to_i.times(&block) }
23
+
24
+ allocated_memory = prof_report.scale_bytes(prof_report.total_allocated_memsize)
25
+ allocated_objects = prof_report.total_allocated
26
+ retained_memory = prof_report.scale_bytes(prof_report.total_retained_memsize)
27
+ retained_objects = prof_report.total_retained
28
+
29
+ puts <<~MSG.send(color)
30
+ With #{label} calls
31
+
32
+ Total allocated: #{allocated_memory} (#{allocated_objects} objects)
33
+ Total retained: #{retained_memory} (#{retained_objects} objects)
34
+ MSG
35
+ end
36
+ end
37
+
38
+ # Set up stage
39
+
40
+ class Drop < Liquid::Drop
41
+ def initialize(obj)
42
+ @obj = obj
43
+ end
44
+ end
45
+
46
+ class ForwardDrop < Drop
47
+ extend Forwardable
48
+ def_delegators :@obj, :name
49
+ end
50
+
51
+ class StaticDrop < Drop
52
+ def name
53
+ @obj.name
54
+ end
55
+ end
56
+
57
+ class Document
58
+ def name
59
+ 'lipsum'
60
+ end
61
+ end
62
+
63
+ # Set up actors
64
+
65
+ document = Document.new
66
+ alpha = ForwardDrop.new(document)
67
+ beta = StaticDrop.new(document)
68
+ count = ARGV[0] || 10_000
69
+
70
+ # Run profilers
71
+ puts "\nMemory profiles for #{count} calls to invoke drop key:"
72
+ Profiler.run do |x|
73
+ x.report('forwarded', :cyan) { alpha['name'] }
74
+ x.report('static', :green) { beta['name'] }
75
+ end
76
+
77
+ # Benchmark
78
+ puts "\nBenchmarking the two scenarios..."
79
+ Benchmark.ips do |x|
80
+ x.report('forwarded'.cyan) { alpha['name'] }
81
+ x.report('static'.green) { beta['name'] }
82
+ x.compare!
83
+ end
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'benchmark/ips'
5
+
6
+ url = 'https://jekyllrb.com'
7
+
8
+ Benchmark.ips do |x|
9
+ x.report('+=') { url += '/' }
10
+ x.report('<<') { url << '/' }
11
+ end
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'benchmark/ips'
5
+
6
+ def str
7
+ 'http://baruco.org/2014/some-talk-with-some-amount-of-value'
8
+ end
9
+
10
+ Benchmark.ips do |x|
11
+ x.report('#tr') { str.tr('some', 'a') }
12
+ x.report('#gsub') { str.gsub('some', 'a') }
13
+ x.report('#gsub!') { str.gsub!('some', 'a') }
14
+ x.report('#sub') { str.sub('some', 'a') }
15
+ x.report('#sub!') { str.sub!('some', 'a') }
16
+ end
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'benchmark/ips'
5
+
6
+ Benchmark.ips do |x|
7
+ x.report('block') { (1..100).map(&:to_s) }
8
+ x.report('&:to_s') { (1..100).map(&:to_s) }
9
+ end
@@ -0,0 +1,149 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Jekyll
6
+ # Checks for `assert_equal(exp, act, msg = nil)` calls containing literal values as
7
+ # second argument. The second argument should ideally be a method called on the tested
8
+ # instance.
9
+ #
10
+ # @example
11
+ # # bad
12
+ # assert_equal @foo.bar, "foobar"
13
+ # assert_equal @alpha.beta, { "foo" => "bar", "lorem" => "ipsum" }
14
+ # assert_equal @alpha.omega, ["foobar", "lipsum"]
15
+ #
16
+ # # good
17
+ # assert_equal "foobar", @foo.bar
18
+ #
19
+ # assert_equal(
20
+ # { "foo" => "bar", "lorem" => "ipsum" },
21
+ # @alpha.beta
22
+ # )
23
+ #
24
+ # assert_equal(
25
+ # ["foobar", "lipsum"],
26
+ # @alpha.omega
27
+ # )
28
+ #
29
+ class AssertEqualLiteralActual < Cop
30
+ MSG = "Provide the 'expected value' as the first argument to `assert_equal`.".freeze
31
+
32
+ SIMPLE_LITERALS = %i(
33
+ true
34
+ false
35
+ nil
36
+ int
37
+ float
38
+ str
39
+ sym
40
+ complex
41
+ rational
42
+ regopt
43
+ ).freeze
44
+
45
+ COMPLEX_LITERALS = %i(
46
+ array
47
+ hash
48
+ pair
49
+ irange
50
+ erange
51
+ regexp
52
+ ).freeze
53
+
54
+ def_node_matcher :literal_actual?, <<-PATTERN
55
+ (send nil? :assert_equal $(send ...) $#literal?)
56
+ PATTERN
57
+
58
+ def_node_matcher :literal_actual_with_msg?, <<-PATTERN
59
+ (send nil? :assert_equal $(send ...) $#literal? $#opt_msg?)
60
+ PATTERN
61
+
62
+ def on_send(node)
63
+ return unless literal_actual?(node) || literal_actual_with_msg?(node)
64
+ add_offense(node, location: :expression)
65
+ end
66
+
67
+ def autocorrect(node)
68
+ lambda do |corrector|
69
+ corrector.replace(node.loc.expression, replacement(node))
70
+ end
71
+ end
72
+
73
+ private
74
+
75
+ def opt_msg?(node)
76
+ node&.source
77
+ end
78
+
79
+ # This is not implement using a NodePattern because it seems
80
+ # to not be able to match against an explicit (nil) sexp
81
+ def literal?(node)
82
+ node && (simple_literal?(node) || complex_literal?(node))
83
+ end
84
+
85
+ def simple_literal?(node)
86
+ SIMPLE_LITERALS.include?(node.type)
87
+ end
88
+
89
+ def complex_literal?(node)
90
+ COMPLEX_LITERALS.include?(node.type) &&
91
+ node.each_child_node.all?(&method(:literal?))
92
+ end
93
+
94
+ def replacement(node)
95
+ _, _, first_param, second_param, optional_param = *node
96
+
97
+ replaced_text = \
98
+ if second_param.type == :hash
99
+ replace_hash_with_variable(first_param.source, second_param.source)
100
+ elsif second_param.type == :array && second_param.source != "[]"
101
+ replace_array_with_variable(first_param.source, second_param.source)
102
+ else
103
+ replace_based_on_line_length(first_param.source, second_param.source)
104
+ end
105
+
106
+ return "#{replaced_text}, #{optional_param.source}" if optional_param
107
+ replaced_text
108
+ end
109
+
110
+ def replace_based_on_line_length(first_expression, second_expression)
111
+ result = "assert_equal #{second_expression}, #{first_expression}"
112
+ return result if result.length < 80
113
+
114
+ # fold long lines independent of Rubocop configuration for better readability
115
+ <<~TEXT
116
+ assert_equal(
117
+ #{second_expression},
118
+ #{first_expression}
119
+ )
120
+ TEXT
121
+ end
122
+
123
+ def replace_hash_with_variable(first_expression, second_expression)
124
+ expect_expression = if second_expression.start_with?("{")
125
+ second_expression
126
+ else
127
+ "{#{second_expression}}"
128
+ end
129
+ <<~TEXT
130
+ expected = #{expect_expression}
131
+ assert_equal expected, #{first_expression}
132
+ TEXT
133
+ end
134
+
135
+ def replace_array_with_variable(first_expression, second_expression)
136
+ expect_expression = if second_expression.start_with?("%")
137
+ second_expression
138
+ else
139
+ Array(second_expression)
140
+ end
141
+ <<~TEXT
142
+ expected = #{expect_expression}
143
+ assert_equal expected, #{first_expression}
144
+ TEXT
145
+ end
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubocop"
4
+
5
+ module RuboCop
6
+ module Cop
7
+ module Jekyll
8
+ class NoPAllowed < Cop
9
+ MSG = "Avoid using `p` to print things. Use `Jekyll.logger` instead.".freeze
10
+
11
+ def_node_search :p_called?, <<-PATTERN
12
+ (send _ :p _)
13
+ PATTERN
14
+
15
+ def on_send(node)
16
+ if p_called?(node)
17
+ add_offense(node, :location => :selector)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubocop"
4
+
5
+ module RuboCop
6
+ module Cop
7
+ module Jekyll
8
+ class NoPutsAllowed < Cop
9
+ MSG = "Avoid using `puts` to print things. Use `Jekyll.logger` instead.".freeze
10
+
11
+ def_node_search :puts_called?, <<-PATTERN
12
+ (send nil? :puts _)
13
+ PATTERN
14
+
15
+ def on_send(node)
16
+ if puts_called?(node)
17
+ add_offense(node, :location => :selector)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
data/rubocop/jekyll.rb ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ Dir[File.join(File.expand_path("jekyll", __dir__), "*.rb")].each do |ruby_file|
4
+ require ruby_file
5
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lbenicio-minimal-v1
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leonardo Benicio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-03 00:00:00.000000000 Z
11
+ date: 2022-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll-seo-tag
@@ -156,8 +156,72 @@ email:
156
156
  executables: []
157
157
  extensions: []
158
158
  extra_rdoc_files: []
159
- files: []
160
- homepage: https://github.com/lbenicio/lbenicio-minimal1
159
+ files:
160
+ - ".rubocop.yml"
161
+ - _includes/analytics.html
162
+ - _includes/anchor_headings.html
163
+ - _includes/blog-navigation.html
164
+ - _includes/conclusion.html
165
+ - _includes/footer.html
166
+ - _includes/fork.html
167
+ - _includes/head.html
168
+ - _includes/navigation.html
169
+ - _includes/pagination.html
170
+ - _includes/postList.html
171
+ - _layouts/autopage_category.html
172
+ - _layouts/autopage_collection.html
173
+ - _layouts/autopage_tags.html
174
+ - _layouts/default.html
175
+ - _layouts/home.html
176
+ - _layouts/posts.html
177
+ - assets/favicon.ico
178
+ - assets/monokai.scss
179
+ - assets/postStyle.scss
180
+ - assets/profile.jpg
181
+ - assets/style.scss
182
+ - assets/vendor/all.min.css
183
+ - assets/webfonts/fa-brands-400.eot
184
+ - assets/webfonts/fa-brands-400.svg
185
+ - assets/webfonts/fa-brands-400.ttf
186
+ - assets/webfonts/fa-brands-400.woff
187
+ - assets/webfonts/fa-brands-400.woff2
188
+ - assets/webfonts/fa-regular-400.eot
189
+ - assets/webfonts/fa-regular-400.svg
190
+ - assets/webfonts/fa-regular-400.ttf
191
+ - assets/webfonts/fa-regular-400.woff
192
+ - assets/webfonts/fa-regular-400.woff2
193
+ - assets/webfonts/fa-solid-900.eot
194
+ - assets/webfonts/fa-solid-900.svg
195
+ - assets/webfonts/fa-solid-900.ttf
196
+ - assets/webfonts/fa-solid-900.woff
197
+ - assets/webfonts/fa-solid-900.woff2
198
+ - benchmark/capture-assign.rb
199
+ - benchmark/conditional_liquid.rb
200
+ - benchmark/end-with-vs-regexp
201
+ - benchmark/file-dir-ensure-trailing-slash
202
+ - benchmark/find-filter-vs-where-first-filters.rb
203
+ - benchmark/flat-map
204
+ - benchmark/hash-fetch
205
+ - benchmark/jekyll-sanitize-path
206
+ - benchmark/local-require
207
+ - benchmark/native-vs-pathutil-relative
208
+ - benchmark/parse-date
209
+ - benchmark/parse-include-tag-params.rb
210
+ - benchmark/path-manager.rb
211
+ - benchmark/proc-call-vs-yield
212
+ - benchmark/regexp-vs-include.rb
213
+ - benchmark/sanitize-url.rb
214
+ - benchmark/schwartzian_transform.rb
215
+ - benchmark/sequential-assignment
216
+ - benchmark/static-drop-vs-forwarded.rb
217
+ - benchmark/string-concat
218
+ - benchmark/string-replacement
219
+ - benchmark/symbol-to-proc
220
+ - rubocop/jekyll.rb
221
+ - rubocop/jekyll/assert_equal_literal_actual.rb
222
+ - rubocop/jekyll/no_p_allowed.rb
223
+ - rubocop/jekyll/no_puts_allowed.rb
224
+ homepage: https://github.com/lbenicio/lbenicio-minimal-v1
161
225
  licenses:
162
226
  - GPL-3.0
163
227
  metadata: {}