<commit_before>/** @jsx React.DOM */
$(function () {
 
'use strict';

var t = require('tcomb');
var doc = require('tcomb-doc');
var React = require('react');
var bs = require('tcomb-react-bootstrap');

var Col = bs.Col;
var Row = bs.Row;
var CarouselItem = bs.CarouselItem;
var MenuItem = bs.MenuItem;
var NavItem = bs.NavItem;
var Panel = bs.Panel;
var PageItem = bs.PageItem;
var MenuItem = bs.MenuItem;
var TabPane = bs.TabPane;

var components = [
  "Alert",
  "Badge",
  "Button",
  "ButtonGroup",
  "ButtonToolbar",
  "Carousel",
  "DropdownButton",
  "Glyphicon",
  "Input",
  "Modal",
  "Nav",
  "Navbar",
  "PanelGroup",
  "Pager",
  "Popover",
  "ProgressBar",
  "SplitButton",
  "TabbedArea",
  "Table",
  "Tooltip",
  "Well"
];

//
// import all components
//
components.forEach(function (k) {
  window[k] = bs[k];
});
//
// import all examples
//
var examples = {};
var options = components.map(function (k) {
  return <option key={k} value={k}>{k}</option>;
});

components.forEach(function (k) {
  var $example = $('#' + k);
  if ($example.length) {
    examples[k] = $example.text();
  } else {
    console.warn('missing %s', k)
  }
});

// if true, open the debugger when a failure occurs
var isDebuggerEnabled = false;

// override default fail behaviour of tcomb https://github.com/gcanti/tcomb
t.options.onFail = function (message) {
  if (isDebuggerEnabled) {
    debugger;
  }
  throw new Error(message);
};

//
// utils
//

// return the HTML documentation of a component
function toMarkdown(componentName) {
  var domain = {};
  domain[componentName] = bs[componentName].type;
  // tcomb-doc
  var json = doc.parse(domain).toJSON();
  var markdown = doc.toMarkdown(json);
  return marked(markdown);
}

var Documentation = React.createClass({
  render: function () {
    return (
      <div className="docs">
        <p className="lead">Check out the documentation:</p>
        <p className="text-right"><em className="text-muted"><code>maybe(Type)</code> means an optional instance of <code>Type</code></em></p>
        <div dangerouslySetInnerHTML={{__html: toMarkdown(this.props.componentName)}} />
      </div>
    );
  }
});

// display error and related documentation
function getErrorAlert(err, componentName){
  var isSyntaxError = !!err.lineNumber;
  var message = err.message;
  return (
    <div>
      <Alert bsStyle="danger">
        {message}
      </Alert>
      { isSyntaxError ? "" :
      <Documentation componentName={componentName}/>
      }
    </div>
  );
}
<commit_msg>added tcomb-doc explanation<commit_after>/** @jsx React.DOM */
$(function () {
 
'use strict';

var t = require('tcomb');
var doc = require('tcomb-doc');
var React = require('react');
var bs = require('tcomb-react-bootstrap');

var Col = bs.Col;
var Row = bs.Row;
var CarouselItem = bs.CarouselItem;
var MenuItem = bs.MenuItem;
var NavItem = bs.NavItem;
var Panel = bs.Panel;
var PageItem = bs.PageItem;
var MenuItem = bs.MenuItem;
var TabPane = bs.TabPane;

var components = [
  "Alert",
  "Badge",
  "Button",
  "ButtonGroup",
  "ButtonToolbar",
  "Carousel",
  "DropdownButton",
  "Glyphicon",
  "Input",
  "Modal",
  "Nav",
  "Navbar",
  "PanelGroup",
  "Pager",
  "Popover",
  "ProgressBar",
  "SplitButton",
  "TabbedArea",
  "Table",
  "Tooltip",
  "Well"
];

//
// import all components
//
components.forEach(function (k) {
  window[k] = bs[k];
});
//
// import all examples
//
var examples = {};
var options = components.map(function (k) {
  return <option key={k} value={k}>{k}</option>;
});

components.forEach(function (k) {
  var $example = $('#' + k);
  if ($example.length) {
    examples[k] = $example.text();
  } else {
    console.warn('missing %s', k)
  }
});

// if true, open the debugger when a failure occurs
var isDebuggerEnabled = false;

// override default fail behaviour of tcomb https://github.com/gcanti/tcomb
t.options.onFail = function (message) {
  if (isDebuggerEnabled) {
    debugger;
  }
  throw new Error(message);
};

//
// utils
//

// return the HTML documentation of a component
function toMarkdown(componentName) {
  var domain = {};
  domain[componentName] = bs[componentName].type;
  // tcomb-doc
  var json = doc.parse(domain).toJSON();
  var markdown = doc.toMarkdown(json);
  return marked(markdown);
}

var Documentation = React.createClass({
  render: function () {
    return (
      <div className="docs">
        <p className="lead">Check out the documentation (auto generated from the underlying domain model):</p>
        <p className="text-right"><em className="text-muted"><code>maybe(Type)</code> means an optional instance of <code>Type</code></em></p>
        <div dangerouslySetInnerHTML={{__html: toMarkdown(this.props.componentName)}} />
      </div>
    );
  }
});

// display error and related documentation
function getErrorAlert(err, componentName){
  var isSyntaxError = !!err.lineNumber;
  var message = err.message;
  return (
    <div>
      <Alert bsStyle="danger">
        {message}
      </Alert>
      { isSyntaxError ? "" :
      <Documentation componentName={componentName}/>
      }
    </div>
  );
}

{'fraction_non_alphanumeric': 0.16666666666666666, 'fraction_numerical': 0.0, 'mean_word_length': 3.488986784140969, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, 'https://': 2, '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': '6115662', 'n_tokens_mistral': 1715, 'n_tokens_neox': 1692, 'n_words': 413}