Fixed css crashing

This commit is contained in:
斟酌 鵬兄 2022-08-02 23:46:44 +09:00
parent 27542b133c
commit efb4eb0cde
2 changed files with 39 additions and 23 deletions

View File

@ -16,8 +16,11 @@ class Resolver:
EX_FUNC = "method"
EX_CLASS = "class"
_rLookup = None
def __init__( self, classMap ):
self.classMap = classMap
self._rLookup = {}
self._reload()
def _reload( self ):
@ -30,17 +33,23 @@ class Resolver:
def resource( self, elem ):
if "src" in elem.attrib:
return {
"src": elem.attrib[ "src" ]
, "js": elem.attrib[ "js" ]
, "css": elem.attrib[ "css" ]
}
key = elem.attrib[ "src" ]
if not key in self._rLookup:
self._rLookup[ key ] = {
"src": elem.attrib[ "src" ]
, "js": elem.attrib[ "js" ]
, "css": elem.attrib[ "css" ]
}
return self._rLookup[ key ]
parent = self.parentMap[ elem ]
if parent != None:
return self.resource( parent )
def locate( self, key ):
return self._rLookup.get( key )
def resolve( self, c, classList ):
self.resolved = []
self.__resolve( c, classList )
@ -161,27 +170,23 @@ class BotanClassResolver:
for cdef in classList:
f = cdef[ "src" ]
possibleList = []
cssFile = os.path.splitext( f )[0] + ".css"
if cssFile not in possibleList:
possibleList.append( cssFile )
if not cdef[ "css" ] == "1":
cssList.append( cdef )
f = f.split( PY_SEP )
l = len( f )
for i in range( 1, l ):
cssFile = PY_SEP.join( x for x in f[:-i] ) + PY_SEP + "@_this.css"
if cssFile not in possibleList:
possibleList.append( cssFile )
key = PY_SEP.join( x for x in f[:-i] ) + PY_SEP + "_this.js"
_def = self.resv.locate( key )
possibleList.sort()
if _def and not _def[ "css" ] == "1":
cssList.append( _def )
for f in possibleList:
f = f.replace( "@_this.css", "_this.css" )
if os.path.exists( os.path.join( self.R, f ) ):
cssList.append( f )
cssList.sort( key = lambda x : x[ "src" ] )
def getCache( self, fileList, cName, mode ):
@ -229,7 +234,6 @@ class BotanClassResolver:
# The root file
outputJs = self.BotanFile( "_this.js" )
for f in cList:
f = f[ "src" ]
path = (
@ -277,7 +281,7 @@ class BotanClassResolver:
outputCss = struct + self.BotanFile( "_this.css" )
for f in self.cleanList( cList ):
outputCss += self.BotanFile( f )
outputCss += self.BotanFile( f["src"][:-2] + "css" )
self.JWork.saveCache( os.path.join( self.CR, md5[0] ), outputCss, "css" )

View File

@ -20,7 +20,6 @@ app.conf.update( broker_url = config["BotanJS"]["CeleryBroker"] )
JWork.buildClassMap.delay( jsRoot, bmap )
from botanjs.service.jclassresv import BotanClassResolver as JCResv
srvHandler = JCResv( JWork, jsRoot, bmap, jsCache )
import unittest
@ -28,20 +27,33 @@ class TestStringMethods( unittest.TestCase ):
# Run each twice to test the cache capabilities
def test_ojscall( self ):
srv = JCResv( JWork, jsRoot, bmap, jsCache )
for _ in range(0,2):
s = srvHandler.getAPI( "System", mode = "rjs" )
self.assertTrue( "BotanJS.define( \"System\" );" in s )
s = srv.getAPI( "System", mode = "rjs" )
if not ( "BotanJS.define( \"System\" );" in s ):
print( "A---------------------" )
print( s )
print( "B---------------------" )
self.assertTrue( False)
def test_import( self ):
srv = JCResv( JWork, jsRoot, bmap, jsCache )
for _ in range(0,2):
s = srvHandler.getAPI( "System.Policy", mode = "rjs" )
s = srv.getAPI( "System.Policy", mode = "rjs" )
self.assertTrue( "BotanJS.define( \"System.Policy\" );" in s )
self.assertTrue( "BotanJS.define( \"System.Global\" );" in s )
def test_cssInheritance( self ):
srv = JCResv( JWork, jsRoot, bmap, jsCache )
for _ in range(0,2):
s = srvHandler.getAPI( "System", mode = "rcss" )
s = srv.getAPI( "System", mode = "rcss" )
self.assertTrue( "/* @ */" in s )
# def test_jsZCalls( self ):
# srv = JCResv( JWork, jsRoot, bmap, jsCache )
# for _ in range(0,2):
# s = srv.getAPI( "eJx1zsEKgzAQBNAfKvsPaaj0YE/6A4tuJbDJlM2K9O/rpcUKOQ6PYSZUN9DgbE9WpZtKluJ0F57FLuFfe35jdXpwKp1xlrN/2x3gv/ZVsVBEfqHsVmmQyRNKQ6Nhm0dejtyYPVowT5PKHl2qN36PGyJ0zeUDs1BbKA==", mode = "css" )
# print( s )
if __name__ == '__main__':
unittest.main()