diff --git a/models/EmptySingleFileComponent.bx b/models/EmptySingleFileComponent.bx index ac22dc0..676d96a 100644 --- a/models/EmptySingleFileComponent.bx +++ b/models/EmptySingleFileComponent.bx @@ -1,4 +1,4 @@ -class extends="cbwire.models.Component" { +class extends="{{ EXTENDS_PATH }}" { {{ CFC_CONTENTS }} diff --git a/models/EmptySingleFileComponent.cfc b/models/EmptySingleFileComponent.cfc index 4f95e6d..a6877a6 100644 --- a/models/EmptySingleFileComponent.cfc +++ b/models/EmptySingleFileComponent.cfc @@ -1,4 +1,4 @@ -component extends="cbwire.models.Component" { +component extends="{{ EXTENDS_PATH }}" { {{ CFC_CONTENTS }} diff --git a/models/SingleFileComponentBuilder.cfc b/models/SingleFileComponentBuilder.cfc index b4c1e98..799ada3 100644 --- a/models/SingleFileComponentBuilder.cfc +++ b/models/SingleFileComponentBuilder.cfc @@ -46,6 +46,7 @@ component accessors="true" singleton { local.fileContents = fileRead( arguments.cfmPath ); local.singleFileContents = ""; local.remainingContents = ""; + local.extendsPath = "cbwire.models.Component"; local.startedWire = false; local.endedWire = false; @@ -64,6 +65,19 @@ component accessors="true" singleton { local.insideScriptTag = false; } + // Parse @extends annotation + if ( local.insideScriptTag && local.line contains "@extends" ) { + local.extendsMatch = reFindNoCase( "@extends\s*\(\s*['""]?([^'""\)\s]+)['""]?\s*\)", local.line, 1, true ); + if ( arrayLen( local.extendsMatch.match ) >= 2 && len( local.extendsMatch.match[ 2 ] ) ) { + local.capturedPath = local.extendsMatch.match[ 2 ]; + // Validate that the path contains only valid characters (alphanumeric, dots, underscores) + if ( reFindNoCase( "^[a-zA-Z0-9_\.]+$", local.capturedPath ) ) { + local.extendsPath = local.capturedPath; + } + } + continue; + } + if ( local.insideScriptTag && local.line contains "@startWire" ) { local.startedWire = true; continue; @@ -82,7 +96,8 @@ component accessors="true" singleton { return { "singleFileContents" : local.singleFileContents, - "remainingContents" : local.remainingContents + "remainingContents" : local.remainingContents, + "extendsPath" : local.extendsPath }; } @@ -151,6 +166,13 @@ component accessors="true" singleton { "one" ); + local.emptySingleFileComponent = replaceNoCase( + local.emptySingleFileComponent, + "{{ EXTENDS_PATH }}", + local.parsedContents.extendsPath, + "one" + ); + local.uuid = createUUID(); fileWrite( local.tmpClassPath, local.emptySingleFileComponent ); diff --git a/test-harness/tests/specs/CBWIRESpec.cfc b/test-harness/tests/specs/CBWIRESpec.cfc index b21a291..2cd6ddd 100644 --- a/test-harness/tests/specs/CBWIRESpec.cfc +++ b/test-harness/tests/specs/CBWIRESpec.cfc @@ -303,6 +303,16 @@ component extends="coldbox.system.testing.BaseTestCase" { expect( result ).toInclude( "

Result: Hello World!

" ); } ); + it( "should extend custom basewire from single file component", function() { + var result = CBWIREController.wire( "test.should_extend_custom_basewire_from_single_file_component" ); + expect( result ).toInclude( "

Result: Hello World!

" ); + } ); + + it( title="should extend custom basewire from single file boxlang component", body=function() { + var result = CBWIREController.wire( "test.should_extend_custom_basewire_from_single_file_boxlang_component" ); + expect( result ).toInclude( "

Result: Hello World!

" ); + }, skip=!isBoxLang() ); + it( "should be able to access event from template", function() { var result = CBWIREController.wire( "test.should_be_able_to_access_event_from_template" ); expect( result ).toInclude( "

Event is object: true

" ); diff --git a/test-harness/wires/test/should_extend_custom_basewire_from_single_file_boxlang_component.bxm b/test-harness/wires/test/should_extend_custom_basewire_from_single_file_boxlang_component.bxm new file mode 100644 index 0000000..7ec9cdf --- /dev/null +++ b/test-harness/wires/test/should_extend_custom_basewire_from_single_file_boxlang_component.bxm @@ -0,0 +1,12 @@ + +
+

Result: #sayHello()#

+
+
+ + +// @extends('wires.test.BaseWire') +// @startWire + +// @endWire + diff --git a/test-harness/wires/test/should_extend_custom_basewire_from_single_file_component.cfm b/test-harness/wires/test/should_extend_custom_basewire_from_single_file_component.cfm new file mode 100644 index 0000000..3beff4c --- /dev/null +++ b/test-harness/wires/test/should_extend_custom_basewire_from_single_file_component.cfm @@ -0,0 +1,12 @@ + +
+

Result: #sayHello()#

+
+
+ + +// @extends('wires.test.BaseWire') +// @startWire + +// @endWire +