<commit_before>var React = require('react'), 
    Server = require('node_erlastic').server,
	Bert = require('node_erlastic/bert'),
    styleCollector = require("./style-collector")
Bert.all_binaries_as_string = true

function safe_json_props(props){
  return JSON.stringify(props)
         .replace(/<\/script/g, '<\\/script')
         .replace(/<!--/g, '<\\!--')
}

function render_props(handler,props){
  try{
    var html
    var css = styleCollector.collect(function() {
      html = React.renderToString(React.createElement(handler,props))
    })
    return Bert.tuple(Bert.atom("ok"),{
      html: html,
      css: css,
      init_props: safe_json_props(props)
    })
  }catch(error){
    return Bert.tuple(
             Bert.atom("error"),
               Bert.tuple(
                 Bert.atom("render_error"),
                 error.toString(),
                 (error.stack && error.stack || Bert.atom("nil")),
                 safe_json_props(props) ))
  }
}

// protocol : 
// call {:render_tpl | :render_dyn_tpl, module, submodule | nil, arg}
// - if :render_tpl, take handler from require("template/{module}") or require("template/{module}")[submodule]
//   then reply {:ok,%{html: ReactRenderingOf(handler,arg),init_props: json(arg)}}
// - if :render_dyn_tpl, take a handler selector function from require("template/{module}") or require("template/{module}")[submodule]
//   this function must take 2 arguments : arg, callback, must find an appropriate handler and call
//   callback(handler,prop) to reply the same as :render_tpl
// if error reply {:error, {:render_error,error,stack,props} | {:handler_error,error,stack}}
Server(function(term,from,state,done){
  try{
    var type = term[0],
        module = require("./../../templates/"+term[1]),
        submodule = (term[2] == "nil") ? module : module[term[2]]
    if (type == "render_tpl")
      done("reply", render_props(submodule,term[3]))
    else if (type == "render_dyn_tpl")
      submodule(term[3],function(handler,props){
        done("reply",render_props(handler,props)) })
    else throw new Error("unexpected request")
  }catch(error){
      done("reply", 
       Bert.tuple(<commit_msg>rename templates to components to avoid collisions<commit_after>var React = require('react'), 
    Server = require('node_erlastic').server,
	Bert = require('node_erlastic/bert'),
    styleCollector = require("./style-collector")
Bert.all_binaries_as_string = true

function safe_json_props(props){
  return JSON.stringify(props)
         .replace(/<\/script/g, '<\\/script')
         .replace(/<!--/g, '<\\!--')
}

function render_props(handler,props){
  try{
    var html
    var css = styleCollector.collect(function() {
      html = React.renderToString(React.createElement(handler,props))
    })
    return Bert.tuple(Bert.atom("ok"),{
      html: html,
      css: css,
      init_props: safe_json_props(props)
    })
  }catch(error){
    return Bert.tuple(
             Bert.atom("error"),
               Bert.tuple(
                 Bert.atom("render_error"),
                 error.toString(),
                 (error.stack && error.stack || Bert.atom("nil")),
                 safe_json_props(props) ))
  }
}

// protocol : 
// call {:render_tpl | :render_dyn_tpl, module, submodule | nil, arg}
// - if :render_tpl, take handler from require("components/{module}") or require("template/{module}")[submodule]
//   then reply {:ok,%{html: ReactRenderingOf(handler,arg),init_props: json(arg)}}
// - if :render_dyn_tpl, take a handler selector function from require("template/{module}") or require("template/{module}")[submodule]
//   this function must take 2 arguments : arg, callback, must find an appropriate handler and call
//   callback(handler,prop) to reply the same as :render_tpl
// if error reply {:error, {:render_error,error,stack,props} | {:handler_error,error,stack}}
Server(function(term,from,state,done){
  try{
    var type = term[0],
        module = require("./../../components/"+term[1]),
        submodule = (term[2] == "nil") ? module : module[term[2]]
    if (type == "render_tpl")
      done("reply", render_props(submodule,term[3]))
    else if (type == "render_dyn_tpl")
      submodule(term[3],function(handler,props){
        done("reply",render_props(handler,props)) })
    else throw new Error("unexpected request")
  }catch(error){
      done("reply", 
       Bert.tuple(
{'fraction_non_alphanumeric': 0.16308816811329374, 'fraction_numerical': 0.0031978072179077205, 'mean_word_length': 3.2889324191968656, 'pattern_counts': {'":': 0, '<': 11, '<?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': '911745', 'n_tokens_mistral': 1330, 'n_tokens_neox': 1326, 'n_words': 281}