File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed
Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -392,6 +392,20 @@ describe('generateRandomString', () => {
392392 } ) ;
393393} ) ;
394394
395+ describe ( 'compileHandlebars' , ( ) => {
396+ it ( 'renders the template with the meta context and compile options' , ( ) => {
397+ const rendered = Util . compileHandlebars (
398+ '{{name}} {{{raw}}}' ,
399+ { noEscape : true } ,
400+ {
401+ name : 'docker' ,
402+ raw : '<strong>actions-toolkit</strong>'
403+ }
404+ ) ;
405+ expect ( rendered ) . toBe ( 'docker <strong>actions-toolkit</strong>' ) ;
406+ } ) ;
407+ } ) ;
408+
395409describe ( 'stringToUnicodeEntities' , ( ) => {
396410 it ( 'should convert a string to Unicode entities' , ( ) => {
397411 const input = 'Hello, World!' ;
Original file line number Diff line number Diff line change 1717import crypto from 'crypto' ;
1818import fs from 'fs' ;
1919import path from 'path' ;
20+ import * as handlebars from 'handlebars' ;
2021import * as core from '@actions/core' ;
2122import * as io from '@actions/io' ;
2223import { parse } from 'csv-parse/sync' ;
@@ -202,6 +203,10 @@ export class Util {
202203 return bytes . toString ( 'hex' ) . slice ( 0 , length ) ;
203204 }
204205
206+ public static compileHandlebars ( value : string , options : Parameters < typeof handlebars . compile > [ 1 ] , data : unknown ) : string {
207+ return handlebars . compile ( value , options ) ( data ) ;
208+ }
209+
205210 public static stringToUnicodeEntities ( str : string ) {
206211 return Array . from ( str )
207212 . map ( char => `&#x${ char . charCodeAt ( 0 ) . toString ( 16 ) } ;` )
You can’t perform that action at this time.
0 commit comments