mirror of
https://github.com/danog/gojekyll.git
synced 2024-11-30 07:58:59 +01:00
Rename locals
This commit is contained in:
parent
a63729f6b2
commit
1d9dfa5e78
@ -38,7 +38,7 @@ func (p *Pipeline) ApplyLayout(name string, data []byte, e map[string]interface{
|
||||
func (p *Pipeline) 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.config.MarkdownExt, `,`, -1) {
|
||||
for _, ext := range strings.SplitN(p.cfg.MarkdownExt, `,`, -1) {
|
||||
exts = append(exts, "."+ext)
|
||||
}
|
||||
var (
|
||||
@ -77,7 +77,7 @@ loop:
|
||||
|
||||
// LayoutsDir returns the path to the layouts directory.
|
||||
func (p *Pipeline) layoutDirs() []string {
|
||||
dirs := []string{filepath.Join(p.SourceDir(), p.config.LayoutsDir)}
|
||||
dirs := []string{filepath.Join(p.SourceDir(), p.cfg.LayoutsDir)}
|
||||
if p.ThemeDir != "" {
|
||||
dirs = append(dirs, filepath.Join(p.ThemeDir, "_layouts"))
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ type PipelineInterface interface {
|
||||
// Pipeline applies a rendering transformation to a file.
|
||||
type Pipeline struct {
|
||||
PipelineOptions
|
||||
config config.Config
|
||||
cfg config.Config
|
||||
liquidEngine *liquid.Engine
|
||||
sassTempDir string
|
||||
sassHash string
|
||||
@ -35,7 +35,7 @@ type PipelineOptions struct {
|
||||
|
||||
// NewPipeline makes a rendering pipeline.
|
||||
func NewPipeline(c config.Config, options PipelineOptions) (*Pipeline, error) {
|
||||
p := Pipeline{PipelineOptions: options, config: c}
|
||||
p := Pipeline{PipelineOptions: options, cfg: c}
|
||||
p.liquidEngine = p.makeLiquidEngine()
|
||||
if err := p.CopySassFileIncludes(); err != nil {
|
||||
return nil, err
|
||||
@ -46,7 +46,7 @@ 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 {
|
||||
return p.config.Source
|
||||
return p.cfg.Source
|
||||
}
|
||||
|
||||
// TemplateEngine returns the Liquid engine.
|
||||
@ -56,12 +56,12 @@ func (p *Pipeline) TemplateEngine() *liquid.Engine {
|
||||
|
||||
// OutputExt returns the output extension.
|
||||
func (p *Pipeline) OutputExt(pathname string) string {
|
||||
return p.config.OutputExt(pathname)
|
||||
return p.cfg.OutputExt(pathname)
|
||||
}
|
||||
|
||||
// Render returns nil iff it wrote to the writer
|
||||
func (p *Pipeline) Render(w io.Writer, b []byte, filename string, lineNo int, e map[string]interface{}) ([]byte, error) {
|
||||
if p.config.IsSASSPath(filename) {
|
||||
if p.cfg.IsSASSPath(filename) {
|
||||
buf := new(bytes.Buffer)
|
||||
if err := p.WriteSass(buf, b); err != nil {
|
||||
return nil, err
|
||||
@ -72,7 +72,7 @@ func (p *Pipeline) Render(w io.Writer, b []byte, filename string, lineNo int, e
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if p.config.IsMarkdown(filename) {
|
||||
if p.cfg.IsMarkdown(filename) {
|
||||
b = markdownRenderer(b)
|
||||
}
|
||||
return b, nil
|
||||
@ -92,7 +92,7 @@ func (p *Pipeline) renderTemplate(src []byte, b map[string]interface{}, filename
|
||||
|
||||
func (p *Pipeline) makeLiquidEngine() *liquid.Engine {
|
||||
engine := liquid.NewEngine()
|
||||
filters.AddJekyllFilters(engine, &p.config)
|
||||
tags.AddJekyllTags(engine, &p.config, p.RelativeFilenameToURL)
|
||||
filters.AddJekyllFilters(engine, &p.cfg)
|
||||
tags.AddJekyllTags(engine, &p.cfg, p.RelativeFilenameToURL)
|
||||
return engine
|
||||
}
|
||||
|
@ -19,8 +19,8 @@ const pygmentizeCmd = "pygmentize"
|
||||
var warnedMissingPygmentize = false
|
||||
var highlightArgsRE = regexp.MustCompile(`^\s*(\S+)(\s+linenos)?\s*$`)
|
||||
|
||||
func highlightTag(ctx render.Context) (string, error) {
|
||||
argStr, err := ctx.ExpandTagArg()
|
||||
func highlightTag(rc render.Context) (string, error) {
|
||||
argStr, err := rc.ExpandTagArg()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@ -33,7 +33,7 @@ func highlightTag(ctx render.Context) (string, error) {
|
||||
if args[2] != "" {
|
||||
cmdArgs = append(cmdArgs, "-O", "linenos=1")
|
||||
}
|
||||
s, err := ctx.InnerString()
|
||||
s, err := rc.InnerString()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -8,17 +8,17 @@ import (
|
||||
"github.com/osteele/liquid/render"
|
||||
)
|
||||
|
||||
func (tc tagContext) includeTag(ctx render.Context) (string, error) {
|
||||
return includeFromDir(ctx, filepath.Join(tc.config.Source, tc.config.IncludesDir))
|
||||
func (tc tagContext) includeTag(rc render.Context) (string, error) {
|
||||
return includeFromDir(rc, filepath.Join(tc.cfg.Source, tc.cfg.IncludesDir))
|
||||
}
|
||||
|
||||
func (tc tagContext) includeRelativeTag(ctx render.Context) (string, error) {
|
||||
func (tc tagContext) includeRelativeTag(rc render.Context) (string, error) {
|
||||
// TODO "Note that you cannot use the ../ syntax"
|
||||
return includeFromDir(ctx, path.Dir(ctx.SourceFile()))
|
||||
return includeFromDir(rc, path.Dir(rc.SourceFile()))
|
||||
}
|
||||
|
||||
func includeFromDir(ctx render.Context, dirname string) (string, error) {
|
||||
argsline, err := ctx.ExpandTagArg()
|
||||
func includeFromDir(rc render.Context, dirname string) (string, error) {
|
||||
argsline, err := rc.ExpandTagArg()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@ -29,10 +29,10 @@ func includeFromDir(ctx render.Context, dirname string) (string, error) {
|
||||
if len(args.Args) != 1 {
|
||||
return "", fmt.Errorf("parse error")
|
||||
}
|
||||
include, err := args.EvalOptions(ctx)
|
||||
include, err := args.EvalOptions(rc)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
filename := filepath.Join(dirname, args.Args[0])
|
||||
return ctx.RenderFile(filename, map[string]interface{}{"include": include})
|
||||
return rc.RenderFile(filename, map[string]interface{}{"include": include})
|
||||
}
|
||||
|
18
tags/tags.go
18
tags/tags.go
@ -24,25 +24,25 @@ func AddJekyllTags(e *liquid.Engine, c *config.Config, lh LinkTagHandler) {
|
||||
|
||||
// tagContext provides the context to a tag renderer.
|
||||
type tagContext struct {
|
||||
config *config.Config
|
||||
lh LinkTagHandler
|
||||
cfg *config.Config
|
||||
lh LinkTagHandler
|
||||
}
|
||||
|
||||
// CreateUnimplementedTag creates a tag definition that prints a warning the first
|
||||
// time it's rendered, and otherwise does nothing.
|
||||
func CreateUnimplementedTag() liquid.Renderer {
|
||||
warned := false
|
||||
return func(ctx render.Context) (string, error) {
|
||||
return func(rc render.Context) (string, error) {
|
||||
if !warned {
|
||||
fmt.Printf("The %q tag has not been implemented. It is being ignored.\n", ctx.TagName())
|
||||
fmt.Printf("The %q tag has not been implemented. It is being ignored.\n", rc.TagName())
|
||||
warned = true
|
||||
}
|
||||
return "", nil
|
||||
}
|
||||
}
|
||||
|
||||
func (tc tagContext) linkTag(ctx render.Context) (string, error) {
|
||||
filename := ctx.TagArgs()
|
||||
func (tc tagContext) linkTag(rc render.Context) (string, error) {
|
||||
filename := rc.TagArgs()
|
||||
url, found := tc.lh(filename)
|
||||
if !found {
|
||||
return "", fmt.Errorf("missing link filename: %s", filename)
|
||||
@ -50,13 +50,13 @@ func (tc tagContext) linkTag(ctx render.Context) (string, error) {
|
||||
return url, nil
|
||||
}
|
||||
|
||||
func (tc tagContext) postURLTag(ctx render.Context) (string, error) {
|
||||
func (tc tagContext) postURLTag(rc render.Context) (string, error) {
|
||||
var (
|
||||
filename = ctx.TagArgs()
|
||||
filename = rc.TagArgs()
|
||||
found = false
|
||||
url string
|
||||
)
|
||||
for _, ext := range append(tc.config.MarkdownExtensions(), "") {
|
||||
for _, ext := range append(tc.cfg.MarkdownExtensions(), "") {
|
||||
url, found = tc.lh(path.Join("_posts", filename+ext))
|
||||
if found {
|
||||
break
|
||||
|
Loading…
Reference in New Issue
Block a user