mirror of
https://github.com/skishore/makemeahanzi.git
synced 2025-10-29 01:46:07 +08:00
Add code to load glyph data into Meteor
This commit is contained in:
7065
client/bootstrap.css
vendored
7065
client/bootstrap.css
vendored
File diff suppressed because it is too large
Load Diff
@ -1,13 +0,0 @@
|
||||
Session.setDefault('counter', 0);
|
||||
|
||||
Template.hello.helpers({
|
||||
counter: function () {
|
||||
return Session.get('counter');
|
||||
}
|
||||
});
|
||||
|
||||
Template.hello.events({
|
||||
'click button': function () {
|
||||
Session.set('counter', Session.get('counter') + 1);
|
||||
}
|
||||
});
|
||||
21
client/external/bootstrap/3.1.1/MIT-LICENSE.txt
vendored
Normal file
21
client/external/bootstrap/3.1.1/MIT-LICENSE.txt
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2011-2014 Twitter, Inc
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
6
client/external/bootstrap/3.1.1/bootstrap.min.js
vendored
Normal file
6
client/external/bootstrap/3.1.1/bootstrap.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
11
client/external/bootswatch/3.1.1/bootstrap.min.css
vendored
Normal file
11
client/external/bootswatch/3.1.1/bootstrap.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -2,21 +2,38 @@
|
||||
<title>zh-Hans</title>
|
||||
</head>
|
||||
<body>
|
||||
{{> nav}}
|
||||
{{> hello}}
|
||||
{{> navbar}}
|
||||
{{> progress}}
|
||||
</body>
|
||||
|
||||
<template name="nav">
|
||||
<div class="navbar navbar-default navbar-fixed-top">
|
||||
<template name="navbar">
|
||||
<div class="navbar navbar-default navbar-static-top">
|
||||
<div class="container-fluid">
|
||||
<div class="navbar-header">
|
||||
<div class="navbar-brand">zh-Hans character decomposition</div>
|
||||
</div>
|
||||
<ul class="nav navbar navbar-nav navbar-right">
|
||||
<button id="reload-button" class="btn btn-danger">Reload</button>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template name="hello">
|
||||
<button>Click me!</button>
|
||||
<p>You've pressed the button {{counter}} times.</p>
|
||||
<template name="progress">
|
||||
<div id="progress" class="modal fade" tabIndex="2"
|
||||
data-backdrop="static" data-keyboard="false">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-body">Reloading glyph data...</div>
|
||||
<div class="modal-footer">
|
||||
<div class="progress">
|
||||
<div class="progress-bar progress-bar-striped active"
|
||||
role="progressbar" style="width: {{percent}}%"
|
||||
aria-valuenow="{{percent}}"
|
||||
aria-valuemin="0" aria-valuemax="100"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
31
client/progress.js
Normal file
31
client/progress.js
Normal file
@ -0,0 +1,31 @@
|
||||
Template.navbar.events({
|
||||
'click #reload-button': function() {
|
||||
Meteor.call('reload');
|
||||
},
|
||||
});
|
||||
|
||||
Template.progress.helpers({
|
||||
percent: function() {
|
||||
return Math.round(100*Session.get('progress.value'));
|
||||
},
|
||||
});
|
||||
|
||||
Tracker.autorun(function() {
|
||||
if (Session.get('progress.show')) {
|
||||
$('#progress').modal({background: 'static', keyboard: false});
|
||||
} else {
|
||||
$('#progress').modal('hide');
|
||||
}
|
||||
});
|
||||
|
||||
Tracker.autorun(function() {
|
||||
var progress = Progress.findOne();
|
||||
if (progress) {
|
||||
Session.set('progress.show', true);
|
||||
Session.set('progress.value', progress.value);
|
||||
} else {
|
||||
Session.set('progress.show', false);
|
||||
}
|
||||
});
|
||||
|
||||
Meteor.subscribe('progress');
|
||||
@ -0,0 +1,25 @@
|
||||
.navbar {
|
||||
cursor: default !important;
|
||||
-webkit-user-select: none !important;
|
||||
}
|
||||
|
||||
.navbar .navbar-brand:hover {
|
||||
color: #ffffff !important;
|
||||
}
|
||||
|
||||
.btn {
|
||||
outline: 0 !important;
|
||||
padding: 4px 12px !important;
|
||||
}
|
||||
|
||||
#reload-button {
|
||||
position: absolute;
|
||||
right: 12px;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
}
|
||||
|
||||
#progress .progress {
|
||||
height: 18px;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
2
lib/collections.js
Normal file
2
lib/collections.js
Normal file
@ -0,0 +1,2 @@
|
||||
Glyphs = new Mongo.Collection('glyphs');
|
||||
Progress = new Mongo.Collection('progress');
|
||||
@ -1,24 +1,67 @@
|
||||
var child_process = Npm.require('child_process');
|
||||
var path = Npm.require('path');
|
||||
|
||||
function get_glyph_data(characters) {
|
||||
var BATCH_SIZE = 64;
|
||||
var GLYPH_RANGE = [0x4e00, 0x9fff];
|
||||
|
||||
var reloading = false;
|
||||
|
||||
function get_glyph_data(characters, callback) {
|
||||
var json = '';
|
||||
var font = path.join(process.env.PWD, 'derived', 'ukai.svg');
|
||||
var main = path.join(process.env.PWD, 'scripts', 'main.py');
|
||||
var child = child_process.spawn(main, ['-f', font].concat(characters));
|
||||
child.stdout.on('data', function(data) {
|
||||
child.stdout.on('data', Meteor.bindEnvironment(function(data) {
|
||||
json += data;
|
||||
});
|
||||
child.stderr.on('data', function(data) {
|
||||
console.error('' + data);
|
||||
});
|
||||
child.on('close', function(code) {
|
||||
console.log('Subprocess exited with code: ' + code);
|
||||
console.log('Got JSON data:');
|
||||
return JSON.parse(json);
|
||||
}));
|
||||
child.on('close', Meteor.bindEnvironment(function(code) {
|
||||
var glyphs = [];
|
||||
try {
|
||||
glyphs = JSON.parse(json);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
glyphs.length = 0;
|
||||
}
|
||||
callback(glyphs, code);
|
||||
}));
|
||||
}
|
||||
|
||||
function iterate(start, end, index) {
|
||||
index = index || start;
|
||||
if (index >= end) {
|
||||
Progress.remove({});
|
||||
reloading = false;
|
||||
return;
|
||||
}
|
||||
Progress.upsert({}, {value: (index - start)/(end - start)});
|
||||
var max = Math.min(index + BATCH_SIZE, end);
|
||||
var characters = [];
|
||||
for (var i = index; i < max; i++) {
|
||||
characters.push(i.toString(16));
|
||||
}
|
||||
get_glyph_data(characters, function(glyphs) {
|
||||
for (var i = 0; i < glyphs.length; i++) {
|
||||
var glyph = glyphs[i];
|
||||
Glyphs.upsert({name: glyph.name}, glyph);
|
||||
}
|
||||
Meteor.setTimeout(function() { iterate(start, end, max); }, 0);
|
||||
});
|
||||
}
|
||||
|
||||
Meteor.startup(function() {
|
||||
get_glyph_data(['4dff', '4e00', '4e01']);
|
||||
Meteor.methods({
|
||||
reload: function() {
|
||||
if (!reloading) {
|
||||
iterate(GLYPH_RANGE[0], GLYPH_RANGE[1]);
|
||||
reloading = true;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Meteor.publish('progress', function() {
|
||||
return Progress.find();
|
||||
});
|
||||
|
||||
Meteor.startup(function() {
|
||||
Progress.remove({});
|
||||
Glyphs._ensureIndex({name: 1}, {unique: true});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user