modules.js tested to run but requires fix in jstimestamps.py to run packages correctly
This commit is contained in:
parent
589f916daa
commit
4276fee221
5 changed files with 53 additions and 25 deletions
|
|
@ -70,4 +70,4 @@ class wnJSCompiler:
|
|||
|
||||
if __name__=="__main__":
|
||||
a = wnJSCompiler()
|
||||
print a.compilejs('../js/wntest')
|
||||
print a.compilejs('../js/wn')
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ try:
|
|||
global jsonout
|
||||
import webnotes.utils.jsnamespace as jsn
|
||||
filename = jsn.jsNamespace.modname_to_filename(module_name,jsdir)
|
||||
print 'filename is ' + filename
|
||||
import os
|
||||
try:
|
||||
f = open(os.path.join(filename))
|
||||
|
|
@ -41,6 +40,7 @@ try:
|
|||
jsonout[module_name]=out
|
||||
|
||||
def load_js_module(module_name):
|
||||
global jsonout
|
||||
from webnotes import defs
|
||||
devmode = getattr(defs,'developer_mode')
|
||||
if devmode:
|
||||
|
|
@ -49,12 +49,11 @@ try:
|
|||
if module_name not in jsonout:
|
||||
dependent_mods = get_dependencies(module_name)
|
||||
for module in dependent_mods:
|
||||
load_js_module(module)
|
||||
load_js_from_file(module_name)
|
||||
load_js_from_file(module)
|
||||
load_js_from_file(module_name)
|
||||
|
||||
def get_dependencies(module_name):
|
||||
import webnotes.utils.jsdependency as jsd
|
||||
print 'module_name is ' + module_name
|
||||
ret = jsd.jsDependencyBuilder.build_dependency(jsdir,module_name)
|
||||
return ret
|
||||
|
||||
|
|
@ -74,7 +73,8 @@ try:
|
|||
except:
|
||||
pass
|
||||
|
||||
load_js_module('wntest.a.s')
|
||||
load_js_module(form.getvalue('module'))
|
||||
#load_js_module('wn.modules')
|
||||
|
||||
if compress and len(out)>512:
|
||||
out_buf = compress_string(str_out)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
class generateTimestamp:
|
||||
ts_filename = 'timestamp.json'
|
||||
ts_filename = 'timestamp.js'
|
||||
@staticmethod
|
||||
def list_js_files(jsdir,ext='js'):
|
||||
import os
|
||||
|
|
@ -13,7 +13,7 @@ class generateTimestamp:
|
|||
for filename in files:
|
||||
if filename.endswith(ext):
|
||||
all_files.append(os.path.join(root,filename))
|
||||
|
||||
|
||||
os.chdir(oldcwd)
|
||||
for i in nono:
|
||||
for j in all_files:
|
||||
|
|
@ -41,6 +41,7 @@ class generateTimestamp:
|
|||
filename = filename.lstrip('./')
|
||||
filename = filename.rstrip('.js')
|
||||
filename = filename.replace('/','.')
|
||||
#TODO Remove _packagename from the end if file is a package
|
||||
tsdict[filename] = ts
|
||||
os.chdir(oldcwd)
|
||||
return tsdict
|
||||
|
|
@ -69,6 +70,8 @@ class generateTimestamp:
|
|||
import json
|
||||
import os
|
||||
tsdict = generateTimestamp.gents(jsdir)
|
||||
f = open(os.path.join(jsdir,generateTimestamp.ts_filename),'w')
|
||||
f = open(os.path.join(jsdir,'wn',generateTimestamp.ts_filename),'w') #FIXME Hard coded!
|
||||
f.write('wn={}\n')
|
||||
f.write('wn.timestamp=')
|
||||
f.write(json.dumps(tsdict))
|
||||
f.close()
|
||||
|
|
|
|||
|
|
@ -13,37 +13,51 @@ wn.module = {
|
|||
if(wn[module_name]) return;
|
||||
wn.module.load(module_name, callback);
|
||||
},
|
||||
|
||||
|
||||
load: function(module_name, callback) {
|
||||
// if loaded in local and recent
|
||||
alert('checking in local')
|
||||
if(wn.module.in_local(module_name)) {
|
||||
if(callback) callback();
|
||||
return;
|
||||
}
|
||||
alert('loading from server')
|
||||
wn.module.get_from_server(module_name,callback )
|
||||
|
||||
|
||||
},
|
||||
get_from_server : function(module_name, callback) {
|
||||
|
||||
var req = $.ajax({
|
||||
url: 'js/' + module_name.replace(/./g, "/"),
|
||||
datatype:'script',
|
||||
success: wn.module.accept
|
||||
});
|
||||
req.module_name = module_name;
|
||||
req.callback = callback;
|
||||
req = $.ajax({
|
||||
url: 'cgi-bin/getjsfile.cgi?module=' + module_name, // TODO use getjsfile.cgi, replace not reqd
|
||||
datatype:'text',
|
||||
success: [wn.module.accept,callback]
|
||||
})
|
||||
},
|
||||
|
||||
in_local: function(module_name) {
|
||||
var m = localStorage.getItem(module_name);
|
||||
if(m && m.timestamp == wn.timestamps[module_name]) {
|
||||
// check if module in local and recent
|
||||
var m = JSON.parse(localStorage.getItem(module_name));
|
||||
alert('in_local' + m.timestamp)
|
||||
if( m && m.timestamp == wn.timestamps[module_name]) {
|
||||
eval(m.code);
|
||||
return true;
|
||||
}
|
||||
return false
|
||||
},
|
||||
|
||||
accept: function(data, status, req) {
|
||||
var m = {
|
||||
timestamp: wn.timestamps[req.module_name],
|
||||
code: data,
|
||||
accept: function(data, status, jqXHR) {
|
||||
|
||||
data = JSON.parse(data)
|
||||
for (var codename in data)
|
||||
{
|
||||
localStorage.setItem(codename, JSON.stringify({
|
||||
|
||||
timestamp : wn.timestamps[codename],
|
||||
code : data[codename]
|
||||
|
||||
}))
|
||||
eval(data[codename])
|
||||
}
|
||||
localStorage.setItem(req.module_name, m);
|
||||
if(req.callback) req.callback();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
11
test.html
Normal file
11
test.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<html>
|
||||
<head>
|
||||
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.min.js"> </script>
|
||||
<script type="text/javascript" src="js/wn/timestamp.js"> </script>
|
||||
<script type="text/javascript" src="js/utils/json.js"></script>
|
||||
<script type="text/javascript" src="js/wn/modules.js"> </script>
|
||||
</head>
|
||||
<body>
|
||||
loaded
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue