Using the Foundry CF Path Module

So as I announced in my last entry, I’ve been working on something called Foundry for CF. Foundry’s aim is to provide a platform for modular CF applications and utilities.

It is not a framework used for building a full blown web application. It doesn’t have ORM, databases, controllers, views, etc. It serves a different purpose.

But I’m not going to talk about Foundry today, I’m going to talk about 1 piece of Foundry, the Path module.

Now, Most of us have used ColdFusion’s nice and convenient cfdirectory, cffile, and path functions. These are great, and perfect for what they do and what most people need them for. But they aren’t infinitely useful for building paths, and manipulating hyphothetical path structures that may or may not exist. They are meant to work with the file system directly (generally).

If you’re familiar with NodeJS, you will be right at home here and this will be redundant information to you… but my goal for the basics of Foundry was to port the majority of Node’s core modules over to CF Components. The main reason I started this was to learn more about Node, JavaScript, AND ColdFusion’s newer scripting abilities with closures and function expressions. But also because it’s damn neat to be able to almost line for line port over useful code from the ever so hopping Node community.

Almost lost sight of the topic again… sorry…

The Path.cfc component of Foundry Core is a direct port of the Node module to CF.
This module is incredibly useful and is used in like 90% of all Node modules so therefor it was a natural fit in Foundry.

Path.cfc is fairly self explanitory for the most part, it deals with… well paths.
But not PHYSICAL paths that exist on the drive, but paths that could or may exist.

Let’s start with a few examples…


Let’s say you would like to step up 3 directories of a given path string.
Ideally, in a terminal, you would take your current directory and type “cd ../../../” and instantly be taken to that directory.

In ColdFusion, you could do this with something like so:


This definitely would work… but… not very elegant or clean.

With Foundry Path module, you would just type:

