Check-in [80a85d9c20]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:[bb41cfce87] Added a TS version of John Resig's microtemplates and added in to the correct place in the demo app. Not working at the moment. Need to debug.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:80a85d9c207ef5ea0e913069f9bd47f6bddabb77
User & Date: User 2016-11-08 04:12:52
Context
2016-11-09
01:24
[bb41cfce87] Fixed the problem with using templates and moved the answers area inside the main div. It works! check-in: 97c2719229 user: adamc tags: trunk
2016-11-08
04:12
[bb41cfce87] Added a TS version of John Resig's microtemplates and added in to the correct place in the demo app. Not working at the moment. Need to debug. check-in: 80a85d9c20 user: User tags: trunk
2016-10-29
02:10
Added a goos documentation comment for the new exact combinator. check-in: 3218c25782 user: adamc tags: trunk
Changes

Changes to app/chattymath.css.

18
19
20
21
22
23
24














form button {
    margin-top: 1em;
}

label {
    margin-top: 1em;
}





















>
>
>
>
>
>
>
>
>
>
>
>
>
>
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
form button {
    margin-top: 1em;
}

label {
    margin-top: 1em;
}

#answers {
    margin-top: 2em;
    height: 50%;
    overflow-y: auto;
}

.answer {
    margin-top: 1em;
}

span.questionpart {
    font-style: italic;
}

Changes to app/chattymath.html.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26







27
28
29
30
31
32
<!doctype html>
<html class="no-js" lang="">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>Chatty Math</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link rel="stylesheet" href="spectre.min.css">
    <link rel="stylesheet" href="chattymath.css">
</head>

<body>
    <div id="main">
        <h1>Chatty Math</h1>
        <h3>Enter simple math problems, and Chatty Math will solve them for you.</h3>
        <form>
            <label class="form-label" for="question">Your math problem</label>
            <input class="form-input" id="question" type="text" placeholder="a simple math problem" />
            <button class="btn btn-primary input-group-btn" id="answerRequest">Solve it!</button>
            <label class="form-label" for="answer">The answer</label>
            <input class="form-input" id="answer" type="text" placeholder="answer" />
        </form>
    </div>







    <script src="jquery.min.js"></script>
    <script>window.jQuery || document.write('<script src="jquery.min.js"><\/script>')</script>
    <script src="chattybundle.js"></script>
</body>

</html>




|
|
|
|
|

|
|



|
|
|
|
|
|
|
<
<
|
|
>
>
>
>
>
>
>
|
|
|

<

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22


23
24
25
26
27
28
29
30
31
32
33
34
35

36
<!doctype html>
<html class="no-js" lang="">

<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<title>Chatty Math</title>
	<meta name="description" content="">
	<meta name="viewport" content="width=device-width, initial-scale=1">

	<link rel="stylesheet" href="spectre.min.css">
	<link rel="stylesheet" href="chattymath.css">
</head>

<body>
	<div id="main">
		<h1>Chatty Math</h1>
		<h3>Enter simple math problems, and Chatty Math will solve them for you.</h3>
		<form>
			<label class="form-label" for="question">Your math problem</label>
			<input class="form-input" id="question" type="text" placeholder="a simple math problem" />
			<button class="btn btn-primary input-group-btn" id="answerRequest">Solve it!</button>


		</form>
	</div>
    <script id="answerTemplate" type="text/html">
        <div class="answer">
            <span class="questionpart"><%= question %></span>&nbsp;
            <span class="answerpart"><%= answer %></span>
        </div>
    </script> 
    <div id="answers"></div>
	<script src="jquery.min.js"></script>
	<script>window.jQuery || document.write('<script src="jquery.min.js"><\/script>')</script>
	<script src="chattybundle.js"></script>
</body>

</html>

Changes to app/chattymath.ts.

1
2
3

4
5
6
7
8
9
10
...
302
303
304
305
306
307
308


309
310



311
312
/// <reference path="../typings/globals/jQuery/index" />

import * as pcomb from "../src/pcomb";


enum MathOps {
    NotSet = 0,
    Add,
    Subtract,
    Multipy,
    Divide
................................................................................

let $ = jQuery;
let yourChatty = new Chatty();

$(document).ready(function () {
    $("#answerRequest").click(function (e) {
        e.preventDefault();


        let answer = yourChatty.ask($("#question").val());
        $("#answer").val(answer);



    });
});



>







 







>
>
|
<
>
>
>


1
2
3
4
5
6
7
8
9
10
11
...
303
304
305
306
307
308
309
310
311
312

313
314
315
316
317
/// <reference path="../typings/globals/jQuery/index" />

import * as pcomb from "../src/pcomb";
import * as tmpl from "./template";

enum MathOps {
    NotSet = 0,
    Add,
    Subtract,
    Multipy,
    Divide
................................................................................

let $ = jQuery;
let yourChatty = new Chatty();

$(document).ready(function () {
    $("#answerRequest").click(function (e) {
        e.preventDefault();
        let data = {
            "question": $("#question").val(),
            "answer": yourChatty.ask($("#question").val())

        };

        $("#answers").append(tmpl.tmpl("#answerTemplate", data));
    });
});

Added app/template.ts.































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
let cache: Object = new Object();

export function tmpl(str: string, data ?: Object): string {
    let fn = !/\W/.test(str) ?
        cache[str] = cache[str] ||
        tmpl(document.getElementById(str).innerHTML) :

        //
        // Generate a reusable function that will serve as a template
        // generator (and which will be cached).
        //
        new Function("obj",
            "var p=[],print=function(){p.push.apply(p,arguments);};" +

            // Introduce the data as local variables using with
            "with(obj){p.push('" +

            // Convert the template into pure JavaScript
            str
                .replace(/[\r\t\n]/g, " ")
                .split("<%").join("\t")
                .replace(/((^|%>)[^\t]*)'/g, "$1\r")
                .replace(/\t=(.*?)%>/g, "',$1,'")
                .split("\t").join("');")
                .split("%>").join("p.push('")
                .split("\r").join("\\'")
            + "');}return p.join('');");

    // Provide some basic currying to the user
    return data ? fn(data) : fn;
}

Changes to gulpfile.js.

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
    .on('end', function() { done(); });
});

gulp.task('demo', function () {
  gulp.src('app/*.ts')
    .pipe(ts({
      declarationFiles: true,
      sourceMap: true,
      noImplicitAny: true
    }))
    .pipe(gulp.dest('app/'));
});

gulp.task('build-test', function (done) {
  gulp.src('tests/*.ts')
    .pipe(ts({







|
<







16
17
18
19
20
21
22
23

24
25
26
27
28
29
30
    .on('end', function() { done(); });
});

gulp.task('demo', function () {
  gulp.src('app/*.ts')
    .pipe(ts({
      declarationFiles: true,
      sourceMap: true

    }))
    .pipe(gulp.dest('app/'));
});

gulp.task('build-test', function (done) {
  gulp.src('tests/*.ts')
    .pipe(ts({