<commit_before>module Tanuki

  # Tanuki::TemplateCompiler is used for, well, compiling templates.
  class TemplateCompiler

    class << self

      # Compiles a template from a given +src+ string to +ios+ for method +sym+ in class +klass+.
      def compile_template(ios, src, klass, sym)
        ios << "# encoding: #{src.encoding}\nclass #{klass}\ndef #{sym}_view(*args,&block)\nproc do|_,ctx|\n" \
          "if _has_tpl ctx,self.class,:#{sym}\nctx=_ctx(ctx)"
        last_state = compile(ios, src)
        ios << "\n_.('',ctx)" unless PRINT_STATES.include? last_state
        ios << "\nelse\n(_run_tpl ctx,self,:#{sym},*args,&block).(_,ctx)\nend\nend\nend\nend"
      end

      # Compiles code from a given +src+ string to +ios+.
      def compile(ios, src)
        state = :outer
        last_state = nil
        index = 0
        trim_newline = false<commit_msg>Added tag examples to TemplateCompiler docs<commit_after>module Tanuki

  # Tanuki::TemplateCompiler is used for, well, compiling templates.
  #
  # Tanuki templates are text (or HTML) files with an extended tag syntax.
  # ERB syntax is forward compatible with Tanuki template syntax.
  #
  # The following tags are recognized:
  #
  #   <% Ruby code -- output to stdout %>
  #   <% Ruby expression -- replace with result %>
  #   <%# comment -- ignored -- useful in testing %>
  #   % a line of Ruby code -- treated as <% line %>
  #   %% replaced with % if first thing on a line
  #   <%% or %%> -- replace with <% or %> respectively
  #   <%! Ruby expression -- must return a template %> -- renders a template
  #   <%_visitor Ruby code %> -- see Tanuki::Application::visitor for details
  #   <l10n><en>English text</en> ... -- other localizations </l10n>
  class TemplateCompiler

    class << self

      # Compiles a template from a given +src+ string to +ios+ for method +sym+ in class +klass+.
      def compile_template(ios, src, klass, sym)
        ios << "# encoding: #{src.encoding}\nclass #{klass}\ndef #{sym}_view(*args,&block)\nproc do|_,ctx|\n" \
          "if _has_tpl ctx,self.class,:#{sym}\nctx=_ctx(ctx)"
        last_state = compile(ios, src)
        ios << "\n_.('',ctx)" unless PRINT_STATES.include? last_state
        ios << "\nelse\n(_run_tpl ctx,self,:#{sym},*args,&block).(_,ctx)\nend\nend\nend\nend"
      end

      # Compiles code from a given +src+ string to +ios+.
      def compile(ios, src)
        state = :outer
        last_state = nil
        index = 0
        trim_newline = false
{'fraction_non_alphanumeric': 0.13924558587479935, 'fraction_numerical': 0.002407704654895666, 'mean_word_length': 2.788753799392097, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1662304', 'n_tokens_mistral': 802, 'n_tokens_neox': 771, 'n_words': 237}