Conditional or loop statements in rtf template
I have predefined rtf template file RTF_Template.rtf as follows:
{rtf1ansideff0{fonttbl{f0 fswiss Helvetica;}{f1 Courier;}}
{colortbl;red255green0blue0;red0green0blue255;}
widowctrlhyphauto
{pard ql f0 sa180 li0 fi0 b fs36 FirstName LastNamepar}
{pard ql f0 sa180 li0 fi0 {b UEI:} 103910par}
{pard ql f0 sa180 li0 fi0 {b Sex:u160?}Femalepar}
{pard ql f0 sa180 li0 fi0 {b DOB:} 10/31/1980par}
{pard ql f0 sa180 li0 fi0 {b Email:} sample@email.com par}
I am making changing in this format something like:
rtf_template = Rails.root.join('doc', 'rtf_templates', 'RTF_Template.rtf')
content = File.read(rtf_template)
content.gsub!('FirstName LastName', @student.full_name)
content.gsub!('UEI', StudentIdentifier.primary_identifier.first&.name)
content.gsub!('103910', @student.primary_identifier&.value)
content.gsub!('Female', @student.gender)
content.gsub!('10/31/1980', @student.date_of_birth.strftime('%m-%d-%Y'))
content.gsub!('sample@email.com', @student.email)
Problem:
Currently, I am only showing the first StudentIdentifier which is the primary one on line: content.gsub!('UEI', StudentIdentifier.primary_identifier.first&.name)
and setting value for same identifier on Line: content.gsub!('103910', @student.primary_identifier&.value)
The user can have multiple identifiers and value against that each identifier.
I can access those all identifier using a loop @student.identifiers.each do |p_id|
then identifier name in p_id[0] and value in p_id[1]
I want to show all identifiers on the same place (after name, before sex) in the same template.
ruby-on-rails rtf
add a comment |
I have predefined rtf template file RTF_Template.rtf as follows:
{rtf1ansideff0{fonttbl{f0 fswiss Helvetica;}{f1 Courier;}}
{colortbl;red255green0blue0;red0green0blue255;}
widowctrlhyphauto
{pard ql f0 sa180 li0 fi0 b fs36 FirstName LastNamepar}
{pard ql f0 sa180 li0 fi0 {b UEI:} 103910par}
{pard ql f0 sa180 li0 fi0 {b Sex:u160?}Femalepar}
{pard ql f0 sa180 li0 fi0 {b DOB:} 10/31/1980par}
{pard ql f0 sa180 li0 fi0 {b Email:} sample@email.com par}
I am making changing in this format something like:
rtf_template = Rails.root.join('doc', 'rtf_templates', 'RTF_Template.rtf')
content = File.read(rtf_template)
content.gsub!('FirstName LastName', @student.full_name)
content.gsub!('UEI', StudentIdentifier.primary_identifier.first&.name)
content.gsub!('103910', @student.primary_identifier&.value)
content.gsub!('Female', @student.gender)
content.gsub!('10/31/1980', @student.date_of_birth.strftime('%m-%d-%Y'))
content.gsub!('sample@email.com', @student.email)
Problem:
Currently, I am only showing the first StudentIdentifier which is the primary one on line: content.gsub!('UEI', StudentIdentifier.primary_identifier.first&.name)
and setting value for same identifier on Line: content.gsub!('103910', @student.primary_identifier&.value)
The user can have multiple identifiers and value against that each identifier.
I can access those all identifier using a loop @student.identifiers.each do |p_id|
then identifier name in p_id[0] and value in p_id[1]
I want to show all identifiers on the same place (after name, before sex) in the same template.
ruby-on-rails rtf
add a comment |
I have predefined rtf template file RTF_Template.rtf as follows:
{rtf1ansideff0{fonttbl{f0 fswiss Helvetica;}{f1 Courier;}}
{colortbl;red255green0blue0;red0green0blue255;}
widowctrlhyphauto
{pard ql f0 sa180 li0 fi0 b fs36 FirstName LastNamepar}
{pard ql f0 sa180 li0 fi0 {b UEI:} 103910par}
{pard ql f0 sa180 li0 fi0 {b Sex:u160?}Femalepar}
{pard ql f0 sa180 li0 fi0 {b DOB:} 10/31/1980par}
{pard ql f0 sa180 li0 fi0 {b Email:} sample@email.com par}
I am making changing in this format something like:
rtf_template = Rails.root.join('doc', 'rtf_templates', 'RTF_Template.rtf')
content = File.read(rtf_template)
content.gsub!('FirstName LastName', @student.full_name)
content.gsub!('UEI', StudentIdentifier.primary_identifier.first&.name)
content.gsub!('103910', @student.primary_identifier&.value)
content.gsub!('Female', @student.gender)
content.gsub!('10/31/1980', @student.date_of_birth.strftime('%m-%d-%Y'))
content.gsub!('sample@email.com', @student.email)
Problem:
Currently, I am only showing the first StudentIdentifier which is the primary one on line: content.gsub!('UEI', StudentIdentifier.primary_identifier.first&.name)
and setting value for same identifier on Line: content.gsub!('103910', @student.primary_identifier&.value)
The user can have multiple identifiers and value against that each identifier.
I can access those all identifier using a loop @student.identifiers.each do |p_id|
then identifier name in p_id[0] and value in p_id[1]
I want to show all identifiers on the same place (after name, before sex) in the same template.
ruby-on-rails rtf
I have predefined rtf template file RTF_Template.rtf as follows:
{rtf1ansideff0{fonttbl{f0 fswiss Helvetica;}{f1 Courier;}}
{colortbl;red255green0blue0;red0green0blue255;}
widowctrlhyphauto
{pard ql f0 sa180 li0 fi0 b fs36 FirstName LastNamepar}
{pard ql f0 sa180 li0 fi0 {b UEI:} 103910par}
{pard ql f0 sa180 li0 fi0 {b Sex:u160?}Femalepar}
{pard ql f0 sa180 li0 fi0 {b DOB:} 10/31/1980par}
{pard ql f0 sa180 li0 fi0 {b Email:} sample@email.com par}
I am making changing in this format something like:
rtf_template = Rails.root.join('doc', 'rtf_templates', 'RTF_Template.rtf')
content = File.read(rtf_template)
content.gsub!('FirstName LastName', @student.full_name)
content.gsub!('UEI', StudentIdentifier.primary_identifier.first&.name)
content.gsub!('103910', @student.primary_identifier&.value)
content.gsub!('Female', @student.gender)
content.gsub!('10/31/1980', @student.date_of_birth.strftime('%m-%d-%Y'))
content.gsub!('sample@email.com', @student.email)
Problem:
Currently, I am only showing the first StudentIdentifier which is the primary one on line: content.gsub!('UEI', StudentIdentifier.primary_identifier.first&.name)
and setting value for same identifier on Line: content.gsub!('103910', @student.primary_identifier&.value)
The user can have multiple identifiers and value against that each identifier.
I can access those all identifier using a loop @student.identifiers.each do |p_id|
then identifier name in p_id[0] and value in p_id[1]
I want to show all identifiers on the same place (after name, before sex) in the same template.
ruby-on-rails rtf
ruby-on-rails rtf
asked Jan 1 at 3:32
Waqas NazirWaqas Nazir
557
557
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Your code simply needs to substitute one placeholder with a sequence of RTF code lines.
Template:
{rtf1ansideff0{fonttbl{f0 fswiss Helvetica;}{f1 Courier;}}
{colortbl;red255green0blue0;red0green0blue255;}
widowctrlhyphauto
{pard ql f0 sa180 li0 fi0 b fs36 FirstName LastNamepar}
identifier_list
{pard ql f0 sa180 li0 fi0 {b Sex:u160?}Femalepar}
{pard ql f0 sa180 li0 fi0 {b DOB:} 10/31/1980par}
{pard ql f0 sa180 li0 fi0 {b Email:} sample@email.com par}
And then concatenate your identifier name / value pairs including the surrounding RTF code, for example
{pard ql f0 sa180 li0 fi0 {b UEI1:} 103911par}
{pard ql f0 sa180 li0 fi0 {b UEI2:} 103912par}
{pard ql f0 sa180 li0 fi0 {b UEI3:} 103913par}
And finally replace the placeholder
content.gsub!('identifier_list', myIdentifierListsWithRTF)
(note: I am no ruby on rails programmer so I can only give the idea, not the actual code)
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53992857%2fconditional-or-loop-statements-in-rtf-template%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your code simply needs to substitute one placeholder with a sequence of RTF code lines.
Template:
{rtf1ansideff0{fonttbl{f0 fswiss Helvetica;}{f1 Courier;}}
{colortbl;red255green0blue0;red0green0blue255;}
widowctrlhyphauto
{pard ql f0 sa180 li0 fi0 b fs36 FirstName LastNamepar}
identifier_list
{pard ql f0 sa180 li0 fi0 {b Sex:u160?}Femalepar}
{pard ql f0 sa180 li0 fi0 {b DOB:} 10/31/1980par}
{pard ql f0 sa180 li0 fi0 {b Email:} sample@email.com par}
And then concatenate your identifier name / value pairs including the surrounding RTF code, for example
{pard ql f0 sa180 li0 fi0 {b UEI1:} 103911par}
{pard ql f0 sa180 li0 fi0 {b UEI2:} 103912par}
{pard ql f0 sa180 li0 fi0 {b UEI3:} 103913par}
And finally replace the placeholder
content.gsub!('identifier_list', myIdentifierListsWithRTF)
(note: I am no ruby on rails programmer so I can only give the idea, not the actual code)
add a comment |
Your code simply needs to substitute one placeholder with a sequence of RTF code lines.
Template:
{rtf1ansideff0{fonttbl{f0 fswiss Helvetica;}{f1 Courier;}}
{colortbl;red255green0blue0;red0green0blue255;}
widowctrlhyphauto
{pard ql f0 sa180 li0 fi0 b fs36 FirstName LastNamepar}
identifier_list
{pard ql f0 sa180 li0 fi0 {b Sex:u160?}Femalepar}
{pard ql f0 sa180 li0 fi0 {b DOB:} 10/31/1980par}
{pard ql f0 sa180 li0 fi0 {b Email:} sample@email.com par}
And then concatenate your identifier name / value pairs including the surrounding RTF code, for example
{pard ql f0 sa180 li0 fi0 {b UEI1:} 103911par}
{pard ql f0 sa180 li0 fi0 {b UEI2:} 103912par}
{pard ql f0 sa180 li0 fi0 {b UEI3:} 103913par}
And finally replace the placeholder
content.gsub!('identifier_list', myIdentifierListsWithRTF)
(note: I am no ruby on rails programmer so I can only give the idea, not the actual code)
add a comment |
Your code simply needs to substitute one placeholder with a sequence of RTF code lines.
Template:
{rtf1ansideff0{fonttbl{f0 fswiss Helvetica;}{f1 Courier;}}
{colortbl;red255green0blue0;red0green0blue255;}
widowctrlhyphauto
{pard ql f0 sa180 li0 fi0 b fs36 FirstName LastNamepar}
identifier_list
{pard ql f0 sa180 li0 fi0 {b Sex:u160?}Femalepar}
{pard ql f0 sa180 li0 fi0 {b DOB:} 10/31/1980par}
{pard ql f0 sa180 li0 fi0 {b Email:} sample@email.com par}
And then concatenate your identifier name / value pairs including the surrounding RTF code, for example
{pard ql f0 sa180 li0 fi0 {b UEI1:} 103911par}
{pard ql f0 sa180 li0 fi0 {b UEI2:} 103912par}
{pard ql f0 sa180 li0 fi0 {b UEI3:} 103913par}
And finally replace the placeholder
content.gsub!('identifier_list', myIdentifierListsWithRTF)
(note: I am no ruby on rails programmer so I can only give the idea, not the actual code)
Your code simply needs to substitute one placeholder with a sequence of RTF code lines.
Template:
{rtf1ansideff0{fonttbl{f0 fswiss Helvetica;}{f1 Courier;}}
{colortbl;red255green0blue0;red0green0blue255;}
widowctrlhyphauto
{pard ql f0 sa180 li0 fi0 b fs36 FirstName LastNamepar}
identifier_list
{pard ql f0 sa180 li0 fi0 {b Sex:u160?}Femalepar}
{pard ql f0 sa180 li0 fi0 {b DOB:} 10/31/1980par}
{pard ql f0 sa180 li0 fi0 {b Email:} sample@email.com par}
And then concatenate your identifier name / value pairs including the surrounding RTF code, for example
{pard ql f0 sa180 li0 fi0 {b UEI1:} 103911par}
{pard ql f0 sa180 li0 fi0 {b UEI2:} 103912par}
{pard ql f0 sa180 li0 fi0 {b UEI3:} 103913par}
And finally replace the placeholder
content.gsub!('identifier_list', myIdentifierListsWithRTF)
(note: I am no ruby on rails programmer so I can only give the idea, not the actual code)
answered Feb 8 at 19:10
mjnmjn
26k22143318
26k22143318
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53992857%2fconditional-or-loop-statements-in-rtf-template%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown