Skip to content

Commit 20ffb5c

Browse files
committed
Merge branch 'development' of github.com:coldbox-modules/cbwire into development
2 parents b002db5 + 984cc32 commit 20ffb5c

10 files changed

Lines changed: 77 additions & 25 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ jobs:
9595

9696
- name: Upload Test Results Artifacts
9797
if: always()
98-
uses: actions/upload-artifact@v5
98+
uses: actions/upload-artifact@v7
9999
with:
100100
name: test-results-${{ matrix.cfengine }}
101101
path: |
@@ -104,7 +104,7 @@ jobs:
104104
# Leaving this here for future debugging
105105
# - name: Upload tmp folder as artifact
106106
# if: always()
107-
# uses: actions/upload-artifact@v5
107+
# uses: actions/upload-artifact@v7
108108
# with:
109109
# name: tmp-folder
110110
# path: models/tmp/
@@ -129,7 +129,7 @@ jobs:
129129
130130
- name: Upload Debugging Info To Artifacts
131131
if: ${{ failure() }}
132-
uses: actions/upload-artifact@v5
132+
uses: actions/upload-artifact@v7
133133
with:
134134
name: Failure Debugging Info - ${{ matrix.cfengine }}
135135
path: |

.github/workflows/pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ jobs:
8383
8484
- name: Upload Debugging Info To Artifacts
8585
if: ${{ failure() }}
86-
uses: actions/upload-artifact@v5
86+
uses: actions/upload-artifact@v7
8787
with:
8888
name: Failure Debugging Info - ${{ matrix.cfengine }}
8989
path: |

models/Component.cfc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ component output="true" accessors="true" {
8181
variables._redirect = "";
8282
variables._redirectUsingNavigate = false;
8383
variables._isolate = false;
84+
variables._path = "";
8485
variables._renderedContent = "";
8586
variables._scripts = [:];
8687
variables._assets = [:];
@@ -229,7 +230,7 @@ component output="true" accessors="true" {
229230
*/
230231
function template( viewPath, params = {} ) {
231232
// Normalize the view path
232-
local.normalizedPath = variables._renderService.normalizeViewPath( arguments.viewPath );
233+
local.normalizedPath = variables._renderService.normalizeViewPath( arguments.viewPath, variables._path );
233234
// Render the view content and trim the result
234235
return variables._renderService.renderViewContent( this, local.normalizedPath, arguments.params );
235236
}

models/services/RenderService.cfc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ component accessors="true" singleton {
6767

6868
wire.set_renderedContent( local.viewContent );
6969
return local.viewContent;
70-
}
70+
}
7171

7272
return wire.get_renderedContent();
7373
}
@@ -164,14 +164,15 @@ component accessors="true" singleton {
164164
}
165165

