Is there a way to overwrite CKAN Javascript files in a plugin? - javascript

I'm writing a custom plugin for CKAN and in this plugin I want to overwrite the file https://github.com/ckan/ckan/blob/2.8/ckan/public/base/javascript/modules/image-upload.js from CKAN with a new implementation. Is there a way to do this?
I tried adding the file on the same path in the plugin, but that didn't work.

You can create a fanstatic directory in your extension and move the files there. Then use add_resource function to register that directory as explained here. As an additional example check this extension(register, directory)

Related

Electron modify file store in .asar

I would like, from the Electron index.html file, to modify a config file present in the.asar of my application. In my case I need to change, if necessary, my application database config in order to work.
I understood that .asar is in readOnly and I wanted to know if there is a way to modify this config file from electron without changing its position in my application?
I see the extraResources option but I did not understand how its work.
It's also important that the config file stay in myapp/config folder.
Thanks for your help :)
What build tool do you use? If you are using electron builder, you can check out asarUnpack in configuration file here or extraFiles here
I was able to edit the read-only file by first changing the file permissions programmatically and then editing it.
fs.chmod(filename, 0666, (error) => {
console.log('Changed file permissions');
});
...
code to modify file
...
asar is in readonly
as you mentioned asar intended to be readonly package. For runtime-changing config, you should place it outside of asar and change values accordingly.
To manage settings you should use a node package that's specifically designed for this, like electron-settings or preferences.
As an alternative one may manually read an write config files that you place in the platform's native config directory.
Mutable application settings shouldn't be stored in the asar file. If it's required to replace a file in an asar archive for any other reason, use the the asar program to extract the entire archive to a temporary directory, replace the file(s) you want, then create a new asar file, replacing the original asar file.
To unpack .asar files -> asar extract electron.asar app
modify as per your needs
To pack .asar files -> asar pack . electron.asar

How to auto-load JS file from classpath on BIRT

