<commit_before>require 'erb'
require 'java'

class JRubyJellyScriptImpl < org::kohsuke::stapler::jelly::jruby::JRubyJellyScript
  def initialize(template)
    super()
    @template = ERB.new(template,nil,nil,"self.output")
  end

  def run(jelly_context,xml_output)
    JRubyContext.new(self,jelly_context,xml_output).evaluate_template(@template)
  end

  class JRubyContext
    include org::kohsuke::stapler::jelly::jruby::IJRubyContext

    attr_accessor :context,:xml,:script

    def initialize(script,context,xml)
      @script = script
      @context = context
      @xml = xml
    end

    def evaluate_template(erb)
      erb.run(WriterBinding.new(self).instance_eval{binding})
    end

    def getJellyContext()
      @context;
    end

    def setJellyContext(context)
      @context = context
    end

    def getOutput()
      @output
    end

    def setOutput(output)
      @output = output
    end
  end

  # variables exposed to ERB
  class WriterBinding
    attr_reader :output

    def initialize(context)
      @output = self
      @context = context
    end

    def output=(_)
      # ignoring the assignment, because we want our concat method to be invoked
    end

    def context()
      @context.context
    end

      # this is where we handle all the variable references
    def method_missing(name,*args)
      # variables defined in the current context
      v = context.getVariable(name.to_s)
      return v if v!=nil

      # TODO: how do I report an error that we didn't understand this?
      nil
    end

    # load taglib
    def taglib(uri)
      # TODO: cache
      Taglib.new(@context,uri)
    end

    # ERB calls this method every time it wants to write some string
    def concat(str)
      @context.xml.write(str) if str!=nil
    end
  end

  # receives tag invocations as method calls
  class Taglib
    def initialize(context,uri)
      @context = context
      @uri = uri
    end

    # this is the actual taglib invocation like f.entry(:a => b, :c => d)
    def method_missing(name,*args,&block)
      @context.script.invokeTaglib(@context, @context.context, @context.xml, @uri, name.to_s, args[0], block)
    end
  end
end

<commit_msg>cowboyd told me that this is how you make it fail<commit_after>require 'erb'
require 'java'

class JRubyJellyScriptImpl < org::kohsuke::stapler::jelly::jruby::JRubyJellyScript
  def initialize(template)
    super()
    @template = ERB.new(template,nil,nil,"self.output")
  end

  def run(jelly_context,xml_output)
    JRubyContext.new(self,jelly_context,xml_output).evaluate_template(@template)
  end

  class JRubyContext
    include org::kohsuke::stapler::jelly::jruby::IJRubyContext

    attr_accessor :context,:xml,:script

    def initialize(script,context,xml)
      @script = script
      @context = context
      @xml = xml
    end

    def evaluate_template(erb)
      erb.run(WriterBinding.new(self).instance_eval{binding})
    end

    def getJellyContext()
      @context;
    end

    def setJellyContext(context)
      @context = context
    end

    def getOutput()
      @output
    end

    def setOutput(output)
      @output = output
    end
  end

  # variables exposed to ERB
  class WriterBinding
    attr_reader :output

    def initialize(context)
      @output = self
      @context = context
    end

    def output=(_)
      # ignoring the assignment, because we want our concat method to be invoked
    end

    def context()
      @context.context
    end

      # this is where we handle all the variable references
    def method_missing(name,*args)
      # variables defined in the current context
      v = context.getVariable(name.to_s)
      return v if v!=nil

      super # make it fail
    end

    # load taglib
    def taglib(uri)
      # TODO: cache
      Taglib.new(@context,uri)
    end

    # ERB calls this method every time it wants to write some string
    def concat(str)
      @context.xml.write(str) if str!=nil
    end
  end

  # receives tag invocations as method calls
  class Taglib
    def initialize(context,uri)
      @context = context
      @uri = uri
    end

    # this is the actual taglib invocation like f.entry(:a => b, :c => d)
    def method_missing(name,*args,&block)
      @context.script.invokeTaglib(@context, @context.context, @context.xml, @uri, name.to_s, args[0], block)
    end
  end
end


{'fraction_non_alphanumeric': 0.0890064397424103, 'fraction_numerical': 0.00045998160073597056, 'mean_word_length': 2.821616871704745, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 16}, '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': '6081311', 'n_tokens_mistral': 1404, 'n_tokens_neox': 1328, 'n_words': 383}