Fix case issues with Params

There are currently several Params and case related issues floating around in Hugo.

This is very confusing for users and one of the most common support questions on the forum.

And while there have been done some great leg work in Viper etc., this is of limited value since this and similar doesn't work:

`Params.myCamelCasedParam`

Hugo has control over all the template method invocations, and can take care of all the lower-casing of the map lookup keys.

But that doesn't help with direct template lookups of type `Site.Params.TWITTER_CONFIG.USER_ID`.

This commit solves that by doing some carefully crafted modifications of the templates' AST -- lowercasing the params keys.

This is low-level work, but it's not like the template API wil change -- and this is important enough to defend such "bit fiddling".

Tests are added for all the template engines: Go templates, Ace and Amber.

Fixes #2615
Fixes #1129
Fixes #2590
This commit is contained in:
Bjørn Erik Pedersen
2016-11-22 09:04:38 +01:00
committed by GitHub
parent 1eb3c4a8e7
commit 239c75c7f8
6 changed files with 760 additions and 12 deletions

View File

@@ -1670,7 +1670,7 @@ func (s *Site) renderPages() error {
err := <-errs
if err != nil {
return fmt.Errorf("Error(s) rendering pages: %s", err)
return fmt.Errorf("Error(s) rendering pages: %.60s…", err)
}
return nil
}
@@ -1770,7 +1770,7 @@ func (s *Site) renderTaxonomiesLists(prepare bool) error {
err := <-errs
if err != nil {
return fmt.Errorf("Error(s) rendering taxonomies: %s", err)
return fmt.Errorf("Error(s) rendering taxonomies: %.60s…", err)
}
return nil
}
@@ -2439,7 +2439,7 @@ func (s *Site) renderForLayouts(name string, d interface{}, w io.Writer, layouts
if err := s.renderThing(d, layout, w); err != nil {
// Behavior here should be dependent on if running in server or watch mode.
distinctErrorLogger.Printf("Error while rendering %s: %v", name, err)
distinctErrorLogger.Printf("Error while rendering %s: %.60s…", name, err)
if !s.running() && !testMode {
// TODO(bep) check if this can be propagated
os.Exit(-1)