Jinja2: combine/precompile templates into one - jinja2

I have an application that uses a hierarchy of Jinja2 templates to build reports. At the same time, I have a requirement to distribute my application as executable files built with PyInstaller. When I try to discover my templates using the normal approach with loaders and environment, Jinja cannot find my templates because of the way PyInstaller works. However, I can load my templates directly, but they cannot be rendered because they need to be loaded "normally" to get at the "super" templates.
What I was thinking is try to turn all those hierarchies of templates into flat templates at build time and then incorporating those into my PyInstaller-built executables, but I couldn't figure out how.
Is it possible? Or is there a better way of doing it? (And yes, we will drop the PyInstaller thing in the future)

Related

Simple "server-side" HTML partials/templates/layouts?

I'm working with two students to produce a few HTML pages (a homepage and two secondary page layouts) that will later be implemented into a larger CMS.
I'd like to be able to abstract the shared HTML (head metadata, primary navigation, footer, etc.) into separate files so we only have to update them in a single place, execute a shell command to generate new, complete output. Since these pages are only ever going to become templates for another team, I don't even need to integrate any external data sources.
I know Jade would work for this but our partials/layouts/whatever need to look like HTML. I keep coming back to precompiling Handlebars templates but I'm not having much luck getting them to work.
Since we're using Foundation 5, Ruby and Node are already part of our toolchain. Suggestions?
I really like Middleman for this kind of thing. Layouts and partials and local data, etc. Wonderfully useful for doing front-end prototyping for what will eventually become a Rails application.

Pretty-print Lua source-code in external file, without embedding it in the HTML file

Since my experience with HTML is fairly rudimentary (and pretty old), I am not sure if my requirement is realistic.
Lets say that I have quite a few files containing Lua source-code, and all of them have the ".lua" extension and available in a particular subdirectory. What I'd like to do is create a static index.html file, which when loaded in a browser, would show the list of the lua source-code files in a drop-down. Once one of the source-code files is selected, I'd like that the file gets loaded into an "area" on the same page, and is pretty-printed, i.e. with syntax-highlighting in browser. I was wondering if I could use something like the google-code-prettyfy for the syntax-highlighting part ? Also, I am not clear if an external lua sourcecode file can be loaded, and displayed within a certain region of html page as being rendered. If yes, would appreciate elaboration on the how part.
A tool like LDoc can be used to accomplish a lot of what you want, much as Doxygen would be used for a C language source kit.
Both are heavily driven by inclusion of specially formatted comments that carry documentation.
I know Doxygen can fold source code into the generated document set, I don't recall about LDoc. Both are actively under development.
It isn't necessarily a bad idea to use both tools on a project, especially if you have C source code implementing Lua modules. You could use Doxygen to build the overall document tree for your engine and C modules, and LDoc to build documentation of the Lua parts. It should be possible with a little care and configuration of both tools to get them to play well together.

RazorGenerator.MsBuild - Achieving harmony from Developer machine to Buildserver

We are currently using the RazorGenerator library to generate pre-compiled views for a project. Up until now we have been using the Visual Studio Extension to handle the generation, with these generated files also being committed to our repository.
This is causing bit of a pain point as we constantly have to resolve merge defects in a generated file. With that in mind I've set about to try and integrate the RazorGenerator.MsBuild target library into our build process so we can get away from storing the code-genned files in our repository.
So far I've disabled the VS Extension, and got the build target working as required however I've now lost intellisense and resharper support for the generated files as they are no longer part of the Solution.
I'm wondering if anyone else has come down this path before, Ideally what I'm trying to achieve is using the Build target to generate the cs files, removing the need to include these cs files in the repository, and still having Intellisense/Resharper coverage for the generated files.
Any thoughts?
I've resolved this problem by creating a an empty partial class for each of the cshtml templates which implements our own base class, which in-turn implements RazorGenerator.Templating.RazorTemplateBase.
By doing it this way we have access to all the publicly accessible properties and methods exposed on those classes which makes intellisense/resharper happy and at build time the templates .cs files are generated which do the heavy lifting for outputting the layout etc.

merging 2 html files into a single vm (velocity macro)

I have two html files, I used 2 different frameworks to create 2 different web application for smart phones and other devices such as tablets.
now I have to use Velocity Macro, and merge this two html files into a single vm, that generates 2 outputs depending on a configuration.
i have been searching for methods to do this and I found this: http://www.roseindia.net/apachevelocity/macro-wrap-html.shtml
My question is do I need to build a Java fie just like in the link and then make a vm file, or can I just make a single vm file without making any java files?
if my question in unclear let me know I try to explain more.
The Java class shown there is just to demonstrate the template, and all the template does is demonstrate how to use the Velocity #macro directive.
IMO putting both HTML files into a single VM template is a bad idea, because it will be large and difficult to understand, modify, and debug. Instead, consider using the #parse or #include directives.
Alternatively, consider a mechanism at a higher level to serve the appropriate pages directly instead of pushing the template decision-making process into the templates themselves--this is arguably the best solution.

Using Django to create static, CD held website

I've been tasked at work to create a 'website' on a CD for a client. I've made a start where basically everything is hardcoded pure html, and god how easily you forget how amazing templates are, so much freakin' boilerplate. So I would prefer to somehow create a set of linked html pages using a template system.
Is there some method of easily producing a set of linked html files (suitable for CD, i.e. no webserver) using something like Django? The project is doable by hand, but there's a lot of overhead.
Would love to hear alternative ideas as well, not set on Django, just what I'm kind of familiar with.
Note: Can't include any software, can't use anything from the internet. Flat html, on the cd.
You might be interested in a static-site generator like Hyde (Python) or Jekyll (Ruby). Essentially lets you create pages in Markdown/Textile/whatever with templates, and then generate static HTML files with a simple shell command. You can deploy it however you want, since it's just files.
I've used Jekyll myself because I heard about it first (despite being a Python guy primarily), but Hyde seems a bit more competent (CSS processors, for example). Jekyll is more widely used, I think.
(Using Django would mean that you'd have to run a Django installation on some server just to create the content and then generate "linked html files"...)
Here is another approach: http://lethain.com/intricate-static-websites-with-django-templates/