//given the path /Users/rountrjf/Projects/my_cool_app/
<cfset myPath = Path.resolve("/Users/rountrjf/Projects/my_cool_app/test/what/hotness,'../../../') />
<cfoutput>#myPath#</cfoutput> <!--- output: /Users/rountrjf/Projects/my_cool_app/ --->

Now, you might say… well I could have done that by just typing expandPath('/').
That’s true, but that only works for your current CF context and will only return the root of that context.

Path.cfc works with ANY PATH string, it’s aim is not to make or manipulate paths relative to any physical path, as stated before, it manipulates path strings.

Foundry is meant to do more than attach to your existing web applications, it’s meant to be a workhorse for building useful things that don’t always end up in a tag. It’s meant for doing heavy lifting and help you approach the problems of the next generation of CF.

<cfset myPath = Path.resolve('/Users/rountrjf/Projects/my_cool_app/test/what/hotness','../images/','../../','../controllers') />

This one is much harder to mentally wrap your head around outside of context of a terminal window but if you walk through it from left to right, you can resolve it…

So we start in the hotness directory, and we type cd ../images/
That places us in the images directory within the what directory. So /test/what/images.

From there, we cd ../../ which would take us out of images, and up 2 directories which would put us /test/ again.

Then we do a cd ../controllers which would take us out of test and up a directory, then into the controllers directory.

Our final resolved path should be /Users/rountrjf/Projects/my_cool_app/controllers.

That’s just the resolve function, and whether or not you find it applicable in your development will determine if you’re still thinking in the typical CF mindset of building streamlined web apps with a front end public purpose, versus a workhorse to help you develop useful extensions to CF.


This is quite the opposite of Path.resolve().
Path.resolve() always returns an absolute path where relative’s goal is to give you a relative path.

Let’s say you need to determine what steps it would take to get to a path from another path… given the example above, let’s try this out…

<!--- grab the path module --->
<cfset path = new foundry.core.path() />

<!--- use it --->
<cfset myRelativePath = Path.relative('/Users/rountrjf/Projects/my_cool_app/test/what/hotness','/Users/rountrjf/Projects/my_cool_app/controllers') />

This statement will return the relative path to the controllers directory based on the first path provided in argument[1].

So let’s say we’re in /test/what/hotness and we want to know the steps it takes to get to controllers. The response would be ../../../controllers since controllers is in the my_cool_app/ directory

Easy, but not something you use everyday in regular CF apps probably until you start thinking about building other things with CF.

There are 7 functions in the Path.cfc and these are 2 of big ones.


Join is a very useful function.

It’s about the equivalent of the following:

<cfset myPaths = [
] />

<cfset joinedPaths = arrayToList(myPaths,'/') />

Except for the fact that it actually cleans it all up and makes it valid based on your file system (windows or posix).

The result of the above example would be roughly /Users\rountrjf\//Projects/\my_cool_app/..//test

But if you use Path.join():

<cfset joinedPaths = Path.join('/Users\rountrjf\','/Projects','\my_cool_app','/test','..') />

//or on windows
<cfset joinedPaths = Path.join('c:','Users/rountrjf\','/Projects','\my_cool_app','/test','..') />

This would return /Users/rountrjf/Projects/my_cool_app on posix, or on Windows provided you added a C: or something in front, you would get C:\Users\rountrjf\Projects\my_cool_app

It’s sort of like path.resolve, except it doesn’t need a from path, it simply joins all your paths by a separator and normalizes the output based on the current operating system it’s running on. (ie. / for posix and \ for windows).

Also, it ignores non-string arguments.
If you just had a jumbled struct of mixed paths + arrays mixed in, it would ignore the arrays and join the paths.

The rest…

The rest of them are much simpler in nature…
I’ll have you checkout the rest via Foundry documentation for more information.
Or, the node documentation too! It all applies.

Path module documentation for Foundry:

Modular ColdFusion with Foundry

What is it?

Foundry is a ColdFusion platform for building modular components for applications.


Please be patient with Foundry, as pieces of this functionality are conceptual and are still being proven / developed.

Up until now, there hasn’t been a great way to adequately use CF to build, share, re-use and manage Components.
That is why Foundry was created.

What can it do for me?

Whether you’re building a large CMS application, or a smaller utility library, there comes a time when you need to use it in more applications.
You may also want to share it, and allow others to use it in their applications.

Foundry builds upon common principles found in many other environments such as Ruby (and RubyGems), and Node (and npm).

These principles include (not limited to):

  • Easily defining required dependencies at the top of Component files.
  • Pre-defining required dependencies in a single config file and then requiring them.
  • Managing dependencies by being able to install / update them on the fly without visiting sites like Riaforge, Github, etc.
  • Semantic Versioning standards to keep track of versions of modules.
  • Set of core components that augment your module building experience.

Now you can use CF to build more than just web apps.

Getting Started

You can jump in at any level with Foundry.

The easiest way to get started is by simply including a “foundry.json” file within your application’s root.
This defines some basic information about your application that will help Foundry know more about your application and what it needs to run properly.
Soon you will even be able to publish your apps to our registry at fpmcf.org so that others can quickly use your modules within their own applications.

Without installing Foundry, this doesn’t offer much in terms of further implementing Foundry principles into your modules.
To learn how to install Foundry, follow the Installation guide in the section titled ‘Installing Foundry’ below.

To utilize advanced functionality provided by Foundry, you can begin by making your base components extend “foundry.core”.

component name="MyAwesomeComponent" extends="foundry.core" {


Installing Foundry

Foundry’s core is very basic in nature, but powerful when applied.
Many of it’s principles are probably already used in your applications today so it shouldn’t be hard to implement them.

1.) Download Foundry or better yet, use Git

$ cd ~/my_projects_folder/
$ git clone https://github.com/joshuairl/foundry.git foundry

2.) Create a mapping (and/or symlink/virtualweb in your project) to /foundry.
Logical Path: /foundry
Physical Path: /Users/me/my_projects_folder/foundry

3.) Create a new site / project folder or navigate to your existing one you would like to use Foundry on.

4.) Create a new file in your project’s folder called foundry.json.
Paste the following into it and change the values accordingly.

  "name": "my_app_module",
  "version": "0.0.1",
  "author": "Joshua F. Rountree",


