<commit_before>angular.module('sgApp')
  .controller('SectionsCtrl', [
    '$scope', '$stateParams', '$location', '$state', '$rootScope', 'Styleguide',
    function($scope, $stateParams, $location, $state, $rootScope, Styleguide) {

    if ($stateParams.section) {
      $scope.currentSection = $stateParams.section;
      $rootScope.currentSection = $scope.currentSection;
    } else {
      $location.url('overview');
    }

    // Check if section is a main section
    $scope.filterMainSection = function(section) {
      return !/([0-9]\.)/.test(section.reference);
    }

    $rootScope.$watch(function() {
      return Styleguide.sections.data;
    }, function() {
      setPageTitle($scope.currentSection);
    });

    $rootScope.$watch(function() {
      return Styleguide.config.data;
    }, function(l) {
      setPageTitle($scope.currentSection);
    });

    function setPageTitle(section) {
      if (!Styleguide.config.data || !Styleguide.sections.data) {
        return;
      }
      if (section === 'all') {
        $rootScope.pageTitle = 'All sections - ' + Styleguide.config.data.title;
      } else {
        var result = Styleguide.sections.data.filter(function(item) {
          return item.reference === section;
        });
        if (result.length > 0) {
          var element = result[0];
          $rootScope.pageTitle = element.reference + ' ' + element.header + ' - ' + Styleguide.config.data.title
        }
      }
    }

    // Check section level (main/sub/sub-sub/sub-sub-sub)
    $scope.getLevel = function(section) {
      if (/([0-9]\.[0-9]\.[0-9]\.)/.test(section.reference)) {
        return 'sub-sub-sub';
      }
      if (/([0-9]\.[0-9]\.)/.test(section.reference)) {
        return 'sub-sub';
      }
      if (/([0-9]\.)/.test(section.reference)) {
        return 'sub';
      }
      return 'main';
    }

    $scope.getActive = function(section) {
      return section.reference == $rootScope.currentReference.section.reference? 'active' : '';
    }

    $scope.getClass = function(section) {
      return this.getLevel(section) + ' ' + this.getActive(section);
    }

    $scope.filterSection = function(section) {
      if ($scope.currentSection === 'all') return true;
      var re = new RegExp('(^' + $scope.currentSection + '$)|(^' +
        $scope.currentSection + '\\.)');
      return re.test(section.reference);
    }

    $scope.getCommonClass = function() {
      return Styleguide.config.data.commonClass;
    }<commit_msg>Simplify creating sub/sub-sub/sub-sub-sub classes<commit_after>angular.module('sgApp')
  .controller('SectionsCtrl', [
    '$scope', '$stateParams', '$location', '$state', '$rootScope', 'Styleguide',
    function($scope, $stateParams, $location, $state, $rootScope, Styleguide) {

    if ($stateParams.section) {
      $scope.currentSection = $stateParams.section;
      $rootScope.currentSection = $scope.currentSection;
    } else {
      $location.url('overview');
    }

    // Check if section is a main section
    $scope.filterMainSection = function(section) {
      return !/([0-9]\.)/.test(section.reference);
    }

    $rootScope.$watch(function() {
      return Styleguide.sections.data;
    }, function() {
      setPageTitle($scope.currentSection);
    });

    $rootScope.$watch(function() {
      return Styleguide.config.data;
    }, function(l) {
      setPageTitle($scope.currentSection);
    });

    function setPageTitle(section) {
      if (!Styleguide.config.data || !Styleguide.sections.data) {
        return;
      }
      if (section === 'all') {
        $rootScope.pageTitle = 'All sections - ' + Styleguide.config.data.title;
      } else {
        var result = Styleguide.sections.data.filter(function(item) {
          return item.reference === section;
        });
        if (result.length > 0) {
          var element = result[0];
          $rootScope.pageTitle = element.reference + ' ' + element.header + ' - ' + Styleguide.config.data.title
        }
      }
    }

    // Check section level (main/sub/sub-sub/sub-sub-sub)
    $scope.getLevel = function(section) {
      if (/([0-9]\.)/.test(section.reference)) {
        return section.reference.split('.').map(function(i){
          return 'sub'
        }).join('-').substring(4);
      }
      return 'main';
    }

    $scope.getActive = function(section) {
      return section.reference == $rootScope.currentReference.section.reference? 'active' : '';
    }

    $scope.getClass = function(section) {
      return this.getLevel(section) + ' ' + this.getActive(section);
    }

    $scope.filterSection = function(section) {
      if ($scope.currentSection === 'all') return true;
      var re = new RegExp('(^' + $scope.currentSection + '$)|(^' +
        $scope.currentSection + '\\.)');
      return re.test(section.reference);
    }

    $scope.getCommonClass = function() {
      return Styleguide.config.data.commonClass;
    }
{'fraction_non_alphanumeric': 0.16822810590631365, 'fraction_numerical': 0.004684317718940937, 'mean_word_length': 2.5768390386016025, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1989328', 'n_tokens_mistral': 1523, 'n_tokens_neox': 1523, 'n_words': 244}