Skip to content

Commit

Permalink
Merge pull request #121 from Lemoncode/feature/#115-update-generate-h…
Browse files Browse the repository at this point in the history
…ard-skill-section

updated soft skills
  • Loading branch information
manudous authored Jul 7, 2023
2 parents 8977282 + 13ac354 commit ad03e05
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 36 deletions.
1 change: 1 addition & 0 deletions packages/manfred2word/src/common-app/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './render-elements.helpers';
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
24 changes: 24 additions & 0 deletions packages/manfred2word/src/common-app/model/doc-parts.vm.ts
Original file line number Diff line number Diff line change
@@ -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<ISectionOptions, 'children'>;
export type DocumentStyle = Omit<IPropertiesOptions, 'sections'>;
export type TableStyles = Omit<ITableOptions, 'rows'>;
export type TableCellStyles = Omit<ITableCellOptions, 'children'>;
export type TableRowStyles = Omit<ITableRowOptions, 'children'>;
export type TextRunStyles = Omit<IRunOptions, 'text'>;
export type ParagraphStyles = IParagraphPropertiesOptions;
export type ImageStyles = Omit<IImageOptions, 'data'>;

export interface RowProperties {
rowStyles?: TableRowStyles;
cellStyles?: TableCellStyles;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ export const levelSkillList: SkillType[] = [
{ level: 'high', spanish: 'Alto' },
{ level: 'expert', spanish: 'Experto' },
];

export const sectionTitle = 'Soft Skills';

0 comments on commit ad03e05

Please sign in to comment.