Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Added description about Sablon #5

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions lib/curated.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ def contributors
path = "lib/#{collection}/#{Utils.underscore(Utils.demodulize(self))}.rb"
Utils.github_contributors_for_file('jetrockets/curated', path)
end

private

def helper_utils
@helper_utils ||= Class.new do
include Utils
end.new
end
end

attr_rw :package
Expand Down
1 change: 1 addition & 0 deletions lib/curated/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require_relative 'utils/github'
require_relative 'utils/string'
require_relative 'utils/npm'
require_relative 'utils/md_formating'

module Utils
end
11 changes: 11 additions & 0 deletions lib/curated/utils/md_formating.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module Utils
extend self

def code_block(language, text = nil)
value = (+"```#{language}") << "\n#{text}```"

block_given? ? yield(value) : value
end
end
31 changes: 31 additions & 0 deletions lib/ruby/sablon.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

class Curated::Sablon < Curated::RubyGem
package 'sablon'
homepage 'https://github.com/senny/sablon'
category Category::Other

pros "We've been usi Sablon in some projects for inserting content in docx templates."
# rubocop:disable Layout/ClosingParenthesisIndentation
pros "It is easy to use this gem:\n #{helper_utils.code_block "ruby", <<~RUBY
# First prepare docx file and add `MergeField` inside. For example the name of this MergeField is some_variable
require 'sablon'

template = Sablon.template(File.expand_path('/Users/bs/Documents/example_merge_field.docx'))
context = { some_variable: 'This text will be added instead of `some_variable` in resulted docx file' }

template.render_to_file File.expand_path('~/Users/bs/Documents/output.docx'), context
RUBY
}"
# rubocop:enable Layout/ClosingParenthesisIndentation
pros "You can add to your documents simple values(which are the results of calculations in your methods),
formatted html blocks containing everything you need (tables, unsorted lists, sorted lists,
any text markup you need to add to the final docx file)"
cons "It does not support ODT format. And if you try to save docx file with MergeFields from LibreOffice your fields
will be saved as plain text, so you will not be able to paste the content into the document."
cons "If in your original template there is numbering (like 1.1, 1.2, 1.3, 1.4, 2.1, 2.2, 2,3, 2.4)
and for example you need in some cases to insert HTML block of text at number 1.3 and in some cases at number 2.3,
then be prepared to write code that will add numbering to HTML text block and writing logic in what case to insert
paragraph 1.3 and in what 2.3. Any addition of an HTML block to the document template will completely replace
the line in which MergeField is added"
end