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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ mkmf.log

/test/sandbox/*
!/test/sandbox/.gitkeep

.DS_Store
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion lib/sablon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions lib/sablon/operations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 10 additions & 10 deletions lib/sablon/parser/mail_merge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,15 +37,15 @@ 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

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?
Expand Down Expand Up @@ -86,15 +86,15 @@ 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

class SimpleField < MergeField
def initialize(node)
super()
@node = node
@raw_expression = @node['w:instr']
@raw_expression = @node["w:instr"]
end

def replace(content, env)
Expand All @@ -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
Expand Down
58 changes: 0 additions & 58 deletions lib/sablon/processor/image.rb

This file was deleted.

2 changes: 1 addition & 1 deletion sablon.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading