Skip to content

Commit 8a6a6d0

Browse files
committed
Fixed formatting of index.html
1 parent 479db84 commit 8a6a6d0

File tree

1 file changed

+171
-182
lines changed

1 file changed

+171
-182
lines changed

index.html

Lines changed: 171 additions & 182 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
</style>
2323
<style>
2424
</style>
25-
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
25+
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
2626
<script src="realtime.Sugar.js"></script>
2727
</head>
2828
<body>
@@ -43,7 +43,8 @@
4343
<script src="parser/parser.js"></script>
4444
<script src="compiler.js"></script>
4545
<script>
46-
var loaded=false;
46+
var loaded = false;
47+
4748
function repl_parse(src) {
4849
if (src === undefined) {
4950
src = repl_in.value;
@@ -61,8 +62,7 @@
6162
}
6263

6364
function repl_eval(src) {
64-
if(!loaded)
65-
{
65+
if(!loaded) {
6666
console.log("The system is not initialized yet.");
6767
return;
6868
}
@@ -95,190 +95,179 @@
9595
}
9696
</script>
9797
<script>
98-
var context;
99-
function setButton(){
100-
var button = document.getElementById('auth_button');
101-
button.style.visibility="visible";
102-
button.addEventListener('click', authorize);
103-
}
104-
function unSetButton(){
105-
106-
var button = document.getElementById('auth_button');
107-
button.style.visibility="hidden";
108-
109-
}
110-
function authorize() {
111-
// Attempt to authorize
112-
realtimeUtils.authorize(function(response){
113-
if(response.error){
114-
// Authorization failed because this is the first time the user has used your application,
115-
// show the authorize button to prompt them to authorize manually.
116-
setButton();
117-
}
118-
else {
119-
unSetButton();
120-
start(hiveLoaded);
121-
}
122-
},true);
123-
}
124-
authCallback=authorize;
125-
function hiveLoaded(model){
126-
if(model.getRoot().get('context')==null)
127-
{
128-
initializeObjects();
129-
}else{
130-
context= model.getRoot().get('context');
131-
}
132-
openModelViewer();
133-
loaded=true;
134-
}
135-
// startups the system
136-
function initializeObjects() {
137-
138-
context = CreateContext();
139-
140-
model.getRoot().set('context',context);
141-
142-
context.set('object', model.createMap());
98+
var context;
99+
100+
function setButton() {
101+
var button = document.getElementById('auth_button');
102+
button.style.visibility="visible";
103+
button.addEventListener('click', authorize);
104+
}
105+
106+
function unSetButton() {
107+
var button = document.getElementById('auth_button');
108+
button.style.visibility="hidden";
109+
}
110+
111+
function authorize() {
112+
// Attempt to authorize
113+
realtimeUtils.authorize(function(response) {
114+
if(response.error) {
115+
// Authorization failed because this is the first time the user has used your application,
116+
// show the authorize button to prompt them to authorize manually.
117+
setButton();
118+
} else {
119+
unSetButton();
120+
start(hiveLoaded);
121+
}
122+
}, true);
123+
}
124+
125+
authCallback = authorize;
143126

144-
context.get('object').set('basicNew', CreateMethod(
145-
'basicNew',"(function () { var self =model.createMap();context.set('self',self); initObject(self,context);return self;})",context));
146-
147-
compiler.evaluate("null := (object basicNew addMethod:[isNull| true]) addMethod:[toString|'null']")
148-
InitializeNumbers();
149-
InitializeStrings();
150-
InitializeLists();
151-
InitializeOthers();
152-
153-
154-
}
155-
function initObject(obj,context)
156-
{
157-
obj.set('addMethod:',CreateMethod(
158-
'addMethod:',"(function(b){context.lookup('self').get().set(b.get('selector'),b); return context.lookup('self').get();})",context));
159-
obj.set('toString',CreateMethod('toString',"(function(){ return CreateString('An Object');})",context));
160-
obj.set('Equals:',CreateMethod(
161-
'Equals:',"(function(other){if(context.lookup('self').get()==other){return context.lookup('true').get();}else{return context.lookup('false').get();}})",context));
162-
163-
obj.set('isNull',CreateMethod('isNull',"(function(){ return context.lookup('false').get();})",context));
164-
165-
}
166-
function InitializeNumbers()
167-
{
168-
compiler.evaluate("Number := object basicNew");
169-
170-
compiler.evaluate("Number addMethod:[value | self]");
171-
context.get('Number').set('+', CreateMethod(
172-
'+',"(function (b) {return (context.lookup('self').get() + b);})",context));
173-
context.get('Number').set('/', CreateMethod(
174-
'/',"(function (b) {return (context.lookup('self').get() / b);})",context));
175-
127+
function hiveLoaded(model) {
128+
if(model.getRoot().get('context') == null) {
129+
initializeObjects();
130+
} else {
131+
context = model.getRoot().get('context');
132+
}
133+
openModelViewer();
134+
loaded = true;
135+
}
136+
137+
// startups the system
138+
function initializeObjects() {
139+
140+
context = CreateContext();
141+
142+
model.getRoot().set('context',context);
143+
144+
context.set('object', model.createMap());
145+
146+
context.get('object').set('basicNew', CreateMethod(
147+
'basicNew',"(function () { var self = model.createMap();context.set('self',self); initObject(self,context);return self;})",context));
148+
149+
compiler.evaluate("null := (object basicNew addMethod:[isNull| true]) addMethod:[toString|'null']")
150+
InitializeNumbers();
151+
InitializeStrings();
152+
InitializeLists();
153+
InitializeOthers();
154+
}
155+
156+
function initObject(obj,context) {
157+
obj.set('addMethod:',CreateMethod(
158+
'addMethod:',"(function(b){context.lookup('self').get().set(b.get('selector'),b); return context.lookup('self').get();})",context));
159+
obj.set('toString',CreateMethod('toString',"(function(){ return CreateString('An Object');})",context));
160+
obj.set('Equals:',CreateMethod(
161+
'Equals:',"(function(other){if(context.lookup('self').get()==other){return context.lookup('true').get();}else{return context.lookup('false').get();}})",context));
162+
163+
obj.set('isNull',CreateMethod('isNull',"(function(){ return context.lookup('false').get();})",context));
164+
}
165+
166+
function InitializeNumbers() {
167+
compiler.evaluate("Number := object basicNew");
168+
169+
compiler.evaluate("Number addMethod:[value | self]");
170+
context.get('Number').set('+', CreateMethod(
171+
'+',"(function (b) {return (context.lookup('self').get() + b);})",context));
172+
context.get('Number').set('/', CreateMethod(
173+
'/',"(function (b) {return (context.lookup('self').get() / b);})",context));
174+
176175

177-
compiler.evaluate("Number addMethod:[* b | self / (1/b) ]");
178-
compiler.evaluate("Number addMethod:[- b | self + (-1 * b) ]");
179-
180-
context.get('Number').set('>', CreateMethod(
181-
'>',"(function (b) {if(context.lookup('self').get() > b){return context.lookup('true').get();}else{return context.lookup('false').get();}})",context));
182-
context.get('Number').set('<', CreateMethod(
183-
'<',"(function (b) {if(context.lookup('self').get() < b){return context.lookup('true').get();}else{return context.lookup('false').get();}})",context));
184-
185-
compiler.evaluate("Number addMethod:[>= b | (self < b) Not ]");
186-
187-
compiler.evaluate("Number addMethod:[<= b | (self > b) Not ]");
188-
compiler.evaluate("Number addMethod:[=b | self Equals:b]");
189-
context.get('Number').set('toString',CreateMethod('toString',"(function(){ return CreateString(context.lookup('self').get().toString());})",context));
190-
}
191-
function InitializeStrings()
192-
{
193-
compiler.evaluate("String := object basicNew");
194-
compiler.evaluate("String addMethod:[toString | self]");
195-
compiler.evaluate("String addMethod:[value | self]");
196-
197-
//concat
198-
context.get('String').set('+', CreateMethod(
199-
'+',"(function (b) {return (model.createString(context.lookup('self').get().toString() + b.receive('toString')().text));})",context));
200-
//append
201-
context.get('String').set('+=', CreateMethod(
202-
'+=',"(function (b) {context.lookup('self').get().append(b.receive('toString')().text);return (context.lookup('self').get());})",context));
203-
//length
204-
context.get('String').set('length', CreateMethod(
205-
'length',"(function () {return (context.lookup('self').get().length);})",context));
206-
//toList
207-
context.get('String').set('toList', CreateMethod(
208-
'toList',"(function () {return (model.createList(context.lookup('self').get().text));})",context));
176+
compiler.evaluate("Number addMethod:[* b | self / (1/b) ]");
177+
compiler.evaluate("Number addMethod:[- b | self + (-1 * b) ]");
178+
179+
context.get('Number').set('>', CreateMethod(
180+
'>',"(function (b) {if(context.lookup('self').get() > b){return context.lookup('true').get();}else{return context.lookup('false').get();}})",context));
181+
context.get('Number').set('<', CreateMethod(
182+
'<',"(function (b) {if(context.lookup('self').get() < b){return context.lookup('true').get();}else{return context.lookup('false').get();}})",context));
183+
184+
compiler.evaluate("Number addMethod:[>= b | (self < b) Not ]");
185+
186+
compiler.evaluate("Number addMethod:[<= b | (self > b) Not ]");
187+
compiler.evaluate("Number addMethod:[=b | self Equals:b]");
188+
context.get('Number').set('toString',CreateMethod('toString',"(function(){ return CreateString(context.lookup('self').get().toString());})",context));
189+
}
209190

210-
}
211-
function InitializeLists()
212-
{
213-
compiler.evaluate("List := object basicNew");
214-
215-
context.get('List').set('at:', CreateMethod(
216-
'at:',"(function (index) {var s=context.lookup('self').get(); if(index>=s.length){return context.lookup('null').get();} return s.get(index); })",context));
217-
218-
context.get('List').set('at:put:', CreateMethod(
219-
'at:put:',"(function (index,value) { var s=context.lookup('self').get(); while(index>=s.length){s.push(context.lookup('null').get());} context.lookup('self').get().set(index,value); return context.lookup('self').get(); })",context));
191+
function InitializeStrings() {
192+
compiler.evaluate("String := object basicNew");
193+
compiler.evaluate("String addMethod:[toString | self]");
194+
compiler.evaluate("String addMethod:[value | self]");
195+
196+
//concat
197+
context.get('String').set('+', CreateMethod(
198+
'+',"(function (b) {return (model.createString(context.lookup('self').get().toString() + b.receive('toString')().text));})",context));
199+
//append
200+
context.get('String').set('+=', CreateMethod(
201+
'+=',"(function (b) {context.lookup('self').get().append(b.receive('toString')().text);return (context.lookup('self').get());})",context));
202+
//length
203+
context.get('String').set('length', CreateMethod(
204+
'length',"(function () {return (context.lookup('self').get().length);})",context));
205+
//toList
206+
context.get('String').set('toList', CreateMethod(
207+
'toList',"(function () {return (model.createList(context.lookup('self').get().text));})",context));
208+
}
220209

221-
context.get('List').set('count', CreateMethod(
222-
'count',"(function () {return context.lookup('self').get().length; })",context));
223-
224-
context.get('List').set('removeAt:', CreateMethod(
225-
'removeAt:',"(function (index) {var s =context.lookup('self').get(); s.remove(index); return s; })",context));
226-
compiler.evaluate('List addMethod:[pop| r:= self at:(self count-1). self removeAt:(self count-1). r].List addMethod:[push: value| self at:(self count) put: value].');
227-
228-
}
229-
function InitializeOthers(){
230-
231-
compiler.evaluate("true := ((object basicNew addMethod:[ifTrue:aBlock| aBlock value]) addMethod:[ifFalse:aBlock| ]) addMethod:[ifTrue: aBlock ifFalse: anotherBlock| aBlock value]");
232-
compiler.evaluate("true addMethod:[toString|'true']. true addMethod:[value|true]");
233-
compiler.evaluate("false := ((object basicNew addMethod:[ifTrue:aBlock| ]) addMethod:[ifFalse:aBlock| aBlock value]) addMethod:[ifTrue: aBlock ifFalse: anotherBlock| anotherBlock value]");
234-
compiler.evaluate("false addMethod:[toString|'false']. false addMethod:[value|false]")
235-
236-
//logical operators
237-
compiler.evaluate("true addMethod:[Not| false]. true addMethod:[And: other| other value]. true addMethod:[Or: other| true].");
238-
compiler.evaluate("false addMethod:[Not| true]. false addMethod:[And: other| false]. false addMethod:[Or: other| other value].");
239-
210+
function InitializeLists() {
211+
compiler.evaluate("List := object basicNew");
212+
213+
context.get('List').set('at:', CreateMethod(
214+
'at:',"(function (index) {var s=context.lookup('self').get(); if(index>=s.length){return context.lookup('null').get();} return s.get(index); })",context));
215+
216+
context.get('List').set('at:put:', CreateMethod(
217+
'at:put:',"(function (index,value) { var s=context.lookup('self').get(); while(index>=s.length){s.push(context.lookup('null').get());} context.lookup('self').get().set(index,value); return context.lookup('self').get(); })",context));
218+
219+
context.get('List').set('count', CreateMethod(
220+
'count',"(function () {return context.lookup('self').get().length; })",context));
221+
222+
context.get('List').set('removeAt:', CreateMethod(
223+
'removeAt:',"(function (index) {var s =context.lookup('self').get(); s.remove(index); return s; })",context));
224+
compiler.evaluate('List addMethod:[pop| r:= self at:(self count-1). self removeAt:(self count-1). r].List addMethod:[push: value| self at:(self count) put: value].');
225+
}
226+
227+
function InitializeOthers() {
228+
compiler.evaluate("true := ((object basicNew addMethod:[ifTrue:aBlock| aBlock value]) addMethod:[ifFalse:aBlock| ]) addMethod:[ifTrue: aBlock ifFalse: anotherBlock| aBlock value]");
229+
compiler.evaluate("true addMethod:[toString|'true']. true addMethod:[value|true]");
230+
compiler.evaluate("false := ((object basicNew addMethod:[ifTrue:aBlock| ]) addMethod:[ifFalse:aBlock| aBlock value]) addMethod:[ifTrue: aBlock ifFalse: anotherBlock| anotherBlock value]");
231+
compiler.evaluate("false addMethod:[toString|'false']. false addMethod:[value|false]")
232+
233+
//logical operators
234+
compiler.evaluate("true addMethod:[Not| false]. true addMethod:[And: other| other value]. true addMethod:[Or: other| true].");
235+
compiler.evaluate("false addMethod:[Not| true]. false addMethod:[And: other| false]. false addMethod:[Or: other| other value].");
236+
}
237+
</script>
238+
<script>
239+
function HiveEval(context, str) {
240+
return eval(str);
241+
}
240242

241-
}
242-
</script>
243-
<script>
244-
function HiveEval(context, str) {
245-
return eval(str);
246-
}
247-
248-
function CreateString( str)
249-
{return model.createString(str);}
250-
function CreateMethod(selector,func,context)
251-
{
252-
var method= model.createMap();
253-
method.set('context',context);
254-
method.set('source',func);
255-
method.set("selector",selector);
256-
method.set("value",method);
243+
function CreateString(str) {
244+
return model.createString(str);
245+
}
257246

258-
var valctx = CreateContext(context);
259-
valctx.set('self',method);
260-
var valWithArgs =model.createMap();
261-
valWithArgs.set('context',valctx);
262-
valWithArgs.set('selector', 'valWithArguments:');
263-
valWithArgs.set('source', "(function (args) {var s =context.lookup('self').get(); var func = HiveEval(context,s.get('source'));return func.apply(this,args.asArray());})");
264-
method.set('valueWithArguments:',valWithArgs);
265-
return method;
266-
}
247+
function CreateMethod(selector,func,context) {
248+
var method= model.createMap();
249+
method.set('context', context);
250+
method.set('source', func);
251+
method.set("selector", selector);
252+
method.set("value", method);
253+
254+
var valctx = CreateContext(context);
255+
valctx.set('self',method);
256+
var valWithArgs = model.createMap();
257+
valWithArgs.set('context', valctx);
258+
valWithArgs.set('selector', 'valWithArguments:');
259+
valWithArgs.set('source', "(function (args) {var s =context.lookup('self').get(); var func = HiveEval(context,s.get('source'));return func.apply(this,args.asArray());})");
260+
method.set('valueWithArguments:', valWithArgs);
261+
return method;
262+
}
267263

268-
function CreateContext(parent)
269-
{
270-
var context = model.createMap();
271-
272-
if(parent!=null)
273-
{
274-
context.set('parent',parent);
275-
}
276-
277-
278-
return context;
279-
}
280-
281-
282-
</script>
264+
function CreateContext(parent) {
265+
var context = model.createMap();
266+
if(parent!=null) {
267+
context.set('parent',parent);
268+
}
269+
return context;
270+
}
271+
</script>
283272
</body>
284273
</html>

0 commit comments

Comments
 (0)