How to generate files from Liquid blocks in Jekyll? - plugins

I am writing a plugin that defines a new Jekyll block ditaa. Any content in the block should be converted from Ditaa markup to an image file and that image inserted into the post instead of the block. Generating the file works but when copying into or generating in the _site directory, the file is apparently deleted.
Is there a proper/better way to implement a block plugin that generates custom assets?

I've found the proper solution: use the Jekyll::StaticFile class.
When you add one object of this class to the site.static_files array, you are marking this file as pending for copy after the render process is completed. In fact, the copy of such files is done in the site.write process. Take a look at the site_process.rb file in your Jekyll installation.
The usage of this class is easy. When you need to mark a file for future copy, you simply execute a code like this:
site.static_files << Jekyll::StaticFile.new(site, site.source, path, filename)
Where path and filename depends on the location of your file in the src folder.
I had a similar issue developing a LaTeX -> PNG liquid tag. You can take a look at my code at GitHub: https://github.com/fgalindo/jekyll-liquid-latex-plugin

I haven't found the proper way to do it, but one that works. The solution can be found on GitHub and uses Jekylls ability to copy anything that is not prefixed with an underscore to the _site directory. However, this approach has also two drawbacks:
The "source" directory gets polluted with auto-generated files
Deploying without auto-regeneration is a bit awkward because the images are generated after Jekyll already copied all files. So a second Jekyll run is necessary.

I have found the answer.
Replace this
site.static_files << Jekyll::StaticFile.new(site, site.source, path, filename)
with
gnufile = GNUplotFile.new(site, site.source, "_site/media/", "#{#file}")
gnufile.givemethecommands commands
site.static_files << gnufile
and create a GNUplotFile class that inherits Jekyll::StaticFile
class GNUplotFile < Jekyll::StaticFile
def write(dest)
puts "WRITE---->>>>>>>>>>>"
#File.write('_site/media/BTTTTT.svg', DateTime.now)
gnuplot(#commands)
# do nothing
end
def gnuplot(commands)
IO.popen("gnuplot", "w") { |io| io.puts commands }
end
def givemethecommands(commands)
#commands = commands
end
end
The write command runs after the cleanup process. I just have a Liquid block and the above code.

Related

In Scribble how can I get the path to the current file being processed?

I'm using Scribble to pull in parts of files that are stored in other files (not written in Racket). Reading the files and getting the content in works fine, but I don't know how to figure out where the file that the function is being invoked is in, so the only way to get it to work is to pass in a path relative to the root of the document, which is unpleasant.
i.e., I have a directory structure like:
...
hw/
hwN/
assignment.scrbl
template.EXT
...
And in assignment.scrbl, I want to pull in parts of template.EXT, but currently I have to write hw/hwN/template.ext. It would be a lot nicer to, as I can do with #include-section, be able to write just template.EXT, so that if I rearrange the directories I won't break all of these paths.
This is not really specific to Scribble. In Racket, you would do:
(require racket/runtime-path)
(define-runtime-path template.EXT "template.EXT")
then you can use template.EXT to refer to the file.

What is the best way to localize Markdown files in Weblate?

So I have been trialling Weblate using Docker, and pointing it at a Git repo with some .md files I want to localize. I believe a good way of doing this is to use po4a to first convert the .md (basically text) files to a Gettext .pot file then import these as individual components.
My main aim is to make the process as automated as possible but so far it looks like the steps will be something like this:
Convert from .md to .pot using po4a-getextize
Copy .pot file to .en.po file
Commit both files
Create new Component for this file in Weblate, manually putting in
the name of the '.pot' file
Add new languages to translate this Component to
Wait for translators to do their thing
Download all .po files
Convert back to original format with po4a-translate
Feels like I'm missing something with the way Weblate creates components... or how the .pot & .po files work together... ideally I'd like to automatically pick up and create Components when .potfile appear in the repo, then just set up some scripts outside Weblate to automate the conversion to/from the different file formats.
You can use component discovery or API to automatically create the components.

Cond statement doxygen does not work

I am trying to separate out internal and external documentation using the doxygen constructs of cond; but i just cant seem to get get it working. I would essentially like to exclude some files completely and not conditionally. Regardless of where i add the tag (before include, before header guards etc) , the files and source both show up.
What i have tried in vain is to take the test file from doxegen repo for
conditional test and add it to the project.
Steps to reproduce [Linux]
create a new directory.
copy paste the above file (had to rename it to .h as .c was passed over?).
generate dummy config via doxygen -g.
update Doxyfile ENABLED_SECTION = COND_ENABLED.
Run doxygen.
check html/index.html
This however is still visible in the html documentation it generates for the project. I have set the ENABLED_SECTION variable with other values , but cond_enabled function still shows up. Running the testing directory of the project (doxygen) it passes. So i am lost.
Any suggestions?
Tried with latest version 1.8.14.
Thanks!
Regarding the \cond problems (not an answer directly to the real problem you face, I think, but to long for a comment).
The mentioned file is used in the, limited, testing doxygen can do / does and the first lines contain some instructions on what to do. Furthermore there is a default Doxyfile with the tests in use. It is hard to run a separate test outside the doxygen build tree.
Regarding the remark "Running the testing directory of the project (doxygen) it passes." This is correct, here, at the moment, only testing is done against the XML output and the generated output is compared to a once created version of the XML output. No tests are done, at the moment, in respect to HTML or PDF / LaTeX. Recently the test framework has been slightly extended so in the future this should be possible (compare the xhtml and tex output, but some work has still to be done here).
The version of the parser sees the \cond in the first line (normal C comment) as a doxygen command and skips everything till the first \endcond (your friend in these cases is always doxygen -d preprocessor). I think that removing / modifying the first line will result in an already better result. There is however another hiccup for e.g. HTML output. As the function cond_enabled is not documented and EXPAND_ALL is not set to YES the function will not appear in the documentation. So best is also to add a line of documentation with the function cond_enabled.
Regarding the seen HTML problems I modified the the relevant test in doxygen slightly and pushed a proposed patch to github (pull request 714, https://github.com/doxygen/doxygen/pull/714).
Note: the problem of skipping the \cond in normal C comment is quite a bit harder to implement (seen the logical complexity of the doxygen code in pre.l and commentcnv.l.
EDIT: 2018/06/10: The push request has been integrated in the master version on github.

How to import .txt file in Scala

Hi im new to programming, how do i import a .txt file? My code cant find the file, is there any specific directory it has to be put into?
My code:
object Zettel01 extends App {
import scala.io.Source
object Suchtest {
val gesch = Source.fromFile("DieUnendlicheGeschichte.txt").getLines()
for (w <- gesch) println(w)
}
}
I have tried different code but the problem is always the same, i cant find the .txt file...
Thanks in advance for any help
Flurry1337
Every Scala program that you run on your computer is ultimately a java process. This process will have a "working directory", just as every process on your computer does. By default, the working directory is the working directory of the process that started it, that is, the current directory of the shell or command-line interpreter at the time when you started your program.
Now, that means it is important to know how exactly you start your program. If you are using a command line and start your program in the fashion of java MyCoolProgram, then the current directory of the shell will become the working directory of the program. If you use an IDE like Eclipse or IntelliJ IDEA, those typically use the project folder of your IDE project as the working directory of the process that they start.
There is a simple way to find it out quickly: You can always print out the result of new java.io.File(".").getAbsolutePath(). This will print the full path to the working directory. For example, you can write a little Scala program like this:
object PrintWorkingDirectory extends App {
println(new java.io.File(".").getAbsolutePath())
}
and start it. On the console, you should find the full path of the program's working directory. If you put a file named "DieUnendlicheGeschichte.txt" in this directory, your program will find that file under exactly that file name.
Of course, you don't have to dump all your files into that one directory. You can make subdirectories in order to organize your files better. For example, you might put your file in a path like "resources/text/DieUnendlicheGeschichte.txt".
Finally, I would like to point out that there is also a different way to associate resource files with your program, and to load them. The idea is that you put the code (class files) as well as resources like texts, images, CSV files, XML files and the like into one big file. This would be a JAR file. You can then use ClassLoader to access resources inside the JAR file by a URL.
Explaining that process in detail is out of scope for this question; this is just dropping a couple of buzzwords that you (or other readers) can search for in case they want to look up a more elaborated process.
System.getProperty("user.dir") also tells you the working directory.

Issue with doxygen .dox files

I am trying to run doxygen on some source files for a project that I downloaded source files for. The files are located in the following directories:
doc/ - Documentation files, such as .dox files.
src/ - Source files
My settings in my doxygen.config file are:
INPUT = ../ .
FILE_PATTERNS = *.h *.dox *.dxx
When I run doxygen (doxygen doxygen.config), it generates all of the documentation from the .h files correctly, but it does not generate the mainpage correctly. I have a file titled intro.dox in the doc folder, with a command \mainpage Documentation Index, and a bunch of text, but doxygen is not using this to generate the main page.
What am I doing wrong?
There are (at least) two possible reasons for this:
You are not including the /doc directory in you INPUT list. Try modifying this to
INPUT = ../ . ../doc
Did you mean to write ../doc instead of ../? I am guessing that your doxygen.config file is in your src directory. If this is not the case can you make this clear in the question.
Doxygen requires that your documentation files (your .dox files) are plain text with your text wrapped with Doxygen C++ comments (i.e. /** ... */).
Without knowing where doxygen.config is located, and since you are using relative paths in INPUT, it is difficult to determine what might cause this, however since the files you are looking for are in parallel directories, it is possible that doxygen is not search recursively for your files. You may want to confirm that RECURSIVE is set to YES in doxygen.config.