Permalink
Browse files

resources: Move resource interfaces into its own package

  • Loading branch information...
bep committed Jan 2, 2019
1 parent 669ada4 commit ce8a09a4c0661dece931ab1173e4f09e8e04aa38
Showing with 461 additions and 377 deletions.
  1. +4 −4 deps/deps.go
  2. +1 −1 hugolib/collections.go
  3. +1 −1 hugolib/page.go
  4. +1 −1 hugolib/page_output.go
  5. +1 −1 hugolib/page_resource.go
  6. +4 −3 hugolib/pagebundler_handlers.go
  7. +1 −1 hugolib/pages_language_merge_test.go
  8. +1 −1 hugolib/resource_chain_test.go
  9. +2 −2 hugolib/site.go
  10. +8 −6 {resource → resources}/image.go
  11. +2 −2 {resource → resources}/image_cache.go
  12. +2 −2 {resource → resources}/image_test.go
  13. +48 −0 resources/internal/glob.go
  14. +26 −240 {resource → resources}/resource.go
  15. +123 −0 resources/resource/resources.go
  16. +106 −0 resources/resource/resourcetypes.go
  17. +10 −8 {resource → resources}/resource_cache.go
  18. +10 −9 {resource → resources}/resource_factories/bundler/bundler.go
  19. +9 −8 {resource → resources}/resource_factories/create/create.go
  20. +7 −4 {resource → resources}/resource_metadata.go
  21. +6 −5 {resource → resources}/resource_metadata_test.go
  22. +12 −10 {resource → resources}/resource_test.go
  23. +7 −6 {resource → resources}/resource_transformers/integrity/integrity.go
  24. +8 −7 {resource → resources}/resource_transformers/minifier/minify.go
  25. +8 −7 {resource → resources}/resource_transformers/postcss/postcss.go
  26. +8 −7 {resource → resources}/resource_transformers/templates/execute_as_template.go
  27. +7 −5 {resource → resources}/resource_transformers/tocss/scss/client.go
  28. +2 −2 {resource → resources}/resource_transformers/tocss/scss/tocss.go
  29. +2 −2 {resource → resources}/resource_transformers/tocss/scss/tocss_notavailable.go
  30. +2 −2 {resource → resources}/smartcrop.go
  31. BIN {resource → resources}/testdata/1234567890qwertyuiopasdfghjklzxcvbnm5to6eeeeee7via8eleph.jpg
  32. 0 {resource → resources}/testdata/circle.svg
  33. BIN {resource → resources}/testdata/gohugoio.png
  34. BIN {resource → resources}/testdata/sub/gohugoio2.png
  35. BIN {resource → resources}/testdata/sunset.jpg
  36. +4 −3 {resource → resources}/testhelpers_test.go
  37. +13 −12 {resource → resources}/transform.go
  38. +2 −2 {resource → resources}/transform_test.go
  39. +9 −9 tpl/resources/resources.go
  40. +2 −2 tpl/transform/unmarshal.go
  41. +2 −2 tpl/transform/unmarshal_test.go
