activemail 2.1.1 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/lib/activemail/libxml.rb +22 -3
- data/lib/activemail/parse_error_reporter.rb +8 -22
- data/lib/activemail/quality/builtin_rules.rb +1 -1
- data/lib/activemail/unknown_tag_collector.rb +33 -0
- data/lib/activemail/version.rb +1 -1
- data/lib/activemail.rb +18 -15
- data/lib/tasks/activemail.rake +28 -23
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4d8e265cf5a2e60549239d43c4507840393f48eeb51eadc82a1382c24dd8bb9a
|
|
4
|
+
data.tar.gz: 7a8f2390ad674642f451690c3cc3b4642aaad5d0944d90a83207415536caba18
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f0f64fa20326c1b085e5d5db235ff154bf56f1325e65a5e132e5027f01f935410d039ff465710ad00dfdc031e10cc38bb5b88d241aa10727561c9bd673ea7c45
|
|
7
|
+
data.tar.gz: d7bb0939f31a0f2055523a647dd3ccf4a5c16584045a9a6a9cc88fc26c77a8f51d8459f3a4f120da61f76152233ba65bf6ab92612c75178094ed676b3ddb34af
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,18 @@ All notable changes to this project are documented here.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [2.1.2] - 2026-11-21
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- Unknown tags are detected by name, so they are still reported on libxml2
|
|
13
|
+
2.14 and later (Nokogiri 1.20, or a system libxml2), which no longer emits
|
|
14
|
+
the "Tag X invalid" error.
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- Nokogiri `< 2` (was `< 1.20`).
|
|
19
|
+
|
|
8
20
|
## [2.1.1] - 2026-10-19
|
|
9
21
|
|
|
10
22
|
### Fixed
|
|
@@ -249,6 +261,7 @@ toolkit for Rails.
|
|
|
249
261
|
- Rails `>= 7.1` (tested up to 8.1).
|
|
250
262
|
- Nokogiri `>= 1.16`.
|
|
251
263
|
|
|
264
|
+
[2.1.2]: https://github.com/AdVitam/activemail/compare/v2.1.1...v2.1.2
|
|
252
265
|
[2.1.1]: https://github.com/AdVitam/activemail/compare/v2.1.0...v2.1.1
|
|
253
266
|
[2.1.0]: https://github.com/AdVitam/activemail/compare/v2.0.0...v2.1.0
|
|
254
267
|
[2.0.0]: https://github.com/AdVitam/activemail/compare/v1.2.3...v2.0.0
|
data/lib/activemail/libxml.rb
CHANGED
|
@@ -1,8 +1,27 @@
|
|
|
1
1
|
# typed: strict
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
+
require 'nokogiri'
|
|
5
|
+
require 'sorbet-runtime'
|
|
6
|
+
|
|
4
7
|
module ActiveMail
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
module Libxml
|
|
9
|
+
extend T::Sig
|
|
10
|
+
|
|
11
|
+
UNKNOWN_TAG_CODE = 801
|
|
12
|
+
|
|
13
|
+
# The component markup repeats the id of the node it replaces, which libxml2 still has registered.
|
|
14
|
+
ID_REDEFINED_CODE = 513
|
|
15
|
+
|
|
16
|
+
# libxml2 < 2.14 reports every non-HTML4 tag as 801 and >= 2.14 never does: unknown tags are detected by name.
|
|
17
|
+
sig { params(errors: T::Array[Nokogiri::XML::SyntaxError]).returns(T::Array[Nokogiri::XML::SyntaxError]) }
|
|
18
|
+
def self.markup_errors(errors)
|
|
19
|
+
errors.reject { |error| error.code == UNKNOWN_TAG_CODE }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
sig { params(name: String).returns(T::Boolean) }
|
|
23
|
+
def self.known_html_tag?(name)
|
|
24
|
+
!Nokogiri::HTML4::ElementDescription[name].nil?
|
|
25
|
+
end
|
|
26
|
+
end
|
|
8
27
|
end
|
|
@@ -11,38 +11,24 @@ module ActiveMail
|
|
|
11
11
|
class ParseErrorReporter
|
|
12
12
|
extend T::Sig
|
|
13
13
|
|
|
14
|
-
sig { params(
|
|
15
|
-
def initialize(
|
|
14
|
+
sig { params(config: ActiveMail::Configuration).void }
|
|
15
|
+
def initialize(config)
|
|
16
16
|
@config = config
|
|
17
|
-
# dup.freeze: the caller's array stays decoupled and cannot be mutated under us.
|
|
18
|
-
@known_tags = T.let(known_tags.dup.freeze, T::Array[String])
|
|
19
17
|
end
|
|
20
18
|
|
|
21
|
-
sig { params(errors: T::Array[Nokogiri::XML::SyntaxError]).void }
|
|
22
|
-
def call(errors)
|
|
19
|
+
sig { params(errors: T::Array[Nokogiri::XML::SyntaxError], unknown_tags: T::Array[String]).void }
|
|
20
|
+
def call(errors, unknown_tags = [])
|
|
23
21
|
mode = @config.on_parse_error
|
|
24
22
|
return if mode == :ignore
|
|
25
23
|
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
issues = Libxml.markup_errors(errors).map { |error| error.message.to_s.strip } +
|
|
25
|
+
unknown_tags.map { |tag| "unknown tag <#{tag}>" }
|
|
26
|
+
return if issues.empty?
|
|
28
27
|
|
|
29
|
-
messages =
|
|
28
|
+
messages = issues.join('; ')
|
|
30
29
|
raise ActiveMail::ParseError, messages if mode == :raise
|
|
31
30
|
|
|
32
31
|
::ActiveMail.log_warning("[activemail] HTML parse issues: #{messages}")
|
|
33
32
|
end
|
|
34
|
-
|
|
35
|
-
private
|
|
36
|
-
|
|
37
|
-
sig { params(error: Nokogiri::XML::SyntaxError).returns(T::Boolean) }
|
|
38
|
-
def known_tag_error?(error)
|
|
39
|
-
return false unless error.code == LIBXML_UNKNOWN_TAG_CODE
|
|
40
|
-
|
|
41
|
-
# Fragile by necessity: the 801 error does not carry the tag name, only
|
|
42
|
-
# the libxml2 message text does. Locked by test against the pinned
|
|
43
|
-
# Nokogiri; revisit on bump if that test breaks.
|
|
44
|
-
tag = error.message.to_s[/Tag (\S+) invalid/, 1]
|
|
45
|
-
!tag.nil? && @known_tags.include?(tag)
|
|
46
|
-
end
|
|
47
33
|
end
|
|
48
34
|
end
|
|
@@ -81,7 +81,7 @@ module ActiveMail
|
|
|
81
81
|
|
|
82
82
|
sig { params(doc: Nokogiri::XML::Document).returns(T.nilable(String)) }
|
|
83
83
|
def parse_error_message(doc)
|
|
84
|
-
errors = doc.errors
|
|
84
|
+
errors = Libxml.markup_errors(doc.errors)
|
|
85
85
|
return if errors.empty?
|
|
86
86
|
|
|
87
87
|
"malformed HTML: #{errors.first(3).map { |e| e.message.to_s.strip }.join('; ')}"
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require 'sorbet-runtime'
|
|
5
|
+
|
|
6
|
+
require_relative 'libxml'
|
|
7
|
+
|
|
8
|
+
module ActiveMail
|
|
9
|
+
class UnknownTagCollector
|
|
10
|
+
extend T::Sig
|
|
11
|
+
|
|
12
|
+
sig { params(ignored_names: T::Array[String]).void }
|
|
13
|
+
def initialize(ignored_names)
|
|
14
|
+
@ignored_names = T.let(ignored_names.to_set, T::Set[String])
|
|
15
|
+
@unknown = T.let(Set.new, T::Set[String])
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
sig { params(node: Nokogiri::XML::Node).void }
|
|
19
|
+
def collect(node)
|
|
20
|
+
return unless node.element?
|
|
21
|
+
|
|
22
|
+
name = node.name
|
|
23
|
+
return if @ignored_names.include?(name)
|
|
24
|
+
|
|
25
|
+
@unknown << name unless Libxml.known_html_tag?(name)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
sig { returns(T::Array[String]) }
|
|
29
|
+
def names
|
|
30
|
+
@unknown.to_a
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
data/lib/activemail/version.rb
CHANGED
data/lib/activemail.rb
CHANGED
|
@@ -26,6 +26,7 @@ require_relative 'activemail/components/info_box'
|
|
|
26
26
|
require_relative 'activemail/configuration'
|
|
27
27
|
require_relative 'activemail/pipeline'
|
|
28
28
|
require_relative 'activemail/parse_error_reporter'
|
|
29
|
+
require_relative 'activemail/unknown_tag_collector'
|
|
29
30
|
|
|
30
31
|
module ActiveMail
|
|
31
32
|
class Core
|
|
@@ -40,9 +41,6 @@ module ActiveMail
|
|
|
40
41
|
SLOT_TEXT = 'activemail-slot'
|
|
41
42
|
SLOT = T.let("<!--#{SLOT_TEXT}-->".freeze, String)
|
|
42
43
|
|
|
43
|
-
# The component markup repeats the id of the node it replaces, which libxml2 still has registered.
|
|
44
|
-
LIBXML_ID_REDEFINED_CODE = 513
|
|
45
|
-
|
|
46
44
|
RAW_REGEX = T.let(%r{< *raw *>([\s\S]*?)</ *raw *>}i, Regexp)
|
|
47
45
|
|
|
48
46
|
# One pass over the serialized output; <style>/<script> bodies are matched first so they are left alone.
|
|
@@ -90,7 +88,7 @@ module ActiveMail
|
|
|
90
88
|
@component_instances = T.let(build_components(config, components), T::Hash[String, ActiveMail::Components::Base])
|
|
91
89
|
@column_count = T.let(ActiveMail.positive_integer!(:column_count, column_count || config.column_count), Integer)
|
|
92
90
|
@container_width = T.let(ActiveMail.positive_integer!(:container_width, container_width || config.container_width), Integer)
|
|
93
|
-
@error_reporter = T.let(ParseErrorReporter.new(
|
|
91
|
+
@error_reporter = T.let(ParseErrorReporter.new(config), ParseErrorReporter)
|
|
94
92
|
end
|
|
95
93
|
|
|
96
94
|
# Object, not String: ActionView::OutputBuffer is no longer a String since Rails 7.1.
|
|
@@ -100,22 +98,27 @@ module ActiveMail
|
|
|
100
98
|
marker = "activemail-raw-#{SecureRandom.hex(8)}-"
|
|
101
99
|
raws = {}
|
|
102
100
|
str = extract_raws(normalize_input(html_string), marker, raws)
|
|
103
|
-
|
|
104
|
-
html
|
|
105
|
-
@error_reporter.call(html.errors)
|
|
106
|
-
transform_doc(html)
|
|
101
|
+
html = Nokogiri::HTML.public_send(::ActiveMail.full_document?(str) ? :parse : :fragment, str)
|
|
102
|
+
transform_and_report(html)
|
|
107
103
|
re_inject_raws(postprocess(html.to_html), marker, raws)
|
|
108
104
|
end
|
|
109
105
|
|
|
110
106
|
private
|
|
111
107
|
|
|
112
|
-
|
|
113
|
-
|
|
108
|
+
# Errors are read first: parsing component markup later resets the document's error list.
|
|
109
|
+
sig { params(html: T.any(Nokogiri::XML::Document, Nokogiri::XML::DocumentFragment)).void }
|
|
110
|
+
def transform_and_report(html)
|
|
111
|
+
errors = html.errors.dup
|
|
112
|
+
collector = UnknownTagCollector.new(@component_instances.keys)
|
|
113
|
+
transform_doc(html, collector)
|
|
114
|
+
@error_reporter.call(errors, collector.names)
|
|
115
|
+
end
|
|
114
116
|
|
|
115
|
-
sig { params(node: Nokogiri::XML::Node).void }
|
|
116
|
-
def transform_doc(node)
|
|
117
|
-
node.children.each { |child| transform_doc(child) }
|
|
118
|
-
|
|
117
|
+
sig { params(node: Nokogiri::XML::Node, collector: UnknownTagCollector).void }
|
|
118
|
+
def transform_doc(node, collector)
|
|
119
|
+
node.children.each { |child| transform_doc(child, collector) }
|
|
120
|
+
collector.collect(node)
|
|
121
|
+
component = @component_instances[node.name]
|
|
119
122
|
replace_with_component(node, component, component.transform(node, SLOT)) if component
|
|
120
123
|
end
|
|
121
124
|
|
|
@@ -124,7 +127,7 @@ module ActiveMail
|
|
|
124
127
|
sig { params(node: Nokogiri::XML::Node, component: ActiveMail::Components::Base, markup: String).void }
|
|
125
128
|
def replace_with_component(node, component, markup)
|
|
126
129
|
fragment = Nokogiri::HTML::DocumentFragment.new(node.document, markup, node)
|
|
127
|
-
@error_reporter.call(fragment.errors.reject { |error| error.code ==
|
|
130
|
+
@error_reporter.call(fragment.errors.reject { |error| error.code == Libxml::ID_REDEFINED_CODE })
|
|
128
131
|
slots = fragment.xpath('.//comment()').select { |comment| comment.content == SLOT_TEXT }
|
|
129
132
|
ensure_slot_usage!(node, component, slots.size)
|
|
130
133
|
slots.first&.replace(node.children)
|
data/lib/tasks/activemail.rake
CHANGED
|
@@ -1,35 +1,40 @@
|
|
|
1
|
+
# typed: strict
|
|
1
2
|
# frozen_string_literal: true
|
|
2
3
|
|
|
3
4
|
require 'activemail'
|
|
4
5
|
require 'fileutils'
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
class ActiveMailTasks
|
|
8
|
+
extend Rake::DSL
|
|
9
|
+
|
|
10
|
+
namespace :activemail do
|
|
11
|
+
namespace :tokens do
|
|
12
|
+
desc 'Export design tokens to a static SCSS partial (for Propshaft apps that cannot preprocess .scss.erb)'
|
|
13
|
+
# :environment so the host initializer's config.tokens overrides are loaded.
|
|
14
|
+
task :export, [:path] => :environment do |_task, args|
|
|
15
|
+
path = args[:path] || 'app/assets/stylesheets/activemail/_activemail_tokens.scss'
|
|
16
|
+
FileUtils.mkdir_p(File.dirname(path))
|
|
17
|
+
File.write(path, ActiveMail.scss_variables)
|
|
18
|
+
puts "Wrote #{ActiveMail.tokens.to_h.values.sum(&:size)} tokens to #{path}"
|
|
19
|
+
end
|
|
15
20
|
end
|
|
16
|
-
end
|
|
17
21
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
namespace :emails do
|
|
23
|
+
desc 'Render every host mailer preview to disk and run the quality guard on each'
|
|
24
|
+
task render_all: :environment do
|
|
25
|
+
require 'activemail/quality/render_all'
|
|
22
26
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
root = defined?(Rails) && Rails.respond_to?(:root) && Rails.root ? Rails.root : Pathname.pwd
|
|
28
|
+
result = ActiveMail::Quality::RenderAll.new(root: root, config: ActiveMail::Quality.config).call
|
|
29
|
+
puts "Rendered #{result.rendered} email(s) into #{result.output_root}"
|
|
30
|
+
# A green run on zero previews would silently verify nothing — make it visible.
|
|
31
|
+
warn '[activemail] WARNING: no mailer previews were discovered — nothing was checked.' if result.discovered.zero?
|
|
32
|
+
result.render_failures.each { |key, error| puts " render failed: #{key}: #{error}" }
|
|
33
|
+
result.guard_failures.each do |key, violations|
|
|
34
|
+
puts " guard failed: #{key}", violations.map { |v| " - #{v}" }.join("\n")
|
|
35
|
+
end
|
|
36
|
+
abort "\n#{result.broken_required.size} required preview(s) failed: #{result.broken_required.join(', ')}" if result.broken_required.any?
|
|
31
37
|
end
|
|
32
|
-
abort "\n#{result.broken_required.size} required preview(s) failed: #{result.broken_required.join(', ')}" if result.broken_required.any?
|
|
33
38
|
end
|
|
34
39
|
end
|
|
35
40
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: activemail
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.1.
|
|
4
|
+
version: 2.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Advitam
|
|
@@ -18,7 +18,7 @@ dependencies:
|
|
|
18
18
|
version: '1.16'
|
|
19
19
|
- - "<"
|
|
20
20
|
- !ruby/object:Gem::Version
|
|
21
|
-
version: '
|
|
21
|
+
version: '2'
|
|
22
22
|
type: :runtime
|
|
23
23
|
prerelease: false
|
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -28,7 +28,7 @@ dependencies:
|
|
|
28
28
|
version: '1.16'
|
|
29
29
|
- - "<"
|
|
30
30
|
- !ruby/object:Gem::Version
|
|
31
|
-
version: '
|
|
31
|
+
version: '2'
|
|
32
32
|
- !ruby/object:Gem::Dependency
|
|
33
33
|
name: premailer
|
|
34
34
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -148,6 +148,7 @@ files:
|
|
|
148
148
|
- lib/activemail/tokens/button_style.rb
|
|
149
149
|
- lib/activemail/tokens/defaults.rb
|
|
150
150
|
- lib/activemail/tokens/scss_serializer.rb
|
|
151
|
+
- lib/activemail/unknown_tag_collector.rb
|
|
151
152
|
- lib/activemail/version.rb
|
|
152
153
|
- lib/generators/activemail/component_generator.rb
|
|
153
154
|
- lib/generators/activemail/install_generator.rb
|