Thanks to visit codestin.com
Credit goes to github.com

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
21 changes: 21 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,24 @@ jobs:
bundler-cache: true
- name: Run tests
run: bundle exec rake
lint:
runs-on: ubuntu-latest
name: Lint
steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1
bundler-cache: true
- name: Run style checks
run: bundle exec rubocop
buildall:
if: ${{ always() }}
runs-on: ubuntu-latest
name: Build (matrix)
needs: [lint, test]
steps:
- name: Check build matrix status
if: ${{ needs.test.result != 'success' || needs.lint.result != 'success' }}
run: exit 1
9 changes: 9 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This file strictly follows the rules defined in the Ruby style guide:
# http://shopify.github.io/ruby-style-guide/
inherit_gem:
rubocop-shopify: rubocop.yml

AllCops:
TargetRubyVersion: 2.7
NewCops: disable
SuggestExtensions: false
18 changes: 11 additions & 7 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
source 'https://rubygems.org'
# frozen_string_literal: true

source "https://rubygems.org"

gemspec

gem 'actionview'
gem 'rake'
gem 'rake-compiler'
gem 'minitest'
gem 'mocha'
gem "actionview"
gem "minitest"
gem "mocha"
gem "rake"
gem "rake-compiler"

group :deployment, :test do
gem 'pry-byebug'
gem "pry-byebug"
end

gem "rubocop-shopify"
28 changes: 25 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ GEM
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
ast (2.4.0)
ast (2.4.2)
builder (3.2.4)
byebug (9.1.0)
coderay (1.1.2)
Expand All @@ -32,6 +32,7 @@ GEM
erubi (1.11.0)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
json (2.6.2)
loofah (2.18.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
Expand All @@ -42,8 +43,9 @@ GEM
nokogiri (1.13.8)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
parser (2.6.3.0)
ast (~> 2.4.0)
parallel (1.22.1)
parser (3.1.2.1)
ast (~> 2.4.1)
pry (0.11.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
Expand All @@ -56,12 +58,31 @@ GEM
nokogiri (>= 1.6)
rails-html-sanitizer (1.4.3)
loofah (~> 2.3)
rainbow (3.1.1)
rake (13.0.6)
rake-compiler (1.2.0)
rake
regexp_parser (2.5.0)
rexml (3.2.5)
rubocop (1.35.0)
json (~> 2.3)
parallel (~> 1.10)
parser (>= 3.1.2.1)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.20.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.21.0)
parser (>= 3.1.1.0)
rubocop-shopify (2.9.0)
rubocop (~> 1.33)
ruby-progressbar (1.11.0)
smart_properties (1.15.0)
tzinfo (2.0.5)
concurrent-ruby (~> 1.0)
unicode-display_width (2.2.0)

PLATFORMS
ruby
Expand All @@ -74,6 +95,7 @@ DEPENDENCIES
pry-byebug
rake
rake-compiler
rubocop-shopify

BUNDLED WITH
2.2.22
29 changes: 15 additions & 14 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
# frozen_string_literal: true

begin
require 'bundler/setup'
require "bundler/setup"
require "bundler/gem_tasks"
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
end

require 'rake/extensiontask'
require "rake/extensiontask"

Rake::ExtensionTask.new("better_html_ext")

require 'rdoc/task'
require "rdoc/task"

RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'BetterHtml'
rdoc.options << '--line-numbers'
rdoc.rdoc_files.include('README.rdoc')
rdoc.rdoc_files.include('lib/**/*.rb')
rdoc.rdoc_dir = "rdoc"
rdoc.title = "BetterHtml"
rdoc.options << "--line-numbers"
rdoc.rdoc_files.include("README.rdoc")
rdoc.rdoc_files.include("lib/**/*.rb")
end

require 'rake/testtask'
require "rake/testtask"

Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.libs << "lib"
t.libs << "test"
t.pattern = "test/**/*_test.rb"
t.verbose = false
end


task default: [:compile, :test]
22 changes: 12 additions & 10 deletions better_html.gemspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
$:.push File.expand_path("../lib", __FILE__)
# frozen_string_literal: true

$LOAD_PATH.push(File.expand_path("../lib", __FILE__))

# Maintain your gem's version:
require "better_html/version"
Expand All @@ -20,19 +22,19 @@ Gem::Specification.new do |s|
"bug_tracker_uri" => "https://github.com/Shopify/better-html/issues",
"changelog_uri" => "https://github.com/Shopify/better-html/releases",
"source_code_uri" => "https://github.com/Shopify/better-html/tree/v#{s.version}",
"allowed_push_host" => "https://rubygems.org"
"allowed_push_host" => "https://rubygems.org",
}

