summaryrefslogtreecommitdiffstats
path: root/tpl/fmt
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-02-17 13:04:00 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-02-24 18:59:50 +0100
commit08fdca9d9365eaf1e496a12e2af5e18617bd0e66 (patch)
tree6c6942d1b74a4160d93a997860bafd52b92025f5 /tpl/fmt
parent2c20f5bc00b604e72b3b7e401fbdbf9447fe3470 (diff)
Add Markdown diagrams and render hooks for code blocks
You can now create custom hook templates for code blocks, either one for all (`render-codeblock.html`) or for a given code language (e.g. `render-codeblock-go.html`). We also used this new hook to add support for diagrams in Hugo: * Goat (Go ASCII Tool) is built-in and enabled by default; just create a fenced code block with the language `goat` and start draw your Ascii diagrams. * Another popular alternative for diagrams in Markdown, Mermaid (supported by GitHub), can also be implemented with a simple template. See the Hugo documentation for more information. Updates #7765 Closes #9538 Fixes #9553 Fixes #8520 Fixes #6702 Fixes #9558
Diffstat (limited to 'tpl/fmt')
-rw-r--r--tpl/fmt/init_test.go44
1 files changed, 0 insertions, 44 deletions
diff --git a/tpl/fmt/init_test.go b/tpl/fmt/init_test.go
deleted file mode 100644
index 07b740a73..000000000
--- a/tpl/fmt/init_test.go
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright 2017 The Hugo Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package fmt
-
-import (
- "testing"
-
- "github.com/gohugoio/hugo/htesting/hqt"
-
- qt "github.com/frankban/quicktest"
- "github.com/gohugoio/hugo/common/loggers"
- "github.com/gohugoio/hugo/deps"
- "github.com/gohugoio/hugo/tpl/internal"
-)
-
-func TestInit(t *testing.T) {
- c := qt.New(t)
- var found bool
- var ns *internal.TemplateFuncsNamespace
-
- for _, nsf := range internal.TemplateFuncsNamespaceRegistry {
- ns = nsf(&deps.Deps{Log: loggers.NewIgnorableLogger(loggers.NewErrorLogger())})
- if ns.Name == name {
- found = true
- break
- }
- }
-
- c.Assert(found, qt.Equals, true)
- ctx, err := ns.Context()
- c.Assert(err, qt.IsNil)
- c.Assert(ctx, hqt.IsSameType, &Namespace{})
-}
ss="cm"> * These bits get ORed with the address to form * the instruction byte */ /*Instruction Bit masks*/ #define INST_MODE_BM (1 << 7) #define INST_READ_BM (1 << 6) #define INST_16BIT_BM (1 << 5) /*From figure 18 in the datasheet*/ /*bit masks for Rev/Oscillator Control Register*/ #define MUX_CNV_BV 7 #define MUX_CNV_BM (1 << MUX_CNV_BV) #define MUX_M3_BM (1 << 3) /*M3 selects single ended*/ #define MUX_G_BV 4 /*allows for reg = (gain << MUX_G_BV) | ...*/ /*From figure 18 in the datasheet*/ /*bit masks for Rev/Oscillator Control Register*/ #define OSC_OSCR_BM (1 << 5) #define OSC_OSCE_BM (1 << 4) #define OSC_REFE_BM (1 << 3) #define OSC_BUFE_BM (1 << 2) #define OSC_R2V_BM (1 << 1) #define OSC_RBG_BM (1 << 0) #include <linux/module.h> #include <linux/init.h> #include <linux/spi/spi.h> #include <linux/hwmon.h> #include <linux/hwmon-sysfs.h> #include <linux/err.h> #include <linux/mutex.h> #include <linux/delay.h> #define DEVICE_NAME "ads7871" struct ads7871_data { struct device *hwmon_dev; struct mutex update_lock; }; static int ads7871_read_reg8(struct spi_device *spi, int reg) { int ret; reg = reg | INST_READ_BM; ret = spi_w8r8(spi, reg); return ret; } static int ads7871_read_reg16(struct spi_device *spi, int reg) { int ret; reg = reg | INST_READ_BM | INST_16BIT_BM; ret = spi_w8r16(spi, reg); return ret; } static int ads7871_write_reg8(struct spi_device *spi, int reg, u8 val) { u8 tmp[2] = {reg, val}; return spi_write(spi, tmp, sizeof(tmp)); } static ssize_t show_voltage(struct device *dev, struct device_attribute *da, char *buf) { struct spi_device *spi = to_spi_device(dev); struct sensor_device_attribute *attr = to_sensor_dev_attr(da); int ret, val, i = 0; uint8_t channel, mux_cnv; channel = attr->index; /* * TODO: add support for conversions * other than single ended with a gain of 1 */ /*MUX_M3_BM forces single ended*/ /*This is also where the gain of the PGA would be set*/ ads7871_write_reg8(spi, REG_GAIN_MUX, (MUX_CNV_BM | MUX_M3_BM | channel)); ret = ads7871_read_reg8(spi, REG_GAIN_MUX); mux_cnv = ((ret & MUX_CNV_BM) >> MUX_CNV_BV); /* * on 400MHz arm9 platform the conversion * is already done when we do this test */ while ((i < 2) && mux_cnv) { i++; ret = ads7871_read_reg8(spi, REG_GAIN_MUX); mux_cnv = ((ret & MUX_CNV_BM) >> MUX_CNV_BV); msleep_interruptible(1); } if (mux_cnv == 0) { val = ads7871_read_reg16(spi, REG_LS_BYTE); /*result in volts*10000 = (val/8192)*2.5*10000*/ val = ((val >> 2) * 25000) / 8192; return sprintf(buf, "%d\n", val); } else { return -1; } } static ssize_t ads7871_show_name(struct device *dev, struct device_attribute *devattr, char *buf) { return sprintf(buf, "%s\n", to_spi_device(dev)->modalias); } static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, show_voltage, NULL, 0); static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_voltage, NULL, 1); static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_voltage, NULL, 2); static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_voltage, NULL, 3); static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_voltage, NULL, 4); static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, show_voltage, NULL, 5); static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, show_voltage, NULL, 6); static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, show_voltage, NULL, 7); static DEVICE_ATTR(name, S_IRUGO, ads7871_show_name, NULL); static struct attribute *ads7871_attributes[] = { &sensor_dev_attr_in0_input.dev_attr.attr, &sensor_dev_attr_in1_input.dev_attr.attr, &sensor_dev_attr_in2_input.dev_attr.attr, &sensor_dev_attr_in3_input.dev_attr.attr, &sensor_dev_attr_in4_input.dev_attr.attr, &sensor_dev_attr_in5_input.dev_attr.attr, &sensor_dev_attr_in6_input.dev_attr.attr, &sensor_dev_attr_in7_input.dev_attr.attr, &dev_attr_name.attr, NULL }; static const struct attribute_group ads7871_group = { .attrs = ads7871_attributes, }; static int ads7871_probe(struct spi_device *spi) { int ret, err; uint8_t val; struct ads7871_data *pdata; dev_dbg(&spi->dev, "probe\n"); /* Configure the SPI bus */ spi->mode = (SPI_MODE_0); spi->bits_per_word = 8; spi_setup(spi); ads7871_write_reg8(spi, REG_SER_CONTROL, 0); ads7871_write_reg8(spi, REG_AD_CONTROL, 0); val = (OSC_OSCR_BM | OSC_OSCE_BM | OSC_REFE_BM | OSC_BUFE_BM); ads7871_write_reg8(spi, REG_OSC_CONTROL, val); ret = ads7871_read_reg8(spi, REG_OSC_CONTROL); dev_dbg(&spi->dev, "REG_OSC_CONTROL write:%x, read:%x\n", val, ret); /* * because there is no other error checking on an SPI bus * we need to make sure we really have a chip */ if (val != ret) return -ENODEV; pdata = devm_kzalloc(&spi->dev, sizeof(struct ads7871_data), GFP_KERNEL); if (!pdata) return -ENOMEM; err = sysfs_create_group(&spi->dev.kobj, &ads7871_group); if (err < 0) return err; spi_set_drvdata(spi, pdata); pdata->hwmon_dev = hwmon_device_register(&spi->dev); if (IS_ERR(pdata->hwmon_dev)) { err = PTR_ERR(pdata->hwmon_dev); goto error_remove; } return 0; error_remove: sysfs_remove_group(&spi->dev.kobj, &ads7871_group); return err; } static int ads7871_remove(struct spi_device *spi) { struct ads7871_data *pdata = spi_get_drvdata(spi); hwmon_device_unregister(pdata->hwmon_dev); sysfs_remove_group(&spi->dev.kobj, &ads7871_group); return 0; } static struct spi_driver ads7871_driver = { .driver = { .name = DEVICE_NAME, }, .probe = ads7871_probe, .remove = ads7871_remove, }; module_spi_driver(ads7871_driver); MODULE_AUTHOR("Paul Thomas <pthomas8589@gmail.com>"); MODULE_DESCRIPTION("TI ADS7871 A/D driver"); MODULE_LICENSE("GPL");