-
-
Notifications
You must be signed in to change notification settings - Fork 7
fix for two file wire from within a module #262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Changes from 1 commit
b6da14c
bd8c8c6
4597238
0a018fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,7 +67,7 @@ component accessors="true" singleton { | |
|
|
||
| wire.set_renderedContent( local.viewContent ); | ||
| return local.viewContent; | ||
| } | ||
| } | ||
|
|
||
| return wire.get_renderedContent(); | ||
| } | ||
|
|
@@ -164,14 +164,14 @@ component accessors="true" singleton { | |
| } | ||
|
|
||
| /** | ||
| * Normalizes the view path for rendering. This means it will convert the dot notation path | ||
| * Normalizes the view path for rendering. This means it will convert the dot notation path | ||
| * to a slash notation path, check for the existence of .bxm or .cfm files, and ensure the path is correctly formatted. | ||
| * | ||
| * @viewPath string | The dot notation path to the view template to be rendered, without the .cfm extension. | ||
| * | ||
| * @return string | ||
| */ | ||
| function normalizeViewPath( required viewPath ) { | ||
| function normalizeViewPath( required viewPath, required componentPath ) { | ||
| var paths = buildViewPaths( arguments.viewPath ); | ||
|
grantcopley marked this conversation as resolved.
|
||
|
|
||
| if ( paths.normalizedPath contains "cbwire/models/tmp/" ) { | ||
|
|
@@ -190,7 +190,7 @@ component accessors="true" singleton { | |
| throw( type="CBWIREException", message="A .bxm or .cfm template could not be found for '#arguments.viewPath#'." ); | ||
| } | ||
|
|
||
| if ( left( paths.normalizedPath, 6 ) != "wires/" ) { | ||
| if ( !find( "@", arguments.componentPath ) && left( paths.normalizedPath, 6 ) != "wires/" ) { | ||
| paths.normalizedPath = "wires/" & paths.normalizedPath; | ||
| } | ||
|
Comment on lines
175
to
196
|
||
| if ( left( paths.normalizedPath, 1 ) != "/" ) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| component extends="cbwire.models.Component" { | ||
|
|
||
|
|
||
| data = { | ||
| "myDataPropKey" : "My Data Prop Value" | ||
| }; | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <cfoutput> | ||
| <div> | ||
| <cfif datePart( 'h', now() ) lt 12 > | ||
|
grantcopley marked this conversation as resolved.
Outdated
|
||
| <p>Good Morning and hello CBWire Developer from a two file wire in a module!</p> | ||
| <cfelse> | ||
| <p>Good Afternoon and hello CBWire Developer from a two file wire in a module!</p> | ||
| </cfif> | ||
| </div> | ||
| </cfoutput> | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,13 +1,13 @@ | ||||||||||||||||||||||||||||||||||
| component extends="coldbox.system.testing.BaseTestCase" { | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| function beforeAll() { | ||||||||||||||||||||||||||||||||||
| variables.mockController = createStub(); | ||||||||||||||||||||||||||||||||||
| variables.mockUtility = createStub(); | ||||||||||||||||||||||||||||||||||
| variables.mockChecksumService = createStub(); | ||||||||||||||||||||||||||||||||||
| variables.mockValidationService = createStub(); | ||||||||||||||||||||||||||||||||||
| variables.mockRequestService = createStub(); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| variables.renderService = prepareMock( new cbwire.models.services.RenderService() ); | ||||||||||||||||||||||||||||||||||
| renderService.setCBWIREController( mockController ); | ||||||||||||||||||||||||||||||||||
| renderService.setUtilityService( mockUtility ); | ||||||||||||||||||||||||||||||||||
|
|
@@ -263,32 +263,55 @@ component extends="coldbox.system.testing.BaseTestCase" { | |||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| it( "should return .bxm path when .bxm file exists", function() { | ||||||||||||||||||||||||||||||||||
| var input = "my.view.template"; | ||||||||||||||||||||||||||||||||||
| // simulate the components variables._path which is what is passed to the wire() method | ||||||||||||||||||||||||||||||||||
| var component_path = "my.view.template"; | ||||||||||||||||||||||||||||||||||
| var bxmAbsolutePath = expandPath( "/my/view/template.bxm" ); | ||||||||||||||||||||||||||||||||||
|
grantcopley marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||
| var cfmAbsolutePath = expandPath( "/my/view/template.cfm" ); | ||||||||||||||||||||||||||||||||||
| var expectedPath = "/wires/my/view/template.bxm"; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| mockUtility.$( "fileExists" ).$args( bxmAbsolutePath ).$results( true ); | ||||||||||||||||||||||||||||||||||
| mockUtility.$( "fileExists" ).$args( cfmAbsolutePath ).$results( false ); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| var result = renderService.normalizeViewPath( input ); | ||||||||||||||||||||||||||||||||||
| var result = renderService.normalizeViewPath( input, component_path ); | ||||||||||||||||||||||||||||||||||
| expect( result ).toBe( expectedPath ); | ||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| it( "should return .cfm path when only .cfm file exists", function() { | ||||||||||||||||||||||||||||||||||
| var input = "my.view.template"; | ||||||||||||||||||||||||||||||||||
| // simulate the components variables._path which is what is passed to the wire() method | ||||||||||||||||||||||||||||||||||
| var component_path = "my.view.template"; | ||||||||||||||||||||||||||||||||||
| var bxmAbsolutePath = expandPath( "/my/view/template.bxm" ); | ||||||||||||||||||||||||||||||||||
| var cfmAbsolutePath = expandPath( "/my/view/template.cfm" ); | ||||||||||||||||||||||||||||||||||
| var expectedPath = "/wires/my/view/template.cfm"; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| mockUtility.$( "fileExists" ).$args( bxmAbsolutePath ).$results( false ); | ||||||||||||||||||||||||||||||||||
| mockUtility.$( "fileExists" ).$args( cfmAbsolutePath ).$results( true ); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| var result = renderService.normalizeViewPath( input ); | ||||||||||||||||||||||||||||||||||
| var result = renderService.normalizeViewPath( input, component_path ); | ||||||||||||||||||||||||||||||||||
| expect( result ).toBe( expectedPath ); | ||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| it( "should return .cfm module path when wire is located in module wires direcotry", function() { | ||||||||||||||||||||||||||||||||||
|
grantcopley marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||||||||||||||
| var input = "modules_app.testingModule.wires.twoFileModuleComponent"; | ||||||||||||||||||||||||||||||||||
| // simulate the components variables._path which is what is passed to the wire() method | ||||||||||||||||||||||||||||||||||
| var component_path = "twoFileModuleComponent@testingModule"; | ||||||||||||||||||||||||||||||||||
| // use full path to module wire | ||||||||||||||||||||||||||||||||||
| var bxmAbsolutePath = expandPath( "../modules_app/testingModule/wires/twoFileModuleComponent.bxm" ); | ||||||||||||||||||||||||||||||||||
| var cfmAbsolutePath = expandPath( "../modules_app/testingModule/wires/twoFileModuleComponent.cfm" ); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| var expectedPath = "/modules_app/testingModule/wires/twoFileModuleComponent.cfm"; | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
| var input = "modules_app.testingModule.wires.twoFileModuleComponent"; | |
| // simulate the components variables._path which is what is passed to the wire() method | |
| var component_path = "twoFileModuleComponent@testingModule"; | |
| // use full path to module wire | |
| var bxmAbsolutePath = expandPath( "../modules_app/testingModule/wires/twoFileModuleComponent.bxm" ); | |
| var cfmAbsolutePath = expandPath( "../modules_app/testingModule/wires/twoFileModuleComponent.cfm" ); | |
| var expectedPath = "/modules_app/testingModule/wires/twoFileModuleComponent.cfm"; | |
| var input = "modules_app.testingmodule.wires.twoFileModuleComponent"; | |
| // simulate the components variables._path which is what is passed to the wire() method | |
| var component_path = "twoFileModuleComponent@testingmodule"; | |
| // use full path to module wire | |
| var bxmAbsolutePath = expandPath( "/modules_app/testingmodule/wires/twoFileModuleComponent.bxm" ); | |
| var cfmAbsolutePath = expandPath( "/modules_app/testingmodule/wires/twoFileModuleComponent.cfm" ); | |
| var expectedPath = "/modules_app/testingmodule/wires/twoFileModuleComponent.cfm"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 0a018fb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
template()now always passesvariables._pathintonormalizeViewPath(), but_pathis not initialized inonDIComplete()and can be null unless_withPath()has been called. If a component instance callstemplate()before_withPath(),normalizeViewPath()will receive null and can error when callingfind(). Consider defaulting to an empty string when_pathis null, or making the newcomponentPathargument optional/nullable-safe innormalizeViewPath().