Skip to content

Commit

Permalink
Modernize gem.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Oct 28, 2024
1 parent 94f9ae3 commit 523df7d
Show file tree
Hide file tree
Showing 43 changed files with 227 additions and 227 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ jobs:
timeout-minutes: 5
run: bundle exec bake test

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
include-hidden-files: true
if-no-files-found: error
name: coverage-${{matrix.os}}-${{matrix.ruby}}-${{matrix.env}}
path: .covered.db

Expand All @@ -53,7 +55,7 @@ jobs:
ruby-version: "3.3"
bundler-cache: true

- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4

- name: Validate coverage
timeout-minutes: 5
Expand Down
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@ Layout/EmptyLinesAroundModuleBody:

Style/FrozenStringLiteralComment:
Enabled: true

Style/StringLiterals:
Enabled: true
EnforcedStyle: double_quotes
12 changes: 6 additions & 6 deletions bake/xrb/entities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
# Fetch the HTML5 entities from w3.org and update the local cache.
# @parameter force [Boolean] Whether to force regenerate the local cache.
def fetch_entities(force: false)
require 'json'
require 'async'
require 'async/http/internet'
require "json"
require "async"
require "async/http/internet"

internet = Async::HTTP::Internet.new
entites_json_path = self.entites_json_path
Expand All @@ -21,17 +21,17 @@ def fetch_entities(force: false)
end
end

return JSON.parse(File.read(entites_json_path)).delete_if{|string, _| !string.end_with? ';'}
return JSON.parse(File.read(entites_json_path)).delete_if{|string, _| !string.end_with? ";"}
end

# Consume the HTML5 entites and generate parsers to escape them.
# @parameter wet [Boolean] Whether to write updated files.
def update_entities(wet: false)
require 'xrb/template'
require "xrb/template"

paths = {
# 'ext/xrb/entities.rl' => 'ext/xrb/entities.xrb',
'lib/xrb/entities.rb' => 'lib/xrb/entities.xrb',
"lib/xrb/entities.rb" => "lib/xrb/entities.xrb",
}

entities = self.fetch_entities
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/call_vs_yield.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Released under the MIT License.
# Copyright, 2016-2024, by Samuel Williams.

require 'benchmark/ips'
require "benchmark/ips"

describe "block.call vs yield with block vs yield" do
def do_call(&block)
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/escape_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# Released under the MIT License.
# Copyright, 2017-2024, by Samuel Williams.

require 'benchmark/ips'
require 'xrb/markup'
require "benchmark/ips"
require "xrb/markup"

describe XRB::Markup do
let(:code_string) {'javascript:if (foo < bar) {alert("Hello World")}'}
Expand Down
10 changes: 5 additions & 5 deletions benchmarks/interpolation_vs_concat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
# Released under the MIT License.
# Copyright, 2016-2024, by Samuel Williams.

require 'benchmark/ips'
require "benchmark/ips"

describe "String interpolation vs String\#<<" do
it "should be fast to concatenate strings" do
firstname = 'soundarapandian'
middlename = 'rathinasamy'
lastname = 'arumugam'
firstname = "soundarapandian"
middlename = "rathinasamy"
lastname = "arumugam"

Benchmark.ips do |x|
x.report("String\#<<") do |i|
buffer = String.new

while (i -= 1) > 0
buffer << 'Mr. ' << firstname << middlename << lastname << ' aka soundar'
buffer << "Mr. " << firstname << middlename << lastname << " aka soundar"
end
end

Expand Down
4 changes: 2 additions & 2 deletions benchmarks/io_vs_string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# Released under the MIT License.
# Copyright, 2016-2024, by Samuel Williams.

require 'benchmark/ips'
require 'stringio'
require "benchmark/ips"
require "stringio"

describe "String\#<< vs Array\#<< vs StringIO" do
it "should be fast to concatenate strings" do
Expand Down
26 changes: 13 additions & 13 deletions benchmarks/parsers_performance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
# Released under the MIT License.
# Copyright, 2016-2024, by Samuel Williams.

require 'benchmark/ips'
require 'xrb/parsers'
require 'xrb/entities'
require 'xrb/parse_delegate'
require "benchmark/ips"
require "xrb/parsers"
require "xrb/entities"
require "xrb/parse_delegate"

