the blog of joshua rountree

Share your local CFML dev site to your colleagues with Forward

Share your local CFML dev site to your colleagues with Forward

Let’s say you’ve started a new CFML app project in your ~/Projects/my_cfml_project directory.

You’re in Terminal (or Cygwin on windows) and have a version of Ruby / RubyGems installed on your system.

On Mac OS X and most Linux distributions, Ruby / RubyGems is already installed.
For Windows Ruby Installations, you can follow this guide on Forwardhq.com

Assuming you’ve done all that, however…

You’ve already defined a Railo CFML version for your project with cfenv of course… ;)

The Problem

But you have a problem that has came up…
You would LOVE to send your boss and colleague a link to your LOCAL codebase as it exists right now to show them.
If you send them your current URL at http://localhost:8888/my_awesome_file.cfm they will get nothing but nothing.

So… that’s where Forward comes in.

Open up another Terminal Window / Tab or Console screen.

Install Forward with RubyGems

Getting Forward on a system is so easy with RubyGems.

$ gem install forward

Or with sudo gem install forward if you need permissions.

Tunneling your CF / Railo site with Forward

Now that it’s installed, you can use it to give your colleagues web access to your working directory.

Make sure you’re in your project directory.

$ cd ~/Projects/my_cfml_project
$ forward 8888
Forwarding port 8888 to [https://yourcompany.fwd.wf][8]
Ctrl-C to stop forwarding

It’s even under an SSL, awesome right?

But what if my web app has subdomains like http://johnsmith.localhost.dev/?
Well, Forward handles that out of the box too!
Simply go to https://johnsmith.yourcompany.fwd.wf/.

That’s it!

I think it is so awesome that there are niche services out there to make our lives as web developers even better than it already is.

Let me know if you use this technique on a project!

Developing a Mura CMS v6 site locally with cfenv!

Developing a Mura CMS v6 site locally with cfenv!

I want to start by saying… I’ve been using cfenv for my projects now for the past two days and am loving it tremendously. It’s so nice to not have to worry about downloading and configuring railo express versions for each and every app I’m running. I can choose which version of Railo I want to run on a per-project basis or globally for the entire system. Anyway…

Expectations

Let’s get started.

We’re going to open up Terminal (or cygwin on Windows)

Install a Railo Version with CFENV

Let’s install a version of Railo globally (if you haven’t already done so in a previous installation guide).
Going to start by listing out the available versions since I cannot remember what my options are…

$ cfenv install -l
Available versions:
  3.0.2.001
  3.0.3.000
  3.3.3.001
  4.0.4.001
  4.1.1.000
  4.1.1.009

Let’s go with the latest (4.1.1.009)

$ cfenv install 4.1.1.009

Our Project Directory

Create our project directory if we don’t already have it and change into that directory.

$ mkdir -p ~/Projects/my_mura_project
$ cd ~/Projects/my_mura_project

Let’s set our local project directory Railo version to 4.1.1.009 for good measure.
This will ensure our mura project always runs in our consistent Railo 4.1.1.009 because that’s what this particular cms will be running in production.

$ cfenv local 4.1.1.009

Download Mura CMS v6

Now, we still have an empty project directory.
Let’s download and extract the latest Mura CMS version.

$ curl -L --output muracms.zip http://getmura.com/currentversion/
$ tar -zxvf muracms.zip

For good measure, we will remove the muracms.zip file.

$ rm muracms.zip

Create a Database

You’re going to need a database / datasource for Mura to work correctly so open up MySQL or your favorite SQL database system and create one now.
Don’t worry… I’ll wait…

Once you’ve done that, make sure you know the db name, server, user, and password of the database so we can create the datasource.

Run Railo

Now let’s start the Railo server to begin developing our new project.

$ railo_init

Create Datasource

Open up Railo’s Admin Panel in your web browser. http://localhost:8888/railo-context/admin/web.cfm

Setup a password for this web context since it’s your first time running.
Make it easy so you don’t have to sweat it later… this is only development after all.

Click on Datasource on the left menu under Services.

create the datasource

Proceed with giving it a name, and type.
Click create.
Then finish setting it up by entering the server, db name, username, and password of the database in their respective fields and then save & verify it.

Finish Mura Setup

Browse to your webroot at http://localhost:8888/ and fill in the form with the settings above.
You only need to enter the Datasource Name, Super Admin User, Super Admin Password, and Admin Email.
Click ‘Save Settings’

Now click ‘Login to Mura’

Enter your Super Admin Username / Password if you changed it from the default.
Otherwise, it’s:

  • Username: admin
  • Password: admin

Shutting down the app

When you are finished developing for the day, you can CTRL+C on the Terminal window that is running Railo.
This should shut everything down and clear your RAM / CPU.

You’re all set!
Enjoy!

Installing CFENV on Ubuntu

Installing CFENV on Ubuntu

On Ubuntu, it is necessary to use the Git / GitHub method for installation.

1.) Install Git

