From 434abec3078877b96c6018dbcd763dfb5be23a35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ferreira?= Date: Thu, 6 Nov 2025 16:49:25 +0000 Subject: [PATCH] Fix CI --- .gitignore | 2 ++ Gemfile.lock | 6 ++-- lib/sablon.rb | 1 - lib/sablon/operations.rb | 4 +-- lib/sablon/parser/mail_merge.rb | 20 ++++++------ lib/sablon/processor/image.rb | 58 --------------------------------- sablon.gemspec | 2 +- 7 files changed, 18 insertions(+), 75 deletions(-) delete mode 100644 lib/sablon/processor/image.rb diff --git a/.gitignore b/.gitignore index 8c2ebef6..99434867 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,5 @@ mkmf.log /test/sandbox/* !/test/sandbox/.gitkeep + +.DS_Store \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 1ee5272b..9f976f60 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,19 +3,19 @@ PATH specs: sablon (0.4.2) nokogiri (>= 1.10.0) - rubyzip (>= 1.3.0) + rubyzip (>= 1.3.0, < 3.0.0) GEM remote: https://rubygems.org/ specs: minitest (5.25.5) - nokogiri (1.15.7-arm64-darwin) + nokogiri (1.18.10-arm64-darwin) racc (~> 1.4) ostruct (0.6.0) racc (1.8.1) rake (13.1.0) rexml (3.4.1) - rubyzip (2.4.1) + rubyzip (2.3.2) xml-simple (1.1.9) rexml diff --git a/lib/sablon.rb b/lib/sablon.rb index 4844e933..b1a7a90f 100644 --- a/lib/sablon.rb +++ b/lib/sablon.rb @@ -10,7 +10,6 @@ require "sablon/template" require 'sablon/image' require "sablon/processor/document" -require 'sablon/processor/image' require 'sablon/processor/content_type' require "sablon/processor/section_properties" require "sablon/parser/mail_merge" diff --git a/lib/sablon/operations.rb b/lib/sablon/operations.rb index d0a9da28..a45e2fea 100644 --- a/lib/sablon/operations.rb +++ b/lib/sablon/operations.rb @@ -166,9 +166,9 @@ def build_operation(operator, left, right) def parse_operand(operand, env) if operand.start_with?('"', "'") operand[1..-2] - elsif operand.match?(/^\d+$/) + elsif /^\d+$/ =~ operand operand.to_i - elsif operand.match?(/^\d+\.\d+$/) + elsif /^\d+\.\d+$/ =~ operand operand.to_f else Expression.parse(operand).evaluate(env) diff --git a/lib/sablon/parser/mail_merge.rb b/lib/sablon/parser/mail_merge.rb index c70837b3..1d49f599 100644 --- a/lib/sablon/parser/mail_merge.rb +++ b/lib/sablon/parser/mail_merge.rb @@ -14,7 +14,7 @@ def valid? end def expression - ::Regexp.last_match(1) if @raw_expression =~ KEY_PATTERN + $1 if @raw_expression =~ KEY_PATTERN end private @@ -37,7 +37,7 @@ def replace_field_display(node, content, env) end def get_display_node(node) - node.search('.//w:t').first + node.search(".//w:t").first end end @@ -45,7 +45,7 @@ class ComplexField < MergeField def initialize(nodes) super() @nodes = nodes - @raw_expression = @nodes.flat_map { |n| n.search('.//w:instrText').map(&:content) }.join + @raw_expression = @nodes.flat_map {|n| n.search(".//w:instrText").map(&:content) }.join end def valid? @@ -86,7 +86,7 @@ def pattern_node end def separate_node - @nodes.detect { |n| !n.search(".//w:fldChar[@w:fldCharType='separate']").empty? } + @nodes.detect {|n| !n.search(".//w:fldChar[@w:fldCharType='separate']").empty? } end end @@ -94,7 +94,7 @@ class SimpleField < MergeField def initialize(node) super() @node = node - @raw_expression = @node['w:instr'] + @raw_expression = @node["w:instr"] end def replace(content, env) @@ -120,24 +120,24 @@ def ancestors(*args) def start_node @node end - alias end_node start_node + alias_method :end_node, :start_node private def remove_extra_runs! - @node.search('.//w:r')[1..].each(&:remove) + @node.search(".//w:r")[1..-1].each(&:remove) end end def parse_fields(xml) fields = [] xml.traverse do |node| - if node.name == 'fldSimple' + if node.name == "fldSimple" field = SimpleField.new(node) - elsif node.name == 'fldChar' && node['w:fldCharType'] == 'begin' + elsif node.name == "fldChar" && node["w:fldCharType"] == "begin" field = build_complex_field(node) end - fields << field if field&.valid? + fields << field if field && field.valid? end fields end diff --git a/lib/sablon/processor/image.rb b/lib/sablon/processor/image.rb deleted file mode 100644 index dd36a697..00000000 --- a/lib/sablon/processor/image.rb +++ /dev/null @@ -1,58 +0,0 @@ -# The code of that class was inspired in "kubido Fork - https://github.com/kubido/" - -module Sablon - module Processor - class Image - PICTURE_NS_URI = 'http://schemas.openxmlformats.org/drawingml/2006/picture' - MAIN_NS_URI = 'http://schemas.openxmlformats.org/drawingml/2006/main' - RELATIONSHIPS_NS_URI = 'http://schemas.openxmlformats.org/package/2006/relationships' - IMAGE_TYPE = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image' - - def self.process(doc, properties, out) - processor = new(doc, properties, out) - processor.manipulate - end - - def initialize(doc, properties, out) - @doc = doc - @properties = properties - @out = out - end - - def manipulate - next_id = next_rel_id - @@images_rids = {} - relationships = @doc.at_xpath('r:Relationships', r: RELATIONSHIPS_NS_URI) - - @@images.to_a.each do |image| - relationships.add_child("") - image.rid = next_id - @@images_rids[image.name.match(/(.*)\.*[^.]+$/)[1]] = next_id - next_id += 1 - end - - @doc - end - - def self.add_images_to_zip!(context, zip_out) - (@@images = Sablon::Context.values_of(context, Sablon::Image::Definition)).each do |image| - zip_out.put_next_entry(File.join('word', 'media', image.name)) - zip_out.write(image.data) - end - end - - def self.list_ids - @@images_rids - end - - private - - def next_rel_id - @doc.xpath('r:Relationships/r:Relationship', 'r' => RELATIONSHIPS_NS_URI).inject(0) do |max, n| - id = n.attributes['Id'].to_s[3..].to_i - [id, max].max - end + 1 - end - end - end -end diff --git a/sablon.gemspec b/sablon.gemspec index 19fe2f23..2e6fcfb3 100644 --- a/sablon.gemspec +++ b/sablon.gemspec @@ -25,7 +25,7 @@ Gem::Specification.new do |spec| spec.metadata['rubygems_mfa_required'] = 'true' spec.add_runtime_dependency 'nokogiri', '>= 1.10.0' - spec.add_runtime_dependency 'rubyzip', ">= 1.3.0" + spec.add_runtime_dependency 'rubyzip', ">= 1.3.0", "< 3.0.0" spec.add_development_dependency "bundler", ">= 1.6" spec.add_development_dependency "rake", "~> 13.0"