
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
This gem allows you to generate .docx files in your rails or ruby app by embedding variables inside of a .docx template. This is purposefully meant to be simple and feature-light.
Add this line to your application's Gemfile:
gem 'docx_replace'
And then execute:
$ bundle
Or install it yourself as:
$ gem install docx_replace
Inside of a rails controller, your code might look something like this (although I would recommend extracting most of this into a separate class):
def user_report
@user = User.find(params[:user_id])
respond_to do |format|
format.docx do
# Initialize DocxReplace with your template
doc = DocxReplace::Doc.new("#{Rails.root}/lib/docx_templates/my_template.docx", "#{Rails.root}/tmp")
# Replace some variables. $var$ convention is used here, but not required.
doc.replace("$first_name$", @user.first_name)
doc.replace("$last_name$", @user.last_name)
doc.replace("$user_bio$", @user.bio)
# Replace multiple occurrences
doc.replace("$birth_date", @user.birth_date, true)
# Write the document back to a temporary file
tmp_file = Tempfile.new('word_tempate', "#{Rails.root}/tmp")
doc.commit(tmp_file.path)
# Respond to the request by sending the temp file
send_file tmp_file.path, filename: "user_#{@user.id}_report.docx", disposition: 'attachment'
end
end
end
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)Much of this code is based on an older gem called docxedit. This has a few more features, but is very sensitive to the formatting of the .docx template.
FAQs
Unknown package
We found that docx_replace demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.