How to use Thymeleaf layout dialect with Textual Syntax? - thymeleaf

I'm trying to use the layout:decorate directive with a text file (plain text email header/footer)
Template begin called:
[# layout:decorate="~{email/plainPart}" th:with="subject=${subject}" ]
[# layout:fragment="content"]
Thanks for ordering [( ${orderDetail} )].
[/]
[/]
Layout template:
Subject: [( ${subject} )]
[# layout:fragment="content"][/]
The temple renders fine, and without any errors, but I'm not seeing any of the layout template (Subject, for example).

I've been unable to get layout:decorate to work. But based on a Stack Overflow answer about th:replace, I've been able to come up with a sort of solution:
Template:
[#th:block th:replace="email/plainPart.txt"][/th:block]
Thanks for ordering [( ${orderDetail} )].
plainPart.txt:
[( ${subject} )]

Related

Create Two Versions of a Document

I am using quarto to create a lesson with lots of mixed in tex. I want two version of this lesson -- one with answers and one without the answers -- in the same document to avoid trying to keep the two files consistent. What is the easiest way to do this?
I tried
::: {.content-visible XXX}
Will only appear in HTML.
:::
but that only seems to be working if I want to change the document output format. I want it to toggle with just a TRUE or FALSE value. I also tried
```{r, eval = showText, echo = TRUE, output = "asis"}
The probability that $n^2$ items happy is `dpois(n, 1)`.
```
However, this gives me the error
Error: unexpected symbol in "The probability"
Furthermore, it doesn't render the latex $n^2$
UPDATE: I tried the Lua filter approach without success.
---
title: "Conditional Content"
format: pdf
editor: visual
hide-answer: false
filters:
- hide-answer.lua
---
## Answer Test
- This is a list
- This $n^2$ works
- This is another element
- **Question:** What is my name?
::: answer
- Why is this $n^2$ failing?
:::
- Continuation
You can use Lua filter to create an option which if true, will remove all the contents within answer divs.
---
title: Conditional content
format: pdf
hide-answer: true
filters:
- hide-answer.lua
---
## Part 01
**Question 01: What is the probability that .... ?**
::: answer
The probability that $n^2$ items happy is `dpois(n, 1)`.
:::
hide-answer.lua
function answer()
return {
Div = function(el)
if el.classes:includes('answer') then
return pandoc.Null()
else
return el
end
end
}
end
function Pandoc(doc)
local meta = doc.meta
local hide = meta['hide-answer']
if hide then
return doc:walk(answer())
end
end
output when hide-answer: true,
output when hide-answer: false,
I’m trying to do the same at the moment and am exploring the use of profiles. https://quarto.org/docs/projects/profiles.html
I’d love to give a more complete answer, but just wanted to share that. I’m creating a profile for student (without answers) and TA (with answers).
If any experts have further advice, please feel free!
Best wishes!

Eleventy, frontmatter data not being evaluated

I have a template that looks like this:
---
date: "2016-01-01T06:00-06:00"
value: "/{{ page.date | date: '%Y/%m/%d' }}/index.html"
---
Value prints: {{ value }} <br/>
But we expect: {{ page.date | date: '%Y/%m/%d' }}/index.html <br/>
When I render the site then the site looks like this:
Value prints: /{{ page.date | date: '%Y/%m/%d' }}/index.html
But we expect: 2016/01/01/index.html
I really want the value parameter to have the expected value.
As far as I can tell, this sort of thing should work. I want to use this technique to calculate permalinks. My thinking is based on https://www.11ty.dev/docs/permalinks/
I'm running eleventy 0.12.1
Things I've tried:
yaml, json and js frontmatter
markdown template
njk template
literally copy pasting sample code from the docs
At this point I think Eleventy might have a bug
At the moment of writing, eleventy doesn't support template syntax in any frontmatter fields except the permalink field:
permalink: Change the output target of the current template. Normally, you cannot use template syntax to reference other variables in your data, but permalink is an exception.
Source
Instead, you can use computed data, which allows you to set frontmatter data based on other frontmatter fields. Something like this should work:
date: "2016-01-01T06:00-06:00"
eleventyComputed:
value: "/{{ page.date | date: '%Y/%m/%d' }}/index.html"

'<' character in property value strips rest of string

When adding a node in Neo4j with Cypher by:
CREATE (a: testNode {text: 'te>st<ignored' })
RETURN a.text
This returns: "te>st".
How come the rest of the string is stripped due to the character '<'?
Neo4j is not ignoring the rest of the string, It'd storing as it is and also returning the same. But there is some issue with the Neo4j browser, It's not showing it properly.
You can verify this by viewing results in text format in the Neo4j browser.
Please find screenshot below:
Neo4j browser considers it as a start of HTML tag and hence doesn't show it properly. You can try adding HTML tags in the text and it will render the same in the output.
Here is an example:
If you add an input tag it shows the input box.
CREATE (a: testNode {text: 'test input <input type="text" name="fname">' })
RETURN a.text

How can I get Ractive.js to cooperate with Slim templates?

The Ractive tutorial uses this:
<th class='sortable {{ sortColumn === "name" ? "sorted" : "" }}'
on-tap='sort:name'>
Superhero name
</th>
The project I am working on uses Slim. Using html2slim, I am provided with this syntax:
th.sortable.sortColumn.: class=("{{ === \"name\" ? \"sorted\" \"\" }}") on-tap="sort:name"
Superhero name
I don't know if that is valid Slim syntax; I cannot find anything in the Slim documentation to guide me. So I'm lost as to how this should be formatted in Slim, to render properly for Ractive.
The above syntax results in:
syntax error, unexpected tIDENTIFIER, expecting keyword_end
I have searched for gems, SO answers, and broad Googling but cannot find any clues. Has anyone here successfully done something like this?
In slim, use a double equal == to disable escaping in the attribute, see https://github.com/slim-template/slim#quoted-attributes
I believe you can also mix ' and "" to avoid back-slashing, and I think you need to include the data ref in the mustache. The : inline a child element, so you don't want that either. Lastly, I'm not sure you can mix .classname notation with an explicit attribute. So I think it ends up being:
th class=="sortable {{ sortColumn === 'name' ? 'sorted' : '' }}" on-tap="sort:name"
Superhero name

Generate a link_to on the fly if a URL is found inside the contents of a db text field?

I have an automated report tool (corp intranet) where the admins have a few text area boxes to enter some text for different parts of the email body.
What I'd like to do is parse the contents of the text area and wrap any hyperlinks found with link tags (so when the report goes out there are links instead of text urls).
Is ther a simple way to do something like this without figuring out a way of parsing the text to add link tags around a found (['http:','https:','ftp:] TO the first SPACE after)?
Thank You!
Ruby 1.87, Rails 2.3.5
Make a helper :
def make_urls(text)
urls = %r{(?:https?|ftp|mailto)://\S+}i
html_text = text.gsub urls, '\0'
html_text
end
on the view just call this function , you will get the expected output.
like :
irb(main):001:0> string = 'here is a link: http://google.com'
=> "here is a link: http://google.com"
irb(main):002:0> urls = %r{(?:https?|ftp|mailto)://\S+}i
=> /(?:https?|ftp|mailto):\/\/\S+/i
irb(main):003:0> html = string.gsub urls, '\0'
=> "here is a link: http://google.com"
There are many ways to accomplish your goal. One way would be to use Regex. If you have never heard of regex, this wikipedia entry should bring you up to speed.
For example:
content_string = "Blah ablal blabla lbal blah blaha http://www.google.com/ adsf dasd dadf dfasdf dadf sdfasdf dadf dfaksjdf kjdfasdf http://www.apple.com/ blah blah blah."
content_string.split(/\s+/).find_all { |u| u =~ /^https?:/ }
Which will return: ["http://www.google.com/", "http://www.apple.com/"]
Now, for the second half of the problem, you will use the array returned above to subsititue the text links for hyperlinks.
links = ["http://www.google.com/", "http://www.apple.com/"]
links.each do |l|
content_string.gsub!(l, "<a href='#{l}'>#{l}</a>")
end
content_string will now be updated to contain HTML hyperlinks for all http/https URLs.
As I mentioned earlier, there are numerous ways to tackle this problem - to find the URLs you could also do something like:
require 'uri'
URI.extract(content_string, ['http', 'https'])
I hope this helps you.

Resources