<commit_before>module Nyanko
  class Function
    attr_reader :block, :unit, :label

    class << self
      def units
        @units ||= []
      end

      def current_unit
        units.last
      end
    end

    def initialize(unit, label, &block)
      @unit  = unit
      @label = label
      @block = block
    end

    def invoke(context, options = {})
      with_unit_stack(context) do
        with_unit_view_path(context) do
          context.instance_eval(&block)
        end
      end
    end

    def css_classes
      if Config.compatible_css_class
        %W[
          extension
          ext_#{unit.name.underscore}
          ext_#{unit.name.underscore}-#{label}
        ]
      else
        %W[
          unit
          unit__#{unit.name.underscore}
          unit__#{unit.name.underscore}__#{label}
        ]
      end
    end

    private

    def with_unit_stack(context)
      context.units << @unit
      self.class.units << @unit
      yield
    ensure
      self.class.units.pop
      context.units.pop
    end

    def with_unit_view_path(context)
      if context.view?
        origin = context.view_paths
        context.view_paths.unshift unit.view_path
      end
      yield
    ensure
      context.view_paths = origin if context.view?
    end
  end
end<commit_msg>Fix view_paths error that all view_paths are remained<commit_after>module Nyanko
  class Function
    attr_reader :block, :unit, :label

    class << self
      def units
        @units ||= []
      end

      def current_unit
        units.last
      end
    end

    def initialize(unit, label, &block)
      @unit  = unit
      @label = label
      @block = block
    end

    def invoke(context, options = {})
      with_unit_stack(context) do
        with_unit_view_path(context) do
          context.instance_eval(&block)
        end
      end
    end

    def css_classes
      if Config.compatible_css_class
        %W[
          extension
          ext_#{unit.name.underscore}
          ext_#{unit.name.underscore}-#{label}
        ]
      else
        %W[
          unit
          unit__#{unit.name.underscore}
          unit__#{unit.name.underscore}__#{label}
        ]
      end
    end

    private

    def with_unit_stack(context)
      context.units << @unit
      self.class.units << @unit
      yield
    ensure
      self.class.units.pop
      context.units.pop
    end

    def with_unit_view_path(context)
      if context.view?
        context.view_paths.unshift unit.view_path
      end
      yield
    ensure
      context.view_paths.paths.unshift if context.view?
    end
  end
end
{'fraction_non_alphanumeric': 0.08029197080291971, 'fraction_numerical': 0.0, 'mean_word_length': 1.729559748427673, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 3, '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': '4189719', 'n_tokens_mistral': 802, 'n_tokens_neox': 791, 'n_words': 175}