$ sudo apt-get install git

You should already have Git though, RIGHT??!?

2.) Install Dependencies for legacy Railo versions.

Are you running 64bit version of Ubuntu? Please verify these dependencies are installed first by typing:

$ sudo apt-get install libc6-i386 lib32gcc1 lib32z1 lib32stdc++6

3.) Install CFENV Check out cfenv into ~/.cfenv.

$ git clone https://github.com/joshuairl/cfenv.git ~/.cfenv

Add ~/.cfenv/bin to your $PATH for access to the cfenv command-line utility.

$ echo 'export PATH="$HOME/.cfenv/bin:$PATH"' >> ~/.bash_profile Add

cfenv init to your shell to enable shims and autocompletion.

$ echo 'eval "$(cfenv init -)"' >> ~/.bash_profile

Restart your shell so that PATH changes take effect. (Opening a new terminal tab will usually do it.)

Now check if cfenv was set up:

$ type cfenv // "cfenv is a function"

Upgrading CFENV

If you’ve installed cfenv manually using git, you can upgrade your installation to the cutting-edge version at any time.

$ cd ~/.cfenv
$ git pull

To use a specific release of cfenv, check out the corresponding tag:

$ cd ~/.cfenv
$ git fetch
$ git checkout v0.0.6

Using CFENV on a New Project

If you just now have a fresh installation of cfenv then you will need to install a Railo version.

$ cfenv install 4.1.1.009

I personally store all my working projects in a directory called ~/Projects

$ mkdir -p ~/Projects/my_new_cfml_project $ cd ~/Projects/my_new_cfml_project

Let’s set this project’s Railo Version to 4.1.1.009.

$ cfenv local 4.1.1.009

Now let’s create a little test cfml file so we have some output when we start our server.

<cfscript> 
writeOutput('Hello, from your new cfenv context!!!'); 
writeDump(SERVER); 
</cfscript>

Save that file as index.cfm. Now we need to startup our server.

$ railo_init

Visit http://localhost:8888/ in your browser.

With any luck, you should see your test cfml file we created nicely printing out. That’s really all there is to it…

Find more information at: https://github.com/joshuairl/cfenv

Installing CFENV on Mac OS X

Installing CFENV on Mac OS X

Using Homebrew

The first and most common way to install is using Homebrew.

If you don’t know what Homebrew is, visit http://brew.sh/.

I won’t be covering installation of Homebrew in this article.

That being said…

Open up Terminal.app and run the following commands.

$ brew tap joshuairl/homebrew-cfenv 
$ brew update 
$ brew install cfenv

Using Git / GitHub

This will get you going with the latest version of cfenv and make it easy to fork and contribute any changes back upstream. Anyway, we start by installing Git if we don’t already have it. You can do this with homebrew via

brew install git or by downloading Xcode w/ Command Line Tools (recommended). But I’m not going to cover how to do that here.

  1. Check out cfenv into ~/.cfenv.