require 'xrb/query'
require 'rack/utils'
require "xrb/query"
require "rack/utils"

require 'nokogiri'
require "nokogiri"

describe XRB::Parsers do
# include_context "profile"

describe '#parse_markup' do
let(:xhtml_path) {File.expand_path('.corpus/large.xhtml', __dir__)}
describe "#parse_markup" do
let(:xhtml_path) {File.expand_path(".corpus/large.xhtml", __dir__)}
let(:xhtml_buffer) {XRB::FileBuffer.new(xhtml_path)}
let(:entities) {XRB::Entities::HTML5}

Expand Down Expand Up @@ -49,11 +49,11 @@
end
end

describe '#parse_template' do
let(:large_xrb_path) {File.expand_path('.corpus/large.xrb', __dir__)}
describe "#parse_template" do
let(:large_xrb_path) {File.expand_path(".corpus/large.xrb", __dir__)}
let(:xrb_buffer) {XRB::FileBuffer.new(large_xrb_path)}

let(:large_erb_path) {File.expand_path('.corpus/large.erb', __dir__)}
let(:large_erb_path) {File.expand_path(".corpus/large.erb", __dir__)}
let(:erb_buffer) {XRB::FileBuffer.new(large_erb_path)}

it "should be fast to parse large templates" do
Expand All @@ -79,7 +79,7 @@
end
end

describe '#parse_query' do
describe "#parse_query" do
let(:string) {"foo=hi%20there&bar[blah]=123&bar[quux][0]=1&bar[quux][1]=2&bar[quux][2]=3"}

it "should be fast to parse large query strings" do
Expand Down
10 changes: 5 additions & 5 deletions benchmarks/template_performance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
# Released under the MIT License.
# Copyright, 2016-2024, by Samuel Williams.

require 'benchmark/ips'
require 'xrb/parsers'
require 'xrb/template'
require 'erb'
require "benchmark/ips"
require "xrb/parsers"
require "xrb/template"
require "erb"

class Model
def name
Expand Down Expand Up @@ -38,7 +38,7 @@ def reverse(&block)
# expect(object_time).to be < binding_time
# end

let(:interpolations_path) {File.expand_path('.corpus/interpolations.xrb', __dir__)}
let(:interpolations_path) {File.expand_path(".corpus/interpolations.xrb", __dir__)}

it "should be fast for lots of interpolations" do
xrb_template = XRB::Template.new(XRB::Buffer.load_file(interpolations_path))
Expand Down
2 changes: 1 addition & 1 deletion config/sus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

$LOAD_PATH << ::File.expand_path("../ext", __dir__)

require 'covered/sus'
require "covered/sus"
include Covered::Sus
24 changes: 12 additions & 12 deletions examples/erubis/compare.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

# frozen_string_literal: true

require 'bundler/inline'
require "bundler/inline"

gemfile do
source 'https://rubygems.org'
gem 'benchmark-ips'
gem 'xrb'
gem 'erb'
gem 'erubi'
source "https://rubygems.org"
gem "benchmark-ips"
gem "xrb"
gem "erb"
gem "erubi"
end

ERB_SRC = <<~'ERB'
Expand Down Expand Up @@ -72,15 +72,15 @@ def xrb_render

# Compile time:
Benchmark.ips do |x|
x.report('ERB (erubi)') { Erubi::Engine.new(ERB_SRC, freeze_template_literals: false, chain_appends: true).src}
x.report('XRB') { XRB::Template.new(XRB::Buffer.load(XRB_SRC)).code }
x.report("ERB (erubi)") { Erubi::Engine.new(ERB_SRC, freeze_template_literals: false, chain_appends: true).src}
x.report("XRB") { XRB::Template.new(XRB::Buffer.load(XRB_SRC)).code }
x.compare!
end

