diff --git a/packages/manfred2word/src/engine/doc-parts/hard-skill-section/hard-skill-constants.ts b/packages/manfred2word/src/engine/doc-parts/hard-skill-section/hard-skill-constants.ts index b843d27a..4fc678b8 100644 --- a/packages/manfred2word/src/engine/doc-parts/hard-skill-section/hard-skill-constants.ts +++ b/packages/manfred2word/src/engine/doc-parts/hard-skill-section/hard-skill-constants.ts @@ -6,3 +6,5 @@ export const skillLevelValues: SkillLevel[] = [ { english: 'high', spanish: 'alto' }, { english: 'expert', spanish: 'experto' }, ]; + +export const sectionTitle = 'Hard Skills'; diff --git a/packages/manfred2word/src/engine/doc-parts/hard-skill-section/sections-hard-skill-section.parts.ts b/packages/manfred2word/src/engine/doc-parts/hard-skill-section/hard-skill-section.helpers.ts similarity index 70% rename from packages/manfred2word/src/engine/doc-parts/hard-skill-section/sections-hard-skill-section.parts.ts rename to packages/manfred2word/src/engine/doc-parts/hard-skill-section/hard-skill-section.helpers.ts index 94a17607..64dd6b91 100644 --- a/packages/manfred2word/src/engine/doc-parts/hard-skill-section/sections-hard-skill-section.parts.ts +++ b/packages/manfred2word/src/engine/doc-parts/hard-skill-section/hard-skill-section.helpers.ts @@ -1,28 +1,19 @@ import { IParagraphOptions, IRunOptions, Paragraph, Table, TableCell, TableRow, TextRun, XmlComponent } from 'docx'; -import { HardSkillVM } from './hard-skill-section.vm'; -import { generateLineSpacer } from '@/common-app'; import { TableStyles } from '../doc-parts.vm'; -export const renderTitleHardSkillSection = () => { - return new Paragraph({ - spacing: { before: 200 }, - children: [new TextRun({ text: 'Hard Skills', size: '18pt', bold: true })], - }); -}; - export const renderTable = (rows: TableRow[], styles?: TableStyles): XmlComponent => new Table({ ...styles, rows: [...rows], }); -export const renderTableRow = (cells: TableCell[], styles?: TableStyles): XmlComponent => +export const renderTableRow = (cells: TableCell[], styles?: TableStyles): TableRow => new TableRow({ ...styles, children: [...cells], }); -export const renderTableCell = (children: XmlComponent[], styles?: TableStyles): XmlComponent => +export const renderTableCell = (children: XmlComponent[], styles?: TableStyles): TableCell => new TableCell({ ...styles, children: [...children], diff --git a/packages/manfred2word/src/engine/doc-parts/hard-skill-section/hard-skill-section.part.ts b/packages/manfred2word/src/engine/doc-parts/hard-skill-section/hard-skill-section.part.ts index e80de1a1..23fb68a8 100644 --- a/packages/manfred2word/src/engine/doc-parts/hard-skill-section/hard-skill-section.part.ts +++ b/packages/manfred2word/src/engine/doc-parts/hard-skill-section/hard-skill-section.part.ts @@ -1,69 +1,47 @@ -import { - TableCell, - TableRow, - Table, - ITableCellOptions, - XmlComponent, - ITableRowOptions, - TextRun, - Paragraph, -} from 'docx'; +import { TableRow, Table, XmlComponent, HeadingLevel } from 'docx'; import { ManfredAwesomicCV } from '@/model'; import { HardSkillVM } from './hard-skill-section.vm'; import { mapFromCvToHardSkillVm } from './hard-skill-section.mapper'; +import { + renderTable, + renderTableRow, + renderTableCell, + renderParagraph, + renderTextRun, +} from './hard-skill-section.helpers'; +import { sectionTitle } from './hard-skill-constants'; import { styles } from './hard-skill-section.styles'; -import { renderTitleHardSkillSection } from './sections-hard-skill-section.parts'; - -const createTable = (hardSkillList: HardSkillVM[]): Table => - new Table({ - ...styles.table, - rows: [createTableTitle(), createHardSkillListRow(hardSkillList)], - }); - -const createTableTitle = (): TableRow => - new TableRow({ - children: [ - new TableCell({ - children: [renderTitleHardSkillSection()], - }), - ], - }); - -const createHardSkillListRow = (sectionSoftSkillVm: HardSkillVM[]): TableRow => - new TableRow({ - children: [ - new TableCell({ - ...styles.table, - children: [createParagraph(sectionSoftSkillVm)], - }), - ], - }); const getSkillNameList = (skillList: HardSkillVM[]): string[] => skillList.map(item => (item.skill?.name ? item.skill?.name : '')); const createSkillListWithSeparator = (skillList: string[]): XmlComponent[] => - skillList.map((item, index) => { - if (index === skillList.length - 1) { - return createSoftSkillItem(item); - } - return createSoftSkillItem(`${item} | `); - }); + skillList.map((item, index) => (index === skillList.length - 1 ? renderTextRun(item) : renderTextRun(`${item} | `))); -const createParagraph = (skillList: HardSkillVM[]): XmlComponent => { +const createSkillsTableRow = (skillList: HardSkillVM[]): TableRow => { const list = getSkillNameList(skillList); const skillListWithSeparator = createSkillListWithSeparator(list); + const paragraph = renderParagraph(skillListWithSeparator, { spacing: { before: 200 } }); + const cell = renderTableCell([paragraph]); + const row = renderTableRow([cell]); + + return row; +}; + +const createTitleTableRow = (text: string): TableRow => { + const title = renderTextRun(text, { size: '18pt', bold: true }); + const paragraph = renderParagraph([title], { spacing: { before: 200 } }); + const cell = renderTableCell([paragraph]); + const row = renderTableRow([cell]); - return new Paragraph({ - spacing: { before: 200 }, - children: [...skillListWithSeparator], - }); + return row; }; -const createSoftSkillItem = (skill: string): XmlComponent => - skill ? new TextRun({ text: skill, size: '12pt' }) : new TextRun({ text: '', size: '12pt' }); export const generateHardSkillSection = (cv: ManfredAwesomicCV): Table => { const hardSkillList = mapFromCvToHardSkillVm(cv); + const title = createTitleTableRow(sectionTitle); + const hardSkillItems = createSkillsTableRow(hardSkillList); + const table = renderTable([title, hardSkillItems], styles.table); - return createTable(hardSkillList); + return table; };