<commit_before>/**
 * @license
 * Copyright 2013 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
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */



MODEL({
  name: 'DocPropertiesView',
  extendsModel: 'View',
  help: 'Displays the documentation of the given Properties.',

  properties: [
    {
      name:  'data',
      help: 'The model whose properties to view.',
      postSet: function(old, data) {
        if (old) Events.unfollow(old.properties$, this.dao$);
        Events.follow(data.properties$, this.dao$);
        this.updateHTML();
      }
    },
    {
      name:  'dao',
      model_: 'DAOProperty',
      postSet: function() {
        this.filteredDAO = this.dao.where(EQ(Property.HIDDEN, FALSE));

        this.filteredDAO.select(COUNT())(function(c) {
          this.isEmpty = c.count <= 0;
        }.bind(this));

      }
    },
    {
      name:  'filteredDAO',
      model_: 'DAOProperty'
    },
    {
      name: 'isEmpty',
      defaultValue: true,
      postSet: function(_, nu) {
        this.updateHTML();
      }
    }
  ],

  templates: [
    function toInnerHTML()    {/*
    <%    this.destroy();
          if (this.isEmpty) { %>
            <h2>No Properties.</h2>
    <%    } else { %>
            <h2>Properties:</h2>
            <div>$$filteredDAO{ model_: 'DAOListView', rowView: 'DocPropertyRowView', data: this.filteredDAO, model: Property }</div>
    <%    } %>
    */}
  ],

});

MODEL({
  name: 'DocPropertyRowView',
  extendsModel: 'DocBodyView',

  templates: [
    function toInnerHTML() {/*
      <h3><%=this.data.name%></h3>
      <%=this.renderDocSourceHTML()%>
    */}
  ]
});


MODEL({
  name: 'DocBodyView',
  extendsModel: 'View',
  label: 'Documentation Body View Base',
  help: 'Base Model for documentation body-text views.',

  properties: [
    {
      name: 'data',
      help: 'The model or feature from which to extract documentation.',
      required: true,
      preSet: function(old, nu) {
        if (old && Documentation.isInstance(old.documentation)) {
          Events.unfollow(old.documentation$, this.docSource$);
        }
        return nu;
      },
      postSet: function() {
        // grab the documentation and compile a template to use in this view
        if (this.data && Documentation.isInstance(this.data.documentation)) {
          // bind docSource
          Events.follow(this.data.documentation$, this.docSource$);
        }
      }
    },
    {
      name: 'docSource',
      type: 'Documentation',
      help: 'The documentation object to render.',
      postSet: function() {
        this.updateHTML();
      }
    },
  ],

  methods: {
    init: function() {
      this.SUPER();
      if (!this.X.documentViewParentModel) {
        console.log("*** Warning: DocView ",this," can't find documentViewParentModel in its context "+this.X.NAME);
      }
    },

    renderDocSourceHTML: function() {
      // only update if we have all required data
      if (this.docSource.body && this.X.documentViewParentModel
          && this.X.documentViewParentModel.model_ && this.data.model_) {
        // The first time this method is hit, replace it with the one that will
        // compile the template, then call that. Future calls go direct to lazyCompile's
        // returned function. You could also implement this the same way lazyCompile does...
        this.renderDocSourceHTML = TemplateUtil.lazyCompile(this.docSource.body);
        return this.renderDocSourceHTML();
      } else {
        return ""; // no data yet
      }
    },

    /** Create the special reference lookup sub-view from property info. **/
    createReferenceView: function(opt_args) {
      var X = ( opt_args && opt_args.X ) || this.X; // TODO: opt_args should have ref and text auto-set on the view?
      var v = X.DocRefView.create({ ref:opt_args.ref, text: opt_args.text, args: opt_args});
      this.addChild(v);
      return v;
    },

    createTemplateView: function(name, opt_args) {
      // name has been constantized ('PROP_NAME'), but we're
      // only looking for certain doc tags anyway.
      if (name === 'DOC') {
        var v = this.createReferenceView(opt_args);
        return v;
      } else {
        return this.SUPER(name, opt_args);
      }
    }
  }
});


MODEL({
  name: 'DocModelBodyView',
  extendsModel: 'DocBodyView',
  label: 'Documentation Model View',
  help: 'Shows the documentation body for a Model.',

  properties: [
    {
      name: 'data',
      help: 'The Model from which to extract documentation.',
      postSet: function() {
        this.X[this.model_.extendsModel].DATA.postSet.call(this); // TODO: implement this.SUPER() for these
        this.parentModel = this.data;
      }
    },

  ],

  templates: [
    function toInnerHTML()    {/*
      <%    this.destroy(); %>
      <%    if (this.data) {  %>
              <h1><%=this.data.name%></h1>
              <%=this.renderDocSourceHTML()%>
      <%    } %>
    */}
  ],

});

