# -*- tcl -*- # Maintenance Instruction: leave the 999999.xxx.x as is and use 'pmix make' or src/make.tcl to update from -buildversion.txt # # Please consider using a BSD or MIT style license for greatest compatibility with the Tcl ecosystem. # Code using preferred Tcl licenses can be eligible for inclusion in Tcllib, Tklib and the punk package repository. # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ # (C) 2023 # # @@ Meta Begin # Application punk::mix::commandset::layout 999999.0a1.0 # Meta platform tcl # Meta license # @@ Meta End # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ ## Requirements ##e.g package require frobz #sort of a circular dependency when commandset loaded by punk::mix::cli - that's ok, but this could theoretically be loaded by another cli and with another base package require punk::mix package require punk::mix::base # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ namespace eval punk::mix::commandset::layout { namespace export * #per layout functions proc files {layout} { set allfiles [lib::layout_all_files $layout] return [join $allfiles \n] } proc templatefiles {layout} { set templatefiles [lib::layout_scan_for_template_files $layout] return [join $templatefiles \n] } proc templatefiles.relative {layout} { set template_base_dict [punk::mix::base::lib::get_template_basefolders] set bases_containing_layout [list] dict for {tbase folderinfo} $template_base_dict { if {[file exists $tbase/layouts/$layout]} { lappend bases_containing_layout $tbase } } if {![llength $bases_containing_layout]} { puts stderr "Unable to locate folder for layout '$layout'" puts stderr "searched [dict size $template_base_dict] template folders" return } set tpldir [lindex $bases_containing_layout end] set layout_base $tpldir/layouts set layout_dir [file join $layout_base $layout] set stripprefix [file normalize $layout_dir] set templatefiles [lib::layout_scan_for_template_files $layout] set tails [list] foreach templatefullpath $templatefiles { lappend tails [punk::repo::path_strip_alreadynormalized_prefixdepth $templatefullpath $stripprefix] } return [join $tails \n] } #layout collection functions - to be imported with punk::overlay::import_commandset separately namespace eval collection { namespace export * proc _default {{glob {}}} { if {![string length $glob]} { set glob * } set layouts [list] #set tplfolderdict [punk::cap::templates::folders] set tplfolderdict [punk::mix::base::lib::get_template_basefolders] dict for {tdir folderinfo} $tplfolderdict { set layout_base $tdir/layouts #collect all layouts and use lsearch glob rather than the filesystem glob (avoid issues with dotted folder names) set all_layouts [lsort [glob -nocomplain -dir $layout_base -type d -tail *]] foreach match [lsearch -all -inline $all_layouts $glob] { lappend layouts [list $match $folderinfo] } } return [join [lsort -index 0 $layouts] \n] } } namespace eval lib { proc layout_all_files {layout} { set tplbasedict [punk::mix::base::lib::get_template_basefolders] set layouts_found [list] dict for {tplbase folderinfo} $tplbasedict { if {[file isdirectory $tplbase/layouts/$layout]} { lappend layouts_found $tplbase/layouts/$layout } } if {![llength $layouts_found]} { puts stderr "layout '$layout' not found." puts stderr "searched [dict size $tplbasedict] template folders" dict for {tplbase pkg} $tplbasedict { puts stderr " - $tplbase $pkg" } return } set layoutfolder [lindex $layouts_found end] if {![file isdirectory $layoutfolder]} { puts stderr "layout '$layout' not found in /layouts within one of template_folders. (get_template_folder returned: $tplbasedict)" } set file_list [list] util::foreach-file $layoutfolder path { lappend file_list $path } return $file_list } # #todo - allow specifying which package the layout is from: e.g "punk::mix::templates project" ?? proc layout_scan_for_template_files {layout {tags {}}} { #equivalent for projects? punk::mix::commandset::module::lib::templates_dict -scriptpath "" set tplbasedict [punk::mix::base::lib::get_template_basefolders] set layouts_found [list] dict for {tpldir pkg} $tplbasedict { if {[file isdirectory $tpldir/layouts/$layout]} { lappend layouts_found $tpldir/layouts/$layout } } if {![llength $layouts_found]} { puts stderr "layout '$layout' not found." puts stderr "searched [dict size $tplbasedict] template folders" dict for {tpldir pkg} $tplbasedict { puts stderr " - $tpldir $pkg" } return } set layoutfolder [lindex $layouts_found end] #use last matching layout found. review silent if multiple? if {![llength $tags]} { #todo - get standard tags from somewhere set tags [list %project%] } set file_list [list] util::foreach-file $layoutfolder path { set fd [open $path r] fconfigure $fd -translation binary set data [read $fd] close $fd foreach tag $tags { if {[string match "*$tag*" $data]} { lappend file_list $path } } } return $file_list } } } # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ ## Ready package provide punk::mix::commandset::layout [namespace eval punk::mix::commandset::layout { variable version set version 999999.0a1.0 }] return