Skip to content

Commit

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

Updated hard skills section
  • Loading branch information
manudous authored Jul 7, 2023
2 parents 75603eb + 5a00566 commit 8977282
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 88 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
@@ -0,0 +1,28 @@
import { IParagraphOptions, IRunOptions, Paragraph, Table, TableCell, TableRow, TextRun, XmlComponent } from 'docx';
import { TableStyles } from '../doc-parts.vm';

export const renderTable = (rows: TableRow[], styles?: TableStyles): XmlComponent =>
new Table({
...styles,
rows: [...rows],
});

export const renderTableRow = (cells: TableCell[], styles?: TableStyles): TableRow =>
new TableRow({
...styles,
children: [...cells],
});

export const renderTableCell = (children: XmlComponent[], styles?: TableStyles): TableCell =>
new TableCell({
...styles,
children: [...children],
});

export const renderParagraph = (children: XmlComponent[], opcions?: IParagraphOptions): XmlComponent =>
new Paragraph({
...opcions,
children: [...children],
});

export const renderTextRun = (text: string, options?: IRunOptions): XmlComponent => new TextRun({ ...options, text });
Original file line number Diff line number Diff line change
@@ -1,40 +1,47 @@
import { TableCell, TableRow, Table } 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 { renderSectionHardSkillSection, renderTitleHardSkillSection } from './sections-hard-skill-section.parts';

export const generateHardSkillSection = (cv: ManfredAwesomicCV): Table => {
const hardSkillVmArray = mapFromCvToHardSkillVm(cv);
const getSkillNameList = (skillList: HardSkillVM[]): 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: 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 generateHardSkillSectionInner(hardSkillVmArray);
return row;
};

const generateHardSkillSectionInner = (hardSkillVmArray: HardSkillVM[]): Table =>
new Table({
...styles.table,
rows: [generateTitleHardSkill(), ...generateSectionFromVmToRows(hardSkillVmArray)],
});

const generateTitleHardSkill = (): TableRow =>
new TableRow({
children: [
new TableCell({
children: [renderTitleHardSkillSection()],
}),
],
});

const generateSectionFromVmToRows = (hardSkillSectionVm: HardSkillVM[]): TableRow[] =>
Boolean(hardSkillSectionVm) ? hardSkillSectionVm.map(softSkillVm => hardSkillsSection(softSkillVm)) : [];

const hardSkillsSection = (sectionSoftSkillVm: HardSkillVM): TableRow =>
new TableRow({
children: [
new TableCell({
...styles.table,
children: renderSectionHardSkillSection(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 generateHardSkillSection = (cv: ManfredAwesomicCV): Table => {
const hardSkillList = mapFromCvToHardSkillVm(cv);
const title = createTitleTableRow(sectionTitle);
const hardSkillItems = createSkillsTableRow(hardSkillList);
const table = renderTable([title, hardSkillItems], styles.table);

return table;
};

This file was deleted.

0 comments on commit 8977282

Please sign in to comment.