Browse Source

enforce component name based on source file

Nicolas Cannasse 7 months ago
parent
commit
ad25ea873c
2 changed files with 10 additions and 3 deletions
  1. 1 1
      hide/view/Domkit.hx
  2. 9 2
      hrt/impl/DomkitViewer.hx

+ 1 - 1
hide/view/Domkit.hx

@@ -167,7 +167,7 @@ class Domkit extends FileView {
 	}
 	}
 
 
 	override function getDefaultContent() {
 	override function getDefaultContent() {
-		var tag = getPath().split("/").pop().split(".").shift();
+		var tag = getPath().split("/").pop().split(".").shift().split("_").join("-");
 		return haxe.io.Bytes.ofString('<css>\n$tag {\n}\n</css>\n<$tag>\n</$tag>');
 		return haxe.io.Bytes.ofString('<css>\n$tag {\n}\n</css>\n<$tag>\n</$tag>');
 	}
 	}
 
 

+ 9 - 2
hrt/impl/DomkitViewer.hx

@@ -42,7 +42,7 @@ class DomkitViewer {
 	}
 	}
 
 
 	public static function loadSource( path : String, pos : Position, fields : Array<Field> ) {
 	public static function loadSource( path : String, pos : Position, fields : Array<Field> ) {
-		var name = path.split("/").pop();
+		var name = path.split("/").pop().split("_").join("-");
 		var dotPos = name.lastIndexOf(".");
 		var dotPos = name.lastIndexOf(".");
 		if( dotPos >= 0 ) {
 		if( dotPos >= 0 ) {
 			path = path.substr(0, path.length - name.length + dotPos);
 			path = path.substr(0, path.length - name.length + dotPos);
@@ -66,14 +66,21 @@ class DomkitViewer {
 				}
 				}
 				if( c.arguments != null ) c.arguments = null;
 				if( c.arguments != null ) c.arguments = null;
 			}
 			}
+			var found = null;
 			for( c in m.children ) {
 			for( c in m.children ) {
 				switch( c.kind ) {
 				switch( c.kind ) {
 				case Node(n) if( n == name ):
 				case Node(n) if( n == name ):
-					m.children = [c];
+					found = c;
 					break;
 					break;
 				default:
 				default:
 				}
 				}
 			}
 			}
+			if( found == null ) {
+				Context.error("Could not find definition for component '"+name+"'", Context.currentPos());
+				return null;
+			}
+			m.children = [found];
+
 			var params = new hscript.Parser().parseString(data.params, path);
 			var params = new hscript.Parser().parseString(data.params, path);
 			var dynParams = new Map();
 			var dynParams = new Map();
 			var hasDynParam = false;
 			var hasDynParam = false;