Small improvement of wheels code: set external default image path.

72 views
Skip to first unread message

Andor Admiraal

unread,
Aug 27, 2012, 8:32:45 PM8/27/12
to cfwh...@googlegroups.com
Hi everyone,

I have adjusted a small piece of code in cfwheels 1.1.8 to fix a problem that we were having. I would like to suggest this code change for the next version of wheels, but I'm not sure how I should submit code suggestions. Hence I figured I just post it here, in hopes that someone who matters will pick it up. Or perhaps it might help someone who is having the same issue that we had.

Our problem was that we needed to put an external directory as our default image directory. This allows us to move our assets to a content delivery network (CDN) without having to update each and every imageTag() function. In the current code of wheels you can change the default image directory, but only to another internal paths. The below code change allows you to set it to either an internal or an external path, such as a CDN URL.

I have adjusted the file wheels/view/assets.cfm by changing line 170 and 171 from:

if(Left(arguments.source, 7) == "http://" || Left(arguments.source, 8) == "https://")
loc.localFile = false;

To:

if(Left(arguments.source, 7) == "http://" || Left(arguments.source, 8) == "https://")
        {
            loc.localFile = false;
            arguments.src = arguments.source;
        }
else if(Left(application.wheels.imagePath, 7) == "http://" || Left(application.wheels.imagePath, 8) == "https://")
        {
            loc.localFile = false;
            arguments.src = application.wheels.imagePath & "/" & arguments.source;
        }

After this code change, it is possible to set the image default path to either a local or an external URL. You can still use full URLs in the imageTag() function as well to override the default path. We can now switch between the CDN and the local server simply by adjusting the variable application.wheels.imagePath.

Regs,
Andor

Andy Bellenie

unread,
Aug 28, 2012, 6:16:04 AM8/28/12
to cfwh...@googlegroups.com
Hi Andor,

This change is unnecessary. If you're using external images then just use a standard <img> tag.

Cheers,
Andy



--
You received this message because you are subscribed to the Google Groups "ColdFusion on Wheels" group.
To view this discussion on the web visit https://groups.google.com/d/msg/cfwheels/-/pg0xDB54kBkJ.
To post to this group, send email to cfwh...@googlegroups.com.
To unsubscribe from this group, send email to cfwheels+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cfwheels?hl=en.

Andor Admiraal

unread,
Aug 28, 2012, 7:19:36 AM8/28/12
to cfwh...@googlegroups.com
Hi Andy,

I feel the current process is not very consistent. We are allowed to use the imageTag function with an external path. We can also change the default path for the images. But when changing the default path, all of a sudden only local paths are allowed. Also, we can use assetPaths to link javascript and stylesheets from external locations in one simple go, but I'm not sure why the same then is disallowed for images?

Apart from consistency, there is a very practical reason for this change. With this change, you can easily manage your assets within the Wheels framework, without the need to break out of it. You can move your assets locally, to a CDN or to any different location by simply updating the imagePath. Your solution on the other hand requires the change of hundreds or thousands of lines of code (each and every image link). Granted, this can usually be done with search and replace, but one of the nice things about the Wheels framework is that it encourages you to manage your resources in a structured manner. With this small change it becomes possible to shift local assets to a CDN and back again, or to from one CDN to another, simply by updating the imagePath, much in the same way as you can shift javascript and css easily. I would consider that an improvement.

Regs,
Andor

Andy Bellenie

unread,
Aug 28, 2012, 7:41:39 AM8/28/12
to cfwh...@googlegroups.com
Ok, I'll look into it. Can you file an issue?
To view this discussion on the web visit https://groups.google.com/d/msg/cfwheels/-/Ucb-XNzlWuEJ.
Reply all
Reply to author
Forward
0 new messages