Skip to content

Commit f932022

Browse files
author
Adam Tuttle
committed
use a relative path lookup for resources that should be compatible with both Railo and ACF
1 parent c60b4a6 commit f932022

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

core/api.cfc

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,11 @@
257257
',', '|', 'all' ) <!---convert commas to pipes (or's)--->
258258
/>
259259
<!--- if resources folder exists, use internal bean factory --->
260-
<cfset _taffyRequest.resourcePath = getDirectoryFromPath(getBaseTemplatePath()) & '/resources' />
260+
<cfset _taffyRequest.resourcePath = guessResourcesFullPath() />
261261
<cfif directoryExists(_taffyRequest.resourcePath)>
262262
<!--- setup internal bean factory --->
263263
<cfset application._taffy.factory = createObject("component", "taffy.core.factory").init() />
264-
<cfset application._taffy.factory.loadBeansFromPath(_taffyRequest.resourcePath) />
264+
<cfset application._taffy.factory.loadBeansFromPath(_taffyRequest.resourcePath, guessResourcesCFCPath()) />
265265
<cfset application._taffy.beanList = application._taffy.factory.getBeanList() />
266266
<cfset cacheBeanMetaData(application._taffy.factory, application._taffy.beanList) />
267267
<cfset application._taffy.status.internalBeanFactoryUsed = true />
@@ -470,6 +470,22 @@
470470
<cfreturn local.returnData />
471471
</cffunction>
472472

473+
<cffunction name="guessResourcesPath" access="private" output="false" returntype="string">
474+
<cfset local.indexcfmpath = cgi.script_name />
475+
<cfset local.resourcesPath = listDeleteAt(local.indexcfmpath, listLen(local.indexcfmpath, "/"), "/") & "/resources" />
476+
<cfreturn local.resourcesPath />
477+
</cffunction>
478+
479+
<cffunction name="guessResourcesFullPath" access="private" output="false" returntype="string">
480+
<cfreturn expandPath(guessResourcesPath()) />
481+
</cffunction>
482+
483+
<cffunction name="guessResourcesCFCPath" access="private" output="false" returntype="string">
484+
<cfset var path = guessResourcesPath() />
485+
<cfset path = right(path, len(path)-1) />
486+
<cfreturn reReplace(path, "\/", ".", "all") />
487+
</cffunction>
488+
473489
<cffunction name="throwError" access="private" output="false" returntype="void">
474490
<cfargument name="statusCode" type="numeric" default="500" />
475491
<cfargument name="msg" type="string" required="true" hint="message to return to api consumer" />

core/factory.cfc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
</cfscript>
2727
<cffunction name="loadBeansFromPath" access="public" output="false" returnType="void">
2828
<cfargument name="beanPath" type="string" required="true" hint="Absolute path to folder containing beans" />
29+
<cfargument name="resourcesPath" type="string" default="resources" />
2930
<cfset var local = StructNew() />
3031
<!--- if the folder doesn't exist, do nothing --->
3132
<cfif not directoryExists(arguments.beanPath)>
@@ -36,7 +37,7 @@
3637
<!--- cache all of the beans --->
3738
<cfloop query="local.beanQuery">
3839
<cfset local.beanName = left(local.beanQuery.name, len(local.beanQuery.name)-4) /><!--- drop the ".cfc" --->
39-
<cfset this.beans[local.beanName] = createObject("component", "resources." & local.beanName) />
40+
<cfset this.beans[local.beanName] = createObject("component", arguments.resourcesPath & "." & local.beanName) />
4041
</cfloop>
4142
<!--- resolve dependencies --->
4243
<cfloop list="#structKeyList(this.beans)#" index="local.b">

0 commit comments

Comments
 (0)