After a little server configuration, it's easy to turn YAML text in a file into a ColdFusion structure.
I'm using JYaml as my YAML parsing library, but other options are available. Unfortunately, JYaml requires Java 5, which is not the standard ColdFusion operating environment. To remedy this, download a Java 5 JRE and follow Ben Forta's concise directions. Don't forget to put the JYaml jar file in your classpath and restart your ColdFusion server.
Assuming your .cfm file and .yaml file are in the same directory, creating a ColdFusion structure out of it is a easy as:
<cfscript>
Yaml = CreateObject("java", "org.ho.yaml.Yaml");
configFile = CreateObject("java", "java.io.File").init(ExpandPath('.')&"/settings.yaml");
settings = Yaml.load(configFile);
</cfscript>
Dumping the "settings" variable reveals exactly the structure you were expecting.
One caveat: you may experience unexpected behavior when trying to access your struct's properties using dot notation. Instead, use the "associative array" with square brackets option.
So do this:
value = settings['credentials']['username']
not this:
value = settings.credentials.username
1 comments:
BLOGGER
LAMBL
Post a Comment