@@ -16,7 +16,7 @@ import (
"github.com/gohugoio/hugo/media"
"github.com/gohugoio/hugo/metrics"
"github.com/gohugoio/hugo/output"
"github.com/gohugoio/hugo/resource"
"github.com/gohugoio/hugo/resources"
"github.com/gohugoio/hugo/source"
"github.com/gohugoio/hugo/tpl"
jww "github.com/spf13/jwalterweatherman"
@@ -52,7 +52,7 @@ type Deps struct {
SourceSpec *source.SourceSpec `json:"-"`

// The Resource Spec to use
ResourceSpec *resource.Spec
ResourceSpec *resources.Spec

// The configuration to use
Cfg config.Provider `json:"-"`
@@ -214,7 +214,7 @@ func New(cfg DepsCfg) (*Deps, error) {
return nil, errors.WithMessage(err, "failed to create file caches from configuration")
}

resourceSpec, err := resource.NewSpec(ps, fileCaches, logger, cfg.OutputFormats, cfg.MediaTypes)
resourceSpec, err := resources.NewSpec(ps, fileCaches, logger, cfg.OutputFormats, cfg.MediaTypes)
if err != nil {
return nil, err
}
@@ -281,7 +281,7 @@ func (d Deps) ForLanguage(cfg DepsCfg, onCreated func(d *Deps) error) (*Deps, er
// The resource cache is global so reuse.
// TODO(bep) clean up these inits.
resourceCache := d.ResourceSpec.ResourceCache
d.ResourceSpec, err = resource.NewSpec(d.PathSpec, d.ResourceSpec.FileCaches, d.Log, cfg.OutputFormats, cfg.MediaTypes)
d.ResourceSpec, err = resources.NewSpec(d.PathSpec, d.ResourceSpec.FileCaches, d.Log, cfg.OutputFormats, cfg.MediaTypes)
if err != nil {
return nil, err
}
@@ -16,7 +16,7 @@ package hugolib
import (
"fmt"

"github.com/gohugoio/hugo/resource"
"github.com/gohugoio/hugo/resources/resource"

"github.com/gohugoio/hugo/common/collections"
)
@@ -35,7 +35,7 @@ import (

"github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/hugolib/pagemeta"
"github.com/gohugoio/hugo/resource"
"github.com/gohugoio/hugo/resources/resource"

"github.com/gohugoio/hugo/output"
"github.com/mitchellh/mapstructure"
@@ -24,7 +24,7 @@ import (

"github.com/gohugoio/hugo/tpl"

"github.com/gohugoio/hugo/resource"
"github.com/gohugoio/hugo/resources/resource"

"github.com/gohugoio/hugo/media"

@@ -14,7 +14,7 @@
package hugolib

import (
"github.com/gohugoio/hugo/resource"
"github.com/gohugoio/hugo/resources/resource"
)

var (
@@ -22,7 +22,8 @@ import (
"strings"

"github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/resource"
"github.com/gohugoio/hugo/resources"
"github.com/gohugoio/hugo/resources/resource"
)

var (
@@ -255,7 +256,7 @@ func (c *contentHandlers) parsePage(h contentHandler) contentHandler {

// Assign metadata from front matter if set
if len(p.resourcesMetadata) > 0 {
resource.AssignMetadata(p.resourcesMetadata, p.Resources...)
resources.AssignMetadata(p.resourcesMetadata, p.Resources...)
}

}
@@ -309,7 +310,7 @@ func (c *contentHandlers) createResource() contentHandler {
}

resource, err := c.s.ResourceSpec.New(
resource.ResourceSourceDescriptor{
resources.ResourceSourceDescriptor{
TargetPathBuilder: ctx.parentPage.subResourceTargetPathFactory,
SourceFile: ctx.source,
RelTargetFilename: ctx.target,
@@ -17,7 +17,7 @@ import (
"fmt"
"testing"

"github.com/gohugoio/hugo/resource"
"github.com/gohugoio/hugo/resources/resource"
"github.com/stretchr/testify/require"
)

@@ -25,7 +25,7 @@ import (
"github.com/gohugoio/hugo/hugofs"

"github.com/gohugoio/hugo/common/loggers"
"github.com/gohugoio/hugo/resource/resource_transformers/tocss/scss"
"github.com/gohugoio/hugo/resources/resource_transformers/tocss/scss"
)

func TestSCSSWithIncludePaths(t *testing.T) {
@@ -39,7 +39,6 @@ import (
"github.com/gohugoio/hugo/common/hugo"
"github.com/gohugoio/hugo/common/maps"
"github.com/gohugoio/hugo/publisher"
"github.com/gohugoio/hugo/resource"
_errors "github.com/pkg/errors"

"github.com/gohugoio/hugo/langs"
@@ -62,6 +61,7 @@ import (
"github.com/gohugoio/hugo/hugolib/pagemeta"
"github.com/gohugoio/hugo/output"
"github.com/gohugoio/hugo/related"
"github.com/gohugoio/hugo/resources"
"github.com/gohugoio/hugo/source"
"github.com/gohugoio/hugo/tpl"
"github.com/spf13/afero"
@@ -760,7 +760,7 @@ func (s *Site) processPartial(events []fsnotify.Event) (whatChanged, error) {
cachePartitions := make([]string, len(events))

for i, ev := range events {
cachePartitions[i] = resource.ResourceKeyPartition(ev.Name)
cachePartitions[i] = resources.ResourceKeyPartition(ev.Name)

if s.isContentDirEvent(ev) {
logger.Println("Source changed", ev)
@@ -1,4 +1,4 @@
// Copyright 2017-present The Hugo Authors. All rights reserved.
// Copyright 2019 The Hugo Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package resource
package resources

import (
"errors"
@@ -27,6 +27,8 @@ import (
"strings"
"sync"

"github.com/gohugoio/hugo/resources/resource"

_errors "github.com/pkg/errors"

"github.com/disintegration/imaging"
@@ -43,9 +45,9 @@ import (
)

var (
_ Resource = (*Image)(nil)
_ Source = (*Image)(nil)
_ Cloner = (*Image)(nil)
_ resource.Resource = (*Image)(nil)
_ resource.Source = (*Image)(nil)
_ resource.Cloner = (*Image)(nil)
)

// Imaging contains default image processing configuration. This will be fetched
@@ -146,7 +148,7 @@ func (i *Image) Height() int {
}

// WithNewBase implements the Cloner interface.
func (i *Image) WithNewBase(base string) Resource {
func (i *Image) WithNewBase(base string) resource.Resource {
return &Image{
imaging: i.imaging,
format: i.format,
@@ -1,4 +1,4 @@
// Copyright 2018 The Hugo Authors. All rights reserved.
// Copyright 2019 The Hugo Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package resource
package resources

import (
"fmt"
@@ -1,4 +1,4 @@
// Copyright 2018 The Hugo Authors. All rights reserved.
// Copyright 2019 The Hugo Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package resource
package resources

import (
"fmt"
@@ -0,0 +1,48 @@
// Copyright 2019 The Hugo Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package internal

import (
"strings"
"sync"

"github.com/gobwas/glob"
)

var (
globCache = make(map[string]glob.Glob)
globMu sync.RWMutex
)

func GetGlob(pattern string) (glob.Glob, error) {
var g glob.Glob

globMu.RLock()
g, found := globCache[pattern]
globMu.RUnlock()
if !found {
var err error
g, err = glob.Compile(strings.ToLower(pattern), '/')
if err != nil {
return nil, err
}

globMu.Lock()
globCache[pattern] = g
globMu.Unlock()
}

return g, nil

}
Oops, something went wrong.

0 comments on commit ce8a09a

Please sign in to comment.