<commit_before>/**
 * @license
 * Copyright 2015 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 */

CLASS({
  package: 'foam.flow',
  name: 'Section',
  extendsModel: 'View',

  imports: [ 'parentSection' ],
  exports: [ 'as parentSection' ],

  properties: [
    {
      name: 'ordinal',
      defaultValue: ''
    },
    {
      name: 'title'
    },
    {
      model_: 'ViewFactoryProperty',
      name: 'inner'
    },
    {
      model_: 'DAOProperty',
      name: 'subSections',
      view: 'DAOListView',
      factory: function() { return []; }
    }
  ],

  methods: {
    init: function() {
      this.SUPER();
      this.parentSection && this.parentSection.addSubSection(this);
    },

    /** Allow inner to be optional when defined using HTML. **/
    fromElement: function(e) {
      var children = e.children;
      if ( children.length == 1 && children[0].nodeName === 'inner' ) {
        return this.SUPER(e);
      }

      this.inner = e.innerHTML;
      return this;
    },

    addSubSection: function(section) {
      this.subSections.push(section);
      section.ordinal = this.ordinal + this.subSections.length + '.';
    }
  },

  templates: [
    function CSS() {/*
      .flow-section-header {
        font-size: 16px;
        margin-top: 18px;<commit_msg>Fix bug in Section.fromElement() not setting title.<commit_after>/**
 * @license
 * Copyright 2015 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 */

CLASS({
  package: 'foam.flow',
  name: 'Section',
  extendsModel: 'View',

  imports: [ 'parentSection' ],
  exports: [ 'as parentSection' ],

  properties: [
    {
      name: 'ordinal',
      defaultValue: ''
    },
    {
      name: 'title'
    },
    {
      model_: 'ViewFactoryProperty',
      name: 'inner'
    },
    {
      model_: 'DAOProperty',
      name: 'subSections',
      view: 'DAOListView',
      factory: function() { return []; }
    }
  ],

  methods: {
    init: function() {
      this.SUPER();
      this.parentSection && this.parentSection.addSubSection(this);
    },

    /** Allow inner to be optional when defined using HTML. **/
    fromElement: function(e) {
      this.SUPER(e);
      var children = e.children;
      if ( children.length !== 1 || children[0].nodeName !== 'inner' ) {
        this.inner = e.innerHTML;
      }

      return this;
    },

    addSubSection: function(section) {
      this.subSections.push(section);
      section.ordinal = this.ordinal + this.subSections.length + '.';
    }
  },

  templates: [
    function CSS() {/*
      .flow-section-header {
        font-size: 16px;
        margin-top: 18px;
{'fraction_non_alphanumeric': 0.14337508239947264, 'fraction_numerical': 0.00922874093605801, 'mean_word_length': 2.3205689277899344, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1424286', 'n_tokens_mistral': 976, 'n_tokens_neox': 940, 'n_words': 236}