$ git clone https://github.com/joshuairl/cfenv.git ~/.cfenv
  1. Add ~/.cfenv/bin to your $PATH for access to the cfenv command-line utility.
$ echo 'export PATH="$HOME/.cfenv/bin:$PATH"' >> ~/.bash_profile
  1. Add cfenv init to your shell to enable shims and autocompletion.
$ echo 'eval "$(cfenv init -)"' >> ~/.bash_profile
  1. Restart your shell so that PATH changes take effect. (Opening a new terminal tab will usually do it.) Now check if cfenv was set up:
$ type cfenv // "cfenv is a function"

Upgrading CFENV

If you’ve installed cfenv manually using git, you can upgrade your installation to the cutting-edge version at any time.

$ cd ~/.cfenv
$ git pull

To use a specific release of cfenv, check out the corresponding tag:

$ cd ~/.cfenv
$ git fetch
$ git checkout v0.0.6

If you’ve installed via Homebrew, then upgrade via its brew command:

$ brew update
$ brew upgrade cfenv

That’s all there is to it!

For usage information and additional installation tips and steps visit

https://github.com/joshuairl/cfenv#groom-your-apps-cfml-dev-environment-with-cfenv

Dead Simple CFML Dev Environments with CFENV

Dead Simple CFML Dev Environments with CFENV

UPDATE!! 11/06/2013 Read First. 
I just updated this article to reflect some of the 
latest changes made to cfenv. 
Please refer to the README at 
<https://github.com/joshuairl/cfenv> for more complete information.
 If you have ever worked with Ruby on Rails, you know just now simple it is to spin up a new application and server to start developing. Well, due to CFML being Java based... it has loads more to do to startup and handle on the server-side. 

Some History

For awhile, I’ve been working with Railo as my development environment on my Mac. More specifically, Railo Express with Jetty and utilizing the “railo_runner” technique described on Mark Drew’s blog. If you are not familiar with that technique, it’s KIND OF similar to Rails in the sense that you can

mkdir ~/Projects/my_new_project in Terminal, then cd ~/Projects/my_new_project, and then railo_runner and it will place a WEB-INF directory and startup Jetty with Railo Express pointing to that directory. It’s creating a new WEB CONTEXT for this particular directory. It’s beautiful. You do not have to create manual entries in server.xml of Tomcat, or host your code within the webapps directory. It’s nice as is. But I wanted to make it a little better… That’s where railoenv comes in.

What is cfenv?

The railo_runner technique is awesome. But it does require some configuration initially which can get in the way of developing CFML if you’re on a new computer somewhere without Railo. I’ve decided to automate the download/install/configuration of Railo Express & railo_runner into one package and I’m calling it cfenv. The END goal is for this to be very similar in logic to rbenv and nodenv respectively.

Will it conflict with my Adobe ColdFusion and/or prior Railo installations and setups?

No, it won’t. cfenv is self contained and downloads it’s own copy of Railo Express with Jetty and maintains it for you.

How to use cfenv?

First, install cfenv. To do so, follow the instructions found at: https://github.com/joshuairl/cfenv#installation Once you’ve installed it, you will need to use cfenv to install a version of Railo.

$ cfenv install 4.1.1.009

  (which at this time is the latest version) Now we want to set this version to be used in all shells globally.

$ cfenv global 4.1.1.009

To test, create a new directory in your Sites / Projects directory… Mine are found in ~/Projects so that’s what I’ll use in my example.

$ mkdir -p ~/Projects/my_cfml_project 

And change into that directory…

$ cd ~/Projects/my_cfml_project

Now, we initialize a new railo context within the directory…

$ railo_init

You should now see output similar to the following…

