Skip to content

Commit

Permalink
ready to use now?
Browse files Browse the repository at this point in the history
  • Loading branch information
cd rubin committed Jan 17, 2025
1 parent 6e44395 commit c4563b3
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 38 deletions.
1 change: 1 addition & 0 deletions examples/in/_include/another.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_this is the contents of another.md_
4 changes: 4 additions & 0 deletions examples/in/_include/inc_another.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
and include another from an include
| pash.include( '_include/another.md' )
and as a string:
-- ${ pash.include( '_include/another.md' ) } --
2 changes: 2 additions & 0 deletions examples/in/_include/three_four.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
three
four
3 changes: 3 additions & 0 deletions examples/in/_layout/plain.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
${ pash.include( '_include/header.html' ) }
${ pash.content }
${ pash.include( '_include/footer.html' ) }
4 changes: 4 additions & 0 deletions examples/in/inc3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
| context.layout = null
goo
| pash.include( '_include/inc_another.md' )
zoo
4 changes: 4 additions & 0 deletions examples/in/inc4.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
| context.layout = null
goo
${ pash.include( '_include/inc_another.md' ) }
zoo
6 changes: 6 additions & 0 deletions examples/in/inc5.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
| context.layout = '_layout/plain.html'
one
two
BEGIN ${ pash.include( '_include/three_four.html' ) } END
five
six
60 changes: 22 additions & 38 deletions pash.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ globalThis.context = {
}



pash.intermediateTemplet = function( string ) {

let script = ''
Expand All @@ -35,7 +34,7 @@ pash.intermediateTemplet = function( string ) {

}
catch( ex ) {
std.err.puts( `${ex}\n` ); if ( ex.stack ) std.err.puts( ex.stack )
std.err.puts( `× ${ex}\n` ); if ( ex.stack ) std.err.puts( ex.stack )
}

return script
Expand All @@ -59,45 +58,18 @@ pash.templet = function ( filename ) {

script = pash.intermediateTemplet( string )

//std.err.puts( script )

}
catch( ex ) {
std.err.puts( `${ex}\n` ); if ( ex.stack ) std.err.puts( ex.stack )
std.err.puts( `× ${ex}\n` ); if ( ex.stack ) std.err.puts( ex.stack )
}

return script

}


/*
const include = function ( filename ) {
try {
let script = templet( pash.inpath + '/' + filename )
let previous_output = pash.output
let included = ''
pash.output = function( value ) { included += value + '\n' }
std.evalScript( script, { backtrace_barrier: false } )
pash.output = previous_output
if ( included.endsWith( '\n' ) )
included = included.slice( 0, -1 )
return included
}
catch( ex ) {
std.err.puts( `${ ex } (${ filename })\n` ); std.err.puts( ex.stack )
}
}
pash.include = include
*/


pash.evalTemplet = function ( filename ) {

try {
Expand All @@ -108,14 +80,26 @@ pash.evalTemplet = function ( filename ) {

}
catch( ex ) {
std.err.puts( `${ ex } (${ filename })\n` ); std.err.puts( ex.stack )
std.err.puts( `× ${ ex } (${ filename })\n` ); std.err.puts( ex.stack )
}
}


pash.include = function( filename ) {

let included_content = ''

let previous_output_function = pash.output

// override output function temporarily
pash.output = function( value ) { included_content += value + '\n' }
pash.evalTemplet( pash.inpath + '/' + filename )
return ''

pash.output = previous_output_function

if ( included_content.endsWith( '\n' ) ) included_content = included_content.slice( 0, -1 )

return included_content
}


Expand Down Expand Up @@ -208,7 +192,7 @@ const reference_style_images_to_files = function( inpath, outpath, content ) {

}
catch( ex ) {
std.err.puts( `${ ex } (${ inpath })\n` ); std.err.puts( ex.stack )
std.err.puts( `× ${ ex } (${ inpath })\n` ); std.err.puts( ex.stack )
}
}

Expand Down Expand Up @@ -247,13 +231,13 @@ const file_callback = function( inpath, outpath ) {

}
catch( ex ) {
std.err.puts( `${ ex } (${ inpath })\n` ); std.err.puts( ex.stack )
std.err.puts( `× ${ ex } (${ inpath })\n` ); std.err.puts( ex.stack )
}
}



const recurseTree = function ( inpath, outpath, file_callback, dir_callback, level = 0 ) {
const recurseTree = function ( inpath, outpath, file_callback, dir_callback, level = 1 ) {
let result = []

let directoryname = inpath.split( '/' ).at( -1 )
Expand Down Expand Up @@ -337,5 +321,5 @@ Usage:

}
catch( ex ) {
print( `${ex}\n` ); if ( ex.stack ) std.err.puts( ex.stack )
print( `× ${ex}\n` ); if ( ex.stack ) std.err.puts( ex.stack )
}

0 comments on commit c4563b3

Please sign in to comment.