5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-21 19:39:29 +08:00

Support js & css in link tags

This commit is contained in:
Lea Anthony 2021-01-03 21:20:29 +11:00
parent 2dedd0b702
commit e9a0e45d5c
No known key found for this signature in database
GPG Key ID: 33DAF7BB90A58405

View File

@ -102,24 +102,29 @@ func (a *AssetBundle) processHTML(htmldata string) error {
if attr.Key == "href" { if attr.Key == "href" {
asset.Path = attr.Val asset.Path = attr.Val
} }
// stylesheet // standard stylesheet
if attr.Key == "rel" && attr.Val == "stylesheet" { if attr.Key == "rel" && attr.Val == "stylesheet" {
asset.Type = AssetTypes.CSS asset.Type = AssetTypes.CSS
} }
if attr.Key == "as" && attr.Val == "style" {
asset.Type = AssetTypes.CSS
}
if attr.Key == "as" && attr.Val == "script" {
asset.Type = AssetTypes.JS
} }
err := asset.Load(a.basedirectory)
if err != nil {
return err
} }
// Ensure we don't include duplicates // Ensure we don't include duplicates
if !paths.Contains(asset.Path) { if !paths.Contains(asset.Path) {
err := asset.Load(a.basedirectory)
if err != nil {
return err
}
a.assets = append(a.assets, asset) a.assets = append(a.assets, asset)
paths.Add(asset.Path) paths.Add(asset.Path)
} }
} }
if "script" == token.Data { if "script" == token.Data {
tokenType = tokenizer.Next() tokenType = tokenizer.Next()
//just make sure it's actually a text token //just make sure it's actually a text token
asset := &Asset{Type: AssetTypes.JS} asset := &Asset{Type: AssetTypes.JS}
@ -129,11 +134,14 @@ func (a *AssetBundle) processHTML(htmldata string) error {
break break
} }
} }
if !paths.Contains(asset.Path) {
err := asset.Load(a.basedirectory) err := asset.Load(a.basedirectory)
if err != nil { if err != nil {
return err return err
} }
a.assets = append(a.assets, asset) a.assets = append(a.assets, asset)
paths.Add(asset.Path)
}
} }
} }
} }
@ -188,14 +196,14 @@ func (a *AssetBundle) WriteToCFile(targetDir string) (string, error) {
// ConvertToAssetDB returns an assetdb.AssetDB initialized with // ConvertToAssetDB returns an assetdb.AssetDB initialized with
// the items in the AssetBundle // the items in the AssetBundle
func (a *AssetBundle) ConvertToAssetDB() (*assetdb.AssetDB, error) { func (a *AssetBundle) ConvertToAssetDB() (*assetdb.AssetDB, error) {
assetdb := assetdb.NewAssetDB() theassetdb := assetdb.NewAssetDB()
// Loop over the Assets // Loop over the Assets
for _, asset := range a.assets { for _, asset := range a.assets {
assetdb.AddAsset(asset.Path, []byte(asset.Data)) theassetdb.AddAsset(asset.Path, []byte(asset.Data))
} }
return assetdb, nil return theassetdb, nil
} }
// Dump will output the assets to the terminal // Dump will output the assets to the terminal