diff --git a/packages/manfred2word/src/common-app/helpers/index.ts b/packages/manfred2word/src/common-app/helpers/index.ts new file mode 100644 index 00000000..7e906df6 --- /dev/null +++ b/packages/manfred2word/src/common-app/helpers/index.ts @@ -0,0 +1 @@ +export * from './render-elements.helpers'; diff --git a/packages/manfred2word/src/engine/doc-parts/hard-skill-section/hard-skill-section.helpers.ts b/packages/manfred2word/src/common-app/helpers/render-elements.helpers.ts similarity index 94% rename from packages/manfred2word/src/engine/doc-parts/hard-skill-section/hard-skill-section.helpers.ts rename to packages/manfred2word/src/common-app/helpers/render-elements.helpers.ts index 64dd6b91..d4180342 100644 --- a/packages/manfred2word/src/engine/doc-parts/hard-skill-section/hard-skill-section.helpers.ts +++ b/packages/manfred2word/src/common-app/helpers/render-elements.helpers.ts @@ -1,5 +1,5 @@ import { IParagraphOptions, IRunOptions, Paragraph, Table, TableCell, TableRow, TextRun, XmlComponent } from 'docx'; -import { TableStyles } from '../doc-parts.vm'; +import { TableStyles } from '../model/doc-parts.vm'; export const renderTable = (rows: TableRow[], styles?: TableStyles): XmlComponent => new Table({ diff --git a/packages/manfred2word/src/common-app/model/doc-parts.vm.ts b/packages/manfred2word/src/common-app/model/doc-parts.vm.ts new file mode 100644 index 00000000..60e2f495 --- /dev/null +++ b/packages/manfred2word/src/common-app/model/doc-parts.vm.ts @@ -0,0 +1,24 @@ +import { + IImageOptions, + IParagraphPropertiesOptions, + IRunOptions, + ISectionOptions, + ITableCellOptions, + ITableOptions, + ITableRowOptions, +} from 'docx'; +import { IPropertiesOptions } from 'docx/build/file/core-properties'; + +export type SectionStyles = Omit; +export type DocumentStyle = Omit; +export type TableStyles = Omit; +export type TableCellStyles = Omit; +export type TableRowStyles = Omit; +export type TextRunStyles = Omit; +export type ParagraphStyles = IParagraphPropertiesOptions; +export type ImageStyles = Omit; + +export interface RowProperties { + rowStyles?: TableRowStyles; + cellStyles?: TableCellStyles; +} 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 c13d84bd..5de05c7e 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 @@ -3,12 +3,12 @@ import { ManfredAwesomicCV } from '@/model'; import { HardSkillVM } from './hard-skill-section.vm'; import { mapFromCvToHardSkillVm } from './hard-skill-section.mapper'; import { + renderParagraph, renderTable, - renderTableRow, renderTableCell, - renderParagraph, + renderTableRow, renderTextRun, -} from './hard-skill-section.helpers'; +} from '@/common-app/helpers/render-elements.helpers'; import { sectionTitle } from './hard-skill-constants'; import { styles } from './hard-skill-section.styles'; diff --git a/packages/manfred2word/src/engine/doc-parts/soft-skill-section/soft-skill-section.part.ts b/packages/manfred2word/src/engine/doc-parts/soft-skill-section/soft-skill-section.part.ts index ab069197..2b5a68e7 100644 --- a/packages/manfred2word/src/engine/doc-parts/soft-skill-section/soft-skill-section.part.ts +++ b/packages/manfred2word/src/engine/doc-parts/soft-skill-section/soft-skill-section.part.ts @@ -1,40 +1,47 @@ import { ManfredAwesomicCV } from '@/model'; -import { TableCell, TableRow, Table } from 'docx'; -import { titleSoftSkillSection, sectionSoftSkillSection } from './sections-soft-skill-section.parts'; +import { + renderParagraph, + renderTable, + renderTableCell, + renderTableRow, + renderTextRun, +} from '@/common-app/helpers/render-elements.helpers'; +import { TableRow, Table, XmlComponent } from 'docx'; import { SoftSkillVM } from './soft-skill-section.vm'; import { styles } from './soft-skill-section.styles'; import { mapFromCvToSoftSkillVm } from './soft-skill-section.mapper'; +import { sectionTitle } from './soft-skill.constants'; -export const generateSoftSkillSection = (cv: ManfredAwesomicCV): Table => { - const profileSectionVm = mapFromCvToSoftSkillVm(cv); +const getSkillNameList = (skillList: SoftSkillVM[]): string[] => + skillList.map(item => (item.skill?.name ? item.skill?.name : '')); + +const createSkillListWithSeparator = (skillList: string[]): XmlComponent[] => + skillList.map((item, index) => (index === skillList.length - 1 ? renderTextRun(item) : renderTextRun(`${item} / `))); + +const createSkillsTableRow = (skillList: SoftSkillVM[]): 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 generateSoftSkillSectionInner(profileSectionVm); + return row; }; -export const generateSoftSkillSectionInner = (softSkillSctionVm: SoftSkillVM[]): Table => - new Table({ - ...styles.table, - rows: [generateTitleSoftSkill(), ...generateSectionSoftSkillFromVmToRows(softSkillSctionVm)], - }); - -const generateTitleSoftSkill = (): TableRow => - new TableRow({ - children: [ - new TableCell({ - children: [titleSoftSkillSection()], - }), - ], - }); - -const generateSectionSoftSkillFromVmToRows = (softSkillSectionVm: SoftSkillVM[]): TableRow[] => - Boolean(softSkillSectionVm) ? softSkillSectionVm.map(softSkillVm => softSkillsSection(softSkillVm)) : []; - -const softSkillsSection = (sectionSoftSkillVm: SoftSkillVM): TableRow => - new TableRow({ - children: [ - new TableCell({ - ...styles.table, - children: sectionSoftSkillSection(sectionSoftSkillVm), - }), - ], - }); +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 row; +}; + +export const generateSoftSkillSection = (cv: ManfredAwesomicCV): Table => { + const hardSkillList = mapFromCvToSoftSkillVm(cv); + const title = createTitleTableRow(sectionTitle); + const hardSkillItems = createSkillsTableRow(hardSkillList); + const table = renderTable([title, hardSkillItems], styles.table); + + return table; +}; diff --git a/packages/manfred2word/src/engine/doc-parts/soft-skill-section/soft-skill.constants.ts b/packages/manfred2word/src/engine/doc-parts/soft-skill-section/soft-skill.constants.ts index 0d9d54bc..e31259a4 100644 --- a/packages/manfred2word/src/engine/doc-parts/soft-skill-section/soft-skill.constants.ts +++ b/packages/manfred2word/src/engine/doc-parts/soft-skill-section/soft-skill.constants.ts @@ -6,3 +6,5 @@ export const levelSkillList: SkillType[] = [ { level: 'high', spanish: 'Alto' }, { level: 'expert', spanish: 'Experto' }, ]; + +export const sectionTitle = 'Soft Skills';