Replace string / content in Spark.staticFileLocation(path) before render - static-files

I am using Spark.staticFileLocation to serve multiple static HTML / CSS/ JS etc files and folders in resource/public and want to replace content within these files:
staticFileLocation("/public");
Spark.after((request, response) -> {
String body = response.body();
body.replace("stringA", "stringB");
response.body(body);
});
But response.body() is empty (null), even though the files get rendered fine.
I know that I can achieve that with a templating engine, but this creates a huge overhead and compelixity for the simple replacement I want to do.
Does anyone have a better suggestion ?
Thanks a lot !
/edit:
Latest spark version 2.7.2 does not even evaluate the Spark.after() block for static files.

Related

Bundleconfig (seemingly) not creating requested .js files

We have a large solution with a number of files being created by bundleconfig.cs. But for some reason the last two projects added to the solution don't seem to be getting the files creating. The pages that use them fail cause they aren't there, or not being found.
Example of project successfully getting the files created:
const string ANGULAR_APP_ROOT_EDI = "~/app/ediViewer/";
const string VIRTUAL_BUNDLE_PATH_EDI = ANGULAR_APP_ROOT_EDI + "main.js";
bundles.Add(
new ScriptBundle(VIRTUAL_BUNDLE_PATH_EDI)
.Include(ANGULAR_APP_ROOT_EDI + "ediViewerApp.js")
.IncludeDirectory(ANGULAR_APP_ROOT_EDI, "*.js", searchSubdirectories: true)
);
Example of one that's not:
const string ANGULAR_APP_ROOT_EDI_SC = "~/app/SupplyChain/";
const string VIRTUAL_BUNDLE_PATH_EDI_SC = ANGULAR_APP_ROOT_EDI_SC + "main.js";
bundles.Add(
new ScriptBundle(VIRTUAL_BUNDLE_PATH_EDI_SC)
.Include(ANGULAR_APP_ROOT_EDI_SC + "SupplyChainApp.js")
.IncludeDirectory(ANGULAR_APP_ROOT_EDI_SC, "*.js", searchSubdirectories: true)
);
very similar, both Angular(js) projects with similar directory structures. but the second one gets no files. I have other projects with a similar structure that are working.
I was hoping there was a way to put breakpoints in the bundleconfig file to see if if it was hitting the code, but apparently you can't, or I didn't successfully set one up.
There are a number of bundles appearing after the new one (the standard Angular libraries) that are getting created, so it doesn't appear to be stopping in the middle or anything.
The workaround was I simply added the scripts needed manually to the aspx page, but I shouldn't have to. It's happened for two new projects so far, so I'm prepared to bet it may happen for a third, so if I can find a fix it'd be useful.
Any ideas what might be happening, or how I can troubleshoot it?

Gradle openapigenerator not using templates from templateDir

I am trying to use custom templates with the openapigenerator-plugin (v5.4.0), but it seems like the templates are not used
build.gradle.kts
val generateApi = tasks.register<GenerateTask>("generateApi") {
inputSpec.set(buildDir.path + "/path/to/openapi.yml")
generatorName.set("spring")
outputDir.set(buildDir.path + "/generated")
templateDir.set("src/openapi-templates")
}.get()
I replaced the template content so that I definitely see, when it gets used.
src/openapi-templates/api.mustache
testcontent
With this simple setup my <myController>Api.java-files still have the standard content instead of just containing testcontent.
Has anyone any idea what I am doing wrong here?

How to use SassDoc as parser for single file without generating full documentation files

Question relates to http://sassdoc.com package
I would like to parse each *.scss file in ./source folder, but instead of generating sassdoc folder i would like to create partial-html for each parsed file. For example:
parse: variables.scss and receive variables.html, without page header, sidebar - pure content, even without html and body tags.
My current code:
var gulp = require('gulp'),
sassdoc = require('sassdoc');
var paths = {
scss: [
'source/**/*.scss'
]
};
gulp.task('sassdoc', function () {
console.log("sassdoc task finished");
return gulp.src(paths.scss)
.pipe(sassdoc());
});
It's not possible with SassDoc' default theme. So you'd need to build your own theme to acheive this.
http://sassdoc.com/using-your-own-theme
Each item is given a file key in resulting data, so I would leverage that and do some merging.
That could potentially end up in a sassdoc-extra custom filter.
http://sassdoc.com/extra-tools
EDIT:
Actually your question is quite misleanding, you want a variable.html file but with no html ...
If all that you want is the raw JSON data from SassDoc, without any kind of theme processing, then the parse method is what you're looking for.
But again, unless you call SassDoc on each file separately, you'll get all files together, meaning post data processing to split them, that's why a custom theme (even with no html output) is the way to go.

