From f6417c3e874500d6a27f88aac5d57371a3af5912 Mon Sep 17 00:00:00 2001 From: Dmytro Angelovskyi Date: Tue, 9 Apr 2024 20:57:12 +0300 Subject: [PATCH] Fast update and fixes --- .gitignore | 1 + .rubocop.yml | 1 + .ruby-version | 2 +- Gemfile | 10 + Gemfile.lock | 380 +++++++++++++++++++------------ lib/shortcode.rb | 3 - lib/shortcode/configuration.rb | 2 + lib/shortcode/parser.rb | 4 +- lib/shortcode/presenter.rb | 4 +- lib/shortcode/processor.rb | 2 +- lib/shortcode/tag.rb | 4 +- shortcode.gemspec | 13 +- spec/performance_spec.rb | 1 - spec/shortcode/parser_spec.rb | 1 - spec/shortcode/presenter_spec.rb | 1 - spec/shortcode/tag_spec.rb | 2 +- spec/shortcode_spec.rb | 1 - spec/transformer_spec.rb | 1 - 18 files changed, 257 insertions(+), 176 deletions(-) diff --git a/.gitignore b/.gitignore index 762c0c7..0ae67f9 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ test/version_tmp tmp .DS_Store gemfiles/*.lock +.byebug_history \ No newline at end of file diff --git a/.rubocop.yml b/.rubocop.yml index 6c9ec97..9584b4d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -10,6 +10,7 @@ require: rubocop-rspec AllCops: + NewCops: enable Exclude: - 'bin/*' diff --git a/.ruby-version b/.ruby-version index 097a15a..15a2799 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.6.2 +3.3.0 diff --git a/Gemfile b/Gemfile index 6c0b4b1..21eeecb 100644 --- a/Gemfile +++ b/Gemfile @@ -4,3 +4,13 @@ source "https://rubygems.org" gemspec gem "appraisal", "2.2.0" +gem "bundler", "~> 2.5" +gem "byebug" +gem "coveralls", "~> 0.8.23" +gem "haml", "~> 6.3" +gem "rails", "~> 7.1" +gem "rake", "~> 13.2" +gem "rspec", "~> 3.13" +gem "rubocop", "~> 1.62" +gem "rubocop-rspec", "~> 2.28" +gem "slim", "~> 5.2" diff --git a/Gemfile.lock b/Gemfile.lock index bd96c50..f9bbf25 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,194 +2,282 @@ PATH remote: . specs: shortcode (2.0.0) - parslet (= 1.8.0) + parslet (= 2.0.0) GEM remote: https://rubygems.org/ specs: - actioncable (5.2.3) - actionpack (= 5.2.3) + actioncable (7.1.3.2) + actionpack (= 7.1.3.2) + activesupport (= 7.1.3.2) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailer (5.2.3) - actionpack (= 5.2.3) - actionview (= 5.2.3) - activejob (= 5.2.3) + zeitwerk (~> 2.6) + actionmailbox (7.1.3.2) + actionpack (= 7.1.3.2) + activejob (= 7.1.3.2) + activerecord (= 7.1.3.2) + activestorage (= 7.1.3.2) + activesupport (= 7.1.3.2) + mail (>= 2.7.1) + net-imap + net-pop + net-smtp + actionmailer (7.1.3.2) + actionpack (= 7.1.3.2) + actionview (= 7.1.3.2) + activejob (= 7.1.3.2) + activesupport (= 7.1.3.2) mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 2.0) - actionpack (5.2.3) - actionview (= 5.2.3) - activesupport (= 5.2.3) - rack (~> 2.0) + net-imap + net-pop + net-smtp + rails-dom-testing (~> 2.2) + actionpack (7.1.3.2) + actionview (= 7.1.3.2) + activesupport (= 7.1.3.2) + nokogiri (>= 1.8.5) + racc + rack (>= 2.2.4) + rack-session (>= 1.0.1) rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.2.3) - activesupport (= 5.2.3) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + actiontext (7.1.3.2) + actionpack (= 7.1.3.2) + activerecord (= 7.1.3.2) + activestorage (= 7.1.3.2) + activesupport (= 7.1.3.2) + globalid (>= 0.6.0) + nokogiri (>= 1.8.5) + actionview (7.1.3.2) + activesupport (= 7.1.3.2) builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.2.3) - activesupport (= 5.2.3) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + activejob (7.1.3.2) + activesupport (= 7.1.3.2) globalid (>= 0.3.6) - activemodel (5.2.3) - activesupport (= 5.2.3) - activerecord (5.2.3) - activemodel (= 5.2.3) - activesupport (= 5.2.3) - arel (>= 9.0) - activestorage (5.2.3) - actionpack (= 5.2.3) - activerecord (= 5.2.3) - marcel (~> 0.3.1) - activesupport (5.2.3) + activemodel (7.1.3.2) + activesupport (= 7.1.3.2) + activerecord (7.1.3.2) + activemodel (= 7.1.3.2) + activesupport (= 7.1.3.2) + timeout (>= 0.4.0) + activestorage (7.1.3.2) + actionpack (= 7.1.3.2) + activejob (= 7.1.3.2) + activerecord (= 7.1.3.2) + activesupport (= 7.1.3.2) + marcel (~> 1.0) + activesupport (7.1.3.2) + base64 + bigdecimal concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + minitest (>= 5.1) + mutex_m + tzinfo (~> 2.0) appraisal (2.2.0) bundler rake thor (>= 0.14.0) - arel (9.0.0) - ast (2.4.0) - builder (3.2.3) - concurrent-ruby (1.1.5) - coveralls (0.8.22) + ast (2.4.2) + base64 (0.2.0) + bigdecimal (3.1.7) + builder (3.2.4) + byebug (11.1.3) + concurrent-ruby (1.2.3) + connection_pool (2.4.1) + coveralls (0.8.23) json (>= 1.8, < 3) simplecov (~> 0.16.1) term-ansicolor (~> 1.3) - thor (~> 0.19.4) + thor (>= 0.19.4, < 2.0) tins (~> 1.6) - crass (1.0.4) - diff-lcs (1.3) - docile (1.3.1) - erubi (1.8.0) - globalid (0.4.2) - activesupport (>= 4.2.0) - haml (5.0.4) - temple (>= 0.8.0) + crass (1.0.6) + date (3.3.4) + diff-lcs (1.5.1) + docile (1.4.0) + drb (2.2.1) + erubi (1.12.0) + globalid (1.2.1) + activesupport (>= 6.1) + haml (6.3.0) + temple (>= 0.8.2) + thor tilt - i18n (1.6.0) + i18n (1.14.4) concurrent-ruby (~> 1.0) - jaro_winkler (1.5.2) - json (2.2.0) - loofah (2.2.3) + io-console (0.7.2) + irb (1.12.0) + rdoc + reline (>= 0.4.2) + json (2.7.1) + language_server-protocol (3.17.0.3) + loofah (2.22.0) crass (~> 1.0.2) - nokogiri (>= 1.5.9) - mail (2.7.1) + nokogiri (>= 1.12.0) + mail (2.8.1) mini_mime (>= 0.1.1) - marcel (0.3.3) - mimemagic (~> 0.3.2) - method_source (0.9.2) - mimemagic (0.3.3) - mini_mime (1.0.1) - mini_portile2 (2.4.0) - minitest (5.11.3) - nio4r (2.3.1) - nokogiri (1.10.3) - mini_portile2 (~> 2.4.0) - parallel (1.17.0) - parser (2.6.3.0) - ast (~> 2.4.0) - parslet (1.8.0) - rack (2.0.7) - rack-test (1.1.0) - rack (>= 1.0, < 3) - rails (5.2.3) - actioncable (= 5.2.3) - actionmailer (= 5.2.3) - actionpack (= 5.2.3) - actionview (= 5.2.3) - activejob (= 5.2.3) - activemodel (= 5.2.3) - activerecord (= 5.2.3) - activestorage (= 5.2.3) - activesupport (= 5.2.3) - bundler (>= 1.3.0) - railties (= 5.2.3) - sprockets-rails (>= 2.0.0) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) + net-imap + net-pop + net-smtp + marcel (1.0.4) + mini_mime (1.1.5) + mini_portile2 (2.8.5) + minitest (5.22.3) + mutex_m (0.2.0) + net-imap (0.4.10) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.2) + timeout + net-smtp (0.5.0) + net-protocol + nio4r (2.7.1) + nokogiri (1.16.3) + mini_portile2 (~> 2.8.2) + racc (~> 1.4) + parallel (1.24.0) + parser (3.3.0.5) + ast (~> 2.4.1) + racc + parslet (2.0.0) + psych (5.1.2) + stringio + racc (1.7.3) + rack (3.0.10) + rack-session (2.0.0) + rack (>= 3.0.0) + rack-test (2.1.0) + rack (>= 1.3) + rackup (2.1.0) + rack (>= 3) + webrick (~> 1.8) + rails (7.1.3.2) + actioncable (= 7.1.3.2) + actionmailbox (= 7.1.3.2) + actionmailer (= 7.1.3.2) + actionpack (= 7.1.3.2) + actiontext (= 7.1.3.2) + actionview (= 7.1.3.2) + activejob (= 7.1.3.2) + activemodel (= 7.1.3.2) + activerecord (= 7.1.3.2) + activestorage (= 7.1.3.2) + activesupport (= 7.1.3.2) + bundler (>= 1.15.0) + railties (= 7.1.3.2) + rails-dom-testing (2.2.0) + activesupport (>= 5.0.0) + minitest nokogiri (>= 1.6) - rails-html-sanitizer (1.0.4) - loofah (~> 2.2, >= 2.2.2) - railties (5.2.3) - actionpack (= 5.2.3) - activesupport (= 5.2.3) - method_source - rake (>= 0.8.7) - thor (>= 0.19.0, < 2.0) - rainbow (3.0.0) - rake (12.3.0) - rspec (3.7.0) - rspec-core (~> 3.7.0) - rspec-expectations (~> 3.7.0) - rspec-mocks (~> 3.7.0) - rspec-core (3.7.0) - rspec-support (~> 3.7.0) - rspec-expectations (3.7.0) + rails-html-sanitizer (1.6.0) + loofah (~> 2.21) + nokogiri (~> 1.14) + railties (7.1.3.2) + actionpack (= 7.1.3.2) + activesupport (= 7.1.3.2) + irb + rackup (>= 1.0.0) + rake (>= 12.2) + thor (~> 1.0, >= 1.2.2) + zeitwerk (~> 2.6) + rainbow (3.1.1) + rake (13.2.0) + rdoc (6.6.3.1) + psych (>= 4.0.0) + regexp_parser (2.9.0) + reline (0.5.0) + io-console (~> 0.5) + rexml (3.2.6) + rspec (3.13.0) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.0) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.7.0) - rspec-mocks (3.7.0) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.7.0) - rspec-support (3.7.0) - rubocop (0.68.1) - jaro_winkler (~> 1.5.1) + rspec-support (~> 3.13.0) + rspec-support (3.13.1) + rubocop (1.62.1) + json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 2.5, != 2.5.1.1) + parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.31.1, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 1.6) - rubocop-rspec (1.32.0) - rubocop (>= 0.60.0) - ruby-progressbar (1.10.0) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.31.2) + parser (>= 3.3.0.4) + rubocop-capybara (2.20.0) + rubocop (~> 1.41) + rubocop-factory_bot (2.25.1) + rubocop (~> 1.41) + rubocop-rspec (2.28.0) + rubocop (~> 1.40) + rubocop-capybara (~> 2.17) + rubocop-factory_bot (~> 2.22) + rubocop-rspec_rails (~> 2.28) + rubocop-rspec_rails (2.28.2) + rubocop (~> 1.40) + ruby-progressbar (1.13.0) simplecov (0.16.1) docile (~> 1.1) json (>= 1.8, < 3) simplecov-html (~> 0.10.0) simplecov-html (0.10.2) - slim (3.0.8) - temple (>= 0.7.6, < 0.9) - tilt (>= 1.3.3, < 2.1) - sprockets (3.7.2) - concurrent-ruby (~> 1.0) - rack (> 1, < 3) - sprockets-rails (3.2.1) - actionpack (>= 4.0) - activesupport (>= 4.0) - sprockets (>= 3.0.0) - temple (0.8.0) - term-ansicolor (1.7.1) + slim (5.2.1) + temple (~> 0.10.0) + tilt (>= 2.1.0) + stringio (3.1.0) + sync (0.5.0) + temple (0.10.3) + term-ansicolor (1.7.2) tins (~> 1.0) - thor (0.19.4) - thread_safe (0.3.6) - tilt (2.0.8) - tins (1.20.2) - tzinfo (1.2.5) - thread_safe (~> 0.1) - unicode-display_width (1.5.0) - websocket-driver (0.7.0) + thor (1.3.1) + tilt (2.3.0) + timeout (0.4.1) + tins (1.32.1) + sync + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + unicode-display_width (2.5.0) + webrick (1.8.1) + websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.3) + websocket-extensions (0.1.5) + zeitwerk (2.6.13) PLATFORMS ruby DEPENDENCIES appraisal (= 2.2.0) - bundler (~> 2.0) - coveralls (~> 0.8.22) - haml (~> 5.0) - rails (= 5.2.3) - rake (~> 12.0) - rspec (~> 3.7) - rubocop (~> 0.68) - rubocop-rspec (~> 1.32) + bundler (~> 2.5) + byebug + coveralls (~> 0.8.23) + haml (~> 6.3) + rails (~> 7.1) + rake (~> 13.2) + rspec (~> 3.13) + rubocop (~> 1.62) + rubocop-rspec (~> 2.28) shortcode! - slim (~> 3.0) + slim (~> 5.2) BUNDLED WITH - 2.0.1 + 2.5.7 diff --git a/lib/shortcode.rb b/lib/shortcode.rb index b431787..a105839 100644 --- a/lib/shortcode.rb +++ b/lib/shortcode.rb @@ -1,15 +1,12 @@ require "parslet" require "erb" -# rubocop:disable Lint/HandleExceptions begin require "haml" rescue LoadError; end begin require "slim" rescue LoadError; end -# rubocop:enable Lint/HandleExceptions - class Shortcode def process(string, additional_attributes=nil) diff --git a/lib/shortcode/configuration.rb b/lib/shortcode/configuration.rb index 2339a60..a6a885b 100644 --- a/lib/shortcode/configuration.rb +++ b/lib/shortcode/configuration.rb @@ -20,12 +20,14 @@ class Shortcode::Configuration # Set the supported block_tags attr_reader :block_tags + def block_tags=(block_tags) @block_tags = block_tags.sort_by(&:length).reverse end # Set the supported self_closing_tags attr_reader :self_closing_tags + def self_closing_tags=(self_closing_tags) @self_closing_tags = self_closing_tags.sort_by(&:length).reverse end diff --git a/lib/shortcode/parser.rb b/lib/shortcode/parser.rb index 0c15c04..25ecebc 100644 --- a/lib/shortcode/parser.rb +++ b/lib/shortcode/parser.rb @@ -9,8 +9,8 @@ def parse(string) klass_instance.parse(string) end - def open(*args) - klass_instance.open(*args) + def open(*) + klass_instance.open(*) end private diff --git a/lib/shortcode/presenter.rb b/lib/shortcode/presenter.rb index bfb4159..8b18f3a 100644 --- a/lib/shortcode/presenter.rb +++ b/lib/shortcode/presenter.rb @@ -30,9 +30,7 @@ def initialize(name, configuration, attributes, content, additional_attributes) initialize_custom_presenter(name) end - attr_reader :content - - attr_reader :attributes + attr_reader :content, :attributes private diff --git a/lib/shortcode/processor.rb b/lib/shortcode/processor.rb index 32f290d..16aa521 100644 --- a/lib/shortcode/processor.rb +++ b/lib/shortcode/processor.rb @@ -2,7 +2,7 @@ class Shortcode::Processor def process(string, configuration, additional_attributes=nil) transformer(configuration).apply parser(configuration).parse(string), - additional_attributes: additional_attributes + additional_attributes: end private diff --git a/lib/shortcode/tag.rb b/lib/shortcode/tag.rb index 39e4817..6a564e2 100644 --- a/lib/shortcode/tag.rb +++ b/lib/shortcode/tag.rb @@ -26,20 +26,18 @@ def render attr_reader :configuration - # rubocop:disable Metrics/AbcSize def render_template case configuration.template_parser when :erb ERB.new(markup).result(@binding.expose_binding) when :haml - Haml::Engine.new(markup).render(@binding) + Haml::Template.new { markup }.render(@binding) when :slim Slim::Template.new { markup }.render(@binding) else raise Shortcode::TemplateParserNotSupported, configuration.template_parser end end - # rubocop:enable Metrics/AbcSize def first_priority_template configuration.check_config_templates_first ? markup_from_config : markup_from_file diff --git a/shortcode.gemspec b/shortcode.gemspec index b3459ce..7c294d7 100644 --- a/shortcode.gemspec +++ b/shortcode.gemspec @@ -14,18 +14,9 @@ Gem::Specification.new do |spec| spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR) spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } - spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ["lib"] - spec.add_dependency "parslet", "1.8.0" + spec.add_dependency "parslet", "2.0.0" - spec.add_development_dependency "bundler", "~> 2.0" - spec.add_development_dependency "coveralls", "~> 0.8.22" - spec.add_development_dependency "haml", "~> 5.0" - spec.add_development_dependency "rails", "5.2.3" - spec.add_development_dependency "rake", "~> 12.0" - spec.add_development_dependency "rspec", "~> 3.7" - spec.add_development_dependency "rubocop", "~> 0.68" - spec.add_development_dependency "rubocop-rspec", "~> 1.32" - spec.add_development_dependency "slim", "~> 3.0" + spec.metadata["rubygems_mfa_required"] = "true" end diff --git a/spec/performance_spec.rb b/spec/performance_spec.rb index 5947843..0f33a4a 100644 --- a/spec/performance_spec.rb +++ b/spec/performance_spec.rb @@ -1,6 +1,5 @@ require "spec_helper" require "parslet/rig/rspec" -require "pp" require "benchmark" # Uncomment to run performace specs diff --git a/spec/shortcode/parser_spec.rb b/spec/shortcode/parser_spec.rb index b4146e3..28df469 100644 --- a/spec/shortcode/parser_spec.rb +++ b/spec/shortcode/parser_spec.rb @@ -2,7 +2,6 @@ require "spec_helper" require "parslet/rig/rspec" -require "pp" describe Shortcode::Parser do let(:configuration) { Shortcode.new.configuration } diff --git a/spec/shortcode/presenter_spec.rb b/spec/shortcode/presenter_spec.rb index 44c61ac..699931b 100644 --- a/spec/shortcode/presenter_spec.rb +++ b/spec/shortcode/presenter_spec.rb @@ -1,6 +1,5 @@ require "spec_helper" require "parslet/rig/rspec" -require "pp" require "support/presenters/my_presenter" require "support/presenters/other_presenter" diff --git a/spec/shortcode/tag_spec.rb b/spec/shortcode/tag_spec.rb index 9061cca..2ee559c 100644 --- a/spec/shortcode/tag_spec.rb +++ b/spec/shortcode/tag_spec.rb @@ -67,7 +67,7 @@ it "uses the file system template when check_config_templates_first is false" do configuration.check_config_templates_first = false - expect(tag.markup).to eq(File.open("spec/support/templates/erb/quote.html.erb").read) + expect(tag.markup).to eq(File.read("spec/support/templates/erb/quote.html.erb")) end end end diff --git a/spec/shortcode_spec.rb b/spec/shortcode_spec.rb index adf68ab..0341a70 100644 --- a/spec/shortcode_spec.rb +++ b/spec/shortcode_spec.rb @@ -1,6 +1,5 @@ require "spec_helper" require "parslet/rig/rspec" -require "pp" describe Shortcode do let(:simple_quote) { load_fixture :simple_quote } diff --git a/spec/transformer_spec.rb b/spec/transformer_spec.rb index ab350e1..97513b2 100644 --- a/spec/transformer_spec.rb +++ b/spec/transformer_spec.rb @@ -1,6 +1,5 @@ require "spec_helper" require "parslet/rig/rspec" -require "pp" describe Shortcode do let(:configuration) {