“`json advanced foundry.json

  "name": "my_module", //The unique name of your project
  "preferGlobal": "true", //Flag that indicates this package prefers to be installed globally for all your apps.
  "version": "0.3.0", //Version of the package as specified by http://semver.org/.
  "author": "Ricky Bobby <ricky@rickybobby.com>", //The author of the project.
  "description": "a simple tool to help you do cool things.", //The description of the project.

  //An array of structures representing contributors to the project.
  "contributors": [ 
      "name": "John Smith",
      "email": "john@smithcode.dom"
  "bin": {
    "module-cli": "./bin/module" //A structure containing key/pair mappings of binary script names and cf script paths. 
  "scripts": {}, //A structure containing key/pair mappings of foundry modules and cf script paths. (not currently used yet)
  "main": "./lib/http-server", //The main entry point of the package. When calling require('module_name') in Foundry this is the file that will actually be required.
  "repository": {
    "type": "git",
    "url": "https://github.com/joshuairl/my_project.git"
  }, //A structure containing key/pair mappings of source code repositories. 
  "keywords": [
  ], //An array of keywords which describe your package. Useful for people searching the fpmcf.org registry.
  "dependencies" : {
    "UnderscoreCF"   :  "*"
  }, //A structure containing key/pair mappings of foundry packages and versions that this project depends on.

  "license": "MIT", The license which you prefer to release your project under. MIT is a good choice.
  "engines": {
    "adobe": ">=9.0.0" //specifies adobe version required
    "railo": ">=3.3.1" //specifies railo version requird
    "foundy": "0.0.3" //even a place to specify the foundry version (good practice)
  } //A struct containing key/pair mappings of engine versions. This is used to specify the versions of CFML and Foundry your package is known to work correctly with.


5.) Extend your base components to allow for easy usage of external dependencies.

component name="my_base" extends="foundry.core" {
  public my_base function init() {
    variables.path = require("path"); //require the foundry path module, apart of foundry's core.
    variables._ = require("UnderscoreCF"); //require underscore, an external module by @russplaysguitar

  public any function doSomething() {
    myPath = path.resolve('foo/bar', '/tmp/file/', '..', 'a/../subfile');
    myArray = _.forEach();

Where to get it?

You can grab the latest from GitHub.
Feel free to fork and contribute wherever you have time!
Also, I’m building this on Mac OS X. I’ve done some minimal testing on Windows but for the most part, it should be considered broken on Windows as of right now.

FPM – Foundry Package Manager

This is not ready for use yet. As of right now, packages will need to be cloned or downloaded manually until the development of this progresses.

However, I’m proving daily that this is needed.
To download and install dependencies use fpm (proof-of-concept)

Running Railo from any directory in Windows 7

Running Railo from any directory in Windows 7

Yesterday I posted a question on the Railo mailing list to find out if anyone had ever made a shell script / batch file that would spawn Railo contexts based on your current directory.

For instance:

$ cd /path/to/sites_folder/ 
$ mkdir my_new_site 
$ cd my_new_site 
$ railo new

Mark Drew responded almost immediately with some suggestions but nothing bullet proof at first.

Then, a few hours later… He posted a full solution and it works brilliantly. His instructions applied to Mac OS X but they almost directly translate to Windows 7, but if you don’t feel like translating… here is it!


Download and Extract Railo Express

To get started, download Railo Express.

I recommend downloading the version with JRE for the quickest and smoothest setup. Also, keep in mind which version you’re downloading.

The current download page offers 4.0.0.xxx BETA first, and if you scroll down you will see Railo 3.3.4.xxx versions. In the Adobe world, this translates to (fairly smoothly): Railo 3.3.4 ~= CF9, and Railo 4.0.0 ~= CF10.

Extract the contents of the zip file to C:\Railo to keep things as clean and simple as possible.

If you desire to be able to spawn multiple versions of Railo based on a given folder, I suggest you name it Railo3 and Railo4 respectively and ensure all of your paths in all of the steps matches this folder name.

Setup the .bat script

Now, navigate to the C:\Railo directory and copy/paste the file start.bat which should give you a Copy of start.bat file.

Rename that file to railo_init.bat.

Right click on railo_init.bat and click Edit, or Open With > Your Favorite Editor.

The contents of this file should look like this, give or take your path names based on your preference.

set currpath=%CD%
cd %~dp0
java -DSTOP.PORT=8887 -DSTOP.KEY=railo -Xms256M  -Xmx512M -jar l
ib/start.jar -Drespath=%CURRPATH%

Save (CTRL+S) the railo_init.bat and you may close it now.

Modify the railo.xml context

Open up C:\Railo\contexts\railo.xml with your favorite text / markup editor. Notice the commented out line and the new version of that line directly below it.

<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
    <Set name="contextPath">/</Set>
    <Set name="resourceBase"><SystemProperty name="jetty.home" default="."/>/webroot/</Set>
    <Set name="resourceBase"><SystemProperty name="respath" default="."/>/</Set>
    <Set name="defaultsDescriptor"><SystemProperty name="jetty.home" default="."/>/etc/webdefault.xml</Set>

Now save railo.xml and close it.

Update your PATH System Variable

Click Start Orb >

start menu

Right-click Computer > Select Properties from the menu.

Context Menu

Now click Advanced system settings.

advanced system settings

On the Advanced tab, click Environment Variables button.

environment variables button

Under System variables, scroll down to Path, select it and click Edit

Path variables

Now, move your cursor to the end of the Variable value: field, and make yours look like below. Type ;C:\Railo;

editing path variable

Now, click Ok a million times until you’re closed out of all of these windows.

Initialize your first web app directory.

Open up a fresh Windows Console by clicking Start Orb and typing cmd. (NOTE: You may want to right click on cmd and click Run As Administrator if for some reason you run into permissions issues)

Start by typing cd C:\path_to_your_sites_root\ replacing the obvious with your actual sites root folder where you house your web projects.

cd C:\path_to_your_sites\ mkdir my_new_site cd my_new_site railo_init

This should now start copying required files over to your my_new_site directory and start a web server listening on http://localhost:8888/. If you browse to that in your browser, you should be presented with your my_new_site empty directory.

You may now proceed to add your favorite CFML framework or add an index.cfm to get started.

For all future apps, all you have to do is open up a console, type those commands, and it will setup a new Railo context running in that folder. Awesome!


If you have any problems or issues with this solution, please feel free to let me know, or post them to the Railo Google Groups

Future enhancements

I’m currently working on a CFWheels Framework tool written in Node.js that will enhance this process by generating a CFWheels application with my new Asset Pipeline plugin built in.

How to do this in Mac OS X

Here is Mark Drew’s post on his blog with detailed instructions on the Mac OS X implementation: Running Railo from any directory on Mac OS X

The automatic gist!

One thing I wish for any blog platform is the ability to automatically gist all of the code snippets found in a particular blog entry.

I find it very strange that NOBODY (that I know of) has really publicly implemented this as a solution to “gists” for bloggers. The only implementation that I know of was privately announced on a post by Ben Nadel but since then I’ve not found anyone else…

The reason Ben and I like to handle Gists this way is because sometimes your blogs code snippets are better served from your blog… giving you the freedom to later switch syntax highlighters and keep your code indexed within your own blog database or flat files. Removing this dependency on github’s javascript loader, and lettings your code snippets render regardless if github is a slug today or not.

Since I just started using Octopress I’ve decided I’m going to take a stab at implementing this.

Project requirements

  • Fastest and simplest way is to just use the gist gem which offers a command line method for posting gists.
  • Each gist is unique to the post
  • Some sort of unique identifier needs to be referenced everytime a gist is created / updated as to not keep creating new unique gists everytime you compile your Octopress blog.
  • rake generate should handle the gist creation commands, I’m thinking this would be somewhere in the backtick_code_block.rb

WARNING: All code is conceptual, do not use it yet! I’m just brainstorming in this entry…

Modify Octopress Backtick Code Block Plugin

I’m not certain I should be modifying this plugin to make this work but I’m a total Ruby n00b so I’m just finding a nice place to put my thoughts. I’m certain this will end up becoming it’s own plugin.

require './plugins/pygments_code'

module BacktickCodeBlock
  include HighlightCode
  AllOptions = /([^\s]+)\s+(.+?)(https?:\/\/\S+)\s*(.+)?/i
  LangCaption = /([^\s]+)\s*(.+)?/i
  def render_code_block(input)
    @options = nil
    @caption = nil
    @lang = nil
    @url = nil
    @title = nil
    input.gsub(/^`{3} *([^\n]+)?\n(.+?)\n`{3}/m) do
      @options = $1 || ''
      str = $2

      if @options =~ AllOptions
        @lang = $1
        @caption = "<figcaption><span>#{$2}</span><a href='#{$3}'>#{$4 || 'link'}</a></figcaption>"
      elsif @options =~ LangCaption
        @lang = $1
        @caption = "<figcaption><span>#{$2}</span></figcaption>"

      if str.match(/\A( {4}|\t)/)
        str = str.gsub(/^( {4}|\t)/, '')
      if @lang.nil? || @lang == 'plain'
        code = tableize_code(str.gsub('<','&lt;').gsub('>','&gt;'))
        "<figure class='code'>#{@caption}#{code}</figure>"

        system "echo ""#{code}"" | gist -t plain"
        if @lang.include? "-raw"
          raw = "``` #{@options.sub('-raw', '')}\n"
          raw += str
          raw += "\n```\n"
          code = highlight(str, @lang)
          "<figure class='code'>#{@caption}#{code}</figure>"

          system "echo ""#{str}"" | gist -t #{@lang}"

