Sinatra render and passing rendering options for Redcarpet - sinatra

I’m using Sinatra, and Sinatra uses Tilt for template rendering.
By default Redcarpet has many rendering extensions. How can I use some of these extensions via Sinatra’s #render method?
I need to render markdown files with :gh_codeblock extension.

In Sinatra, you don’t usually use the render method directly, rather you use the method corresponding to the appropriate template language, in this case markdown.
You should be able to pass any options you want to this method as a hash, and Sinatra (and Tilt) will pass them to the template engine. However, the latest released Tilt gem (1.3.3) doesn’t pass all the options for markdown through, only :filter_html and :smart, so this won’t work. This is fixed in the current Tilt head, it just hasn’t made its way to a released gem yet.
If you’re using Bundler, you could work around this by using Bundler’s Git support:
gem 'tilt', :git => 'git://github.com/rtomayko/tilt.git'
Alternatively you could download the latest version of Tilt and make sure its lib directory is on your apps load path, perhaps putting it into a vendor directory.

If I read the source code of sinatra, tilt and redcarpet right, you should be able to do something like this:
render('your_view', {:gh_codeblock => true}, {HASH_OF_YOUR_LOCAL_VARIABLES})
The second parameter to render is an options hash that is passed to the template engine. See:
def markdown(template, options={}, locals={})
render :markdown, template, options, locals
end

Related

Swift C Interop: How to avoid absolute paths for modulemap headers?

I am working on building a swift wrapper over a C library (ROS2 RCL), using C interop features. I’m currently using CMake with module maps to achieve this functionality. Currently, my modulemap looks something like this:
module CRcl [system] {
header "/opt/ros/foxy/include/rcl/rcl.h"
link "rcl"
export *
}
This currently builds just fine on my system. However, using the absolute path is a pretty poor solution, as it requires modification for different os’s or custom install paths. I would prefer for it to be automatically discovered.
Ideally, I’d imagine something like this:
module CRcl [system] {
header "rcl/rcl.h"
link "rcl"
export *
}
where I don’t specify an absolute path, instead directing the compiler to find the header via a CLI arg or environment variable.
I have seen various guides for working with frameworks in XCode, but nothing that would be relevant for my setup on Linux. Does anyone know of a way to achieve this functionality?

Simple API call within the context of DocFx preprocessor

I would like to know if it is possible to make a simple API call (e.g. GitHub API v3) within the context of a DocFx custom template preprocessor. I have been trying all sorts of different approaches, but nothing has fully worked so far.
My goal is to make a call to an API to retrieve some data, and then update the model accordingly to be used in the *.liquid or *.tmpl renderers.
I have tried using the http/https node modules. I have also tried using node-fetch. It results in a docfx build error something like:
Error:Error transforming model ".../index.raw.json" generated from
".../index.md" using "conceptual.html.primary.js". Error running
Transform function inside template preprocessor
According to DocFx documentation, preprocessors follow the ES 5.1 standard. My code conforms to this.
Does anyone know if this is possible?
By the way, I am able to do simple model manipulation just fine, so I understand the basic concepts here with the DocFx preprocessors.
Thanks!
For the benefit of others, I discovered DocFX uses jint which cannot require a Node library directly. Therefore, it appears the plugin route is a better way to go for this use case.

$(...).datetimepicker is not a function when use converse.js

I want to implement XMPP chat functionality in my system using converse.js for client side chat interface. but when i use converse.js in my layout page, browser showing me error like
$(...).datetimepicker is not a function
$(...).dataTable is not a function.
I have used bootstrap datetimepicker and datatables. It seems like jquery conflictions.
I have tried to resolve conflictions by changing place of some jquery files. but i didn't get success. So how can i remove conflictions?
EDIT: As of version 3.0.1 this shouldn't be an issue anymore. In previous builds the $.noConflict call wasn't being made. This is now fixed in 3.0.1. If you're using an older version, then the text below is still relevant.
Converse.js comes bundled with jQuery. It uses jQuery's noConflict method to relinquish control of the $ variable and therefore to avoid conflicts with other versions of jQuery, but apparently this doesn't always work reliably.
There are a few things you can try:
Load converse.js before all your other JS libraries.
Alternatively, drop your own jQuery and instead use the one included in converse.js. You can access it via converse.env.jQuery.
Or alternatively use the converse.js bundle that doesn't include jQuery: https://cdn.conversejs.org/dist/converse-no-jquery.min.js

sails.js blueprints override as hook

A while back I asked how to override sails.js blueprints (CRUD blueprint overriding in sails.js)
With v0.11 of sails.js we now have blueprints (and they are awesome :)).
Is it possible to turn off the current blueprints and install a new version of them as a hook?
This issue comment (https://github.com/balderdashy/sails/pull/2173#issuecomment-54165548) from #sgress454 seems to indicate it is/was in the works, but I can't find anything more specific about it.
I know I can override by creating an api/blueprints folder, but it would be easier for my users to consume via an npm install.
You are right, this is possible.
It is actually what happens in Sails's core here : https://github.com/balderdashy/sails/tree/master/lib/hooks/blueprints
Default blueprints are loaded like an Installable Hook would be.
You can just go ahead and copy that MIT licensed code and then replace the content of the actions directory with your own blueprints.
After that, update the object BlueprintController in index.js to make sure it points to your files.
Finally, all the magic happens in the extendControllerMiddleware method. You can see the code will go through each controller to inject your blueprints. The key point here is the replace the call to _.defaults with _.assign because your sails hook will want to overwrite defaults blueprints and not simply add them if they do not exist.

How to specify SonarQube rule description as a markdown/html resource file instead of using annotation?

I have my custom rule, let's say with AEM-1 key. So, as it is done here, I make my AEM-1.html resource file with some simple html content and it does not get's picked up by SonarQube 5.1. It refuses to start, because no description is provided for the rule.
I tried different packages names, tried to look for convention in source code etc. What's missing? Is there any documentation on that?
The naming convention is org/sonar/l10n/{plugin key}_{language}/rules/{repository key}/{rule key}.html.
It was documented in http://docs.sonarqube.org/display/DEV/Internationalization at the time rule descriptions supported localization. That's not the case anymore since version 4.2, but these HTML bundles are still supported.
The correct way since version 4.3 is to use the low-level API org.sonar.api.server.rule.RulesDefinition. It allows you to implement any kind over layer over it (xml, json, annotations, ...).