Generate .php file rather than .html in docfx documentation - docfx

I have been generating documentation with Docfx and everything works fine. Docfx generates .html files which is as expected.
However, since html files an be embedded in php files, I am looking for a way to generate the files as .php files rather than .html which I don't find any information.
I need this feature because I use a PHP templating engine in my application and I wanted to insert template variables in the markdown files for PHP to resolve dynamic values when being loaded in browser.
If this is possible, I would want a guide on how to do this. For instance, if I could locate and modify the file extension in the source code where the files are created.
Thanks in advance.

There's no build-in feature for that. Since I ran into the same problem today, here's a small workaround to archive that (sample in powershell):
$destinationRoot = "path/to/doc"
[RegEx]$Search = '(\.html)"'
$Replace = '.php"'
ForEach ($File in (Get-ChildItem -Path $destinationRoot -Recurse -File)) {
(Get-Content $File.FullName) -Replace $Search,$Replace |
Set-Content $File.FullName
}
After that you have to rename the files via script, too (it's not part of that script). You can archive that via modify the Set-Content $File.FullName command. You may wish to delete the old file, too.
Keep in mind it will replace links in the content, too, if they end with .html", but pages normally will not end with that extension, so it's an acceptable trade-off. If you really ran into that problem, just append a # or something else to the URL.

Related

how to use php scripts in datalife engine template files?

I want to read and display something from the database on the DataLife Engine homepage with php script.
Something like the last few news shows.
But when I call the file containing the PHP script inside the DataLife Engine template files (with the .tpl extension) (like this:{include file="test.tpl"}), this script don't work and don't show anything.
when I call the php file like this ({include file="test.php"}) in .tpl files, Data-Life-Engine show me an error with this description: Include files from root directory is denied.
Please help me to use a PHP script in the DataLife-Engine template file.
Thanks
first you must put your PHP file in the path "engine/modules".
Then call it in your template file as follows:
{include file="engine/modules/TEST.php"}

How to give folder of files as input to SyntaxNet

I am new to Syntaxnet. I followed the basic tutorial, installed syntaxnet and I modified the syntaxnet/demo.sh file and added the following code to context.pbtxt file:
input {
name: 'MAIN-IN'
record_format: 'english-text'
Part {
file_pattern:'/path_to_0095.txt'
}
}
This is helpful only to give the test.txt file as input, Now I want to give a folder of files, ex folder with 100 files as input and get it processed. I tried to give the folder as input which failed. I googled about it, but couldn't find anything useful. So Could any one please let me know how to process multiple files in a folder using syntaxnet ?
We built a Java program around SyntaxNet that dynamically updates the context.pbtxt file with the current file name (after pulling in all of the files in the directory). I don't know if SyntaxNet will allow you to use a directory of files as input.

Executing R scripts in Symfony2

I have to execute (safely) a lot of R scripts from a Symfony2 controller.
I organized in my AcmeStatsBundle a folder named RScripts. There, a lot of R script files are stored, e.g. Test.R
To execute the script in the Test.R file, I should write in my secured action something like:
$rootdir = ...//get the path to the src folder.
exec("Rscript $rootdir/Acme/StatsBundle/RScripts/Test.R");
Which is the command to use to get the right value for $rootdir? Maybe I'm wrong and I should deploy the scripts in the app folder.
Where should I put the generated output (e.g. images), in the web folder?
Should be :
$rootdir = $this->get('kernel')->getRootDir() . '\..\src'
(what's those '\' is that some windows thing ?)

What is the Unix way for a console script to use config files?

Let's imagine we have some script 'm12' (I've just invented this name) that runs
on Linux computers. If it is situated in your $PATH, you can easily run it
from the console like this:
m12
It will work with the default parameters. But you can customize the work of
this script by running it something like:
m12 --enable_feature --select=3
It is great and it will work. But I want to create a config file ~/.m12rc so I
will not need to specify --enable_feature --select=3 every time I run it.
It can be easily done.
The difficult part is starting here.
So, I have ~/.m12rc config file, but I what to start m12 without parameters that
are stored in that config file. What is the Unix way to do this? Should I run
script like this:
m12 --ignore_config
or there is better solution?
Next. Let's imagine I have a config file ~/.m12rc and I want some parameters from that
file, but want to change them a bit. How should I run the script and how the
script should work?
And the last question. Is it a good idea for script to first look for .m12rc
in the current directory, then in ~/ and then in /etc?
I'm asking all these questions because I what to implement config files in my
small script and I want to make the correct decisions about the design.
The book 'The Art of Unix Programming' by E S Raymond discusses such issues.
You can override the config file with --config-file=/dev/null.
You would normally use the order:
System-wide configuration (/etc/m12/m12rc, or just /etc/m12).
User's personal configuration (~/.m12rc)
Local directory configuration (./.m12rc)
Command-line options
with each later-listed item overriding earlier listed items. You should be able to specify the configuration file to read on the command line; arguably, that should be given precedence over other options. Think about --no-system-config or --no-user-config or --no-local-config. Many scripts do not warrant a system config file. Most scripts I've developed would not use both local config and user config. But that's the way my mind works.
The way I package standard options is to have a script in $HOME/bin (say m12a) that does it for me:
#!/bin/sh
exec m12 --enable_feature --select=3 "$#"
If I want those options, I run m12a. If I want some other options, I run raw m12 with the requisite options. I have multiple hundreds of files in my personal bin directory (about 500 on my main machine, a Mac; some of those are executables, but many are scripts).
Let me share my experience. I normally source config file at the beginning of the script. In the config file I also handle all the parameter switches:
DEFAULT_USER=blabla
while getopts ":u" do
case $opt in
u)
export APP_USER=$OPTARG
;;
esac
done
export APP_USER=${APP_USER-$DEFAULT_USER}
Then within the script I just use variables, this let me to have number of script having same input parameters.
In your case I imaging you would move "getopts" section to script and after it source the config file (if there was no switch to skip sourcing).
You should not put yours script config file to etc, it will require root privilidge to do that, and you simple can live with config file in home.
If you would like anyway to put your script for sharing with other users, it should go to /usr/share...
Another solution use thor (ruby gem), its way simpler to handle input parameter, avoiding work to get same result in bash e.g. getopts support only single letter switches.

How do I copy files?

I need to copy a file from one folder to another folder. How can I implement this in Drupal. Give me some ideas with working examples.
Second result on Google for "file copy, drupal"...
file_copy()
Copies a file to a new location.
This is a powerful function that in
many ways performs like an advanced
version of copy().
Checks if $source and $dest are valid
and readable/writable.
Performs a file
copy if $source is not equal to $dest.
If file already exists in $dest either
the call will error out, replace the
file or rename the file based on the
$replace parameter.

Resources