Use YAML with variables

前端 未结 5 1030
你的背包
你的背包 2020-11-28 22:47

Are variables within YAML files possible? For example:

theme:
  name: default
  css_path: compiled/themes/$theme.name
  layout_path: themes/$theme.name
         


        
5条回答
  •  悲哀的现实
    2020-11-28 23:21

    if your requirement is like parsing an replacing multiple variable and then use it as a hash/or anything then you can do something like this

    require 'yaml'
    require 'json'
    yaml = YAML.load_file("xxxx.yaml")
    blueprint = yaml.to_json % { var_a: "xxxx", var_b: "xxxx"}
    hash = JSON.parse(blueprint)
    

    inside the yaml just put variables like this

    "%{var_a}"
    

提交回复
热议问题