Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
juanpms2 committed Jul 7, 2023
1 parent 2339d5b commit 1652b3f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ export const skillLevelValues: SkillLevel[] = [
{ english: 'high', spanish: 'alto' },
{ english: 'expert', spanish: 'experto' },
];

export const sectionTitle = 'Hard Skills';
Original file line number Diff line number Diff line change
@@ -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],
Expand Down
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;
};

0 comments on commit 1652b3f

Please sign in to comment.