Skip to content

Commit

Permalink
Merge branch 'master' of github.com:coldbox-modules/cbwire into devel…
Browse files Browse the repository at this point in the history
…opment
  • Loading branch information
grantcopley committed Sep 29, 2024
2 parents 6fb9f4c + d1e2405 commit bc49fe8
Show file tree
Hide file tree
Showing 40 changed files with 87 additions and 51 deletions.
25 changes: 19 additions & 6 deletions models/Component.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ component output="true" {
*/
function onDIComplete() {
if ( isNull( variables._id ) ) {
variables._id = hash( createUUID() );
variables._id = lCase( hash( createUUID() ) );
}

variables._params = [:];
Expand Down Expand Up @@ -140,12 +140,25 @@ component output="true" {
return variables._CBWIREController;
}

/**
* renderIt left for backwards compatibility.
*
* @return string
*/
function renderIt() {
return "";
}

/**
* Renders the component's HTML output.
* This method should be overridden by subclasses to implement specific rendering logic.
* If not overridden, this method will simply render the view.
*/
function renderIt() {
function onRender() {
local.renderIt = renderIt();
if ( local.renderIt.len() ) {
return local.renderIt;
}
return template( _getViewPath() );
}

Expand Down Expand Up @@ -277,7 +290,7 @@ component output="true" {

/**
* Instantiates a CBWIRE component, mounts it,
* and then calls its internal renderIt() method.
* and then calls its internal onRender() method.
*
* This is nearly identical to the wire method defined
* in the CBWIREController component, but it is intended
Expand Down Expand Up @@ -350,12 +363,12 @@ component output="true" {
// Based on the rendering, determine our outer component tag
local.componentTag = _getComponentTag( local.rendering );
// Track the rendered child
variables._children.append( [
variables._children.append( {
"#arguments.key#": [
local.componentTag,
local.instance._getId()
]
] );
} );

return local.instance._render();
}
Expand Down Expand Up @@ -1649,7 +1662,7 @@ component output="true" {
* Response for actually starting rendering of a component.
*/
function _render( rendering ) {
local.trimmedHTML = isNull( arguments.rendering ) ? trim( renderIt() ) : trim( arguments.rendering );
local.trimmedHTML = isNull( arguments.rendering ) ? trim( onRender() ) : trim( arguments.rendering );
// Validate the HTML content to ensure it has a single outer element
_validateSingleOuterElement( local.trimmedHTML);
// If this is the initial load, encode the snapshot and insert Livewire attributes
Expand Down
2 changes: 1 addition & 1 deletion models/EmptySingleFileComponent.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ component extends="cbwire.models.Component" {

{{ CFC_CONTENTS }}

function renderIt() {
function onRender() {
return template( "{{ TEMPLATE_PATH }}" );
}

Expand Down
30 changes: 24 additions & 6 deletions test-harness/tests/specs/CBWIRESpec.cfc
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
component extends="coldbox.system.testing.BaseTestCase" {

function beforeAll() {
super.beforeAll();
// delete any files in models/tmp folder
local.tempFolder = expandPath( "../../../models/tmp" );
if ( directoryExists( local.tempFolder ) ) {
directoryDelete( local.tempFolder, true );
}
directoryCreate( local.tempFolder );
}

// Lifecycle methods and BDD suites as before...
function run(testResults, testBox) {

Expand Down Expand Up @@ -129,18 +139,23 @@ component extends="coldbox.system.testing.BaseTestCase" {
expect( parsing.snapshot.data.stringBooleanValue ).toBeTrue();
});

it( "should render with a renderIt method", function() {
var result = CBWIREController.wire( "test.should_render_with_a_renderIt_method" );
expect( result ).toInclude( "<p>I rendered from renderIT</p>" );
it( "should render with a onRender method", function() {
var result = CBWIREController.wire( "test.should_render_with_a_onRender_method" );
expect( result ).toInclude( "<p>I rendered from onRender</p>" );
} );

it( "should render with renderIt for backwards compatibility", function() {
var result = CBWIREController.wire( "test.should_render_with_renderIt_for_backwards_compatibility" );
expect( result ).toInclude( "I rendered from renderIt" );
} );

it("should implicitly render a view template", function() {
var result = CBWIREController.wire( "test.should_implicitly_render_a_view_template" );
expect( result ).toInclude( "<p>Implicitly rendered</p>" );
} );

it( "should support passing params into a renderIt method", function() {
var result = CBWIREController.wire( "test.should_support_passing_params_into_a_renderIt_method" );
it( "should support passing params into a onRender method", function() {
var result = CBWIREController.wire( "test.should_support_passing_params_into_a_onRender_method" );
expect( result ).toInclude( "<p>Passed in: 5</p>" );
} );

Expand Down Expand Up @@ -178,9 +193,12 @@ component extends="coldbox.system.testing.BaseTestCase" {
expect( result ).toInclude( "<p>Result: Hello World!</p>" );
} );

it( "should support deep nesting with correct count of children", function() {
xit( "should support deep nesting with correct count of children", function() {
var result = CBWIREController.wire( "test.should_support_deep_nesting" );
var parent = parseRendering( result, 1 );
writeDump( result );
writeDump( parent );
abort;
var child1 = parseRendering( result, 2 );
var child2 = parseRendering( result, 3 );
expect( parent.snapshot.memo.children.count() ).toBe( 2 );
Expand Down
2 changes: 1 addition & 1 deletion test-harness/wires/Actions.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ component extends="cbwire.models.Component" {
reset( "conference" );
}

function renderIt(){
function onRender(){
return template( "wires.actions" );
}
}
2 changes: 1 addition & 1 deletion test-harness/wires/BindingNestedData.cfc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
component extends="cbwire.models.Component" {

function renderIt(){
function onRender(){
return this.renderView( "wires/bindingNestedData" );
}

Expand Down
2 changes: 1 addition & 1 deletion test-harness/wires/ComputedProperty.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ component extends="cbwire.models.Component" {
}
}

function renderIt(){
function onRender(){
return this.renderView( "wires/computedProperty" );
}

Expand Down
2 changes: 1 addition & 1 deletion test-harness/wires/CounterComplete.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ component extends="cbwire.models.Component" {
data.counter += amount;
}

function renderIt() {
function onRender() {
return template( "wires.CounterComplete", { isEven: isEven() } );
}
}
2 changes: 1 addition & 1 deletion test-harness/wires/CounterUsingCBWIRE3.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ component extends="cbwire.models.Component" accessors="true" {
* Renders the component's HTML output with Livewire-compatible attributes.
* @return The HTML representation of the component, including Livewire data attributes.
*/
public string function renderIt() {
public string function onRender() {
return template("wires.CounterUsingDataDot");
}

Expand Down
2 changes: 1 addition & 1 deletion test-harness/wires/DataBindingCount.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ component
data.count += 1;
}

function renderIt(){
function onRender(){
return this.renderView( "wires/dataBindingCount" );
}

Expand Down
2 changes: 1 addition & 1 deletion test-harness/wires/EmitTo.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ component extends="cbwire.models.Component" {
this.emitTo( "wires.FireEvent2", "someEvent" );
}

function renderIt(){
function onRender(){
return this.renderView( "wires/emitTo" );
}

Expand Down
2 changes: 1 addition & 1 deletion test-harness/wires/EmitUp.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ component extends="cbwire.models.Component" {
this.emitUp( "emitUpFired" );
}

function renderIt(){
function onRender(){
return this.renderView( "wires/emitUp" );
}

Expand Down
2 changes: 1 addition & 1 deletion test-harness/wires/FireEvent.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ component extends="cbwire.models.Component" {
this.emit( "someOtherEvent", [ "grant", "allen", "copley" ] );
}

function renderIt(){
function onRender(){
return this.renderView( "wires/fireEvent" );
}

Expand Down
2 changes: 1 addition & 1 deletion test-harness/wires/FireEvent2.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ component extends="cbwire.models.Component" {
data.message = "We have fired someListener() from a second listener!";
}

function renderIt(){
function onRender(){
return this.renderView( "wires/fireEvent" );
}

Expand Down
2 changes: 1 addition & 1 deletion test-harness/wires/FireEventFromComponent.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ component extends="cbwire.models.Component" {
data.message = "We have fired someListener() using this.emit in our component!";
}

function renderIt(){
function onRender(){
return this.renderView( "wires/fireEvent" );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ component extends="cbwire.models.Component" {

data = { "message" : "Hello world" };

function renderIt(){
function onRender(){
return this.view( "wires/helloWorldWithRenderViewPropertyAndArgs" );
}

Expand Down
2 changes: 1 addition & 1 deletion test-harness/wires/Loading.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ component extends="cbwire.models.Component" {
sleep( 5000 );
}

function renderIt(){
function onRender(){
return this.renderView( "wires/loading" );
}

Expand Down
2 changes: 1 addition & 1 deletion test-harness/wires/LoadingAndDisablingButton.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ component extends="cbwire.models.Component" {
sleep( 5000 );
}

function renderIt(){
function onRender(){
return this.renderView( "wires/loadingAndDisablingButton" );
}

Expand Down
2 changes: 1 addition & 1 deletion test-harness/wires/LogBox.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ component extends="cbwire.models.Component"{
log.debug( "Loaded mount()" );
}

function renderIt(){
function onRender(){
return renderView( "wires/logbox" );
}

Expand Down
2 changes: 1 addition & 1 deletion test-harness/wires/Mount.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ component extends="cbwire.models.Component" {
data.message = "Mounted value";
}

function renderIt(){
function onRender(){
return this.renderView( "wires/mount" );
}

Expand Down
2 changes: 1 addition & 1 deletion test-harness/wires/MountHasRequestContext.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ component extends="cbwire.models.Component" {
this.setMessage( event.getValue( "message" ) );
}

function renderIt(){
function onRender(){
return this.renderView( "wires/mount" );
}

Expand Down
2 changes: 1 addition & 1 deletion test-harness/wires/NestedComponent1.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ component extends="cbwire.models.Component" {
data.message = "Something";
}

function renderIt(){
function onRender(){
return this.renderView( "wires/nestedComponent1" );
}

Expand Down
2 changes: 1 addition & 1 deletion test-harness/wires/NestedComponent2.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ component extends="cbwire.models.Component" {
data.message = "Something ( again )!";
}

function renderIt(){
function onRender(){
return this.renderView( "wires/nestedComponent2" );
}

Expand Down
2 changes: 1 addition & 1 deletion test-harness/wires/OnUpdate.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ component extends="cbwire.models.Component" {
data.onUpdateMessage = true;
}

function renderIt() {
function onRender() {
return "
<div>
<div>onUpdate() called: #data.onUpdate#</div>
Expand Down
2 changes: 1 addition & 1 deletion test-harness/wires/PassActionArgs.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ component extends="cbwire.models.Component" {
data.message = "Well hello " & arguments.firstname & " " & arguments.lastname;
}

function renderIt(){
function onRender(){
return renderView( "wires/passActionArgs" );
}

Expand Down
2 changes: 1 addition & 1 deletion test-harness/wires/Poll.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ component extends="cbwire.models.Component" {
return now() & "what!";
}

function renderIt(){
function onRender(){
return this.renderView( "wires/poll" );
}

Expand Down
2 changes: 1 addition & 1 deletion test-harness/wires/PostEmit.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ component extends="cbwire.models.Component" {
data.message = "Called postEmit for event '#arguments.eventName#'!";
}

function renderIt(){
function onRender(){
return this.renderView( "wires/postEmit" );
}

Expand Down
2 changes: 1 addition & 1 deletion test-harness/wires/PreEmit.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ component extends="cbwire.models.Component" {
data.message = "Called preEmit for event '#arguments.eventName#'!";
}

function renderIt(){
function onRender(){
return this.renderView( "wires/preEmit" );
}

Expand Down
2 changes: 1 addition & 1 deletion test-harness/wires/QueryString.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ component extends="cbwire.models.Component" {
data[ "search" ] = event.getValue( "search", "" );
}

function renderIt(){
function onRender(){
return template( "wires.queryString" );
}

Expand Down
2 changes: 1 addition & 1 deletion test-harness/wires/Relocate.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ component
return relocate( url = "https://www.google.com" );
}

function renderIt(){
function onRender(){
return renderView( "wires/relocate" );
}

Expand Down
2 changes: 1 addition & 1 deletion test-harness/wires/ResetPropertiesToInitialState.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ component extends="cbwire.models.Component" {
/**
* Render our wire object.
*/
function renderIt(){
function onRender(){
return this.renderView( "wires/resetPropertiesToInitialState" );
}

Expand Down
2 changes: 1 addition & 1 deletion test-harness/wires/SlowComponent.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ component extends="cbwire.models.Component" {
return "<div>Loading...</div>";
}

function renderIt() {
function onRender() {
return "<div>Loaded after #data.sleepTime# ms</div>";
}
}
2 changes: 1 addition & 1 deletion test-harness/wires/TaskList.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ component extends="cbwire.models.Component" {
reset( "newTask" );
}

function renderIt() {
function onRender() {
return template( "wires.TaskList" );
}

Expand Down
Loading

0 comments on commit bc49fe8

Please sign in to comment.