A new Octopress AutoGist plugin

No idea how to implement my own Octopress plugin yet but it may look like this?
I’m not sure how to do this but we will need to gather all code blocks into an array…
Save each one as a separate file in a temp directory with a file format based on the title of the code block?

#!ruby #contents of file 1

Would create a file like “_gist_temp/932423_file1.rb

      #contents of file 2

Would create a file like “_gist_temp/932423_file2.rb”

The 932423 would be some sort of “post” id (not sure if one of those exists)
Possibly a hash of the post filename?

require './plugins/pygments_code'

module AutoGist
  include HighlightCode
  AllOptions = /([^\s]+)\s+(.+?)(https?:\/\/\S+)\s*(.+)?/i
  LangCaption = /([^\s]+)\s*(.+)?/i
  def render_code_block(input)
    @options = nil
    @caption = nil
    @lang = nil
    @url = nil
    @title = nil
    input.gsub(/^`{3} *([^\n]+)?\n(.+?)\n`{3}/m) do
      @options = $1 || ''
      str = $2

      if @options =~ AllOptions
        @lang = $1
      elsif @options =~ LangCaption
        @lang = $1

      if str.match(/\A( {4}|\t)/)
        str = str.gsub(/^( {4}|\t)/, '')
      if @lang.nil? || @lang == 'plain'
          system "echo ""#{str}"" | gist -t plain"
          system "echo ""#{str}"" | gist -t #{@lang}"