s.extensions = ['ext/better_html_ext/extconf.rb']
s.extensions = ["ext/better_html_ext/extconf.rb"]
s.files = Dir["{app,config,db,lib,ext}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
s.require_paths = ["lib"]

s.add_dependency 'ast', '~> 2.0'
s.add_dependency 'erubi', '~> 1.4'
s.add_dependency 'activesupport', '>= 6.0'
s.add_dependency 'actionview', '>= 6.0'
s.add_dependency 'parser', '>= 2.4'
s.add_dependency 'smart_properties'
s.add_dependency("actionview", ">= 6.0")
s.add_dependency("activesupport", ">= 6.0")
s.add_dependency("ast", "~> 2.0")
s.add_dependency("erubi", "~> 1.4")
s.add_dependency("parser", ">= 2.4")
s.add_dependency("smart_properties")

s.add_development_dependency 'rake', '~> 13'
s.add_development_dependency("rake", "~> 13")
end
10 changes: 7 additions & 3 deletions ext/better_html_ext/extconf.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
require 'mkmf'
# frozen_string_literal: true

require "mkmf"

# rubocop:disable Style/GlobalVars
$CXXFLAGS += " -std=c++11 "
$CXXFLAGS += " -g -O1 -ggdb "
$CFLAGS += " -g -O1 -ggdb "

if ENV['DEBUG']
if ENV["DEBUG"]
$CXXFLAGS += " -DDEBUG "
$CFLAGS += " -DDEBUG "
end
# rubocop:enable Style/GlobalVars

create_makefile('better_html_ext')
create_makefile("better_html_ext")
16 changes: 9 additions & 7 deletions gemfiles/Gemfile-rails-6-0
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
source 'https://rubygems.org'
# frozen_string_literal: true

source "https://rubygems.org"

gemspec path: ".."

gem 'actionview', '~> 6.0.0'
gem 'rake'
gem 'rake-compiler'
gem 'minitest'
gem 'mocha'
gem "actionview", "~> 6.0.0"
gem "rake"
gem "rake-compiler"
gem "minitest"
gem "mocha"

group :deployment, :test do
gem 'pry-byebug'
gem "pry-byebug"
end
16 changes: 9 additions & 7 deletions gemfiles/Gemfile-rails-6-1
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
source 'https://rubygems.org'
# frozen_string_literal: true

source "https://rubygems.org"

gemspec path: ".."

gem 'actionview', '~> 6.1.0'
gem 'rake'
gem 'rake-compiler'
gem 'minitest'
gem 'mocha'
gem "actionview", "~> 6.1.0"
gem "rake"
gem "rake-compiler"
gem "minitest"
gem "mocha"

group :deployment, :test do
gem 'pry-byebug'
gem "pry-byebug"
end
36 changes: 19 additions & 17 deletions lib/better_html.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
require 'active_support/core_ext/hash/keys'
require 'active_support/core_ext/module/delegation'
require 'active_support/core_ext/class/attribute_accessors'
# frozen_string_literal: true

require "active_support/core_ext/hash/keys"
require "active_support/core_ext/module/delegation"
require "active_support/core_ext/class/attribute_accessors"

module BetterHtml
def self.configure
yield config if block_given?
end
class << self
attr_writer :config

def self.config
@config ||= Config.new
end
def config
@config ||= Config.new
end

def self.config=(new_config)
@config = new_config
def configure
yield config if block_given?
end
end
end

require 'better_html/version'
require 'better_html/config'
require 'better_html/helpers'
require 'better_html/errors'
require 'better_html/html_attributes'
require "better_html/version"
require "better_html/config"
require "better_html/helpers"
require "better_html/errors"
require "better_html/html_attributes"

require 'better_html/railtie' if defined?(Rails)
require "better_html/railtie" if defined?(Rails)
23 changes: 14 additions & 9 deletions lib/better_html/ast/iterator.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
require 'ast'
require 'active_support/core_ext/array/wrap'
# frozen_string_literal: true

require "ast"
require "active_support/core_ext/array/wrap"

module BetterHtml
module AST
class Iterator
class << self
def descendants(root_node, type)
Enumerator.new do |yielder|
t = new(type) { |node| yielder << node }
t.traverse(root_node)
end
end
end

def initialize(types, &block)
@types = types.nil? ? nil : Array.wrap(types)
@block = block
end

def traverse(node)
return unless node.is_a?(::AST::Node)

@block.call(node) if @types.nil? || @types.include?(node.type)
traverse_all(node)
end
Expand All @@ -20,13 +32,6 @@ def traverse_all(nodes)
traverse(node) if node.is_a?(::AST::Node)
end
end

def self.descendants(root_node, type)
Enumerator.new do |yielder|
t = new(type) { |node| yielder << node }
t.traverse(root_node)
end
end
end
end
end
6 changes: 4 additions & 2 deletions lib/better_html/ast/node.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require 'ast'
require_relative 'iterator'
# frozen_string_literal: true

require "ast"
require_relative "iterator"

module BetterHtml
module AST
Expand Down
Loading