Prevent Files from being overwritten

Hi guys,

am working a bit further on my Reginald-Framework Plugin. The previous version pointed to remote URLs for loading the required resources (CSS and JS).

Now I thought, it might be better to create local resources. I grabbed the following script (thanks to @benhanna :slight_smile:)

        //Add resources as component (locally)
    
    var toLocalPath = function(p) {
    return p.replace(/\//g, path.sep);
    }
    
    var res_files = ['themagicstyles-min.css', 'overwriterules.css', 'themagicscript-min.js'];
    for(var i = 0; i < res_files.length; i++) {
    var file = f.getResourceFile('resources/' + res_files[i]);
    var r = new PgComponentTypeResource(file);
    r.relative_url = res_files[i];
    r.source = toLocalPath(file);
    r.footer = res_files[i].indexOf('.js') >= 0;
    f.resources.add(r);
    }

It does what it is opposed to.

But when I create a new page and load the plugin, the files will be overwritten - as expected as well (I suppose it’s the p.replace.

Is there a way to prevent me from “replace”?

Or is my idea stupid anyway?

Thanks for your help in advance.

Cheers

Thomas

Hi Thomas,

p.replace() is using a regular expression to replace the file path separator pc-web. I have thought about creating a plugin but haven’t created one yet. I think if I were doing it I would edit those files in an external editor and then reload the plugin to see the effects. Or work on it as a seperate project and then dump the files into the plugin.
It would be interesting to see what Ben’s approach is.
:slightly_smiling_face:

OK - got it!
Cannot explain what I did though.
In fact I had a look into Ben’s great work (the pervious code I had is admittedly not from him - apologize) trying to figure out what’s going on. And with a bit of trying, it started to work. So always remember (Note to myself):
“99% of the mistakes are sitting in front of the screen”.

Cheers

Thomas

1 Like

@SureWeb
I use an external editor, a lot of trial and error and looking at the frameworks bundled with PG for tips as not much info in the docs. Constant loading and unloading of Plugin to test. I find you need to completly unload the plugin JS file in PG and the reload and activate it each time when testing, to see updates (not just deactivate and reactivate).

1 Like

@Thomas

I know you got sorted but maybe this was what you were looking for (from the FA plugin)

 //Auto detect if font-awesome css is included
    f.detect = function(pgPage) {
        return pgPage.hasStylesheet(/font\-awesome/i);
    }