Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: CI
on:
push:
branches: [ main ]
tags: [ 'v*' ]
pull_request:
branches: [ main ]

Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
/pkg/
/spec/reports/
/tmp/
/vendor/
.vscode/

# rspec failure tracking
.rspec_status

# Ignore downloaded style files
.rubocop-http*

.byebug_history
12 changes: 11 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -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
57 changes: 17 additions & 40 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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).
Expand Down
8 changes: 7 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 6 additions & 12 deletions kramdown_rpf.gemspec
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
1 change: 0 additions & 1 deletion lib/kramdown_rpf.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require 'i18n'
require 'kramdown'

require_relative 'kramdown_rpf/version'
require_relative 'kramdown_rpf/kramdown'
Expand Down
1 change: 1 addition & 0 deletions lib/kramdown_rpf/kramdown.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'kramdown'
require 'kramdown/parser/gfm'
require_relative 'rpf'

module Kramdown
Expand Down
24 changes: 13 additions & 11 deletions spec/errors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,32 @@
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)
end
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
Expand Down
29 changes: 15 additions & 14 deletions spec/i18n_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']))
Expand Down
30 changes: 14 additions & 16 deletions spec/kramdown_rpf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require 'bundler/setup'
require 'kramdown_rpf'
require 'byebug'

RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
Expand Down
Loading