Skip to content

Instantly share code, notes, and snippets.

View ndemengel's full-sized avatar

Nicolas Grisey Demengel ndemengel

View GitHub Profile
@ndemengel
ndemengel / whisper-calculator.py
Last active August 24, 2016 11:36 — forked from jjmaestro/whisper-calculator.py
Add weeks support to jjmaestro's script
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def archive_to_bytes(archive):
def to_seconds(s):
SECONDS_IN_A = {
's': 1,
'm': 1 * 60,
'h': 1 * 60 * 60,
@ndemengel
ndemengel / wizard-spec.js
Last active November 13, 2016 19:14
jsdom example
const tu = require('../tu'); // tu == test utils
const expect = tu.expect;
const withDocument = tu.withDocument;
const componentHtmlAndScript = {
html: `
<textarea id="editableArea"></textarea>
<div id="counter"></div>
`,
// load the JS module under test
@ndemengel
ndemengel / index.js
Last active November 13, 2016 19:59
(part of) Hopwork's front JS test harness
const path = require('path');
const _ = require('lodash');
const AssertionError = require('assertion-error');
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
const jsdom = require('jsdom');
const Q = require('q');
const sinonChai = require('sinon-chai');
@ndemengel
ndemengel / editable-rating-stars-spec.js
Last active November 13, 2016 20:58
Example of JS test "interpreting" a JSP (the JSP can be found here: https://gist.github.com/ndemengel/54df1425968d9e8d05d052e71b31e4d9)
const tu = require('../tu');
const expect = tu.expect;
const withDocument = tu.withDocument;
const ratingStarsJspAndScript = {
jsp: 'include/editableRatingStars',
hopModules: 'Hop/components/editable-rating-stars',
attributes: {
param: {path: 'someRadioInput'}
}
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<div class="no-mg editable-rating-stars">
<div class="stars">
<ul class="inline-list no-lstyle">
<c:forEach begin="1" end="5" var="rate">
<li class="star">
@ndemengel
ndemengel / test-bundle.js
Created November 20, 2016 16:25
Webpack: JS entry point importing Handlebars template (result of https://gist.github.com/ndemengel/3bc106eac2c6a8d095ce0bbdab55420c)
// skipped: 17 lines to define webpackBootstrap and __webpack_require__...
webpackBootstrap({
0: function(module, exports, __webpack_require__) {
var helloTemplate = __webpack_require__(371);
console.log(helloTemplate({name: 'John'}));
},
188: function(module, exports) { module.exports = Handlebars; },
371: function(module, exports, __webpack_require__) {
@ndemengel
ndemengel / hello.hbs
Last active November 20, 2016 16:25
Webpack: JS entry point importing Handlebars template (result here: https://gist.github.com/ndemengel/69efe8357a5cdf91a1f7ee9671c4e0cc)
Hello {{name}}!
@ndemengel
ndemengel / handlebars-taglib-example.jsp
Created November 20, 2016 16:26
Handlebars taglib example
<%@ taglib prefix="hbs" uri="http://www.hopwork.com/jsp/jstl/handlebars" %>
<%-- preferred form: all needed data are computed outside of the view and put into ${headerData} --%>
<hbs:render template="common/header" context="${headerData}"/>
<%-- sometimes, it's still useful to tweak the view independently of the data --%>
<hbs:render template="some/other/template">
<hbs:contextProperty name="someCondition" value="true"/>
<hbs:contextProperty name="someConfigProperty" value="SOME_CONFIG_VALUE"/>
<hbs:contextProperty name="data" value="${someData}"/>
@ndemengel
ndemengel / webpack-handlebars-config.js
Last active November 20, 2016 20:56
Webpack configuration for Handlebars templates
jspackConfiguration.module.loaders.push({
test: /\.hbs$/,
loader: 'handlebars-loader' +
// Tell handlebars-loader where our custom helpers are to be found.
// Note: helpers' names are derived from their file name.
'?helperDirs[]=' + __dirname + '/handlebars-helpers' +
// Force handlebars-loader not to include Handlebars runtime,
// since it is already included in our common bundle.
@ndemengel
ndemengel / handlebars-example.hbs
Last active November 20, 2016 21:04
Handlebars example
<p>Handlebars escapes all texts by default. This is safe: {{htmlEscapedVariable}},
this is not {{{nonEscapedVariable}}}.</p>
<ul>
{{#each items}}
{{!-- Within this #each block, "name", "link" and "url" are properties of the current item. --}}
{{!-- Also: @first, @last and @index are automatically provided for convenience. --}}
{{#if @first}}
<li>First item: {{name}}</li>
{{else if link}}