Getting the filename/path from MvvmCross Plugins.DownloadCache

I'm currently using MvvmCross DownloadCache -- and it's working alright -- especially nice when I just need to drop in an Image URL and it automagically downloads / caches the image and serves up a UIImage.
I was hoping to leverage the code for one other use case -- which is I'd like to grab source images from URL's and cache the files on the local file system, but what I really want for this other use case is the image path on the local file system instead of the UIImage itself.
What would help me most if I could get an example of how I might accomplish that. Is it possible to make that happen in a PCL, or does it need to go into the platform specific code?
Thanks -- that works, but just in case anyone else is following along, I wanted to document how I got the Mvx.Resolve<IMvxFileDownloadCache>() to work. In my setup.cs (in the touch project), I had:
protected override void InitializeLastChance ()
{
Cirrious.MvvmCross.Plugins.DownloadCache.PluginLoader.Instance.EnsureLoaded();
Cirrious.MvvmCross.Plugins.File.PluginLoader.Instance.EnsureLoaded();
Cirrious.MvvmCross.Plugins.Json.PluginLoader.Instance.EnsureLoaded();
...
}
But that wasn't enough, because nothing actually registers IMvxFileDownloadCache inside the DownloadCache plugin (which I was expecting, but it's just not the case).
So then I tried adding this line here:
Mvx.LazyConstructAndRegisterSingleton<IMvxFileDownloadCache, MvxFileDownloadCache>();
But that failed because MvxFileDownloadCache constructor takes a few arguments. So I ended up with this:
protected override void InitializeLastChance ()
{
...
var configuration = MvxDownloadCacheConfiguration.Default;
var fileDownloadCache = new MvxFileDownloadCache(
configuration.CacheName,
configuration.CacheFolderPath,
configuration.MaxFiles,
configuration.MaxFileAge);
Mvx.RegisterSingleton<IMvxFileDownloadCache>(fileDownloadCache);
...
}
And the resolve works okay now.
Question:
I do wonder what happens if two MvxFileDownloadCache objects that are configured in exactly the same way will cause issues by stepping on each other. I could avoid that question by changing the cache name on the one I'm constructing by hand, but I do want it to be a single cache (the assets will be the same).
If you look at the source for the plugin, you'll find https://github.com/MvvmCross/MvvmCross/blob/3.2/Plugins/Cirrious/DownloadCache/Cirrious.MvvmCross.Plugins.DownloadCache/IMvxFileDownloadCache.cs - that will give you a local file path for a cached file:
public interface IMvxFileDownloadCache
{
void RequestLocalFilePath(string httpSource, Action<string> success, Action<Exception> error);
}
You can get hold of a service implementing this interface using Mvx.Resolve<IMvxFileDownloadCache>()
To then convert that into a system-wide file path, try NativePath in https://github.com/MvvmCross/MvvmCross/blob/3.2/Plugins/Cirrious/File/Cirrious.MvvmCross.Plugins.File/IMvxFileStore.cs#L27

Clear my cache using cmd command=> ipconfig/dnsflush?

If my computer is the web server for multiple live websites, is there any harm if I type ipconfig/dnsflush in my command prompt editor?
I always got this problem. I embed a flash (swf) in a .html file. Whenever I update the swf, the .html file always use the old swf even if I clear my cache and whatever else.
Is there any ways to have my .html file always get the latest/updated swf file?
Typing ipconfig/dnsflush won't fix your problem, thats flushing the DNS cache, your problem is that your SWF file is being cached by the browser. There are a few ways to stop this. The easiest is probably by adding a random query-string onto the URL of the SWF file in the EMBED/OBJECT tag:
<script type="text/javascript">
<!--
document.write('<object etc ... ');
document.write('<param name="movie" value="filename.swf?r=' + Math.round(Math.random() * 99999) + '">');
document.write(' the other param tags here );
document.write('<embed src="filename.swf?r=' + Math.round(Math.random() * 99999) + '" etc .... </embed>');
document.write('</object>');
//-->
</script>
But be aware that this means your SWF will be downloaded afresh every time, and never from the browser cache. If you don't want this, consider adding a version number in the querystring rather than a random number, and increment this when you want clients to download a new SWF file.
I have a little php snippet that I use to append the unixtime of when i uploaded the file to the server at the end of the flash' url. This way I just upload the new one and everything sorts itself out automagically.

Resources