Skip to content
This repository was archived by the owner on Jun 21, 2024. It is now read-only.

Upgrade to Support Ruby 3.1 and 3.2 #1

Closed
wants to merge 6 commits into from
Closed
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
40 changes: 40 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby

name: Ruby

on:
push:
branches: ['master']
pull_request:
branches: ['master']
schedule:
- cron: '0 0 * * 0'

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['3.1', '3.2']
env:
BUNDLE_GEMFILE: ${{ github.workspace }}/Gemfile
steps:
- uses: actions/checkout@v3
- name: Set up Ruby
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
# change this to (see https://github.com/ruby/setup-ruby#versioning):
# uses: ruby/setup-ruby@v1
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: Run tests
run: bundle exec rake
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
*.o
*.a
mkmf.log
.ruby-version
gemfiles/*.lock
6 changes: 3 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Metrics/MethodLength:
# Offense count: 1
Style/ClassAndModuleCamelCase:
Exclude:
- 'lib/html/pipeline/rouge_filter/version.rb'
- 'lib/html_pipeline/node_filter/rouge_filter.rb'

# Offense count: 1
# Configuration parameters: EnforcedStyle, SupportedStyles.
Expand Down Expand Up @@ -123,7 +123,7 @@ Style/IfUnlessModifier:
# Cop supports --auto-correct.
Style/MutableConstant:
Exclude:
- 'lib/html/pipeline/rouge_filter/version.rb'
- 'lib/html_pipeline/node_filter/rouge_filter.rb'

# Offense count: 1
# Cop supports --auto-correct.
Expand All @@ -150,7 +150,7 @@ Style/StringLiterals:
- 'Rakefile'
- 'html-pipeline-rouge_filter.gemspec'
- 'lib/html/pipeline/rouge_filter.rb'
- 'lib/html/pipeline/rouge_filter/version.rb'
- 'lib/html_pipeline/node_filter/rouge_filter.rb'
- 'test/rouge_filter_test.rb'
- 'test/test_helper.rb'

Expand Down
24 changes: 0 additions & 24 deletions .travis.yml

This file was deleted.

13 changes: 6 additions & 7 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
source "https://rubygems.org"

gem "html-pipeline", ">= 3"

# Specify your gem's dependencies in twemoji.gemspec
gemspec

Expand All @@ -11,13 +13,10 @@ group :development do
end

group :test do
gem "minitest", ">= 5.5"
gem "minitest"

if RUBY_VERSION < "2.2.2"
gem "activesupport", "< 5.0.0", require: false
end
gem "nokogiri", "~> 1.13"

if RUBY_VERSION < "2.1.0"
gem "nokogiri", "< 1.7.0", require: false
end
gem "minitest-focus", "~> 1.1"
gem "rouge", "~> 4.1", require: false
end
16 changes: 9 additions & 7 deletions html-pipeline-rouge_filter.gemspec
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'html/pipeline/rouge_filter/version'
require 'html_pipeline/node_filter/rouge_filter/version'

Gem::Specification.new do |spec|
spec.name = "html-pipeline-rouge_filter"
spec.version = HTML_Pipeline::RougeFilter::VERSION
spec.version = HTML_Pipeline::NodeFilter::RougeFilter::VERSION
spec.authors = ["Juanito Fatas"]
spec.email = ["katehuang0320@gmail.com"]
spec.summary = %q{Rouge integration with html-pipeline.}
spec.description = spec.summary
spec.homepage = "https://github.com/juanitofatas/html-pipeline-rouge_filter"
spec.license = "MIT"

spec.files = `git ls-files -z`.split("\x0")
spec.files = ["lib/*"]
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_dependency "html-pipeline", ">= 1.11"
spec.add_dependency "rouge", ">= 2.0.0", "< 4"
spec.add_dependency "activesupport"
spec.required_ruby_version = ">= 3.1"
spec.required_rubygems_version = ">= 3.3.22"

spec.required_ruby_version = ">= 2.0"
spec.add_dependency "html-pipeline", ">= 3"
spec.add_dependency "rouge", ">= 4"
spec.add_dependency "selma", "~> 0.1"
spec.add_dependency "zeitwerk", "~> 2.5"
end
63 changes: 0 additions & 63 deletions lib/html/pipeline/rouge_filter.rb

This file was deleted.

7 changes: 0 additions & 7 deletions lib/html/pipeline/rouge_filter/version.rb

This file was deleted.

78 changes: 78 additions & 0 deletions lib/html_pipeline/node_filter/rouge_filter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# frozen_string_literal: true

require 'html_pipeline/node_filter'

HTMLPipeline.require_dependency("rouge", "RougeFilter")

class HTMLPipeline
class NodeFilter
class RougeFilter < NodeFilter
SELECTOR = Selma::Selector.new(match_element: "pre, br, lang, class", match_text_within: "pre")

def selector
SELECTOR
end

def handle_element(element)
default = must_str(context[:highlight])
@lang = element["lang"] || default

if replace_br && element.tag_name == "br"
element.after("\n", as: :html)
element.remove
end

klass = element["class"] || "highlight"
element["class"] = "#{klass} #{default_css_class}-#{@lang}" if include_lang?
end

def handle_text_chunk(text)
return if @lang.nil?
return if (lexer = lexer_for(@lang)).nil?

content = text.to_s

text.replace(highlight_with(lexer, content), as: :html)
end

def highlight_with(lexer, text)
formatter.format(lexer.lex(text))
end

def default_css_class
must_str(context[:css_class]) || "highlight"
end

def line_numbers
context[:line_numbers] || false
end

def replace_br
context[:replace_br] || false
end

def formatter(css_class: default_css_class)
Rouge::Formatters::HTMLLegacy.new(css_class: css_class,
line_numbers: line_numbers)
end

def lexer_for(lang)
Rouge::Lexer.find_fancy(lang) || Rouge::Lexers::PlainText
end

def include_lang?
!@lang.nil? && !@lang.empty?
end

private

def must_str(text)
text && text.to_s
end

def rename_br(elem)
elem.sub("br", "\n")
end
end
end
end
7 changes: 7 additions & 0 deletions lib/html_pipeline/node_filter/rouge_filter/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module HTML_Pipeline
class NodeFilter
class RougeFilter
VERSION = "2.0.0"
end
end
end
Loading
Loading