Skip to content

Commit 5199f5c

Browse files
authored
Support HTML attributes in remote assets (#409)
* Support HTML attributes in remote assets * Fix CSS attributes * Adding coveralls * Small fix for coveralls * Help coveralls
1 parent 379ffbf commit 5199f5c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+369
-685
lines changed

Diff for: .github/workflows/build.yml

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ on:
33
branches:
44
- main
55
pull_request:
6+
branches:
7+
- main
68

79
name: Test
810
jobs:
@@ -19,3 +21,9 @@ jobs:
1921
run: npm install
2022
- name: Run Test
2123
run: make test
24+
- name: Coveralls GitHub Action
25+
uses: coverallsapp/github-action@v2
26+
with:
27+
format: golang
28+
file: coverage/cover.out
29+
github-token: ${{ secrets.GITHUB_TOKEN }}

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ You will need to install golang to use this tool. Learn more at [go.dev](https:/
3939
Once go is installed, you can install the `htmlassets` tool with:
4040

4141
```bash
42-
go install github.com/gauntface/go-html-asset-manager/v4/cmds/htmlassets@latest
42+
go install github.com/gauntface/go-html-asset-manager/v5/cmds/htmlassets@latest
4343
```
4444

4545
If you'd like to generate image sizes, you can install the `genimgs` tool with:
4646

4747
```bash
48-
go install github.com/gauntface/go-html-asset-manager/v4/cmds/genimgs@latest
48+
go install github.com/gauntface/go-html-asset-manager/v5/cmds/genimgs@latest
4949
```
5050

5151
## Usage

Diff for: assets/assetid/assetid.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"path/filepath"
2323
"strings"
2424

25-
"github.com/gauntface/go-html-asset-manager/v4/assets"
25+
"github.com/gauntface/go-html-asset-manager/v5/assets"
2626
)
2727

2828
const (

Diff for: assets/assetid/assetid_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"errors"
2121
"testing"
2222

23-
"github.com/gauntface/go-html-asset-manager/v4/assets"
23+
"github.com/gauntface/go-html-asset-manager/v5/assets"
2424
"github.com/google/go-cmp/cmp"
2525
)
2626

Diff for: assets/assetmanager/assetmanager.go

+27-12
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ import (
2525
"sort"
2626
"strings"
2727

28-
"github.com/gauntface/go-html-asset-manager/v4/assets"
29-
"github.com/gauntface/go-html-asset-manager/v4/assets/assetid"
30-
"github.com/gauntface/go-html-asset-manager/v4/utils/files"
31-
"github.com/gauntface/go-html-asset-manager/v4/utils/stringui"
28+
"github.com/gauntface/go-html-asset-manager/v5/assets"
29+
"github.com/gauntface/go-html-asset-manager/v5/assets/assetid"
30+
"github.com/gauntface/go-html-asset-manager/v5/utils/files"
31+
"github.com/gauntface/go-html-asset-manager/v5/utils/stringui"
32+
"golang.org/x/net/html"
3233
)
3334

3435
var (
@@ -306,7 +307,10 @@ func (l *LocalAsset) URL() (string, error) {
306307
}
307308

308309
return path.Join("/", relPath), nil
310+
}
309311

312+
func (l *LocalAsset) Attributes() []html.Attribute {
313+
return nil
310314
}
311315

312316
func (l *LocalAsset) IsLocal() bool {
@@ -325,16 +329,18 @@ func (l *LocalAsset) String() string {
325329
}
326330

327331
type RemoteAsset struct {
328-
id string
329-
url string
330-
assetType assets.Type
332+
id string
333+
url string
334+
attributes []html.Attribute
335+
assetType assets.Type
331336
}
332337

333-
func NewRemoteAsset(ID, url string, ty assets.Type) *RemoteAsset {
338+
func NewRemoteAsset(ID, src string, attributes []html.Attribute, ty assets.Type) *RemoteAsset {
334339
return &RemoteAsset{
335-
id: ID,
336-
url: url,
337-
assetType: ty,
340+
id: ID,
341+
url: src,
342+
attributes: attributes,
343+
assetType: ty,
338344
}
339345
}
340346

@@ -354,6 +360,10 @@ func (r *RemoteAsset) URL() (string, error) {
354360
return r.url, nil
355361
}
356362

363+
func (r *RemoteAsset) Attributes() []html.Attribute {
364+
return r.attributes
365+
}
366+
357367
func (r *RemoteAsset) Contents() (string, error) {
358368
return "", fmt.Errorf("%w for %q", errNoContents, r.url)
359369
}
@@ -363,7 +373,11 @@ func (r *RemoteAsset) IsLocal() bool {
363373
}
364374

365375
func (r *RemoteAsset) String() string {
366-
return fmt.Sprintf("<Remote Asset: %q>", r.url)
376+
attrs := []string{}
377+
for _, a := range r.attributes {
378+
attrs = append(attrs, fmt.Sprintf("%v=%q", a.Key, a.Val))
379+
}
380+
return fmt.Sprintf("<Remote Asset: %q Attributes: [%v]>", r.url, strings.Join(attrs, ", "))
367381
}
368382

369383
func (r *RemoteAsset) Debug(d string) bool {
@@ -397,6 +411,7 @@ type Asset interface {
397411
Media() string
398412
URL() (string, error)
399413
Contents() (string, error)
414+
Attributes() []html.Attribute
400415
IsLocal() bool
401416
String() string
402417
Debug(d string) bool

Diff for: assets/assetmanager/assetmanager_test.go

+29-7
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ import (
2424
"reflect"
2525
"testing"
2626

27-
"github.com/gauntface/go-html-asset-manager/v4/assets"
28-
"github.com/gauntface/go-html-asset-manager/v4/assets/assetid"
27+
"github.com/gauntface/go-html-asset-manager/v5/assets"
28+
"github.com/gauntface/go-html-asset-manager/v5/assets/assetid"
2929
"github.com/google/go-cmp/cmp"
30+
"golang.org/x/net/html"
3031
)
3132

3233
var errInjected = errors.New("injected error")
@@ -1096,25 +1097,46 @@ func TestNewRemoteAsset(t *testing.T) {
10961097
description string
10971098
id string
10981099
url string
1100+
attributes []html.Attribute
10991101
assetType assets.Type
11001102
want *RemoteAsset
11011103
}{
11021104
{
11031105
description: "return new remote asset",
11041106
id: "example-id",
11051107
url: "http://example.com/example.css",
1106-
assetType: assets.InlineCSS,
1108+
attributes: []html.Attribute{
1109+
{
1110+
Key: "example",
1111+
Val: "test",
1112+
},
1113+
{
1114+
Key: "example-2",
1115+
Val: "another test",
1116+
},
1117+
},
1118+
assetType: assets.InlineCSS,
11071119
want: &RemoteAsset{
1108-
id: "example-id",
1109-
url: "http://example.com/example.css",
1120+
id: "example-id",
1121+
url: "http://example.com/example.css",
1122+
attributes: []html.Attribute{
1123+
{
1124+
Key: "example",
1125+
Val: "test",
1126+
},
1127+
{
1128+
Key: "example-2",
1129+
Val: "another test",
1130+
},
1131+
},
11101132
assetType: assets.InlineCSS,
11111133
},
11121134
},
11131135
}
11141136

11151137
for _, tt := range tests {
11161138
t.Run(tt.description, func(t *testing.T) {
1117-
got := NewRemoteAsset(tt.id, tt.url, tt.assetType)
1139+
got := NewRemoteAsset(tt.id, tt.url, tt.attributes, tt.assetType)
11181140
opts := []cmp.Option{
11191141
cmp.AllowUnexported(RemoteAsset{}),
11201142
}
@@ -1180,7 +1202,7 @@ func TestRemoteAsset_String(t *testing.T) {
11801202
asset: &RemoteAsset{
11811203
url: "http://example.com/url.html",
11821204
},
1183-
want: `<Remote Asset: "http://example.com/url.html">`,
1205+
want: `<Remote Asset: "http://example.com/url.html" Attributes: []>`,
11841206
},
11851207
}
11861208

Diff for: assets/assetstubs/assetsstubs.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ package assetstubs
1919
import (
2020
"testing"
2121

22-
"github.com/gauntface/go-html-asset-manager/v4/assets"
23-
"github.com/gauntface/go-html-asset-manager/v4/assets/assetmanager"
22+
"github.com/gauntface/go-html-asset-manager/v5/assets"
23+
"github.com/gauntface/go-html-asset-manager/v5/assets/assetmanager"
24+
"golang.org/x/net/html"
2425
)
2526

2627
type Manager struct {
@@ -64,6 +65,8 @@ type Asset struct {
6465
URLReturn string
6566
URLError error
6667

68+
AttributesReturn []html.Attribute
69+
6770
ContentsReturn string
6871
ContentsError error
6972

@@ -92,6 +95,10 @@ func (a *Asset) URL() (string, error) {
9295
return a.URLReturn, a.URLError
9396
}
9497

98+
func (a *Asset) Attributes() []html.Attribute {
99+
return a.AttributesReturn
100+
}
101+
95102
func (a *Asset) Contents() (string, error) {
96103
return a.ContentsReturn, a.ContentsError
97104
}

Diff for: assets/genimgs/genimgs.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313
"github.com/aws/aws-sdk-go-v2/service/s3"
1414
awstypes "github.com/aws/aws-sdk-go-v2/service/s3/types"
1515
"github.com/disintegration/imaging"
16-
"github.com/gauntface/go-html-asset-manager/v4/utils/config"
17-
"github.com/gauntface/go-html-asset-manager/v4/utils/files"
16+
"github.com/gauntface/go-html-asset-manager/v5/utils/config"
17+
"github.com/gauntface/go-html-asset-manager/v5/utils/files"
1818
)
1919

2020
var (

Diff for: cmds/genimgs/genimgs.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ import (
3838
awstypes "github.com/aws/aws-sdk-go-v2/service/s3/types"
3939
"github.com/chai2010/webp"
4040
"github.com/disintegration/imaging"
41-
"github.com/gauntface/go-html-asset-manager/v4/assets"
42-
"github.com/gauntface/go-html-asset-manager/v4/assets/assetmanager"
43-
"github.com/gauntface/go-html-asset-manager/v4/utils/config"
44-
"github.com/gauntface/go-html-asset-manager/v4/utils/files"
45-
"github.com/gauntface/go-html-asset-manager/v4/utils/sets"
41+
"github.com/gauntface/go-html-asset-manager/v5/assets"
42+
"github.com/gauntface/go-html-asset-manager/v5/assets/assetmanager"
43+
"github.com/gauntface/go-html-asset-manager/v5/utils/config"
44+
"github.com/gauntface/go-html-asset-manager/v5/utils/files"
45+
"github.com/gauntface/go-html-asset-manager/v5/utils/sets"
4646
"github.com/mitchellh/go-homedir"
4747
"github.com/schollz/progressbar/v3"
4848
)

Diff for: cmds/htmlassets/htmlassets.go

+21-21
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,27 @@ import (
3232

3333
awsconfig "github.com/aws/aws-sdk-go-v2/config"
3434
"github.com/aws/aws-sdk-go-v2/service/s3"
35-
"github.com/gauntface/go-html-asset-manager/v4/assets"
36-
"github.com/gauntface/go-html-asset-manager/v4/assets/assetmanager"
37-
"github.com/gauntface/go-html-asset-manager/v4/manipulations"
38-
"github.com/gauntface/go-html-asset-manager/v4/manipulations/asyncsrc"
39-
"github.com/gauntface/go-html-asset-manager/v4/manipulations/iframedefaultsize"
40-
"github.com/gauntface/go-html-asset-manager/v4/manipulations/imgsize"
41-
"github.com/gauntface/go-html-asset-manager/v4/manipulations/imgtopicture"
42-
"github.com/gauntface/go-html-asset-manager/v4/manipulations/injectassets"
43-
"github.com/gauntface/go-html-asset-manager/v4/manipulations/lazyload"
44-
"github.com/gauntface/go-html-asset-manager/v4/manipulations/opengraphimg"
45-
"github.com/gauntface/go-html-asset-manager/v4/manipulations/ratiowrapper"
46-
"github.com/gauntface/go-html-asset-manager/v4/manipulations/stripassets"
47-
"github.com/gauntface/go-html-asset-manager/v4/manipulations/vimeoclean"
48-
"github.com/gauntface/go-html-asset-manager/v4/manipulations/youtubeclean"
49-
"github.com/gauntface/go-html-asset-manager/v4/preprocessors"
50-
"github.com/gauntface/go-html-asset-manager/v4/preprocessors/hamassets"
51-
"github.com/gauntface/go-html-asset-manager/v4/preprocessors/jsonassets"
52-
"github.com/gauntface/go-html-asset-manager/v4/preprocessors/revisionassets"
53-
"github.com/gauntface/go-html-asset-manager/v4/utils/config"
54-
"github.com/gauntface/go-html-asset-manager/v4/utils/html/htmlencoding"
55-
"github.com/gauntface/go-html-asset-manager/v4/utils/vimeoapi"
35+
"github.com/gauntface/go-html-asset-manager/v5/assets"
36+
"github.com/gauntface/go-html-asset-manager/v5/assets/assetmanager"
37+
"github.com/gauntface/go-html-asset-manager/v5/manipulations"
38+
"github.com/gauntface/go-html-asset-manager/v5/manipulations/asyncsrc"
39+
"github.com/gauntface/go-html-asset-manager/v5/manipulations/iframedefaultsize"
40+
"github.com/gauntface/go-html-asset-manager/v5/manipulations/imgsize"
41+
"github.com/gauntface/go-html-asset-manager/v5/manipulations/imgtopicture"
42+
"github.com/gauntface/go-html-asset-manager/v5/manipulations/injectassets"
43+
"github.com/gauntface/go-html-asset-manager/v5/manipulations/lazyload"
44+
"github.com/gauntface/go-html-asset-manager/v5/manipulations/opengraphimg"
45+
"github.com/gauntface/go-html-asset-manager/v5/manipulations/ratiowrapper"
46+
"github.com/gauntface/go-html-asset-manager/v5/manipulations/stripassets"
47+
"github.com/gauntface/go-html-asset-manager/v5/manipulations/vimeoclean"
48+
"github.com/gauntface/go-html-asset-manager/v5/manipulations/youtubeclean"
49+
"github.com/gauntface/go-html-asset-manager/v5/preprocessors"
50+
"github.com/gauntface/go-html-asset-manager/v5/preprocessors/hamassets"
51+
"github.com/gauntface/go-html-asset-manager/v5/preprocessors/jsonassets"
52+
"github.com/gauntface/go-html-asset-manager/v5/preprocessors/revisionassets"
53+
"github.com/gauntface/go-html-asset-manager/v5/utils/config"
54+
"github.com/gauntface/go-html-asset-manager/v5/utils/html/htmlencoding"
55+
"github.com/gauntface/go-html-asset-manager/v5/utils/vimeoapi"
5656
"github.com/mitchellh/go-homedir"
5757
"github.com/schollz/progressbar/v3"
5858
"golang.org/x/net/html"

Diff for: cmds/htmlassets/htmlassets_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ import (
2727
"strings"
2828
"testing"
2929

30-
"github.com/gauntface/go-html-asset-manager/v4/assets"
31-
"github.com/gauntface/go-html-asset-manager/v4/assets/assetmanager"
32-
"github.com/gauntface/go-html-asset-manager/v4/assets/assetstubs"
33-
"github.com/gauntface/go-html-asset-manager/v4/manipulations"
34-
"github.com/gauntface/go-html-asset-manager/v4/preprocessors"
35-
"github.com/gauntface/go-html-asset-manager/v4/utils/config"
30+
"github.com/gauntface/go-html-asset-manager/v5/assets"
31+
"github.com/gauntface/go-html-asset-manager/v5/assets/assetmanager"
32+
"github.com/gauntface/go-html-asset-manager/v5/assets/assetstubs"
33+
"github.com/gauntface/go-html-asset-manager/v5/manipulations"
34+
"github.com/gauntface/go-html-asset-manager/v5/preprocessors"
35+
"github.com/gauntface/go-html-asset-manager/v5/utils/config"
3636
"github.com/google/go-cmp/cmp"
3737
"github.com/google/go-cmp/cmp/cmpopts"
3838
"github.com/mitchellh/go-homedir"
@@ -324,9 +324,9 @@ func Test_manipulations(t *testing.T) {
324324
description: "return errors if processing file fails",
325325
manager: &assetstubs.Manager{
326326
WithTypeReturn: map[assets.Type][]assetmanager.Asset{
327-
assets.HTML: []assetmanager.Asset{
327+
assets.HTML: {
328328
assetstubs.MustNewLocalAsset(t, "/example/", "/example/example-1.html"),
329-
assetmanager.NewRemoteAsset("example", "http://example.com/123", assets.Unknown),
329+
assetmanager.NewRemoteAsset("example", "http://example.com/123", []html.Attribute{}, assets.Unknown),
330330
},
331331
},
332332
},

Diff for: embedassets/assets/js/components/n-ham-c-lite-vi-async.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)