From 5e468359a16b955c1f4a001dab79e78652c86799 Mon Sep 17 00:00:00 2001 From: timurgordon Date: Tue, 18 Feb 2025 05:09:56 +0300 Subject: [PATCH] start implementing docusaurus bizmodel exporting --- lib/biz/bizmodel/export.v | 59 +++++++++++++++++++++++++++++ lib/biz/bizmodel/templates/intro.md | 33 +++++++--------- lib/core/pathlib/factory.v | 10 +++++ lib/core/texttools/casing.v | 38 +++++++++++++++++++ lib/web/docusaurus/factory.v | 2 +- 5 files changed, 122 insertions(+), 20 deletions(-) create mode 100644 lib/biz/bizmodel/export.v create mode 100644 lib/core/texttools/casing.v diff --git a/lib/biz/bizmodel/export.v b/lib/biz/bizmodel/export.v new file mode 100644 index 00000000..1e65bd6b --- /dev/null +++ b/lib/biz/bizmodel/export.v @@ -0,0 +1,59 @@ +module bizmodel + +import freeflowuniverse.herolib.web.docusaurus + +pub struct Export { +pub: + build_path string + format ExportFormat +} + +pub enum ExportFormat { + mdbook + docusaurus +} + +pub fn (b BizModel) export(export Export) ! { + match export.format { + .docusaurus {b.export_docusaurus(export)} + .mdbook {panic('MDBook export not fully implemented')} + } +} + +pub fn (b BizModel) export_docusaurus(export Export) ! { + factory := docusaurus.new( + build_path: export.build_path + ) + + // b.export_summary() + // b.export_business_description() + // b.export_market_analysis() + // b.export_business_model() + b.export_revenue_model(export) + b.export_cost_structure(export) + b.export_operational_plan(export)! + b.export_fundraising(export) +} + +pub fn (b BizModel) export_operational_plan(export Export) ! { + mut hr_page := pathlib.get_file(path: '${export.build_path}/human_resources.md') + hr_page.template_write() + + for employee in b.employees { + mut employee_page := pathlib.get_file(path: '${export.build_path}/${texttools.snake_case(employee.name)}.md')! + employee_page.template_write(employee.md)! + } +} + +pub fn (b BizModel) export_revenue_model(export Export) ! { + mut overview_page := pathlib.get_file(path: '${export.build_path}/revenue_overview.md') + overview_page.template_write() + + mut overview_page := pathlib.get_file(path: '${export.build_path}/revenue_overview.md') + overview_page.template_write() + + for employee in b.employees { + mut employee_page := pathlib.get_file(path: '${export.build_path}/${texttools.snake_case(employee.name)}.md')! + employee_page.template_write(employee.md)! + } +} \ No newline at end of file diff --git a/lib/biz/bizmodel/templates/intro.md b/lib/biz/bizmodel/templates/intro.md index db32a3be..27759c99 100644 --- a/lib/biz/bizmodel/templates/intro.md +++ b/lib/biz/bizmodel/templates/intro.md @@ -2,53 +2,48 @@ ## FUNDING -!!bizmodel.sheet_wiki includefilter:'funding' +@{bizmodel.sheet.wiki(includefilter:'funding')!} ## REVENUE vs COGS -!!bizmodel.sheet_wiki includefilter:rev +@{bizmodel.sheet.wiki(includefilter:'rev')!} #### Revenue Lines -!!bizmodel.sheet_wiki title:'Revenue Total' includefilter:'revtotal' +@{bizmodel.sheet.wiki(title:'Revenue Total', includefilter:'revtotal')!} #### COGS Lines -!!bizmodel.sheet_wiki title:'COGS' includefilter:'cogstotal' +@{bizmodel.sheet.wiki(title:'COGS', includefilter:'cogstotal')!} ## HR -!!bizmodel.sheet_wiki title:'HR Teams' includefilter:'hrnr' -!!bizmodel.sheet_wiki title:'HR Costs' includefilter:'hrcost' +@{bizmodel.sheet.wiki(title:'HR Teams', includefilter:'hrnr')!} + +@{bizmodel.sheet.wiki(title:'HR Costs', includefilter:'hrcost')!} ## Operational Costs -!!bizmodel.sheet_wiki title:'COSTS' includefilter:'ocost' - +@{bizmodel.sheet.wiki(title:'COSTS', includefilter:'ocost')!} ## P&L Overview -!!bizmodel.sheet_wiki title:'P&L Overview' includefilter:'pl' +@{bizmodel.sheet.wiki(title:'P&L Overview', includefilter:'pl')!} - -!!bizmodel.graph_bar_row rowname:revenue_total unit:million title:'A Title' title_sub:'Sub' +@{bizmodel.graph_bar_row(rowname:'revenue_total', unit:'million', title:'A Title', title_sub:'Sub')!} Unit is in Million USD. -!!bizmodel.graph_bar_row rowname:revenue_total unit:million +@{bizmodel.graph_bar_row(rowname:'revenue_total', unit:'million')!} -!!bizmodel.graph_line_row rowname:revenue_total unit:million - -!!bizmodel.graph_pie_row rowname:revenue_total unit:million size:'80%' +@{bizmodel.graph_line_row(rowname:'revenue_total', unit:'million')!} +@{bizmodel.graph_pie_row(rowname:'revenue_total', unit:'million', size:'80%')!} ## Some Details > show how we can do per month -!!bizmodel.sheet_wiki includefilter:'pl' period_months:1 - - - +@{bizmodel.sheet_wiki(includefilter:'pl', period_months:1)!} \ No newline at end of file diff --git a/lib/core/pathlib/factory.v b/lib/core/pathlib/factory.v index 48e0093d..d8448ced 100644 --- a/lib/core/pathlib/factory.v +++ b/lib/core/pathlib/factory.v @@ -34,6 +34,7 @@ pub mut: check bool = true // means will check the dir, link or file exists empty bool // will empty the dir or the file delete bool + increment bool // will increment filename until free name available (filename1...) } // get a directory, or needs to be created @@ -81,6 +82,15 @@ pub fn get_file(args_ GetArgs) !Path { mut p2 := get_no_check(args.path) if args.check { p2.check() + + if args.increment { + if p2.exists() { + incr := if args.path[args.path.len-1].is_digit() { + args.path[args.path.len-1].ascii_str().int() + } else {0} + return get_file(GetArgs {...args, path: '${args.path}${incr}'}) + } + } if args.create { mut parent_ := p2.parent()! parent_.check() diff --git a/lib/core/texttools/casing.v b/lib/core/texttools/casing.v new file mode 100644 index 00000000..123116f8 --- /dev/null +++ b/lib/core/texttools/casing.v @@ -0,0 +1,38 @@ +module texttools + +pub fn snake_case(s string) string { + return separate_words(s).join('_') +} + +pub fn title_case(s string) string { + return separate_words(s).join(' ').title() +} + +pub fn pascal_case(s string) string { + mut pascal := s.replace('_', ' ') + return pascal.title().replace(' ', '') +} + +pub fn camel_case(s string) string { + return pascal_case(s).uncapitalize() +} + +const separators = ['.', '_', '-', '/', ' ', ':', ',', ';'] + +fn separate_words(s string) []string { + mut words := []string{} + mut word := '' + for i, c in s { + if (c.is_capital() || c.ascii_str() in separators) && word != '' { + words << word.to_lower() + word = '' + } + if c.ascii_str() !in separators { + word += c.ascii_str().to_lower() + } + } + if word != '' { + words << word.to_lower() + } + return words +} \ No newline at end of file diff --git a/lib/web/docusaurus/factory.v b/lib/web/docusaurus/factory.v index fe119cf2..61691721 100644 --- a/lib/web/docusaurus/factory.v +++ b/lib/web/docusaurus/factory.v @@ -42,4 +42,4 @@ pub fn new(args_ DocusaurusArgs) !&DocusaurusFactory { ds.template_install(args.update)! return ds -} +} \ No newline at end of file