Skip to content

Commit

Permalink
Rename pipeline -> renderers
Browse files Browse the repository at this point in the history
  • Loading branch information
osteele committed Aug 18, 2017
1 parent 8ac7f1e commit 9816243
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 66 deletions.
4 changes: 2 additions & 2 deletions collection/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/osteele/gojekyll/config"
"github.com/osteele/gojekyll/pages"
"github.com/osteele/gojekyll/pipelines"
"github.com/osteele/gojekyll/renderers"
"github.com/osteele/gojekyll/templates"
"github.com/osteele/liquid"
)
Expand All @@ -26,7 +26,7 @@ type Site interface {
Config() *config.Config
Exclude(string) bool
RelativePath(string) string
RenderingPipeline() pipelines.PipelineInterface
RendererManager() renderers.Renderers
OutputExt(pathname string) string
}

Expand Down
12 changes: 6 additions & 6 deletions collection/collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import (
"testing"

"github.com/osteele/gojekyll/config"
"github.com/osteele/gojekyll/pipelines"
"github.com/osteele/gojekyll/renderers"
"github.com/stretchr/testify/require"
)

type siteFake struct{ c config.Config }

func (s siteFake) Config() *config.Config { return &s.c }
func (s siteFake) Exclude(string) bool { return false }
func (s siteFake) OutputExt(string) string { return "" }
func (s siteFake) RelativePath(string) string { panic("unimplemented") }
func (s siteFake) RenderingPipeline() pipelines.PipelineInterface { panic("unimplemented") }
func (s siteFake) Config() *config.Config { return &s.c }
func (s siteFake) Exclude(string) bool { return false }
func (s siteFake) OutputExt(string) string { return "" }
func (s siteFake) RelativePath(string) string { panic("unimplemented") }
func (s siteFake) RendererManager() renderers.Renderers { panic("unimplemented") }

