diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b11a6e8..f8b37f6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,6 +3,7 @@ name: CI on: push: branches: [ main ] + tags: [ 'v*' ] pull_request: branches: [ main ] @@ -70,8 +71,8 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Create GitHub Release - uses: softprops/action-gh-release@v1 - with: - files: pkg/*.gem - generate_release_notes: true + - name: Create GitHub Release + uses: softprops/action-gh-release@v1 + with: + files: pkg/*.gem + generate_release_notes: true diff --git a/.gitignore b/.gitignore index 120858d..6cb429a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,9 +7,13 @@ /pkg/ /spec/reports/ /tmp/ +/vendor/ .vscode/ # rspec failure tracking .rspec_status +# Ignore downloaded style files +.rubocop-http* + .byebug_history diff --git a/.rubocop.yml b/.rubocop.yml index 2cac09a..f18058c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,4 +1,14 @@ -inherit_from: .rubocop_todo.yml +# RPF Digital Products house styles +inherit_from: + - https://raspberrypifoundation.github.io/digital-engineering/configs/rubocop-base.yml + - https://raspberrypifoundation.github.io/digital-engineering/configs/rubocop-performance.yml + - https://raspberrypifoundation.github.io/digital-engineering/configs/rubocop-rspec.yml + - .rubocop_todo.yml + +# Allow the Exclude arrays to be merged. +inherit_mode: + merge: + - Exclude AllCops: NewCops: enable diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 90db122..1cfc462 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,53 +1,21 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2026-02-12 17:07:44 UTC using RuboCop version 1.84.2. +# on 2026-02-13 09:13:39 UTC using RuboCop version 1.84.2. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 4 -# Configuration parameters: EnforcedStyle, AllowedGems. -# SupportedStyles: Gemfile, gems.rb, gemspec -Gemspec/DevelopmentDependencies: - Exclude: - - 'kramdown_rpf.gemspec' - -# Offense count: 1 -Gemspec/RequiredRubyVersion: - Exclude: - - 'kramdown_rpf.gemspec' - -# Offense count: 7 -# Configuration parameters: AllowedMethods. -# AllowedMethods: enums -Lint/ConstantDefinitionInBlock: - Exclude: - - 'spec/errors_spec.rb' - - 'spec/i18n_spec.rb' - - 'spec/kramdown_rpf_spec.rb' - # Offense count: 3 # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. Metrics/AbcSize: Max: 33 -# Offense count: 2 -# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. -# AllowedMethods: refine -Metrics/BlockLength: - Max: 55 - # Offense count: 1 # Configuration parameters: AllowedMethods, AllowedPatterns. Metrics/CyclomaticComplexity: Max: 13 -# Offense count: 8 -# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. -Metrics/MethodLength: - Max: 29 - # Offense count: 1 # Configuration parameters: CountComments, CountAsOne. Metrics/ModuleLength: @@ -58,14 +26,23 @@ Metrics/ModuleLength: Metrics/PerceivedComplexity: Max: 14 -# Offense count: 6 -# Configuration parameters: AllowedConstants. -Style/Documentation: +# Offense count: 1 +# Configuration parameters: IgnoredMetadata. +RSpec/DescribeClass: + Exclude: + - 'spec/i18n_spec.rb' + +# Offense count: 2 +RSpec/LeakyLocalVariable: Exclude: - - 'spec/**/*' - - 'test/**/*' - - 'lib/kramdown_rpf/kramdown.rb' - - 'lib/kramdown_rpf/rpf.rb' + - 'spec/i18n_spec.rb' + +# Offense count: 1 +# Configuration parameters: CustomTransform, IgnoreMethods, IgnoreMetadata, InflectorPath, EnforcedInflector. +# SupportedInflectors: default, active_support +RSpec/SpecFilePathFormat: + Exclude: + - 'spec/errors_spec.rb' # Offense count: 2 # This cop supports safe autocorrection (--autocorrect). diff --git a/Gemfile b/Gemfile index f9fae16..5417310 100644 --- a/Gemfile +++ b/Gemfile @@ -5,4 +5,10 @@ source 'https://rubygems.org' # Specify your gem's dependencies in kramdown_rpf.gemspec gemspec -gem 'rubocop', '~> 1.84' +group :development do + gem 'rake' + gem 'rspec', require: false + gem 'rubocop', require: false + gem 'rubocop-performance', require: false + gem 'rubocop-rspec', require: false +end diff --git a/kramdown_rpf.gemspec b/kramdown_rpf.gemspec index bd20704..9acda90 100644 --- a/kramdown_rpf.gemspec +++ b/kramdown_rpf.gemspec @@ -1,17 +1,16 @@ # frozen_string_literal: true -lib = File.expand_path('lib', __dir__) -$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require 'kramdown_rpf/version' +require_relative 'lib/kramdown_rpf/version' Gem::Specification.new do |spec| spec.name = 'kramdown-rpf' spec.version = KramdownRPF::VERSION - spec.authors = ['Raspberry Pi Foundation Web Team'] + spec.authors = ['Raspberry Pi Foundation Digital Products Team'] spec.email = ['web@raspberrypi.org'] spec.summary = "Kramdown extensions for the Raspberry Pi Foundation's resources website." spec.homepage = 'https://projects.raspberrypi.org' spec.license = 'MIT' + spec.required_ruby_version = '>= 3.2.0' # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host' # to allow pushing to a single host or delete this section to allow pushing to any host. @@ -30,12 +29,7 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ['lib'] - spec.add_dependency 'i18n', '0.8.6' - spec.add_dependency 'kramdown', '~> 1.2', '>= 1.2.0' - spec.add_dependency 'rexml', '~> 3.4' - - spec.add_development_dependency 'bundler' - spec.add_development_dependency 'byebug' - spec.add_development_dependency 'rake' - spec.add_development_dependency 'rspec' + spec.add_dependency 'i18n' + spec.add_dependency 'kramdown', '~> 2.5' + spec.add_dependency 'kramdown-parser-gfm' end diff --git a/lib/kramdown_rpf.rb b/lib/kramdown_rpf.rb index 731797d..a85e959 100644 --- a/lib/kramdown_rpf.rb +++ b/lib/kramdown_rpf.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require 'i18n' -require 'kramdown' require_relative 'kramdown_rpf/version' require_relative 'kramdown_rpf/kramdown' diff --git a/lib/kramdown_rpf/kramdown.rb b/lib/kramdown_rpf/kramdown.rb index 91039b0..ad5d001 100644 --- a/lib/kramdown_rpf/kramdown.rb +++ b/lib/kramdown_rpf/kramdown.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'kramdown' +require 'kramdown/parser/gfm' require_relative 'rpf' module Kramdown diff --git a/spec/errors_spec.rb b/spec/errors_spec.rb index 0adcd11..449e295 100644 --- a/spec/errors_spec.rb +++ b/spec/errors_spec.rb @@ -3,18 +3,21 @@ require 'spec_helper' RSpec.describe KramdownRPF do - KRAMDOWN_OPTIONS = { - input: 'KramdownRPF', - parse_block_html: true, - syntax_highlighter: nil - }.freeze + let(:kramdown_options) do + { + input: 'KramdownRPF', + parse_block_html: true, + syntax_highlighter: nil + } + end + + before { I18n.locale = 'en' } describe 'with incomplete markup' do - it 'should raise an exception' do - I18n.locale = 'en' + it 'raises an exception' do test_result = Kramdown::Document.new( File.read('examples/errors/collapse.md'), - KRAMDOWN_OPTIONS + kramdown_options ) expect { test_result.to_html }.to raise_error(Kramdown::ParseError) @@ -22,11 +25,10 @@ end describe 'with valid markup' do - it 'should not raise any errors' do - I18n.locale = 'en' + it 'does not raise any errors' do test_result = Kramdown::Document.new( File.read('examples/collapse/collapse.md'), - KRAMDOWN_OPTIONS + kramdown_options ) expect { test_result.to_html }.not_to raise_error diff --git a/spec/i18n_spec.rb b/spec/i18n_spec.rb index c090e45..7de937a 100644 --- a/spec/i18n_spec.rb +++ b/spec/i18n_spec.rb @@ -3,39 +3,40 @@ require 'spec_helper' RSpec.describe 'i18n' do - KRAMDOWN_OPTIONS = { - input: 'KramdownRPF', - parse_block_html: true, - syntax_highlighter: nil - }.freeze + let(:kramdown_options) do + { + input: 'KramdownRPF', + parse_block_html: true, + syntax_highlighter: nil + } + end - LOCALES_DIR = File.join(File.absolute_path('../..', __FILE__), 'locales').freeze - LOCALES_FILES = File.join(LOCALES_DIR, '*.yml').freeze - LOCALES = {}.freeze + locales_dir = File.join(File.absolute_path('../..', __FILE__), 'locales').freeze + locales_files = File.join(locales_dir, '*.yml').freeze - Dir.glob(LOCALES_FILES).each do |file| + Dir.glob(locales_files).each do |file| file_contents = YAML.load_file(file).first locale = file_contents[0] values = file_contents[1]['kramdown_rpf'] context("with #{locale} locale") do - before(:all) do + before do I18n.locale = locale end - it('should convert hint title') do + it('converts hint title') do test_result = Kramdown::Document.new( File.read('examples/i18n/hints.md'), - KRAMDOWN_OPTIONS + kramdown_options ).to_html expect(test_result).to(include(values['hint_title'])) end - it('should convert save prompt') do + it('converts save prompt') do test_result = Kramdown::Document.new( File.read('examples/i18n/save.md'), - KRAMDOWN_OPTIONS + kramdown_options ).to_html expect(test_result).to(include(values['save'])) diff --git a/spec/kramdown_rpf_spec.rb b/spec/kramdown_rpf_spec.rb index 068ae01..97e5e24 100644 --- a/spec/kramdown_rpf_spec.rb +++ b/spec/kramdown_rpf_spec.rb @@ -3,13 +3,7 @@ require 'spec_helper' RSpec.describe KramdownRPF do - KRAMDOWN_OPTIONS = { - input: 'KramdownRPF', - parse_block_html: true, - syntax_highlighter: nil - }.freeze - - CONVERSION_TESTS = %w[ + conversion_tests = %w[ challenge/challenge code/code code/code_default @@ -43,22 +37,26 @@ ].freeze it 'has a version number' do - expect(KramdownRPF::VERSION).not_to be nil + expect(KramdownRPF::VERSION).not_to be_nil end describe 'conversions' do - CONVERSION_TESTS.each do |test_name| + conversion_tests.each do |test_name| context test_name do - reference_result = File.read "examples/#{test_name}.html" - - it 'should be correctly converted' do - I18n.locale = 'en' - - test_result = Kramdown::Document.new( + subject(:test_result) do + Kramdown::Document.new( File.read("examples/#{test_name}.md"), - KRAMDOWN_OPTIONS + input: 'KramdownRPF', + parse_block_html: true, + syntax_highlighter: nil ).to_html + end + + let(:reference_result) { File.read "examples/#{test_name}.html" } + + before { I18n.locale = 'en' } + it 'is correctly converted' do expect(test_result.strip).to eq(reference_result.strip) end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 62a1b2f..6efd082 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,7 +2,6 @@ require 'bundler/setup' require 'kramdown_rpf' -require 'byebug' RSpec.configure do |config| # Enable flags like --only-failures and --next-failure