I created a set of utils to use inside my BIRT reports.
I put them (my-utils.jar) inside BIRT's lib directory:
BIRT_HOME\plugins\org.eclipse.birt.report.viewer_x.x.x.x\birt\scriptlib
They are working fine, but now I want to create a JS file, put it on the classpath to be able to use it functions.
// my-utils.js
GLOBAL_VARIABLE = {
formatSomething: funnction(value) {
// do my stuff with 'value' and return
}
};
I want to use it directly, without explicity load it inside a Dynamic Text or Script event, like this:
GLOBAL_VARIABLE.formatSomething('bla bla bla')
How can I do this?
You want to create an extension point. In Eclipse, create a new blank plugin-project, then add this extension point:
org.eclipse.birt.core.ScriptFunctionService
Create a folder just under the project root, name it for instance "jslib" and put your js files in this folder.
Edit plugin.xml and add a JSLib tag, so that it should look like this:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
id="my.js.function"
name="My custom JS functions"
point="org.eclipse.birt.core.ScriptFunctionService">
</extension>
<JSLib
location="jslib">
</JSLib>
</plugin>
Export the plugin as a jar and deploy it in Eclipse and/or web applications and your js functions should be available. More informations about custom birt functions here
Note that Dominique's solution is only for the case when the functions are implemented using Java.
The following solution is for the case when the functions are implemented using Javascript:
First, you don't need to add the **.js* files to the classpath.
Instead, you put them into the directory specified for resources and reference them in your report (or in one of the libraries that you are using in your reports). See the following example:
Directory structure:
workspace
\birt # I have this configured as as "Report Project" in the WS
my_report.rptdesign
\res
my-utils.js
In the preferences menu:
Report Design / Resource / Resource folder = <Current Project Folder>/res
(At runtime, you can set the resource folder using the API, I don't know how to configure this for the Web Viewer example)
In my_report.rptdesign, see the properties of the report itself. Inside the "Resources" tab, add my-utils.js to the Javascript Files.
Now you can use the functions of your library in your report.

How to use webshim with assetic in a Symfony2 project?

I would like to use Webshim in a Symfony2 project.
So far, the webshim library is in mybundle/Resources/public/components/webshim...
The webshim library has a polyfiller.js that loads specified scripts from the ./shims directory. This is also clearly explained from the webshim docs:
The code inside of the polyfiller.js automatically detects the path to the script it is run from and assumes, that the shims folder is in the same directory. This means, you have to make sure, that either the shims folder is placed parallel to the code of the polyfiller.js or to configure the path using the basePath option.
I'm using other libraries and they all end in the /web/js or /web/css directories as they should do. They are combined and have names like "6464de0.js" and are perfectly accessible.
But, webshim tries to load scripts from the shims folder. This makes sense when you look at the docs.
This is an example of 404's in the console:
GET http://domain.dev/app_dev.php/js/shims/combos/1.js 404 (Not Found)
How can I make the webshim library work with assetic?
I have the same issue and here is what I did:
Put the 'shims' folder in the public folder of your desired bundle (eg. AcmeBundle/Resources/public/js/shims) then when you do assets:install using the console command it will be installed in the Symfony/web directory.
Then set the webshim option so that it points to that path:
webshim.setOptions('basePath', '/bundles/acme/js/shims/');

Missing something trying to get bootstrap included into meteor as a local git submodule

I'm trying to install a local copy of bootstrap into a meteor project to make it easier to customise it.
I was using the bootsrap-3 smart package and it was working pretty well, so removed that, created the directory tree and files described in Use Twitter Bootstrap 3 RC1 with Meteor and executed meteor add bootstrap which displayed the text from the summary string, but, no bootstrap is included in the project.
I added bootstrap with
git submodule add git://github.com/twitter/bootstrap.git public/bootstrap
and adjusted the paths appropriately in the packages/bootstrap/package.js file (even tried absolute paths to try and get it to work).
package.js looks like
Package.describe({
summary: "Load locale bootstrap scripts"
});
Package.on_use(function(api) {
api.add_files('../../public/bootstrap/dist/js/bootstrap.min.js', 'client');
});
I'm missing something, but struggling to find it.
Peter
You could stick to the standard way of creating packages by just putting Bootstrap 3's css, fonts, and js directories at the top-level of your package directory, and link to them like this in package.js:
api.add_files('css/bootstrap.css', 'client');
api.add_files('js/bootstrap.min.js', 'client');
...
If you care about the icons, add the fonts the same way. Then, create an override css file which loads last, overriding the paths to the icons in the Bootstrap css. An example of this override file is in Meteor's official Bootstrap 2 package, here. Also see the package.js file from the same, here (though I think you could skip using NPM to concatenate the path names).
One easy way to add bootstrap is just to place the files in your client directory, probably at client/lib. That is the simplest way if you are going to maintain and customise the files yourself. You will probably want both the .css and .js from bootstrap.
For a package, I would look at bootstrap3-less. It can be added with meteorite and gives you the less files which you can customise. If that doesn't suit you then you can at least see how the package.js there looks and how the package is organised.

How do I make text files accessible to the server on Meteor

I'm surprised I can't google my answer here... it seems no one else is having the issue.
When you run the meteor service the js, html, etc. is packaged in the .meteor/local/build folder, but it appears to exclude stuff that isn't js or html. I have a folder called "magicsets" and one called "magicimgs" and neither are in the /local/build folder. This is obviously why, when i attempt to use fs to readfile, it fails to find the file "magicsets/M14.json"
I tried putting the magicsets folder into a folder named "private", but that didn't accomplish anything.
How do I make files accessible locally to my server via FS and how do I make files accessible publically to my server via raw urls?
I'm sure I'm missing something very simple, because there are lots of more complicated questions and answers on SO, yet there is no answer for this. Thanks.
Meteor 0.6.5 which was released yesterday has a new feature which helps loads with this.
Make a directory called /private which you can access with the new Assets.getText or Assets.getBinary functions.
The stuff in the /private directory will then be bundled up into a directory called assets in /program/server/assets and it will not be accessible to the web & you wouldn't need to worry about using fs either. You could just use Assets.getText instead
To make a publicly accessible file put it in /public. So if you had a.jpg at /public/a.jpg it would be accessible at http://yourdomain.com/a.jpg
If you want text files to be available to the webserver i.e. the server that defaults to port 3000, create a folder called public in the root of the project/app directory. drop your folder and files there. You would then be able to access them as http://localhost:3000/magicsets/M14.json
update: it looks like can override the bundler, but it does require changing some of the core code there's no .meteorignore file yet. check this SO answer out: https://stackoverflow.com/a/16742853/105282
To serve a directory of files publicly independent of what Meteor is doing, you can use the following approach. I do this, for example, when I need to link an entire (Javascript) git repo into my Meteor app so I can work on a checked out version of the library.
The following works for 0.6.5. It basically servers up a checked out folder of OpenLayers in /lib:
connect = Npm.require('connect')
RoutePolicy.declare('/lib', 'network')
WebApp.connectHandlers
.use(connect.bodyParser())
.use('/lib', connect.static("/home/mao/projects/openlayers/lib"))
For more information, see https://github.com/meteor/meteor/issues/1229.

Categories

Resources