func TestNewCollection(t *testing.T) {
site := siteFake{config.Default()}
Expand Down
2 changes: 1 addition & 1 deletion filters/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func whereFilter(array []map[string]interface{}, key string, value interface{})
// string filters

func scssifyFilter(s string) (string, error) {
// this doesn't try to share context or setup with the rendering pipeline,
// this doesn't try to share context or setup with the rendering manager,
// and it doesn't minify
buf := new(bytes.Buffer)
comp, err := libsass.New(buf, bytes.NewBufferString(s))
Expand Down
4 changes: 2 additions & 2 deletions pages/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"io"

"github.com/osteele/gojekyll/config"
"github.com/osteele/gojekyll/pipelines"
"github.com/osteele/gojekyll/renderers"
)

// A Document is a Jekyll post, page, or file.
Expand All @@ -26,6 +26,6 @@ type Document interface {
type Site interface {
Config() *config.Config
RelativePath(string) string
RenderingPipeline() pipelines.PipelineInterface
RendererManager() renderers.Renderers
OutputExt(pathname string) string
}
20 changes: 10 additions & 10 deletions pages/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"

"github.com/osteele/gojekyll/config"
"github.com/osteele/gojekyll/pipelines"
"github.com/osteele/gojekyll/renderers"
"github.com/osteele/liquid"
"github.com/stretchr/testify/require"
)
Expand All @@ -16,19 +16,19 @@ type siteFake struct {
cfg config.Config
}

func (s siteFake) Config() *config.Config { return &s.cfg }
func (s siteFake) RelativePath(p string) string { return p }
func (s siteFake) RenderingPipeline() pipelines.PipelineInterface { return &pipelineFake{s.t} }
func (s siteFake) OutputExt(p string) string { return filepath.Ext(p) }
func (s siteFake) Config() *config.Config { return &s.cfg }
func (s siteFake) RelativePath(p string) string { return p }
func (s siteFake) RendererManager() renderers.Renderers { return &renderManagerFake{s.t} }
func (s siteFake) OutputExt(p string) string { return filepath.Ext(p) }

type pipelineFake struct{ t *testing.T }
type renderManagerFake struct{ t *testing.T }

func (p pipelineFake) OutputExt(string) string { return ".html" }
func (p pipelineFake) ApplyLayout(layout string, src []byte, vars liquid.Bindings) ([]byte, error) {
func (p renderManagerFake) OutputExt(string) string { return ".html" }
func (p renderManagerFake) ApplyLayout(layout string, src []byte, vars liquid.Bindings) ([]byte, error) {
require.Equal(p.t, "layout1", layout)
return nil, nil
}
func (p pipelineFake) Render(w io.Writer, src []byte, vars liquid.Bindings, filename string, lineNo int) error {
func (p renderManagerFake) Render(w io.Writer, src []byte, vars liquid.Bindings, filename string, lineNo int) error {
_, err := io.WriteString(w, "rendered: ")
if err != nil {
return err
Expand All @@ -37,6 +37,6 @@ func (p pipelineFake) Render(w io.Writer, src []byte, vars liquid.Bindings, file
return err
}

func (p pipelineFake) RenderTemplate(src []byte, vars liquid.Bindings, filename string, lineNo int) ([]byte, error) {
func (p renderManagerFake) RenderTemplate(src []byte, vars liquid.Bindings, filename string, lineNo int) ([]byte, error) {
return append([]byte("rendered: "), src...), nil
}
4 changes: 2 additions & 2 deletions pages/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (p *page) Write(w io.Writer) error {
content := p.content
layout, ok := p.frontMatter["layout"].(string)
if ok && layout != "" {
rp := p.site.RenderingPipeline()
rp := p.site.RendererManager()
b, e := rp.ApplyLayout(layout, []byte(content), p.TemplateContext())
if e != nil {
return e
Expand Down Expand Up @@ -215,7 +215,7 @@ func (p *page) SetContent(content string) {
}

func (p *page) computeContent() (cn string, ex string, err error) {
pl := p.site.RenderingPipeline()
pl := p.site.RendererManager()
buf := new(bytes.Buffer)
err = pl.Render(buf, p.raw, p.TemplateContext(), p.filename, p.firstLine)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions pipelines/layouts.go → renderers/layouts.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pipelines
package renderers

import (
"fmt"
Expand All @@ -14,7 +14,7 @@ import (
)

// ApplyLayout applies the named layout to the data.
func (p *Pipeline) ApplyLayout(name string, data []byte, vars liquid.Bindings) ([]byte, error) {
func (p *Manager) ApplyLayout(name string, data []byte, vars liquid.Bindings) ([]byte, error) {
for name != "" {
var lfm map[string]interface{}
tpl, err := p.FindLayout(name, &lfm)
Expand All @@ -35,7 +35,7 @@ func (p *Pipeline) ApplyLayout(name string, data []byte, vars liquid.Bindings) (
}

// FindLayout returns a template for the named layout.
func (p *Pipeline) FindLayout(base string, fm *map[string]interface{}) (tpl *liquid.Template, err error) {
func (p *Manager) FindLayout(base string, fm *map[string]interface{}) (tpl *liquid.Template, err error) {
// not cached, but the time here is negligible
exts := []string{"", ".html"}
for _, ext := range strings.SplitN(p.cfg.MarkdownExt, `,`, -1) {
Expand Down Expand Up @@ -76,7 +76,7 @@ loop:
}

// LayoutsDir returns the path to the layouts directory.
func (p *Pipeline) layoutDirs() []string {
func (p *Manager) layoutDirs() []string {
dirs := []string{filepath.Join(p.sourceDir(), p.cfg.LayoutsDir)}
if p.ThemeDir != "" {
dirs = append(dirs, filepath.Join(p.ThemeDir, "_layouts"))
Expand Down
2 changes: 1 addition & 1 deletion pipelines/markdown.go → renderers/markdown.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pipelines
package renderers

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion pipelines/markdown_test.go → renderers/markdown_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pipelines
package renderers

import (
"testing"
Expand Down
2 changes: 1 addition & 1 deletion pipelines/pipeline_test.go → renderers/pipeline_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pipelines
package renderers

import (
"testing"
Expand Down
34 changes: 17 additions & 17 deletions pipelines/pipeline.go → renderers/renderers.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pipelines
package renderers

import (
"io"
Expand All @@ -11,32 +11,32 @@ import (
"github.com/osteele/liquid"
)

// PipelineInterface applies transformations to a document.
type PipelineInterface interface {
// Renderers applies transformations to a document.
type Renderers interface {
ApplyLayout(string, []byte, liquid.Bindings) ([]byte, error)
OutputExt(pathname string) string
Render(io.Writer, []byte, liquid.Bindings, string, int) error
RenderTemplate([]byte, liquid.Bindings, string, int) ([]byte, error)
}

// Pipeline applies a rendering transformation to a file.
type Pipeline struct {
PipelineOptions
// Manager applies a rendering transformation to a file.
type Manager struct {
Options
cfg config.Config
liquidEngine *liquid.Engine
sassTempDir string
sassHash string
}

// PipelineOptions configures a pipeline.
type PipelineOptions struct {
// Options configures a rendering manager.
type Options struct {
RelativeFilenameToURL tags.LinkTagHandler
ThemeDir string
}

// NewPipeline makes a rendering pipeline.
func NewPipeline(c config.Config, options PipelineOptions) (*Pipeline, error) {
p := Pipeline{PipelineOptions: options, cfg: c}
// New makes a rendering manager.
func New(c config.Config, options Options) (*Manager, error) {
p := Manager{Options: options, cfg: c}
p.liquidEngine = p.makeLiquidEngine()
if err := p.CopySassFileIncludes(); err != nil {
return nil, err
Expand All @@ -46,22 +46,22 @@ func NewPipeline(c config.Config, options PipelineOptions) (*Pipeline, error) {

// sourceDir returns the site source directory. Seeing how far we can bend
// the Law of Demeter.
func (p *Pipeline) sourceDir() string {
func (p *Manager) sourceDir() string {
return p.cfg.Source
}

// TemplateEngine returns the Liquid engine.
func (p *Pipeline) TemplateEngine() *liquid.Engine {
func (p *Manager) TemplateEngine() *liquid.Engine {
return p.liquidEngine
}

// OutputExt returns the output extension.
func (p *Pipeline) OutputExt(pathname string) string {
func (p *Manager) OutputExt(pathname string) string {
return p.cfg.OutputExt(pathname)
}

// Render sends content through SASS and/or Liquid -> Markdown
func (p *Pipeline) Render(w io.Writer, src []byte, vars liquid.Bindings, filename string, lineNo int) error {
func (p *Manager) Render(w io.Writer, src []byte, vars liquid.Bindings, filename string, lineNo int) error {
if p.cfg.IsSASSPath(filename) {
return p.WriteSass(w, src)
}
Expand All @@ -77,7 +77,7 @@ func (p *Pipeline) Render(w io.Writer, src []byte, vars liquid.Bindings, filenam
}

// RenderTemplate renders a Liquid template
func (p *Pipeline) RenderTemplate(src []byte, vars liquid.Bindings, filename string, lineNo int) ([]byte, error) {
func (p *Manager) RenderTemplate(src []byte, vars liquid.Bindings, filename string, lineNo int) ([]byte, error) {
tpl, err := p.liquidEngine.ParseTemplateLocation(src, filename, lineNo)
if err != nil {
return nil, utils.WrapPathError(err, filename)
Expand All @@ -89,7 +89,7 @@ func (p *Pipeline) RenderTemplate(src []byte, vars liquid.Bindings, filename str
return out, err
}

func (p *Pipeline) makeLiquidEngine() *liquid.Engine {
func (p *Manager) makeLiquidEngine() *liquid.Engine {
dirs := []string{filepath.Join(p.cfg.Source, p.cfg.IncludesDir)}
if p.ThemeDir != "" {
dirs = append(dirs, filepath.Join(p.ThemeDir, "_includes"))
Expand Down
8 changes: 4 additions & 4 deletions pipelines/sass.go → renderers/sass.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pipelines
package renderers

import (
"bytes"
Expand All @@ -20,7 +20,7 @@ import (

// CopySassFileIncludes copies sass partials into a temporary directory,
// removing initial underscores.
func (p *Pipeline) CopySassFileIncludes() error {
func (p *Manager) CopySassFileIncludes() error {
// TODO delete the temp directory when done?
// TODO use libsass.ImportsOption instead?
if p.sassTempDir == "" {
Expand Down Expand Up @@ -67,12 +67,12 @@ func copySassFiles(src, dst string, h io.Writer) error {
}

// SassIncludePaths returns an array of sass include directories.
func (p *Pipeline) SassIncludePaths() []string {
func (p *Manager) SassIncludePaths() []string {
return []string{p.sassTempDir}
}

// WriteSass converts a SASS file and writes it to w.
func (p *Pipeline) WriteSass(w io.Writer, b []byte) error {
func (p *Manager) WriteSass(w io.Writer, b []byte) error {
s, err := cache.WithFile(fmt.Sprintf("sass: %s", p.sassHash), string(b), func() (s string, err error) {
buf := new(bytes.Buffer)
comp, err := libsass.New(buf, bytes.NewBuffer(b))
Expand Down
2 changes: 1 addition & 1 deletion site/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (s *Site) Read() error {
if err := s.ReadCollections(); err != nil {
return err
}
if err := s.initializeRenderingPipeline(); err != nil {
if err := s.initializeRenderers(); err != nil {
return err
}
return s.runHooks(func(p plugins.Plugin) error { return p.PostRead(s) })
Expand Down
2 changes: 1 addition & 1 deletion site/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (s *Site) render() error {

func (s *Site) ensureRendered() (err error) {
s.renderOnce.Do(func() {
err = s.initializeRenderingPipeline()
err = s.initializeRenderers()
if err != nil {
return
}
Expand Down
26 changes: 13 additions & 13 deletions site/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/osteele/gojekyll/collection"
"github.com/osteele/gojekyll/config"
"github.com/osteele/gojekyll/pages"
"github.com/osteele/gojekyll/pipelines"
"github.com/osteele/gojekyll/plugins"
"github.com/osteele/gojekyll/renderers"
"github.com/osteele/gojekyll/utils"
"github.com/osteele/liquid"
)
Expand All @@ -28,7 +28,7 @@ type Site struct {
docs []pages.Document // all documents, whether or not they are output
nonCollectionPages []pages.Page

pipeline *pipelines.Pipeline
renderer *renderers.Manager
renderOnce sync.Once

drop map[string]interface{} // cached drop value
Expand Down Expand Up @@ -153,30 +153,30 @@ func (s *Site) FilenameURLPath(relpath string) (string, bool) {
return "", false
}

// RenderingPipeline returns the rendering pipeline.
func (s *Site) RenderingPipeline() pipelines.PipelineInterface {
if s.pipeline == nil {
panic(fmt.Errorf("uninitialized rendering pipeline"))
// RendererManager returns the rendering manager.
func (s *Site) RendererManager() renderers.Renderers {
if s.renderer == nil {
panic(fmt.Errorf("uninitialized rendering manager"))
}
return s.pipeline
return s.renderer
}

// TemplateEngine is part of the plugins.Site interface.
func (s *Site) TemplateEngine() *liquid.Engine {
return s.pipeline.TemplateEngine()
return s.renderer.TemplateEngine()
}

// initializeRenderingPipeline initializes the rendering pipeline
func (s *Site) initializeRenderingPipeline() (err error) {
options := pipelines.PipelineOptions{
// initializeRenderers initializes the rendering manager
func (s *Site) initializeRenderers() (err error) {
options := renderers.Options{
RelativeFilenameToURL: s.FilenameURLPath,
ThemeDir: s.themeDir,
}
s.pipeline, err = pipelines.NewPipeline(s.config, options)
s.renderer, err = renderers.New(s.config, options)
if err != nil {
return err
}
engine := s.pipeline.TemplateEngine()
engine := s.renderer.TemplateEngine()
return s.runHooks(func(p plugins.Plugin) error {
return p.ConfigureTemplateEngine(engine)
})
Expand Down

0 comments on commit 9816243

Please sign in to comment.