mirror of
https://github.com/danog/gojekyll.git
synced 2024-12-02 16:27:46 +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) {
|
func (p *Pipeline) FindLayout(base string, fm *map[string]interface{}) (tpl *liquid.Template, err error) {
|
||||||
// not cached, but the time here is negligible
|
// not cached, but the time here is negligible
|
||||||
exts := []string{"", ".html"}
|
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)
|
exts = append(exts, "."+ext)
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
@ -77,7 +77,7 @@ loop:
|
|||||||
|
|
||||||
// LayoutsDir returns the path to the layouts directory.
|
// LayoutsDir returns the path to the layouts directory.
|
||||||
func (p *Pipeline) layoutDirs() []string {
|
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 != "" {
|
if p.ThemeDir != "" {
|
||||||
dirs = append(dirs, filepath.Join(p.ThemeDir, "_layouts"))
|
dirs = append(dirs, filepath.Join(p.ThemeDir, "_layouts"))
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ type PipelineInterface interface {
|
|||||||
// Pipeline applies a rendering transformation to a file.
|
// Pipeline applies a rendering transformation to a file.
|
||||||
type Pipeline struct {
|
type Pipeline struct {
|
||||||
PipelineOptions
|
PipelineOptions
|
||||||
config config.Config
|
cfg config.Config
|
||||||
liquidEngine *liquid.Engine
|
liquidEngine *liquid.Engine
|
||||||
sassTempDir string
|
sassTempDir string
|
||||||
sassHash string
|
sassHash string
|
||||||
@ -35,7 +35,7 @@ type PipelineOptions struct {
|
|||||||
|
|
||||||
// NewPipeline makes a rendering pipeline.
|
// NewPipeline makes a rendering pipeline.
|
||||||
func NewPipeline(c config.Config, options PipelineOptions) (*Pipeline, error) {
|
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()
|
p.liquidEngine = p.makeLiquidEngine()
|
||||||
if err := p.CopySassFileIncludes(); err != nil {
|
if err := p.CopySassFileIncludes(); err != nil {
|
||||||
return nil, err
|
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
|
// SourceDir returns the site source directory. Seeing how far we can bend
|
||||||
// the Law of Demeter.
|
// the Law of Demeter.
|
||||||
func (p *Pipeline) SourceDir() string {
|
func (p *Pipeline) SourceDir() string {
|
||||||
return p.config.Source
|
return p.cfg.Source
|
||||||
}
|
}
|
||||||
|
|
||||||
// TemplateEngine returns the Liquid engine.
|
// TemplateEngine returns the Liquid engine.
|
||||||
@ -56,12 +56,12 @@ func (p *Pipeline) TemplateEngine() *liquid.Engine {
|
|||||||
|
|
||||||
// OutputExt returns the output extension.
|
// OutputExt returns the output extension.
|
||||||
func (p *Pipeline) OutputExt(pathname string) string {
|
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
|
// 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) {
|
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)
|
buf := new(bytes.Buffer)
|
||||||
if err := p.WriteSass(buf, b); err != nil {
|
if err := p.WriteSass(buf, b); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -72,7 +72,7 @@ func (p *Pipeline) Render(w io.Writer, b []byte, filename string, lineNo int, e
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if p.config.IsMarkdown(filename) {
|
if p.cfg.IsMarkdown(filename) {
|
||||||
b = markdownRenderer(b)
|
b = markdownRenderer(b)
|
||||||
}
|
}
|
||||||
return b, nil
|
return b, nil
|
||||||
@ -92,7 +92,7 @@ func (p *Pipeline) renderTemplate(src []byte, b map[string]interface{}, filename
|
|||||||
|
|
||||||
func (p *Pipeline) makeLiquidEngine() *liquid.Engine {
|
func (p *Pipeline) makeLiquidEngine() *liquid.Engine {
|
||||||
engine := liquid.NewEngine()
|
engine := liquid.NewEngine()
|
||||||
filters.AddJekyllFilters(engine, &p.config)
|
filters.AddJekyllFilters(engine, &p.cfg)
|
||||||
tags.AddJekyllTags(engine, &p.config, p.RelativeFilenameToURL)
|
tags.AddJekyllTags(engine, &p.cfg, p.RelativeFilenameToURL)
|
||||||
return engine
|
return engine
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,8 @@ const pygmentizeCmd = "pygmentize"
|
|||||||
var warnedMissingPygmentize = false
|
var warnedMissingPygmentize = false
|
||||||
var highlightArgsRE = regexp.MustCompile(`^\s*(\S+)(\s+linenos)?\s*$`)
|
var highlightArgsRE = regexp.MustCompile(`^\s*(\S+)(\s+linenos)?\s*$`)
|
||||||
|
|
||||||
func highlightTag(ctx render.Context) (string, error) {
|
func highlightTag(rc render.Context) (string, error) {
|
||||||
argStr, err := ctx.ExpandTagArg()
|
argStr, err := rc.ExpandTagArg()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@ -33,7 +33,7 @@ func highlightTag(ctx render.Context) (string, error) {
|
|||||||
if args[2] != "" {
|
if args[2] != "" {
|
||||||
cmdArgs = append(cmdArgs, "-O", "linenos=1")
|
cmdArgs = append(cmdArgs, "-O", "linenos=1")
|
||||||
}
|
}
|
||||||
s, err := ctx.InnerString()
|
s, err := rc.InnerString()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -8,17 +8,17 @@ import (
|
|||||||
"github.com/osteele/liquid/render"
|
"github.com/osteele/liquid/render"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (tc tagContext) includeTag(ctx render.Context) (string, error) {
|
func (tc tagContext) includeTag(rc render.Context) (string, error) {
|
||||||
return includeFromDir(ctx, filepath.Join(tc.config.Source, tc.config.IncludesDir))
|
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"
|
// 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) {
|
func includeFromDir(rc render.Context, dirname string) (string, error) {
|
||||||
argsline, err := ctx.ExpandTagArg()
|
argsline, err := rc.ExpandTagArg()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@ -29,10 +29,10 @@ func includeFromDir(ctx render.Context, dirname string) (string, error) {
|
|||||||
if len(args.Args) != 1 {
|
if len(args.Args) != 1 {
|
||||||
return "", fmt.Errorf("parse error")
|
return "", fmt.Errorf("parse error")
|
||||||
}
|
}
|
||||||
include, err := args.EvalOptions(ctx)
|
include, err := args.EvalOptions(rc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
filename := filepath.Join(dirname, args.Args[0])
|
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.
|
// tagContext provides the context to a tag renderer.
|
||||||
type tagContext struct {
|
type tagContext struct {
|
||||||
config *config.Config
|
cfg *config.Config
|
||||||
lh LinkTagHandler
|
lh LinkTagHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateUnimplementedTag creates a tag definition that prints a warning the first
|
// CreateUnimplementedTag creates a tag definition that prints a warning the first
|
||||||
// time it's rendered, and otherwise does nothing.
|
// time it's rendered, and otherwise does nothing.
|
||||||
func CreateUnimplementedTag() liquid.Renderer {
|
func CreateUnimplementedTag() liquid.Renderer {
|
||||||
warned := false
|
warned := false
|
||||||
return func(ctx render.Context) (string, error) {
|
return func(rc render.Context) (string, error) {
|
||||||
if !warned {
|
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
|
warned = true
|
||||||
}
|
}
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tc tagContext) linkTag(ctx render.Context) (string, error) {
|
func (tc tagContext) linkTag(rc render.Context) (string, error) {
|
||||||
filename := ctx.TagArgs()
|
filename := rc.TagArgs()
|
||||||
url, found := tc.lh(filename)
|
url, found := tc.lh(filename)
|
||||||
if !found {
|
if !found {
|
||||||
return "", fmt.Errorf("missing link filename: %s", filename)
|
return "", fmt.Errorf("missing link filename: %s", filename)
|
||||||
@ -50,13 +50,13 @@ func (tc tagContext) linkTag(ctx render.Context) (string, error) {
|
|||||||
return url, nil
|
return url, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tc tagContext) postURLTag(ctx render.Context) (string, error) {
|
func (tc tagContext) postURLTag(rc render.Context) (string, error) {
|
||||||
var (
|
var (
|
||||||
filename = ctx.TagArgs()
|
filename = rc.TagArgs()
|
||||||
found = false
|
found = false
|
||||||
url string
|
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))
|
url, found = tc.lh(path.Join("_posts", filename+ext))
|
||||||
if found {
|
if found {
|
||||||
break
|
break
|
||||||
|
Loading…
Reference in New Issue
Block a user