Class: Lydown::Translation::Ripple::NamedMacro
- Inherits:
-
Root
- Object
- Treetop::Runtime::SyntaxNode
- Root
- Lydown::Translation::Ripple::NamedMacro
- Defined in:
- lib/lydown/translation/ripple/nodes.rb
Defined Under Namespace
Classes: Stop
Constant Summary collapse
- PLACE_HOLDERS =
{ '#' => '_', '@' => '@', 'r' => 'r' }
Instance Method Summary collapse
Methods inherited from Root
#_translate, #check_line_break, #source_line
Instance Method Details
#translate(stream, opts) ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/lydown/translation/ripple/nodes.rb', line 166 def translate(stream, opts) check_line_break(stream, opts) macro_name = text_value.sub('$', '') if opts[:macros][macro_name] macro = translate_macro(opts[:macros][macro_name]) stream << "{#{macro}}" opts[:current_macro] = macro opts[:post_macro_value] = nil else raise LydownError, "Could not find named macro #{macro_name}" end end |
#translate_macro(macro) ⇒ Object
185 186 187 188 |
# File 'lib/lydown/translation/ripple/nodes.rb', line 185 def translate_macro(macro) macro.gsub(/([r#@])([0-9\.]*)/) {|m| "#{$2}#{PLACE_HOLDERS[$1]}"}. gsub(' ', '') end |