mccme-rountrjf:my_cfml_project joshua$ railo_init
WARNING: System properties and/or JVM args set.  Consider using --dry-run or --exec
[ShutdownMonitor] STOP.PORT=8887
[ShutdownMonitor] STOP.KEY=railo
[ShutdownMonitor] ServerSocket[addr=/127.0.0.1,port=0,localport=8887]
Starting ShutdownMonitorThread
railo-server-root:/opt/railo/lib/ext/railo-server
Fri Nov 01 12:28:58 EDT 2013 Load Build in Core
===================================================================
SERVER CONTEXT
-------------------------------------------------------------------
- config:/opt/railo/lib/ext/railo-server/context
- loader-version:4.2
===================================================================

Fri Nov 01 12:28:58 EDT 2013-807 using JRE Date Library
Fri Nov 01 12:28:58 EDT 2013-831 write file:/opt/railo/lib/ext/railo-server/context/railo-server.xml
Fri Nov 01 12:28:59 EDT 2013-514 write file:/opt/railo/lib/ext/railo-server/context/library/tag/Dump.cfc
Fri Nov 01 12:28:59 EDT 2013-514 write file:/opt/railo/lib/ext/railo-server/context/library/tag/MediaPlayer.cfc

...

===================================================================

WEB CONTEXT (26e8ec2748b7d9a30de915bf6b5d1e3f)
-------------------------------------------------------------------
- config:/Users/joshua/Projects/my_cfml_project/WEB-INF/railo
- webroot:/Users/joshua/Projects/my_cfml_project
- hash:26e8ec2748b7d9a30de915bf6b5d1e3f
- label:26e8ec2748b7d9a30de915bf6b5d1e3f
===================================================================
Fri Nov 01 12:29:00 EDT 2013-5 write file:/Users/joshua/Projects/my_cfml_project/WEB-INF/railo/railo-web.xml.cfm
Fri Nov 01 12:29:00 EDT 2013-12 write file:/Users/joshua/Projects/my_cfml_project/WEB-INF/railo/locales/pt-PT-date.df
Fri Nov 01 12:29:00 EDT 2013-13 write file:/Users/joshua/Projects/my_cfml_project/WEB-INF/railo/video/video.xml

...

Your new web context is now running at http://localhost:8888/

Let’s create a test file for our context to load. Open up your favorite CFML Editor and add the

my_cfml_project directory to it as a new project.

Create a new file called index.cfm

Add something along these lines to the file for kicks…

<cfscript>
writeOutput('Hello, from your new cfenv context!!!'); 
writeDump(SERVER); 
</cfscript>   

Save it, and refresh http://localhost:8888/ and you should see something beautiful. :D Let me know if you guys try it. You can contribute bug reports, code, etc. at https://github.com/joshuairl/cfenv

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…

Path.resolve()

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:

#GetDirectoryFromPath(GetDirectoryFromPath(GetDirectoryFromPath(GetCurrentTemplatePat())#

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.

Path.relative()

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.

Path.join()

Join is a very useful function.

It’s about the equivalent of the following:

<cfset myPaths = [
   '/Users\rountrjf\',
   '/Projects',
   '\my_cool_app',
   '/test',
   '..'
] />

<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:
https://github.com/foundrycf/foundry/blob/master/doc/path.markdown

Modular ColdFusion with Foundry

What is it?

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

Preface

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”.

#!javascript
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",
  "description":"",
  "version": "0.0.1",
  "main":"./lib/main",
  "author": "Joshua F. Rountree",
  "dependencies":{
    "UnderscoreCF":"~>0.0.0"
  }
}

or

“`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": [
    "cli",
    "http",
    "server"
  ], //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.

```javascript
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!

Instructions

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
<?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>
</Configure>

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!

Issues

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.

#!ruby
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>"
      end

      if str.match(/\A( {4}|\t)/)
        str = str.gsub(/^( {4}|\t)/, '')
      end
      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"
      else
        if @lang.include? "-raw"
          raw = "``` #{@options.sub('-raw', '')}\n"
          raw += str
          raw += "\n```\n"
        else
          code = highlight(str, @lang)
          "<figure class='code'>#{@caption}#{code}</figure>"

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

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?

#!ruby
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
      end

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

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.

1 of 2
12