Permalink
Browse files

Support YAML booleans. Mustang now guesses yaml file path if left off.

  • Loading branch information...
1 parent 9e84cd0 commit a9583f2ccc4adc80467f4c0f34d269f830cb2a74 @joshthecoder committed Mar 16, 2010
Showing with 31 additions and 5 deletions.
  1. +4 −0 examples/simple.yaml
  2. +14 −1 mustang/YAMLContext.ooc
  3. +13 −4 mustang/mustang.ooc
View
@@ -0,0 +1,4 @@
+name: Josh
+value: 1,000,000
+taxed_value: 800,000
+in_ca: Yes
View
@@ -34,13 +34,26 @@ YAMLContext: class extends Context {
nodeToValue: static func(node: DocumentNode) -> Value {
match node class {
- case ScalarNode => StringValue new((node as ScalarNode) value)
+ case ScalarNode => scalarToValue(node as ScalarNode)
case SequenceNode => sequenceToListValue(node as SequenceNode)
case MappingNode => mappingToHashValue(node as MappingNode)
case => Exception new("Unknown node type!") throw(); null
}
}
+ scalarToValue: static func(scalar: ScalarNode) -> Value {
+ normalizedValue := scalar value trim() toLower()
+
+ //TODO: boolean detection should be moved into ooc-yaml (datatype detection)
+ match normalizedValue {
+ case "true" => BoolValue new(true)
+ case "yes" => BoolValue new(true)
+ case "false" => BoolValue new(false)
+ case "no" => BoolValue new(false)
+ case => StringValue new(scalar value)
+ }
+ }
+
sequenceToListValue: static func(seq: SequenceNode) -> ListValue {
list := ListValue new()
View
@@ -3,13 +3,22 @@ import structs/ArrayList
import mustang/[Template, YAMLContext]
main: func(args: ArrayList<String>) -> Int {
- if(args size() < 3) {
- "Usage: mustang <TEMPLATE> <YAML>" println()
+ if(args size() < 2) {
+ "Usage: mustang <TEMPLATE> [YAML]" println()
return 1
}
- context := YAMLContext loadFromFile(args[2])
- template := Template loadFromFile(args[1])
+ templateFile := args[1]
+ yamlFile: String
+ if(args size() != 3) {
+ yamlFile = "%s.yaml" format(templateFile substring(0, templateFile lastIndexOf('.')))
+ }
+ else {
+ yamlFile = args[2]
+ }
+
+ context := YAMLContext loadFromFile(yamlFile)
+ template := Template loadFromFile(templateFile)
template render(context) println()
return 0

0 comments on commit a9583f2

Please sign in to comment.