Closed d12frosted closed 3 years ago
:injector (lambda (template)
(cl-case template
(:header-template (ht (:hello "test")))))
:injector can be other name
or a simpler version:
:injector (lambda (template)
(cl-case template
(:header-template (list :hello "test"))))
@tumashu let me know what you think 😸
I rethink this problem, this feature is just set template's argument, so a more simpler interfact may like below, we can add multi :template-argument in owp/project-config-alist :-)
:template-argument ("footer.mustache" "emacs-version" emacs-version)
:template-argument ("*.mustache" "myvar" my-value)
: ....
As for the approach, my suggesting is add a new function owp/ht, which is like:
(owp/ht "template-name.mustache"
other-ht-argument
)
any suggestion?
If we add owp/ht, deal with list is very simple, dolist+puthash is enough :-)
@tumashu
To be honest, I like this even more. Gives much more opportunities on modifying argument passed to moustache. Will update you once I finish it.
If you like the :template-argument approach, just code it , I will merge it when you finish.
We can also support this kind format :-)
:template-arguments ("footer.mustache" "var1" var1-value "var2" var2-value ...)
:template-arguments ("*.mustache" "var3" var3-value)
Which is same the below, but shorter.
:template-argument ("footer.mustache" "var1" var1-value )
:template-argument ("footer.mustache" "var2" var2-value )
...
:template-argument ("*.mustache" "var3" var3-value)
:template-arguments ("footer.mustache" "var1" var1-value "var2" var2-value ...)
This is what I wanted to do 😸
I have thought about it a little more and realised that we only allow to 'inject' custom context for :header-template
, :navigation-bar-template
, :content-template
and :footer-template
. Using something that lets you inject context to any named file is kind of misleading, because it doesn't work 😸
Besides, it complicates understanding of project configuration list. From user point of view it's an alist. User might think that using props with the same name there just overrides previous one. But we use that list as a plist. And now we allow to add props with the same name.
This is not a big issue, it's easy to get the list of all arguments like this:
(let ((project-plist
(cdr (assoc owp/current-project-name
owp/project-config-alist))))
(cl-loop for (key value) on project-plist by 'cddr
if (eq key :template-argument)
collect value))
But my point is about user-point of view.
I think that initial implementation was good except for overcomplicating things with ht
.
What do you thing about following interface:
;; configuration
(owp/add-project-config
`("tumashu.github.com"
:repository-directory "~/project/emacs-packages/tumashu.github.com"
:remote (git "https://github.com/tumashu/tumashu.github.com.git" "master")
;; you can use `rclone` with `:remote (rclone "remote-name" "/remote/path/location")` instead.
:site-domain "http://tumashu.github.com/"
:site-main-title "Tumashu 的个人小站"
:site-sub-title "(九天十地,太上忘情!!!)"
:theme (worg)
:source-browse-url ("Github" "https://github.com/tumashu/tumashu.github.com")
:personal-avatar "/media/img/horse.jpg"
:personal-duoshuo-shortname "tumashu-website"
:web-server-port 7654
:footer-template-context ("emacs-version" emacs-version)
:header-template-context ("prop1" "val1" "prop2" "val2")
:any-template-context ("glob1" "globval1")
))
Please notice :any-template-context
😸 I really like the idea to allow user to set context to all templates.
Priority of contexts is following: specific, global, default. So anything that is defined in :any-template-context
is overridden by specific context configuration like :header-template-context
.
What do you think?
if you like we could use (:prop1 "val1" :prop2 "val2")
instead of ("prop1" "val1" "prop2" "val2")
.
we only allow to 'inject' custom context for :header-template, :navigation-bar-template, :content-template and :footer-template.
This is not true, if we let user set addtion arguments of template, we should let user set all templates org-webpage have many other templates: for example: git
:footer-template-context ("emacs-version" emacs-version)
:header-template-context ("prop1" "val1" "prop2" "val2")
I do not like this idea, maybe we only need:
:template-arguments ("var1" value1 "var2" value2)
template argument need template support, if template file have not use it, it useless user can user var prefix to deal with:
:template-arguments ("header-var1" value1 "footer-var2" value2)
as for the approach: I think owp/ht is a better way, it make code looks cleaner, ht-merge two big form looks very very ugly.
This is not true, if we let user set addtion arguments of template, we should let user set all templates org-webpage have many other templates
Well yeah, that's my point. Currently this PR provides only ability to inject context to templates used owp-template
(:header-template
, :navigation-bar-template
, :content-template
and :footer-template
). And in every listed case owp-template
hardcodes file names. So there is no point in letting user to set extra context for file another-template.mustache
(just an example).
Also AFAIK context is shared from parent template to partial template, so again, if footer.mustache
includes footer-partial.mustache
, it's enough to inject context to :footer-template
. Another thing is that org-webpage
doesn't support partials, right?
Sorry, I am still not very familiar with the project, so I might miss important piece of knowledge here.
for example: git
Sorry, but what template is this? Where is it used? Is there any point in injecting custom context into that template?
I do not like this idea
Could you please elaborate?
:template-arguments ("var1" value1 "var2" value2)
Do you mean that it's injected to all templates?
as for the approach: I think owp/ht is a better way, it make code looks cleaner, ht-merge two big form looks very very ugly.
Ok, we can avoid using ht-merge
if we iterate and ht-set
. Not a big deal 😸
I went ahead and implemented what I was talking about so it's less abstract 😸
:template-context ("glob1" "globval1" "glob2" "globval2")
:footer-template-context ("emacs-version" ,emacs-version "glob1" "override")
:header-template-context ("prop1" "val1" "prop2" "val2")))
In footer glob1
is override
and in header it's globval1
.
Could you please elaborate?
Because, org-webpage have many template, maybe have more in the future, owp/project-config-alist is the most important api of org-webpage. I only add powful key + good document, If I add :header-template-context and :footer-template-context, maybe I need add :navbar-template-context :footnote-template-context in the future, this is a ugly things.
Sorry, but what template is this? Where is it used? Is there any point in injecting custom context into that template?
org-webpage will generate bash-script to upload website, only support git and rclone, this feature use
three template, and user can customize their template also
I am not using org2web
and will not finish PR. Sorry for taking your time.
I couldn't find a way to pass custom context to moustache render function. Let me know if I missed it.
In general I find it useful when working on your own theme.