Skip to content

Commit

Permalink
feature: add string_tools config
Browse files Browse the repository at this point in the history
  • Loading branch information
GIGrave committed Nov 2, 2023
1 parent cf251c8 commit c0b9bf3
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
/gemfiles
/.idea
Makefile.local
log/
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ source 'https://rubygems.org'
gemspec

gem 'actionpack', '~> 4.2.0', require: false
gem 'loofah', '< 2.20.0', require: false
gem 'pg', '< 1', require: false
1 change: 1 addition & 0 deletions dip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ version: '1'
environment:
DOCKER_RUBY_VERSION: 2.4
RUBY_IMAGE_TAG: 2.4-latest
POSTGRES_IMAGE_TAG: 11
COMPOSE_FILE_EXT: development
RAILS_ENV: test

Expand Down
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,15 @@ services:
environment:
- SSH_AUTH_SOCK=/ssh/auth/sock
- BUNDLE_PATH=/bundle/$DOCKER_RUBY_VERSION
- BUNDLE_APP_CONFIG=/app/.bundle
- TEST_DB_HOST=db
- TEST_DB_NAME=docker
- TEST_DB_USERNAME=postgres
command: bash
depends_on:
- db

db:
image: abakpress/postgres-db:$POSTGRES_IMAGE_TAG
environment:
- POSTGRES_DB=docker
7 changes: 5 additions & 2 deletions lib/string_tools.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# coding: utf-8
# frozen_string_literal: true
require 'string_tools/version'
require 'rails'
require 'action_view'
require 'active_record'
require 'ru_propisju'
require 'sanitize'
require 'active_support/core_ext/string'
require 'string_tools/core_ext/string'
require 'string_tools/engine'

module StringTools
autoload :HTML, 'string_tools/html'
Expand Down Expand Up @@ -181,7 +184,7 @@ def sanitize(str, attrs = {})
str,
:attributes => attributes,
:elements => elements,
:css => {:properties => Sanitize::Config::RELAXED[:css][:properties], protocols: protocols},
:css => ::Rails.application.config.string_tools.fetch(:css_sanitize).merge(protocols: protocols),
:remove_contents => remove_contents || Set['style', 'script'],
:allow_comments => false,
:transformers => transformers
Expand Down
14 changes: 14 additions & 0 deletions lib/string_tools/engine.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module StringTools
class Engine < ::Rails::Engine
config.autoload_paths += Dir[config.root.join('lib')]

initializer :string_tools, before: :load_init_rb do |app|
app.config.string_tools = {
css_sanitize: {properties: Sanitize::Config::RELAXED[:css][:properties]},
}
end
end
end

5 changes: 5 additions & 0 deletions spec/internal/config/database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
test:
adapter: postgresql
host: <%= ENV.fetch("TEST_DB_HOST", "localhost") %>
database: <%= ENV.fetch("TEST_DB_NAME", "docker") %>
username: <%= ENV.fetch("TEST_DB_USERNAME", "docker") %>
10 changes: 10 additions & 0 deletions spec/internal/config/environments/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

HOST = 'test.host'
HOST_SHORT = 'test.host'
ASSETS_HOST = 'www.example.org'
ADMIN_HOST = 'admin.example.org'

DO_NOT_REPLY = '[email protected]'
DO_NOT_REPLY_RETURN_PATH = '[email protected]'
APP_NAME = 'example'
5 changes: 5 additions & 0 deletions spec/internal/config/routes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

Rails.application.routes.draw do
default_url_options host: HOST
end
5 changes: 5 additions & 0 deletions spec/internal/db/schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

ActiveRecord::Schema.define do
#
end
9 changes: 9 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
# frozen_string_literal: true

$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
require 'simplecov'

SimpleCov.start do
add_filter "/spec/"
end

require 'bundler/setup'

require 'string_tools'
require 'pry-byebug'

require 'combustion'

Combustion.initialize! :all

require 'rspec/rails'
7 changes: 5 additions & 2 deletions string_tools.gemspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding: utf-8
# frozen_string_literal: true

lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'string_tools/version'
Expand All @@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib']

spec.add_runtime_dependency 'rails', '>= 4.2', '< 5'
spec.add_runtime_dependency 'actionpack', '>= 4.2.0'
spec.add_runtime_dependency 'activesupport', '>= 4.2.0'
spec.add_runtime_dependency 'rchardet19', '~> 1.3.5'
Expand All @@ -28,10 +29,12 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency 'sanitize', '>= 3.1.2'
spec.add_runtime_dependency 'nokogiri'
spec.add_runtime_dependency 'simpleidn', '>= 0.0.5'
spec.add_runtime_dependency 'pg'

spec.add_development_dependency 'bundler', '~> 1.17.3'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'rspec', '>= 3.4'
spec.add_development_dependency 'rspec-rails', '~> 3.0'
spec.add_development_dependency 'combustion', '>= 0.5.4'
spec.add_development_dependency 'appraisal', '>= 1.0.2'
spec.add_development_dependency 'simplecov', '>= 0.9'
spec.add_development_dependency 'pry-byebug'
Expand Down

0 comments on commit c0b9bf3

Please sign in to comment.