Well, that’s all the time I have for today so I’ll be thinking more about this and make some changes appropriately. If I get a new plugin released, I’ll definitely share it! Let me know if anyone has any input on how they would invision this working.

Okay so here it is…

So I’ve been meaning to start a blog for 6 years now and many attempts have failed thus far.
I can’t make any promises on this one.

Truth is, it’s hard to find time between work and my family time… so I’ve decided to try something new.
I wanted to be able to blog from anywhere, but not necessarily have to be connected to a wordpress account or server to post a new entry.

Decided to try out Octopress since I’m addicted to github and well… why not…

One of the key times during my day that I have free to blog would be during my long commute to and from the office. The only problem is, I’m driving…

I’m going to try to blog by using speech to text dictation and then clean it up when I arrive at my destination.

I would compose a new post using rake new_post[“title”] but then I would just start talking and let it type for me.
I’m thinking if I get my thoughts in a file, I’ll be more likely to follow through with finishing a blog entry and publishing.

So let’s give this a try… stay tuned!

Living in a world without $()

Recently we were presented an opportunity to redevelop and application we originally developed in a very traditional manner.

I say traditional because the most revolutionary difference between it and it’s initial 1.0 release was the strings of jQuery globs in view pages, and some flashy new CSS / UI. We called it 2.0! Oh we thought we had made life spectacular… How awesome is this jQuery stuff…

Of course, it wasn’t our fault… The entire world took jQuery and ran with it like it was the savior of all things JS.

Of course, this post isn’t going to be about jQuery or moving to some other new thing… It’s mostly about what it represents. It’s a cog that filled my time indirectly preventing growth. It’s not it’s fault, or Resig’s fault (even tho I’d like it if I could put it all on him :p) … It’s just life I suppose.

All I can do is try to stay relevant in what seems to be a train of web tech that I’m running beside. No matter which car I leap to, I’m still never caught up.

That’s why I’m chasing the bleeding edge. I’ll never catch it.

Am I a UX Designer? A CTO? a web researcher? a database engineer (is that real?)? a web developer? Front end developer? Today I love coffee-script, yesterday, you loved it. Tomorrow, I think I’m going to like Ruby, three years ago you loved it. Java is dead? I better learn it? ColdFusion? Seriously?

I still feel like the web is so under developed and primitive. Everything that comes along is either a patch or a rigged method to a much larger problem. How can I get my views to stay accurately bound to my models… What if the model changes… Ut oh!

Ok this entry took a very strange turn… I’m just fried.

It’s been a never ending cycle lately with me.

Decide on a framework, or boilerplate my day away…

Should I spend a week trying to figure out how to make commonjs work in the browser? Or spend a week trying to figure out how to use sprockets in a java servlet app?

Should I approach this problem with my own brain? Or scan github’s useless search engine for code that magically solves mine and the worlds problems?

Or maybe I should just make my app work by stringing globs of jquery in my views and focus on delivering my product and live a life regretting I was too tired and lazy to stay relevant.

Or by researching, am I being lazy? Too terrified of the real world of JavaScript to pull the trigger on something and progress?

Am I addicted to preparing to code? Am I so afraid of doing it wrong that I don’t do it at all? Where do I draw the line?

Do I lean on Ember? Or lean on myself with Backbone?

Do I care more about what legacy my code leaves behind me, or what other developers will think of me for how I’ve written it? Do I feel like by taking these extra steps, that someday it will pay off and I’ll stand out in the crowd? Who am I kidding, I’m weaning myself off of jQuery… Am I ahead of the game? Or behind it? Am I above average at what I do? Or below?

What’s the meaning of life?

Okay I’m done.

If you’re still here, I’m sorry!

Hopefully there won’t be many more of these entries… Where is my JavaScript robot?