docx-builder 0.2.2 → 0.2.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a12d4646ce0b78cc0977eb4c1fa6a6d4082911dc1546c567b299a58f9b84e56
4
- data.tar.gz: 13197d06bd647197e7fb0857ce7f10c3d4f9c119c3e0a28503d2ad20c73a44fa
3
+ metadata.gz: 208b51187c9e384db0e9d585552b8696e0a868709d2ee7348ae57e3d96566e1e
4
+ data.tar.gz: 54cdcbe11f62f7dcb3ab6fdcd4575f8d2ca09f876da8c0a8e7c8a57209313b42
5
5
  SHA512:
6
- metadata.gz: 36580ca2af1ab880193203d304f8030125a53e6139e66c750d33f6f7846e33ccd0efe581d37eed5948708f8a933beef76d527922d3eadc018501028ca9521c51
7
- data.tar.gz: cd3a2fd33771dcfc717f0e2ecf5340125ec80e9be792ed073425c2126c5684c2a66fc7ecbf269b795c5593fa08bab8f256af608861de0d62624b57ca60836bbf
6
+ metadata.gz: 43f1e1c08dd0f604ba920ad88c139e4797e4b8a6ed7b9d2edf2f5d363c92b19bb9e1b889e32f3a6f4b4deb9c5920e8d197a2815320b167b6049ec8a0636506ae
7
+ data.tar.gz: 3b71f7b11e68f1c8e19616265401c4f03d392fbd503ab34aef98f8d237ff5a08545108593c4f53daf3e4d1e5e195905326bd9e005b91ec422eea87b2e014f24f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- docx-builder (0.2.2)
4
+ docx-builder (0.2.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,10 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Docx
2
4
  module Builder
3
5
  class Configuration
4
6
  attr_accessor :null_placeholder
7
+ attr_accessor :logger
5
8
 
6
9
  def initialize
7
10
  @null_placeholder = ''
11
+ @logger = Docx::Logger.new(STDOUT)
8
12
  end
9
13
  end
10
14
  end
@@ -13,10 +13,13 @@ module Docx
13
13
 
14
14
  def render(data)
15
15
  @sections.map do |section|
16
+ Docx::Builder.logger.debug("Cleaning template variables for section #{section}")
16
17
  cleaned_document = clean(@document.read(section))
18
+ Docx::Builder.logger.debug("Replacing template tags ('{{%' -> '<%') for section #{section}")
17
19
  erb_template = build_erb_template(cleaned_document)
20
+ Docx::Builder.logger.debug("Rendering template for section #{section} with data")
18
21
  processed_document = render_erb_template(erb_template, data)
19
- [section, processed_document]
22
+ [section, processed_document]
20
23
  end.to_h
21
24
  end
22
25
 
@@ -39,6 +42,7 @@ module Docx
39
42
 
40
43
  # creates xml template keys in input docx (template file)
41
44
  def save(path, new_document)
45
+ Docx::Builder.logger.info("Saving output file into path #{path.to_s}")
42
46
  File.open(path, 'wb') do |f|
43
47
  new_document_xml_string = Docx::Builder::Encoder.build_new_document_xml(@document, new_document)
44
48
  f.write(new_document_xml_string)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Docx
4
4
  module Builder
5
- VERSION = "0.2.2"
5
+ VERSION = "0.2.3"
6
6
  end
7
7
  end
@@ -23,7 +23,7 @@ module Docx
23
23
  cleaner_methods.each do |clean_method|
24
24
  ret = Docx::Builder::Cleaners.send(clean_method, ret)
25
25
  end
26
- puts "Returning cleaned variable: #{ret}"
26
+ Docx::Builder.logger.debug("Returning cleaned variable: #{ret}")
27
27
  ret
28
28
  end
29
29
 
data/lib/docx/builder.rb CHANGED
@@ -4,6 +4,7 @@ require 'rubygems'
4
4
  require 'zip'
5
5
  require 'nokogiri'
6
6
 
7
+ require_relative "logger"
7
8
  require_relative "builder/version"
8
9
  require_relative "builder/decoder"
9
10
  require_relative "builder/encoder"
@@ -19,6 +20,10 @@ module Docx
19
20
  @configuration ||= Configuration.new
20
21
  end
21
22
 
23
+ def logger
24
+ configuration.logger
25
+ end
26
+
22
27
  def configure
23
28
  yield(configuration)
24
29
  end
@@ -0,0 +1,19 @@
1
+ require 'logger'
2
+
3
+ module Docx
4
+ class Logger < ::Logger
5
+ def initialize(*args, **kwargs)
6
+ super
7
+ @formatter = SimpleFormatter.new
8
+ @level = ENV['LOG_LEVEL'].to_i if ENV.keys.include?('LOG_LEVEL')
9
+ end
10
+
11
+ # Simple formatter which only displays the message
12
+ class SimpleFormatter < ::Logger::Formatter
13
+ # This method is invoked when a log event occurs
14
+ def call(severity, timestamp, progname, msg)
15
+ "#{String === msg ? msg : msg.inspect}\n"
16
+ end
17
+ end
18
+ end
19
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docx-builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tecnologia Cashme
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-04-06 00:00:00.000000000 Z
11
+ date: 2022-04-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Builds a new docx file using ERB template
14
14
  email:
@@ -38,6 +38,7 @@ files:
38
38
  - lib/docx/builder/template.rb
39
39
  - lib/docx/builder/version.rb
40
40
  - lib/docx/builder/xml_processor.rb
41
+ - lib/docx/logger.rb
41
42
  - publish.sh
42
43
  - tmp/.gitkeep
43
44
  homepage: https://github.com/cash-me/docx-builder