refactor: Generalize playbook find method and restructure site module
- Replace `actions_find` with a more generic `find(filter:)` - Rename `siteconfig` module and related types to `site` - Introduce a `Site` object to encapsulate configuration - Update site generation to accept a playbook object directly - Remove redundant blank lines and format code
This commit is contained in:
@@ -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)!
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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')!
|
||||
|
||||
@@ -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', '')!
|
||||
|
||||
@@ -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
|
||||
@@ -19,7 +19,7 @@ pub mut:
|
||||
args DSiteGetArgs
|
||||
errors []SiteError
|
||||
config Configuration
|
||||
siteconfig siteconfig.SiteConfig
|
||||
siteconfig sitemodule.SiteConfig
|
||||
factory &DocusaurusFactory @[skip; str: skip] // Reference to the parent
|
||||
}
|
||||
|
||||
|
||||
@@ -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_
|
||||
@@ -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,7 +71,6 @@ pub fn (mut f DocusaurusFactory) add(args_ DSiteGetArgs) !&DocSite {
|
||||
// reset: args.update
|
||||
// )!
|
||||
|
||||
|
||||
mut ds := DocSite{
|
||||
name: args.name
|
||||
path_src: pathlib.get_dir(path: args.path, create: false)!
|
||||
|
||||
@@ -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{}
|
||||
|
||||
@@ -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()!
|
||||
}
|
||||
|
||||
@@ -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)!
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user