Skip to content

Commit

Permalink
added namespace dir support with @package_name/somefile.thtml resolvi…
Browse files Browse the repository at this point in the history
…ng to [set ::package_name::__thtml__]/somefile.thtml
  • Loading branch information
jerily committed Aug 1, 2024
1 parent a5949e0 commit c14e957
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tcl/util.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,31 @@ proc ::thtml::util::doublequote_and_escape_newlines {str {lengthVar ""}} {
return [doublequote [string map {"\n" {\n} "\r" {\r} "\\" {\\}} ${str}]]
}

proc ::thtml::util::get_namespace_dir {nsp} {
if { ![info exists ::${nsp}::__thtml__] } {
error "Variable ::${nsp}::__thtml__ not found"
}
return [set ::${nsp}::__thtml__]
}

proc ::thtml::util::resolve_filepath {filepath} {

if { $filepath eq {} } {
error "Empty filepath"
}

set first_char [string index $filepath 0]
if { $first_char eq {@}} {
set index [string first / $filepath]
if { $index eq -1 } {
error "Invalid filepath: $filepath"
}
set nsp [string range $filepath 1 [expr { $index - 1}]]
set dir [get_namespace_dir $nsp]
set filepath [string range $filepath [expr { 1 + $index }] end]
return [file normalize [file join $dir $filepath]]
}

set rootdir [::thtml::get_rootdir]
return [file normalize [file join $rootdir www $filepath]]
}
Expand Down

0 comments on commit c14e957

Please sign in to comment.