summaryrefslogtreecommitdiffstats
path: root/helpers/general_test.go
AgeCommit message (Collapse)Author
2018-06-10Add support for theme composition and inheritanceBjørn Erik Pedersen
This commit adds support for theme composition and inheritance in Hugo. With this, it helps thinking about a theme as a set of ordered components: ```toml theme = ["my-shortcodes", "base-theme", "hyde"] ``` The theme definition example above in `config.toml` creates a theme with the 3 components with presedence from left to right. So, Hugo will, for any given file, data entry etc., look first in the project, and then in `my-shortcode`, `base-theme` and lastly `hyde`. Hugo uses two different algorithms to merge the filesystems, depending on the file type: * For `i18n` and `data` files, Hugo merges deeply using the translation id and data key inside the files. * For `static`, `layouts` (templates) and `archetypes` files, these are merged on file level. So the left-most file will be chosen. The name used in the `theme` definition above must match a folder in `/your-site/themes`, e.g. `/your-site/themes/my-shortcodes`. There are plans to improve on this and get a URL scheme so this can be resolved automatically. Also note that a component that is part of a theme can have its own configuration file, e.g. `config.toml`. There are currently some restrictions to what a theme component can configure: * `params` (global and per language) * `menu` (global and per language) * `outputformats` and `mediatypes` The same rules apply here: The left-most param/menu etc. with the same ID will win. There are some hidden and experimental namespace support in the above, which we will work to improve in the future, but theme authors are encouraged to create their own namespaces to avoid naming conflicts. A final note: Themes/components can also have a `theme` definition in their `config.toml` and similar, which is the "inheritance" part of this commit's title. This is currently not supported by the Hugo theme site. We will have to wait for some "auto dependency" feature to be implemented for that to happen, but this can be a powerful feature if you want to create your own theme-variant based on others. Fixes #4460 Fixes #4450
2017-12-28helpers: Avoid writing the last MD5 buff part twiceBjørn Erik Pedersen
2017-12-28resource: Use MD5 to identify image filesBjørn Erik Pedersen
But only a set of byte chunks spread around in the image file to calculate the fingerprint, which is much faster than reading the whole file: ```bash BenchmarkMD5FromFileFast/full=false-4 300000 4356 ns/op 240 B/op 5 allocs/op BenchmarkMD5FromFileFast/full=true-4 30000 42899 ns/op 32944 B/op 5 allocs/op ``` Fixes #4186
2017-11-30Add Pandoc support, refactor external helpersBrian Chen
Recognize the Pandoc format under the file extension .pandoc or .pdc, and shell out to pandoc as an external helper to format Pandoc content. Refactor out repeated code with external helpers. Change the error output formatting. I did not see any of the external helpers print the string "<input>" to represent stdin as a file; just prepending the file name to error output is more general and doesn't sacrifice that much in terms of readability. Closes #234
2017-07-31Make the title case style guide configurableBjørn Erik Pedersen
This works for the `title` func and the other places where Hugo makes title case. * AP style (new default) * Chicago style * Go style (what we have today) Fixes #989
2017-07-04hugolib: Extend the sections APIBjørn Erik Pedersen
This commit adds some section related methods that have been asked for: * .CurrentSection * .IsDescendant * .IsAncestor Fixes #3591
2017-04-30tpl: Add template function namespacesCameron Moore
This commit moves almost all of the template functions into separate packages under tpl/ and adds a namespace framework. All changes should be backward compatible for end users, as all existing function names in the template funcMap are left intact. Seq and DoArithmatic have been moved out of the helpers package and into template namespaces. Most of the tests involved have been refactored, and many new tests have been written. There's still work to do, but this is a big improvement. I got a little overzealous and added some new functions along the way: - strings.Contains - strings.ContainsAny - strings.HasSuffix - strings.TrimPrefix - strings.TrimSuffix Documentation is forthcoming. Fixes #3042
2017-02-21all: Add org-mode supportChase Adams
Fixes #1483 See #936
2016-10-16Fix case issue Viper vs Blackfriday configBjørn Erik Pedersen
There are still work to be done in the case department, but that will have to be another day. Fixes #2581 See https://github.com/spf13/viper/issues/261
2016-06-25helpers: Remove ToReader funcsCameron Moore
Remove StringToReader and BytesToReader in favor of using the stdlib directly.
2016-03-14helpers: Remove unused codeBjørn Erik Pedersen
2015-12-10Add copyright header to that source files that don’t have one.Anthony Fok
See #1646
2015-11-23Improve "watching for ..." loggingBjørn Erik Pedersen
2015-11-19Remove some superficial testsBjørn Erik Pedersen
2015-05-28Support `Fish and Chips` sectionbep
Section names are also used as the title of the list pages, but naming section folders as `Fish and Chips` and similar didn't work very well. This commit fixes that. This commit also changes the title casing of the section titles. Some may argue that this is a breaking change, but the old behaviour was also pretty broken, even for languages that use title capitalizations, as it didn't follow any particular style guide, `fish and chips` became `Fish And Chips` etc. Now it just turns the first letter into upper case, so `Fish and Chips` will be left as `Fish and Chips`. People wanting the good old behaviour can use the `title` template func. Fixes #1176
2015-05-08Update test logs for uniformity and consistencybep
Many minor fixes to make test logs more consistent and correct a mispelling. Standardize on "[%i] got X but expected Y" for log messages. Using a consistent layout makes it easier to read the test results. This was mostly changing "Got" to "got". Swapped the order of values on several calls to bring them in line with the convention. A few log messages had a sequence number added to identify the exact scenario that failed. Otherwise, there would be no way to ascertain which failed When there are many scenarios. Correct spelling of "expected." Fixes #1028 Merged be2097e1ad789eca5d893805a059d94defbe5c48 [close #1040]
2015-05-08Very experimental support for mmarkAnthony Fok
Either name the content files as `*.mmark`, or add `markup = "mmark"` in the front matter of your `*.md` content files.
2015-04-03helpers: fix some go vet errorsbep
2015-03-30Add some more corner tests for ReaderContainsbep
2015-03-29Handle views in combo with Ace base templatesbep
As views looks like a regular template, but doesn't need a base template, we have to look inside it. Altough really not needed by this commit, reading the full file content into memory just to do a substring search is a waste. So this commit implements a `ReaderContains` func that in most cases should be much faster than doing an `ioutil.ReadAll` and `bytes.Contains`: ``` benchmark old ns/op new ns/op delta BenchmarkReaderContains 78452 20260 -74.18% benchmark old allocs new allocs delta BenchmarkReaderContains 46 20 -56.52% benchmark old bytes new bytes delta BenchmarkReaderContains 46496 1258 -97.29% ``` Fixes #999
2015-03-18Comment out shaky Seq testbep
2015-03-18Improve type handling in Seqbep
2015-03-12Add Seq template funcbep
Very similar to GNU's seq. Fixes #552 Conflicts: tpl/template.go
2015-03-12Experimental AsciiDoc support with external helpersAnthony Fok
See #470 * Based on existing support for reStructuredText files * Handles content files with extensions `.asciidoc` and `.ad` * Pipes content through `asciidoctor --safe -`. If `asciidoctor` is not installed, then `asciidoc --safe -`. * To make sure `asciidoctor` or `asciidoc` is found, after adding a piece of AsciiDoc content, run `hugo` with the `-v` flag and look for this message: INFO: 2015/01/23 Rendering with /usr/bin/asciidoctor ... Caveats: * The final "Last updated" timestamp is currently not stripped. * When `hugo` is run with `-v`, you may see a lot of these messages INFO: 2015/01/23 Rendering with /usr/bin/asciidoctor ... if you have lots of `*.ad`, `*.adoc` or `*.asciidoc` files. * Some versions of `asciidoc` may have trouble with its safe mode. To test if you are affected, try this: $ echo "Hello" | asciidoc --safe - asciidoc: ERROR: unsafe: ifeval invalid asciidoc: FAILED: ifeval invalid safe document If so, I recommend that you install `asciidoctor` instead. Feedback and patches welcome! Ideally, we should be using https://github.com/VonC/asciidocgo, @VonC's wonderful Go implementation of Asciidoctor. However, there is still a bit of work needed for asciidocgo to expose its API so that Hugo can actually use it. Until then, hope this "experimental AsciiDoc support through external helpers" can serve as a stopgap solution for our community. :-) 2015-01-30: Updated for the replaceShortcodeTokens() syntax change 2015-02-21: Add `.adoc` extension as suggested by @Fale Conflicts: helpers/content.go
2015-03-07helpers: apply some Golint rulesbep
2015-03-06Fix errors reported by Go Vetbep
2015-01-31Add writable context to Nodebep
The variable scope in the Go templates makes it hard, if possible at all, to write templates with counter variables or similar state. This commit fixes that by adding a writable context to Node, backed by a map: Scratch. This context has three methods, Get, Set and Add. The Add is tailored for counter variables, but can be used for any built-in numeric values or strings.
2015-01-20Add more tests to general helperbep
2015-01-09Moved a test regarding a content.go function to a new test file content_test.go.Marek Stanley
Added some tests for general helpers, especially as a way to document the expected behavior, and as a warm-up welcome contribution.
2014-11-04Added the general modules test filesOwen Waller
Added the new general module's test file, general_test.go. This replaces the helpers_test.go file. There is also a minor defect fix in general.go's StripHTML function. The correct xhtml tag for a break is <br /> not </br>. I've also removed the unnecessary spaces before the replacement "\n". The new test module also reflects this change. Conflicts: helpers/general.go