standard-procedure-consolidate 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 52bf3de85226b0aa00c8a2d5ad8caa7e0dbc7aa2e8707150d844e34a3313fcf9
4
+ data.tar.gz: cf92c7c1fc1978cc7e615674d01e542d4ca5b4588da08856b6608301efd83109
5
+ SHA512:
6
+ metadata.gz: 1a2c3dfa7bc6fe20d8f3ddc2bdfe9f1c94fe53ddd1daf75009f96af35ba20f1d7acdaf6b1f3563b9484f50fa4a0a5b53ab4c2e161008f0131fd03d39b67df76f
7
+ data.tar.gz: f169d41a245b6dbe95d20eeded64c5ff684ec4822dfab36ed342374916c6e7eb2c6dee82cc14fc89bc1d141ba4c1b259629e8b6ba219952bd949db0f53384aa8
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/testdouble/standard
3
+ ruby_version: 2.6
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-07-25
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at rahoulb@echodek.co. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Rahoul Baruah
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # Standard::Procedure::Consolidate
2
+
3
+ A simple gem for performing mailmerge on Microsoft Word .docx files.
4
+
5
+ Important: I can't claim the credit for this - I found [this gist](https://gist.github.com/ericmason/7200448) and have just adapted it.
6
+
7
+ It's pretty simple, so it probably won't work with complex Word documents, but it does what I need. YMMV.
8
+
9
+
10
+ ## Installation
11
+
12
+ $ bundle add standard-procedure-consolidate
13
+
14
+ ## Usage
15
+
16
+ ```ruby
17
+ Consolidate::Docx::Merge.open "/path/to/docx" do |merge|
18
+ merge.data "Name" => "Alice Aadvark", "Company" => "TinyCo", "Job_Title" => "CEO"
19
+ merge.write_to "/path/to/output.docx"
20
+ end
21
+
22
+ ```
23
+
24
+ NOTE: The merge fields are case-sensitive - which is why they should be supplied as strings (using the older `{ "key" => "value" }` style ruby hash).
25
+
26
+ ## Development
27
+
28
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
29
+
30
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
31
+
32
+ ## Contributing
33
+
34
+ Bug reports and pull requests are welcome on GitHub at https://github.com/standard-procedure/standard-procedure-consolidate. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/standard-procedure/standard-procedure-consolidate/blob/main/CODE_OF_CONDUCT.md).
35
+
36
+ ## License
37
+
38
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
39
+
40
+ ## Code of Conduct
41
+
42
+ Everyone interacting in the Standard::Procedure::Consolidate project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/standard-procedure-consolidate/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "standard/rake"
9
+
10
+ task default: %i[spec standard]
@@ -0,0 +1 @@
1
+ 87f75155b27d6d5888d141bc11d8389fa1c1acd658747d62b34a26f75f2961e914b5dec5c599af33f682444632e38506a7d4b7d35bff5f1956588c46b6a3fa65
data/exe/consolidate ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "consolidate"
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "zip"
4
+ require "nokogiri"
5
+
6
+ module Consolidate
7
+ module Docx
8
+ class Merge
9
+ def self.open(path, force_settings: true, &block)
10
+ new(path, force_settings: force_settings, &block)
11
+ end
12
+
13
+ def data fields = {}
14
+ fields = fields.transform_keys(&:to_s)
15
+
16
+ xml = @zip.read("word/document.xml")
17
+ doc = Nokogiri::XML(xml) { |x| x.noent }
18
+
19
+ doc = substitute_style_one_with xml, doc, fields
20
+ doc = substitute_style_two_with xml, doc, fields
21
+
22
+ @output["word/document.xml"] = doc.serialize save_with: 0
23
+ end
24
+
25
+ def write_to path
26
+ Zip::File.open(path, Zip::File::CREATE) do |out|
27
+ @zip.each do |entry|
28
+ out.get_output_stream(entry.name) do |o|
29
+ o.write(@output[entry.name] || @zip.read(entry.name))
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ protected
36
+
37
+ def initialize(path, force_settings: true, &block)
38
+ raise "No block given" unless block
39
+ @output = {}
40
+ set_standard_settings if force_settings
41
+ begin
42
+ @zip = Zip::File.open(path)
43
+ yield self
44
+ ensure
45
+ @zip.close
46
+ end
47
+ end
48
+
49
+ def substitute_style_one_with xml, doc, fields
50
+ # Word's first way of doing things
51
+ (doc / "//w:fldSimple").each do |field|
52
+ if field.attributes["instr"].value =~ /MERGEFIELD (\S+)/
53
+ text_node = (field / ".//w:t").first
54
+ next unless text_node
55
+ text_node.inner_html = fields[$1].to_s
56
+ end
57
+ end
58
+ doc
59
+ end
60
+
61
+ def substitute_style_two_with xml, doc, fields
62
+ # Word's second way of doing things
63
+ (doc / "//w:instrText").each do |instr|
64
+ if instr.inner_text =~ /MERGEFIELD (\S+)/
65
+ text_node = instr.parent.next_sibling.next_sibling.xpath(".//w:t").first
66
+ text_node ||= instr.parent.next_sibling.next_sibling.next_sibling.xpath(".//w:t").first
67
+ next unless text_node
68
+ text_node.inner_html = fields[$1].to_s
69
+ end
70
+ end
71
+ doc
72
+ end
73
+
74
+ def set_standard_settings
75
+ @output["word/settings.xml"] = %(<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
76
+ <w:settings xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:sl="http://schemas.openxmlformats.org/schemaLibrary/2006/main"><w:zoom w:percent="100"/></w:settings>)
77
+ end
78
+
79
+ def close
80
+ @zip.close
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Consolidate
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,4 @@
1
+ module Consolidate
2
+ require_relative "consolidate/version"
3
+ require_relative "consolidate/docx/merge"
4
+ end
@@ -0,0 +1,8 @@
1
+ module Standard
2
+ module Procedure
3
+ module Consolidate
4
+ VERSION: String
5
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
6
+ end
7
+ end
8
+ end
data/tmp/.keep ADDED
File without changes
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: standard-procedure-consolidate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rahoul Baruah
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-07-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubyzip
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Simple ruby mailmerge for Microsoft Word .docx files.
42
+ email:
43
+ - rahoulb@standardprocedure.app
44
+ executables:
45
+ - consolidate
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".rspec"
50
+ - ".standard.yml"
51
+ - CHANGELOG.md
52
+ - CODE_OF_CONDUCT.md
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - checksums/standard-procedure-consolidate-0.1.0.gem.sha512
57
+ - exe/consolidate
58
+ - lib/consolidate.rb
59
+ - lib/consolidate/docx/merge.rb
60
+ - lib/consolidate/version.rb
61
+ - sig/standard/procedure/consolidate.rbs
62
+ - tmp/.keep
63
+ homepage: https://github.com/standard-procedure/standard-procedure-consolidate
64
+ licenses:
65
+ - MIT
66
+ metadata:
67
+ allowed_push_host: https://rubygems.org
68
+ homepage_uri: https://github.com/standard-procedure/standard-procedure-consolidate
69
+ source_code_uri: https://github.com/standard-procedure/standard-procedure-consolidate
70
+ changelog_uri: https://github.com/standard-procedure/standard-procedure-consolidate/blob/main/CHANGELOG.md
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 2.6.0
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubygems_version: 3.4.14
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: Simple ruby mailmerge for Microsoft Word .docx files.
90
+ test_files: []