Benchmark.ips do |x|
x.report('ERB (eval)') { ERB_TEMPLATE.result }
x.report('XRB') { XRB_TEMPLATE.to_string }
x.report('XRB (method)') { Templates.xrb_render }
x.report('ERB (erubi)') { Templates.erubi_render }
x.report("ERB (eval)") { ERB_TEMPLATE.result }
x.report("XRB") { XRB_TEMPLATE.to_string }
x.report("XRB (method)") { Templates.xrb_render }
x.report("ERB (erubi)") { Templates.erubi_render }
x.compare!
end
6 changes: 3 additions & 3 deletions examples/trenni-3.9/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# Released under the MIT License.
# Copyright, 2024, by Samuel Williams.

require 'trenni'
require 'trenni/version'
require "trenni"
require "trenni/version"

class Formatter
def title_for(options)
Expand All @@ -31,5 +31,5 @@ def row(options = {}, &block)

puts "Trenni version: #{Trenni::VERSION}"

template = Trenni::Template.load_file('test.trenni')
template = Trenni::Template.load_file("test.trenni")
puts template.to_string(binding)
4 changes: 2 additions & 2 deletions examples/xrb/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Released under the MIT License.
# Copyright, 2024, by Samuel Williams.

require 'xrb'
require "xrb"

class Formatter
def title_for(options)
Expand All @@ -28,7 +28,7 @@ def row(options = {}, &block)
end
end

template = XRB::Template.load_file('test.xrb')
template = XRB::Template.load_file("test.xrb")

puts template.send(:code)

Expand Down
4 changes: 2 additions & 2 deletions ext/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

return if RUBY_DESCRIPTION =~ /jruby/

require 'mkmf'
require "mkmf"

$CFLAGS << " -O3 -Wall -Wno-unknown-pragmas -std=c99"

Expand All @@ -17,4 +17,4 @@

create_header

create_makefile('XRB_Extension')
create_makefile("XRB_Extension")
4 changes: 2 additions & 2 deletions gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Released under the MIT License.
# Copyright, 2012-2024, by Samuel Williams.

source 'https://rubygems.org'
source "https://rubygems.org"

gemspec

Expand All @@ -23,7 +23,7 @@
gem "bake-test"
gem "bake-test-external"

gem 'ruby-prof', platforms: [:mri]
gem "ruby-prof", platforms: [:mri]
gem "benchmark-ips"

gem "rack"
Expand Down
10 changes: 5 additions & 5 deletions lib/xrb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# Released under the MIT License.
# Copyright, 2012-2024, by Samuel Williams.

require_relative 'xrb/version'
require_relative 'xrb/native'
require_relative 'xrb/builder'
require_relative 'xrb/template'
require_relative "xrb/version"
require_relative "xrb/native"
require_relative "xrb/builder"
require_relative "xrb/template"

require_relative 'xrb/reference'
require_relative "xrb/reference"
2 changes: 1 addition & 1 deletion lib/xrb/buffer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

module XRB
class Buffer
def initialize(string, path: '<string>')
def initialize(string, path: "<string>")
@string = string
@path = path
end
Expand Down
8 changes: 4 additions & 4 deletions lib/xrb/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# Released under the MIT License.
# Copyright, 2012-2024, by Samuel Williams.

require_relative 'markup'
require_relative 'tag'
require_relative "markup"
require_relative "tag"

module XRB
# Build markup quickly and efficiently.
Expand Down Expand Up @@ -109,11 +109,11 @@ def indentation
if @indent
INDENT * (@level.size - 1)
else
''
""
end
end

def doctype(attributes = 'html')
def doctype(attributes = "html")
@output << "<!doctype #{attributes}>\n"
end

Expand Down
2 changes: 1 addition & 1 deletion lib/xrb/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Released under the MIT License.
# Copyright, 2016-2024, by Samuel Williams.

require_relative 'buffer'
require_relative "buffer"

module XRB
class Error < StandardError
Expand Down
4 changes: 1 addition & 3 deletions lib/xrb/fallback/markup.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# frozen_string_literal: true

# line 1 "lib/xrb/fallback/markup.rl"
# Released under the MIT License.
# Copyright, 2016-2024, by Samuel Williams.


# line 190 "lib/xrb/fallback/markup.rl"


require_relative '../error'
require_relative "../error"

module XRB
module Fallback
Expand Down
Loading

0 comments on commit 523df7d

Please sign in to comment.