166166
/**
167-
* Normalizes the view path for rendering. This means it will convert the dot notation path
167+
* Normalizes the view path for rendering. This means it will convert the dot notation path
168168
* to a slash notation path, check for the existence of .bxm or .cfm files, and ensure the path is correctly formatted.
169169
*
170170
* @viewPath string | The dot notation path to the view template to be rendered, without the .cfm extension.
171+
* @componentPath string | The component path, used to determine if the normalized path should be prefixed with "wires/".
171172
*
172173
* @return string
173174
*/
174-
function normalizeViewPath( required viewPath ) {
175+
function normalizeViewPath( required viewPath, required componentPath ) {
175176
var paths = buildViewPaths( arguments.viewPath );
176177

177178
if ( paths.normalizedPath contains "cbwire/models/tmp/" ) {
@@ -190,7 +191,7 @@ component accessors="true" singleton {
190191
throw( type="CBWIREException", message="A .bxm or .cfm template could not be found for '#arguments.viewPath#'." );
191192
}
192193

193-
if ( left( paths.normalizedPath, 6 ) != "wires/" ) {
194+
if ( !isNull( arguments.componentPath ) && !find( "@", arguments.componentPath ) && left( paths.normalizedPath, 6 ) != "wires/" ) {
194195
paths.normalizedPath = "wires/" & paths.normalizedPath;
195196
}
196197
if ( left( paths.normalizedPath, 1 ) != "/" ) {

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"devDependencies": {
3-
"rollup": "^2.58.0"
3+
"rollup": "^2.80.0"
44
}
55
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
component extends="cbwire.models.Component" {
2+
3+
4+
data = {
5+
"myDataPropKey" : "My Data Prop Value"
6+
};
7+
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<cfoutput>
2+
<div>
3+
<cfif datePart( "h", now() ) lt 12 >
4+
<p>Good Morning and hello CBWire Developer from a two file wire in a module!</p>
5+
<cfelse>
6+
<p>Good Afternoon and hello CBWire Developer from a two file wire in a module!</p>
7+
</cfif>
8+
</div>
9+
</cfoutput>

test-harness/tests/specs/CBWIRESpec.cfc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1836,11 +1836,16 @@ component extends="coldbox.system.testing.BaseTestCase" {
18361836
} ).toThrow( type="ModuleNotFound" );
18371837
} );
18381838

1839-
it( "should render component from module using default wires location", function() {
1839+
it( "should render single file component from module using default wires location", function() {
18401840
var result = cbwireController.wire( "NestedModuleDefaultComponent@testingmodule" );
18411841
expect( result ).toContain( "Nested module component using default wires location" );
18421842
} );
18431843

1844+
it( "should render a two file component from module using default wires location", function() {
1845+
var result = cbwireController.wire( "twoFileModuleComponent@testingmodule" );
1846+
expect( result ).toContain( "hello CBWire Developer from a two file wire in a module" );
1847+
} );
1848+
18441849
it( "should render component from module using nested folder", function() {
18451850
var result = cbwireController.wire( "wires.nestedComponent.NestedFolderComponent@testingmodule" );
18461851
expect( result ).toContain( "Nested folder component" );

test-harness/tests/specs/unit/services/RenderServiceSpec.cfc

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
component extends="coldbox.system.testing.BaseTestCase" {
22

3-
3+
44
function beforeAll() {
55
variables.mockController = createStub();
66
variables.mockUtility = createStub();
77
variables.mockChecksumService = createStub();
88
variables.mockValidationService = createStub();
99
variables.mockRequestService = createStub();
10-
10+
1111
variables.renderService = prepareMock( new cbwire.models.services.RenderService() );
1212
renderService.setCBWIREController( mockController );
1313
renderService.setUtilityService( mockUtility );
@@ -263,32 +263,55 @@ component extends="coldbox.system.testing.BaseTestCase" {
263263

264264
it( "should return .bxm path when .bxm file exists", function() {
265265
var input = "my.view.template";
266+
// simulate the components variables._path which is what is passed to the wire() method
267+
var componentPath = "my.view.template";
266268
var bxmAbsolutePath = expandPath( "/my/view/template.bxm" );
267269
var cfmAbsolutePath = expandPath( "/my/view/template.cfm" );
268270
var expectedPath = "/wires/my/view/template.bxm";
269271

270272
mockUtility.$( "fileExists" ).$args( bxmAbsolutePath ).$results( true );
271273
mockUtility.$( "fileExists" ).$args( cfmAbsolutePath ).$results( false );
272274

273-
var result = renderService.normalizeViewPath( input );
275+
var result = renderService.normalizeViewPath( input, componentPath );
274276
expect( result ).toBe( expectedPath );
275277
});
276278

277279
it( "should return .cfm path when only .cfm file exists", function() {
278280
var input = "my.view.template";
281+
// simulate the components variables._path which is what is passed to the wire() method
282+
var component_path = "my.view.template";
279283
var bxmAbsolutePath = expandPath( "/my/view/template.bxm" );
280284
var cfmAbsolutePath = expandPath( "/my/view/template.cfm" );
281285
var expectedPath = "/wires/my/view/template.cfm";
282286

283287
mockUtility.$( "fileExists" ).$args( bxmAbsolutePath ).$results( false );
284288
mockUtility.$( "fileExists" ).$args( cfmAbsolutePath ).$results( true );
285289

286-
var result = renderService.normalizeViewPath( input );
290+
var result = renderService.normalizeViewPath( input, component_path );
291+
expect( result ).toBe( expectedPath );
292+
});
293+
294+
it( "should return .cfm module path when wire is located in module wires directory", function() {
295+
var input = "modules_app.testingmodule.wires.twoFileModuleComponent";
296+
// simulate the components variables._path which is what is passed to the wire() method
297+
var component_path = "twoFileModuleComponent@testingmodule";
298+
// use full path to module wire
299+
var bxmAbsolutePath = expandPath( "../modules_app/testingmodule/wires/twoFileModuleComponent.bxm" );
300+
var cfmAbsolutePath = expandPath( "../modules_app/testingmodule/wires/twoFileModuleComponent.cfm" );
301+
302+
var expectedPath = "/modules_app/testingmodule/wires/twoFileModuleComponent.cfm";
303+
// mock the file exists calls for both .bxm and .cfm paths
304+
mockUtility.$( "fileExists" ).$args( bxmAbsolutePath ).$results( false );
305+
mockUtility.$( "fileExists" ).$args( cfmAbsolutePath ).$results( true );
306+
307+
var result = renderService.normalizeViewPath( input, component_path );
287308
expect( result ).toBe( expectedPath );
288309
});
289310

290311
it( "should throw when neither .bxm nor .cfm exists", function() {
291312
var input = "my.view.template";
313+
// simulate the components variables._path which is what is passed to the wire() method
314+
var component_path = "my.view.template";
292315
var bxmAbsolutePath = expandPath( "/nonexistent/view.bxm" );
293316
var cfmAbsolutePath = expandPath( "/nonexistent/view.cfm" );
294317
var expectedPath = "/wires/my/view/template.cfm";
@@ -297,29 +320,34 @@ component extends="coldbox.system.testing.BaseTestCase" {
297320
mockUtility.$( "fileExists" ).$args( cfmAbsolutePath ).$results( false );
298321

299322
expect( function() {
300-
renderService.normalizeViewPath( "nonexistent.view" );
323+
renderService.normalizeViewPath( "nonexistent.view", component_path );
301324
}).toThrow( "CBWIREException" );
302325
});
303326

304327
it( "should return path with .bxm for tmp path when .bxm exists", function() {
305328
var input = "cbwire.models.tmp.componentName";
329+
// simulate the components variables._path which is what is passed to the wire() method
330+
var component_path = "cbwire.models.tmp.componentName";
306331

307332
mockUtility.$( "fileExists" ).$args( expandPath( "/cbwire/models/tmp/componentName.bxm" ) ).$results( true );
308333
mockUtility.$( "fileExists" ).$args( expandPath( "/cbwire/models/tmp/componentName.cfm" ) ).$results( false );
309334

310-
var result = renderService.normalizeViewPath( input );
335+
var result = renderService.normalizeViewPath( input, component_path );
311336
expect( result ).toBe( "/cbwire/models/tmp/componentName.bxm" );
312337
});
313338

314339
it( "should return path with .cfm for tmp path when .cfm exists", function() {
315340
var input = "cbwire.models.tmp.componentName";
341+
// simulate the components variables._path which is what is passed to the wire() method
342+
var component_path = "cbwire.models.tmp.componentName";
316343

317344
mockUtility.$( "fileExists" ).$args( expandPath( "/cbwire/models/tmp/componentName.bxm" ) ).$results( false );
318345
mockUtility.$( "fileExists" ).$args( expandPath( "/cbwire/models/tmp/componentName.cfm" ) ).$results( true );
319346

320-
var result = renderService.normalizeViewPath( input );
347+
var result = renderService.normalizeViewPath( input, component_path );
321348
expect( result ).toBe( "/cbwire/models/tmp/componentName.cfm" );
322349
});
350+
323351
});
324352

325353
describe( "getTemplatePath()", function() {

0 commit comments

Comments
 (0)