Skip to content

Commit

Permalink
added dynamicParams for domkit
Browse files Browse the repository at this point in the history
  • Loading branch information
ncannasse committed Jan 6, 2025
1 parent a2c2fe3 commit 5248853
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions hrt/impl/DomkitViewer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,27 @@ import haxe.macro.Context;

class DomkitViewer {

static function codeCodains( code : haxe.macro.Expr, dynParams : Map<String,Bool> ) {
return switch( code.expr ) {
case EConst(CIdent(v)) if( dynParams.exists(v) ): true;
default: false;
}
}

static function removeDynParamsRec( m : domkit.MarkupParser.Markup, dynParams : Map<String,Bool> ) {
if( m.attributes != null ) {
for( a in m.attributes )
switch( a.value ) {
case Code(code) if( codeCodains(code,dynParams) ):
m.attributes.remove(a);
default:
}
}
if( m.children != null )
for( c in m.children )
removeDynParamsRec(c, dynParams);
}

public static function loadSource( path : String, pos : Position, fields : Array<Field> ) {
var fullPath = try Context.resolvePath(path+".domkit") catch( e : Dynamic ) return null;
if( fullPath == null )
Expand All @@ -25,6 +46,30 @@ class DomkitViewer {
case Node(n) if( n.indexOf(":") >= 0 ): m.children[0].kind = Node(n.split(":")[0]);
default:
}
var params = new hscript.Parser().parseString(data.params);
var dynParams = new Map();
var hasDynParam = false;
switch( params.e ) {
case EObject(fields):
for( f in fields )
if( f.name == "dynamicParams" ) {
switch( f.e.e ) {
case EArrayDecl(values):
for( v in values )
switch( v.e ) {
case EConst(CString(v)):
dynParams.set(v, true);
hasDynParam = true;
default:
}
default:
}
}
default:
}
if( hasDynParam )
removeDynParamsRec(m, dynParams);

fields.push({
name : "__CSS",
access : [AStatic],
Expand Down

0 comments on commit 5248853

Please sign in to comment.