Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion models/EmptySingleFileComponent.bx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class extends="cbwire.models.Component" {
class extends="{{ EXTENDS_PATH }}" {

{{ CFC_CONTENTS }}

Expand Down
2 changes: 1 addition & 1 deletion models/EmptySingleFileComponent.cfc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
component extends="cbwire.models.Component" {
component extends="{{ EXTENDS_PATH }}" {

{{ CFC_CONTENTS }}

Expand Down
24 changes: 23 additions & 1 deletion models/SingleFileComponentBuilder.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -82,7 +96,8 @@ component accessors="true" singleton {

return {
"singleFileContents" : local.singleFileContents,
"remainingContents" : local.remainingContents
"remainingContents" : local.remainingContents,
"extendsPath" : local.extendsPath
};
}

Expand Down Expand Up @@ -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 );
Expand Down
10 changes: 10 additions & 0 deletions test-harness/tests/specs/CBWIRESpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,16 @@ component extends="coldbox.system.testing.BaseTestCase" {
expect( result ).toInclude( "<p>Result: Hello World!</p>" );
} );

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( "<p>Result: Hello World!</p>" );
} );

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( "<p>Result: Hello World!</p>" );
}, 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( "<p>Event is object: true</p>" );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<bx:output>
<div>
<p>Result: #sayHello()#</p>
</div>
</bx:output>

<bx:script>
// @extends('wires.test.BaseWire')
// @startWire

// @endWire
</bx:script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<cfoutput>
<div>
<p>Result: #sayHello()#</p>
</div>
</cfoutput>

<cfscript>
// @extends('wires.test.BaseWire')
// @startWire

// @endWire
</cfscript>