-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
32 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 2 additions & 11 deletions
13
...tion/sections-hard-skill-section.parts.ts → ...ill-section/hard-skill-section.helpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 28 additions & 50 deletions
78
packages/manfred2word/src/engine/doc-parts/hard-skill-section/hard-skill-section.part.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; |