update
I've created a little repository that simply exposes the final utility as npm
module.
It's called html-escaper
there is basically one rule only: do not ever replace one char after another if you are transforming a string into another.
// Based on this blog post: https://medium.com/@iquardt/taming-the-dom-50c8f1a6e892 | |
/* RULES | |
* Only the program may manipulate the output display, never the user | |
* User input is presented in the form of events | |
* GUI elements generate events only in response to user input, never in response to program output | |
*/ |
function i18n(template) { | |
for (var | |
info = i18n.db[i18n.locale][template.join('\x01')], | |
out = [info.t[0]], | |
i = 1, length = info.t.length; i < length; i++ | |
) out[i] = arguments[1 + info.v[i - 1]] + info.t[i]; | |
return out.join(''); | |
} | |
i18n.locale = 'en'; | |
i18n.db = {}; |
import React from 'react'; | |
import renderer from 'react-test-renderer'; | |
//children mock need to be defined before parent module import | |
jest.mock('react-bootstrap-table', () => { | |
return { | |
BootstrapTable: 'BootstrapTable', | |
TableHeaderColumn: 'TableHeaderColumn', | |
}; | |
}); |
/*! (c) 2016 Andrea Giammarchi - MIT Style License */ | |
// simple state-like objects handler | |
// based on prototypal inheritance | |
function State() {'use strict';} | |
// States are serializable dictionaries | |
// toJSON and toString are the only reserved keywords | |
// every other name can be used as name (included __proto__) |
// Most components are defined fully by their render function, | |
// and all they need to access is the props | |
var myComponent = createComponent(function (props) { | |
return React.DOM.h1({}, "Hello " + props.name); | |
}); | |
// ...which can be done very succinctly with ES6: | |
const {h1, div} = React.DOM; | |
const myComponent = createComponent(({name}) => h1({}, `Hello ${name}`)); |
var path = require('path'); | |
var fs = require('fs'); | |
var cheerio = require('cheerio'); | |
var createTemplate = function(id, markup) { | |
var $ = cheerio.load('<script type="text/ng-template"></script>'); | |
$('script').attr('id', id).html(markup).html(); | |
return $.html(); | |
}; |
update
I've created a little repository that simply exposes the final utility as npm
module.
It's called html-escaper
there is basically one rule only: do not ever replace one char after another if you are transforming a string into another.
var Promise = global.Promise || require('lie'); | |
function noop(){} | |
function typeIsObject(x) { | |
return (typeof x === 'object' && x !== null) || typeof x === 'function'; | |
} | |
function ExclusiveStreamReader () { | |
throw new Error('not implimented'); | |
} | |
function ReadableStream(opts) { | |
var start = opts.start || noop; |
function toJSON(node) { | |
let propFix = { for: 'htmlFor', class: 'className' }; | |
let specialGetters = { | |
style: (node) => node.style.cssText, | |
}; | |
let attrDefaultValues = { style: '' }; | |
let obj = { | |
nodeType: node.nodeType, | |
}; | |
if (node.tagName) { |
class UserController < ApplicationController | |
def create | |
@user = User.create(UserInput.new(params).create) | |
end | |
def update | |
@user = User.find(params[:id].to_i) | |
@user.update_attributes(UserInput.new(params).update) | |
end | |