diff --git a/lib/biz/bizmodel/play.v b/lib/biz/bizmodel/play.v index 1067a3b4..949fb370 100644 --- a/lib/biz/bizmodel/play.v +++ b/lib/biz/bizmodel/play.v @@ -7,15 +7,13 @@ import freeflowuniverse.herolib.ui.console const action_priorities = { 0: ['department_define', 'costcenter_define'] 1: ['revenue_define', 'funding_define'] - 2: ['cost_define','employee_define'] + 2: ['cost_define', 'employee_define'] 3: ['sheet_wiki', 'graph_bar_row', 'graph_pie_row', 'graph_line_row', 'row_overview'] } - pub fn play(mut plbook PlayBook) ! { - // group actions by which bizmodel they belong to - actions_by_biz := arrays.group_by[string, &Action](plbook.actions_find(actor: 'bizmodel')!, + actions_by_biz := arrays.group_by[string, &Action](plbook.find(filter: 'bizmodel.*')!, fn (a &Action) string { return a.params.get('bizname') or { 'default' } }) @@ -25,11 +23,10 @@ pub fn play(mut plbook PlayBook) ! { mut model := getset(biz)! model.play(mut plbook)! } - } pub fn (mut m BizModel) play(mut plbook PlayBook) ! { - mut actions := plbook.actions_find(actor: 'bizmodel')! + mut actions := plbook.find(filter: 'bizmodel.*')! for action in actions.filter(it.name in action_priorities[0]) { m.act(*action)! @@ -51,9 +48,7 @@ pub fn (mut m BizModel) play(mut plbook PlayBook) ! { // m.sheet.pprint(nr_columns: 10)! - for action in actions.filter(it.name in action_priorities[3]) { m.act(*action)! } - } diff --git a/lib/core/generator/generic/model.v b/lib/core/generator/generic/model.v index 808fa056..23a75122 100644 --- a/lib/core/generator/generic/model.v +++ b/lib/core/generator/generic/model.v @@ -39,9 +39,11 @@ fn args_get(path string) !GeneratorArgs { return error("can't find path with .heroscript in ${path}, is a bug") } - mut plbook := playbook.new(text: config_path.read()!) or { return error('failed to create playbook: ${err}') } + mut plbook := playbook.new(text: config_path.read()!) or { + return error('failed to create playbook: ${err}') + } - mut install_actions := plbook.actions_find(actor:'hero_code', name: 'generate_installer')! + mut install_actions := plbook.find(filter: 'hero_code.generate_installer')! if install_actions.len > 0 { for install_action in install_actions { mut p := install_action.params @@ -65,7 +67,7 @@ fn args_get(path string) !GeneratorArgs { } } - mut client_actions := plbook.actions_find(actor:'hero_code', name: 'generate_client')! + mut client_actions := plbook.find(filter: 'hero_code.generate_client')! if client_actions.len > 0 { for client_action in client_actions { mut p := client_action.params diff --git a/lib/threefold/grid4/cloudslices/play.v b/lib/threefold/grid4/cloudslices/play.v index bc190b0a..ecdc4742 100644 --- a/lib/threefold/grid4/cloudslices/play.v +++ b/lib/threefold/grid4/cloudslices/play.v @@ -4,7 +4,7 @@ import freeflowuniverse.herolib.core.playbook { PlayBook } // this play script should never be called from hero directly its called by gridsimulator pub fn play(mut plbook PlayBook) !map[string]&Node { - mut actions2 := plbook.actions_find(actor: 'tfgrid_simulator')! + mut actions2 := plbook.find(filter: 'tfgrid_simulator.*')! mut nodesdict := map[string]&Node{} for action in actions2 { diff --git a/lib/threefold/grid4/farmingsimulator/play.v b/lib/threefold/grid4/farmingsimulator/play.v index e8190094..28952963 100644 --- a/lib/threefold/grid4/farmingsimulator/play.v +++ b/lib/threefold/grid4/farmingsimulator/play.v @@ -8,7 +8,7 @@ pub fn play(mut plbook PlayBook) ! { // mut sheet_name := '' // first make sure we find a run action to know the name - mut my_actions := plbook.actions_find(actor: 'tfgridsimulation_farming')! + mut my_actions := plbook.find(filter: 'tfgridsimulation_farming.*')! if my_actions.len == 0 { return @@ -37,7 +37,7 @@ pub fn play(mut plbook PlayBook) ! { } pub fn (mut s Simulator) play(mut plbook PlayBook) ! { - mut actions2 := plbook.actions_find(actor: 'tfgridsimulation_farming')! + mut actions2 := plbook.find(filter: 'tfgridsimulation_farming.*')! if actions2.len == 0 { // means nothing to do return quickly @@ -93,7 +93,7 @@ pub fn (mut s Simulator) play(mut plbook PlayBook) ! { } // NOW ADD THE REGIONAL INTERNETS - mut actions3 := plbook.actions_find(actor: 'tfgridsimulation_farming')! + mut actions3 := plbook.find(filter: 'tfgridsimulation_farming.*')! for action_ri in actions3 { if action_ri.name == 'regional_internet_add' { mut iname := action_ri.params.get('name')! @@ -110,7 +110,7 @@ pub fn (mut s Simulator) play(mut plbook PlayBook) ! { } // now do the simulation, run it - mut actions4 := plbook.actions_find(actor: 'tfgridsimulation_farming')! + mut actions4 := plbook.find(filter: 'tfgridsimulation_farming.*')! for action_ri in actions4 { if action_ri.name == 'regional_internet_add' { mut iname := action_ri.params.get('name')! diff --git a/lib/threefold/grid4/gridsimulator/play.v b/lib/threefold/grid4/gridsimulator/play.v index 642d22f5..197e3a5d 100644 --- a/lib/threefold/grid4/gridsimulator/play.v +++ b/lib/threefold/grid4/gridsimulator/play.v @@ -5,7 +5,7 @@ import freeflowuniverse.herolib.threefold.grid4.cloudslices pub fn play(mut plbook PlayBook) ! { // first make sure we find a run action to know the name - mut my_actions := plbook.actions_find(actor: 'tfgrid_simulator')! + mut my_actions := plbook.find(filter: 'tfgrid_simulator.*')! if my_actions.len == 0 { return @@ -33,7 +33,7 @@ pub fn play(mut plbook PlayBook) ! { pub fn (mut self Simulator) play(mut plbook PlayBook) ! { // make sure we know the inca price - mut actions4 := plbook.actions_find(actor: 'tfgrid_simulator')! + mut actions4 := plbook.find(filter: 'tfgrid_simulator.*')! if actions4.len == 0 { return @@ -61,7 +61,7 @@ pub fn (mut self Simulator) play(mut plbook PlayBook) ! { return error("can't find incaprice_define action for tfgrid_simulator, needs to define INCA price.") } - mut actions2 := plbook.actions_find(actor: 'tfgrid_simulator')! + mut actions2 := plbook.find(filter: 'tfgrid_simulator.*')! for action in actions2 { if action.name == 'node_growth_define' { mut node_name := action.params.get_default('node_name', '')! diff --git a/lib/web/docusaurus/dsite.v b/lib/web/docusaurus/dsite.v index 334a9373..7bfc3f0b 100644 --- a/lib/web/docusaurus/dsite.v +++ b/lib/web/docusaurus/dsite.v @@ -3,7 +3,7 @@ module docusaurus import freeflowuniverse.herolib.osal.screen import os import freeflowuniverse.herolib.core.pathlib -import freeflowuniverse.herolib.web.siteconfig +import freeflowuniverse.herolib.web.site as sitemodule import freeflowuniverse.herolib.develop.gittools import freeflowuniverse.herolib.osal.core as osal import freeflowuniverse.herolib.ui.console @@ -12,32 +12,32 @@ import time @[heap] pub struct DocSite { pub mut: - name string - url string - path_src pathlib.Path + name string + url string + path_src pathlib.Path path_publish pathlib.Path args DSiteGetArgs errors []SiteError config Configuration - siteconfig siteconfig.SiteConfig + siteconfig sitemodule.SiteConfig factory &DocusaurusFactory @[skip; str: skip] // Reference to the parent } @[params] pub struct DSiteGetArgs { pub mut: - name string - nameshort string - path string - git_url string - git_reset bool - git_root string - git_pull bool - open bool // Added - watch_changes bool // Added - path_publish string // Added - init bool // Added - update bool // Added (maps to template_update in DocusaurusArgs) + name string + nameshort string + path string + git_url string + git_reset bool + git_root string + git_pull bool + open bool // Added + watch_changes bool // Added + path_publish string // Added + init bool // Added + update bool // Added (maps to template_update in DocusaurusArgs) } pub fn (mut s DocSite) build() ! { diff --git a/lib/web/docusaurus/dsite_add.v b/lib/web/docusaurus/dsite_add.v index 31d7013a..b06f93be 100644 --- a/lib/web/docusaurus/dsite_add.v +++ b/lib/web/docusaurus/dsite_add.v @@ -4,12 +4,11 @@ import os import freeflowuniverse.herolib.core.pathlib import freeflowuniverse.herolib.core.texttools import freeflowuniverse.herolib.develop.gittools -import freeflowuniverse.herolib.web.siteconfig +import freeflowuniverse.herolib.web.site import freeflowuniverse.herolib.ui.console import freeflowuniverse.herolib.osal.core as osal // import freeflowuniverse.herolib.data.doctree - pub fn (mut f DocusaurusFactory) add(args_ DSiteGetArgs) !&DocSite { console.print_header(' Docusaurus: ${args_.name}') mut args := args_ @@ -53,7 +52,7 @@ pub fn (mut f DocusaurusFactory) add(args_ DSiteGetArgs) !&DocSite { if args.nameshort.len == 0 { args.nameshort = args.name } - + args.name = texttools.name_fix(args.name) args.nameshort = texttools.name_fix(args.nameshort) @@ -61,8 +60,9 @@ pub fn (mut f DocusaurusFactory) add(args_ DSiteGetArgs) !&DocSite { args.path_publish = '${f.path_publish}/${args.name}' } - //this will get us the siteconfig run through plbook - mut mysiteconfig := *siteconfig.new(configpath)! + // this will get us the siteconfig run through plbook + mut mysite := site.new(name: args.name)! + mut mysiteconfig := mysite.siteconfig // NOT NEEDED IS DONE FROM HEROSCRIPT BEFORE // //now run the plbook to get all relevant for the site, {SITENAME} has been set in the context.session @@ -71,9 +71,8 @@ pub fn (mut f DocusaurusFactory) add(args_ DSiteGetArgs) !&DocSite { // reset: args.update // )! - mut ds := DocSite{ - name: args.name + name: args.name path_src: pathlib.get_dir(path: args.path, create: false)! path_publish: pathlib.get_dir(path: args.path_publish)! args: args diff --git a/lib/web/docusaurus/dsite_configuration.v b/lib/web/docusaurus/dsite_configuration.v index f7ffaf2a..fc49b80c 100644 --- a/lib/web/docusaurus/dsite_configuration.v +++ b/lib/web/docusaurus/dsite_configuration.v @@ -3,7 +3,7 @@ module docusaurus // import os // import json // import freeflowuniverse.herolib.core.pathlib -import freeflowuniverse.herolib.web.siteconfig // For siteconfig.SiteConfig and siteconfig.new +import freeflowuniverse.herolib.web.site // For site.SiteConfig and site.new // import strings // No longer needed as we are not concatenating // import freeflowuniverse.herolib.core.playbook // No longer directly needed here @@ -79,9 +79,9 @@ pub mut: } fn config_load(path string) !Configuration { - // Use siteconfig.new from factory.v. This function handles PlayBook creation, playing, and Redis interaction. - site_cfg_ref := siteconfig.new(path)! - site_cfg_from_heroscript := *site_cfg_ref // Dereference to get the actual SiteConfig struct + // Use site.new from factory.v. This function handles PlayBook creation, playing, and Redis interaction. + site_ref := site.new(name: 'default')! + site_cfg_from_heroscript := site_ref.siteconfig // Get the actual SiteConfig struct // Transform siteconfig.SiteConfig to docusaurus.Configuration mut nav_items := []NavbarItem{} diff --git a/lib/web/docusaurus/dsite_generate.v b/lib/web/docusaurus/dsite_generate.v index d5b1ca8b..b2b63259 100644 --- a/lib/web/docusaurus/dsite_generate.v +++ b/lib/web/docusaurus/dsite_generate.v @@ -2,13 +2,14 @@ module docusaurus import freeflowuniverse.herolib.develop.gittools import freeflowuniverse.herolib.core.pathlib +import freeflowuniverse.herolib.core.playbook import json import os import freeflowuniverse.herolib.osal.core as osal import freeflowuniverse.herolib.ui.console import freeflowuniverse.herolib.core.texttools.regext // import freeflowuniverse.herolib.data.doctree -import freeflowuniverse.herolib.web.site +import freeflowuniverse.herolib.web.site as sitegen pub fn (mut site DocSite) generate() ! { console.print_header(' site generate: ${site.name} on ${site.factory.path_build.path}') @@ -46,9 +47,9 @@ pub fn (mut site DocSite) generate() ! { mut footer_file := pathlib.get_file(path: '${cfg_path}/footer.json', create: true)! footer_file.write(json.encode_pretty(site.config.footer))! - osal.rm("${site.factory.path_build.path}/docs")! + osal.rm('${site.factory.path_build.path}/docs')! - if os.exists("${site.path_src.path}/docs"){ + if os.exists('${site.path_src.path}/docs') { mut aa := site.path_src.dir_get('docs')! aa.copy(dest: '${site.factory.path_build.path}/docs', delete: true)! } @@ -62,12 +63,10 @@ pub fn (mut site DocSite) generate() ! { // draft:1 hide_title:1 configpath := '${site.path_src.path}/cfg' - sitegen.play(mut sitegen.Args{ - heroscript_path: configpath - dest: '${site.factory.path_build.path}/docs' - flat: true - sitename: site.name - })! + + // Create a playbook from the config path and run site processing + mut plbook := playbook.new(path: configpath)! + sitegen.play(mut plbook)! site.process_imports()! } diff --git a/lib/web/site/generator_docusaurus.v b/lib/web/site/generator_docusaurus.v index 2e35fe5f..be2a311a 100644 --- a/lib/web/site/generator_docusaurus.v +++ b/lib/web/site/generator_docusaurus.v @@ -8,10 +8,10 @@ import os pub struct SiteGenerator { pub mut: - siteconfig_name string - path pathlib.Path - client &doctreeclient.DocTreeClient - flat bool // if flat then won't use sitenames as subdir's + siteconfig_name string + path pathlib.Path + client &doctreeclient.DocTreeClient + flat bool // if flat then won't use sitenames as subdir's } @[params] @@ -22,7 +22,7 @@ pub mut: } // new creates a new siteconfig and stores it in redis, or gets an existing one -pub fn (siteconfig SiteConfig)generate(args SiteGeneratorArgs) ! { +pub fn (site Site) generate(args SiteGeneratorArgs) ! { mut path := args.path if path == '' { path = '${os.home_dir()}/hero/var/sitegen' @@ -33,11 +33,11 @@ pub fn (siteconfig SiteConfig)generate(args SiteGeneratorArgs) ! { flat: args.flat } - for section in siteconfig.sections { + for section in site.sections { factory.section_generate(section)! } - for page in siteconfig.pages { + for page in site.pages { factory.page_generate(page)! } }