diff options
Diffstat (limited to 'lib/coderay/encoders')
-rw-r--r-- | lib/coderay/encoders/filter.rb | 16 | ||||
-rw-r--r-- | lib/coderay/encoders/yaml.rb | 32 |
2 files changed, 38 insertions, 10 deletions
diff --git a/lib/coderay/encoders/filter.rb b/lib/coderay/encoders/filter.rb index 6b78ad3..13621ff 100644 --- a/lib/coderay/encoders/filter.rb +++ b/lib/coderay/encoders/filter.rb @@ -15,14 +15,20 @@ module Encoders @out = Tokens.new end - def text_token text, kind - @out.text_token text, kind if include_text_token? text, kind + def include_text_token? text, kind + true end - def include_text_token? text, kind + def include_block_token? action, kind true end + public + + def text_token text, kind + @out.text_token text, kind if include_text_token? text, kind + end + def begin_group kind @out.begin_group kind if include_block_token? :begin_group, kind end @@ -39,10 +45,6 @@ module Encoders @out.end_line kind if include_block_token? :end_line, kind end - def include_block_token? action, kind - true - end - end end diff --git a/lib/coderay/encoders/yaml.rb b/lib/coderay/encoders/yaml.rb index 5564e58..49cf86c 100644 --- a/lib/coderay/encoders/yaml.rb +++ b/lib/coderay/encoders/yaml.rb @@ -11,11 +11,37 @@ module Encoders FILE_EXTENSION = 'yaml' protected - def compile tokens, options + def setup options require 'yaml' - @out = tokens.to_a.to_yaml + @out = [] end - + + def finish options + @out.to_a.to_yaml + end + + public + + def text_token text, kind + @out << [text, kind] + end + + def begin_group kind + @out << [:begin_group, kind] + end + + def end_group kind + @out << [:end_group, kind] + end + + def begin_line kind + @out << [:begin_line, kind] + end + + def end_line kind + @out << [:end_line, kind] + end + end end |