Method: AutoStacker24::Preprocessor.interpolate
- Defined in:
- lib/autostacker24/template_preprocessor.rb
.interpolate(s) ⇒ Object
interpolates a string with ‘@’ expressions and returns a string or a hash it implements the following non context free grammar in pseudo antlr3
string : RAW? (expr RAW?)*; expr : ‘@’ ‘name (attr+ | map)? ‘’?; name : ID (‘::’ ID)?; attr : (‘.’ ID)+; map : ‘[’ key (‘,’ key)? ‘]’; key : ID | expr; ID : [a-zA-Z0-9]+; RAW : (~[‘@’]* | FILE)=; FILE : ‘@file://’ [^@\s]+ (‘@’ | ‘ ’); FILE_C : ‘@[^] ‘}’;
93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/autostacker24/template_preprocessor.rb', line 93 def self.interpolate(s) parts = [] while s.length > 0 raw, s = parse_raw(s) parts << raw unless raw.empty? expr, s = parse_expr(s) parts << expr if expr end case parts.length when 0 then '' when 1 then parts[0] else {'Fn::Join' => ['', parts]} end end |