MODEL({
  name: 'DocFeatureBodyView',
  extendsModel: 'DocBodyView',
  label: 'Documentation Feature View',
  help: 'Shows documentation body for a feature of a Model.',

  // You must set both data and parentModel

  templates: [
    function toInnerHTML()    {/*
      <%    this.destroy(); %>
      <%    if (this.data) {  %>
              <h2><%=this.data.name%></h2>
              <%=this.renderDocSourceHTML()%><commit_msg>Fixed dupe title in DocModelBodyView<commit_after>/**
 * @license
 * Copyright 2013 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
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */



MODEL({
  name: 'DocPropertiesView',
  extendsModel: 'View',
  help: 'Displays the documentation of the given Properties.',

  properties: [
    {
      name:  'data',
      help: 'The model whose properties to view.',
      postSet: function(old, data) {
        if (old) Events.unfollow(old.properties$, this.dao$);
        Events.follow(data.properties$, this.dao$);
        this.updateHTML();
      }
    },
    {
      name:  'dao',
      model_: 'DAOProperty',
      postSet: function() {
        this.filteredDAO = this.dao.where(EQ(Property.HIDDEN, FALSE));

        this.filteredDAO.select(COUNT())(function(c) {
          this.isEmpty = c.count <= 0;
        }.bind(this));

      }
    },
    {
      name:  'filteredDAO',
      model_: 'DAOProperty'
    },
    {
      name: 'isEmpty',
      defaultValue: true,
      postSet: function(_, nu) {
        this.updateHTML();
      }
    }
  ],

  templates: [
    function toInnerHTML()    {/*
    <%    this.destroy();
          if (this.isEmpty) { %>
            <h2>No Properties.</h2>
    <%    } else { %>
            <h2>Properties:</h2>
            <div>$$filteredDAO{ model_: 'DAOListView', rowView: 'DocPropertyRowView', data: this.filteredDAO, model: Property }</div>
    <%    } %>
    */}
  ],

});

MODEL({
  name: 'DocPropertyRowView',
  extendsModel: 'DocBodyView',

  templates: [
    function toInnerHTML() {/*
      <h3><%=this.data.name%></h3>
      <%=this.renderDocSourceHTML()%>
    */}
  ]
});


MODEL({
  name: 'DocBodyView',
  extendsModel: 'View',
  label: 'Documentation Body View Base',
  help: 'Base Model for documentation body-text views.',

  properties: [
    {
      name: 'data',
      help: 'The model or feature from which to extract documentation.',
      required: true,
      preSet: function(old, nu) {
        if (old && Documentation.isInstance(old.documentation)) {
          Events.unfollow(old.documentation$, this.docSource$);
        }
        return nu;
      },
      postSet: function() {
        // grab the documentation and compile a template to use in this view
        if (this.data && Documentation.isInstance(this.data.documentation)) {
          // bind docSource
          Events.follow(this.data.documentation$, this.docSource$);
        }
      }
    },
    {
      name: 'docSource',
      type: 'Documentation',
      help: 'The documentation object to render.',
      postSet: function() {
        this.updateHTML();
      }
    },
  ],

  methods: {
    init: function() {
      this.SUPER();
      if (!this.X.documentViewParentModel) {
        console.log("*** Warning: DocView ",this," can't find documentViewParentModel in its context "+this.X.NAME);
      }
    },

    renderDocSourceHTML: function() {
      // only update if we have all required data
      if (this.docSource.body && this.X.documentViewParentModel
          && this.X.documentViewParentModel.model_ && this.data.model_) {
        // The first time this method is hit, replace it with the one that will
        // compile the template, then call that. Future calls go direct to lazyCompile's
        // returned function. You could also implement this the same way lazyCompile does...
        this.renderDocSourceHTML = TemplateUtil.lazyCompile(this.docSource.body);
        return this.renderDocSourceHTML();
      } else {
        return ""; // no data yet
      }
    },

    /** Create the special reference lookup sub-view from property info. **/
    createReferenceView: function(opt_args) {
      var X = ( opt_args && opt_args.X ) || this.X; // TODO: opt_args should have ref and text auto-set on the view?
      var v = X.DocRefView.create({ ref:opt_args.ref, text: opt_args.text, args: opt_args});
      this.addChild(v);
      return v;
    },

    createTemplateView: function(name, opt_args) {
      // name has been constantized ('PROP_NAME'), but we're
      // only looking for certain doc tags anyway.
      if (name === 'DOC') {
        var v = this.createReferenceView(opt_args);
        return v;
      } else {
        return this.SUPER(name, opt_args);
      }
    }
  }
});


MODEL({
  name: 'DocModelBodyView',
  extendsModel: 'DocBodyView',
  label: 'Documentation Model View',
  help: 'Shows the documentation body for a Model.',

  properties: [
    {
      name: 'data',
      help: 'The Model from which to extract documentation.',
      postSet: function() {
        this.X[this.model_.extendsModel].DATA.postSet.call(this); // TODO: implement this.SUPER() for these
        this.parentModel = this.data;
      }
    },

  ],

  templates: [
    function toInnerHTML()    {/*
      <%    this.destroy(); %>
      <%    if (this.data) {  %>
              <%=this.renderDocSourceHTML()%>
      <%    } %>
    */}
  ],

});

MODEL({
  name: 'DocFeatureBodyView',
  extendsModel: 'DocBodyView',
  label: 'Documentation Feature View',
  help: 'Shows documentation body for a feature of a Model.',

  // You must set both data and parentModel

  templates: [
    function toInnerHTML()    {/*
      <%    this.destroy(); %>
      <%    if (this.data) {  %>
              <h2><%=this.data.name%></h2>
              <%=this.renderDocSourceHTML()%>
{'fraction_non_alphanumeric': 0.134152585765489, 'fraction_numerical': 0.0030721966205837174, 'mean_word_length': 2.376260443676174, 'pattern_counts': {'":': 0, '<': 54, '<?xml version=': 0, '>': 52, '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': '5356119', 'n_tokens_mistral': 3586, 'n_tokens_neox': 3464, 'n_words': 958}