How to Modify the StrongLoop's LoopBack Explorer CSS - css

We're using Strongloop's LoopBack for our REST APIs and would like to modify the CSS for the LoopBack Explorer. However, it's not clear which CSS files are being used (LoopBack vs Swagger) and where they're located. I was not able to find specific documentation for this.

You can modify more than just the css. And also, if you generate your Loopback application using slc loopback like I did, you'll find that your server/server.js doesn't look immediately in a way you can configure it like it's shown in the accepted answer.
Instead you can use server/component-config.json to instruct the loopback component explorer to use an alternative directory for static files for the swagger-ui. With the uiDirs configuration below I configured it to go look for static files in the server/explorer directory.
{
"loopback-component-explorer": {
"mountPath": "/explorer",
"uiDirs": "server/explorer",
"apiInfo": {
"title": "My API",
"description": "Description of my API"
}
}
}
* When using IISNode uiDirs has to be set to "explorer" otherwise it's "server/explorer" as per #phegde 's comment
In my server directory I created a index.html which is a copy from node_modules/loopback-component-explorer/public/index.html and also I created an images folder with a custom logo.
And finally, If you want to have custom css, copy node_modules/loopback-component-explorer/public/css/loopbackStyles.css into server/explorer/css/loopbackStyles.css

You can provide your own version of Swagger UI files via options.uiDirs.
Edit your server/server.js and add this config option to the explorer:
app.use(explorer(app, { uiDirs: path.resolve(__dirname, 'explorer') }));
Copy the directory node_modules/loopback-explorer/public/css to server/explorer/css
Customize the copied CSS files as you need.
You should lock loopback-explorer's major & minor version in your package.json. Newer versions of loopback-explorer may change the CSS in which case your customization may stop working.

If you didn't lock the loopback-explorer in package.json or if you started your application from the new release of loopback(v2.x), you have to make another change:
If you generated your loopback app with the generator tool, edit server/component-config.json and change it to this:
{
"loopback-component-explorer": null
}
2.Copy the directory node_modules/loopback-explorer/public/ to server/explorer/ as Miroslav said. If you copy the whole directory you can also change the index.html file.
Edit server/server.js file and add this line: app.use('/explorer',explorer.routes(app, { uiDirs: path.resolve(__dirname, 'explorer') })); also you have to add the explorer module at the top of the file: var explorer = require('loopback-component-explorer');
4.Customize the ui of your explorer, all the necessary files are in server/explorer

With the loopback-component-explorer the uiDirs defined in component-config.json should be added something like the below (which solved my issue).
"uiDirs": ["server/explorer"]
instead of
"uiDirs": "server/api-explorer",

I am able to apply custom css styles to loopback api explorer header.
Steps I followed as mentioned below
Goto node_modules > loopback-component-explorer > public > css folder
Copy loopbackStyles.css
Create a new folder called explorer under server folder
create css folder under explorer and paste the css file under css folder i.e., loopbackStyles.css
Add below config to component-config.json file
{
"loopback-component-explorer": {
"mountPath": "/explorer",
"generateOperationScopedModels": true,
"uiDirs": "server/explorer"
}
}
To change loopback header color I have just overrided backgroun-color with my own color in body #header css selector in loopbackStyles.css
To replace the default header logo name with our custom name. I have added following css styles in loopbackStyles.css
.swagger-ui-wrap #logo{
display: none;
}
.swagger-ui-wrap:after {
content: "MyOwn API Explorer";
color: #fff;
font-weight: bold;
}

Related

Emmet-Atom custom snippets not working as intended

As I am extremely new to programming I might just be overlooking some obvious issue so please bare with me.
I wanted to use custom snippets to extend the already existing ones to speed up my future workflow.
I created a snippets.json file, which contains this code
{
"html": {
"snippets": {
"page": "header>h1^main+footer{${0:©}}",
"a:link": "a[href='http://${0}']"
}
},
"css": {
"snippets": {}
}
}
when typing page, then pressing tab (or ctrl+e) in my HTML file, it doesn't output the Markdown, instead it just prints header>h1^main+footer{}
I put the a:link in there because it's a snippet that already exists within Emmet to test if the issue was with my custom snippets file.
And yes, the issue persists, instead of giving me the Markdown it only says a[href='http://']
Inside the Atom settings are 2 checkboxes:
Format Line Breaks
Use Emmet Comments
I have checked and unchecked both individually and together, nothing has resolved the Problem.
Settings inside of Atom

How to disable CSS errors for HTML files using Visual Studio Code (on Mac)

I am using Visual Studio Code (on a Mac) to write AngularJS style HTML. When I insert an inline expression for a CSS value, I get the annoying red Intellisense error, as shown in the screenshot below. Also, please note that I have disabled all extensions to ensure that none were the cause of my issue.
The main question is this: how do I disable the CSS errors in VSCode for Mac?
Thanks for any suggestions!
open your settings.json file by cmd+shift+p OR crl+shift+p and typing setting.json
in that file add this line
"html.validate.styles": false
VSCode is still very new to me, but after some tinkering I found an option that disables all CSS validation rules. I set the value to false and the errors are now longer showing up. The setting in your settings.json file should appear as as follows:
{
"folders": [
{
"path": "/Users/Paulie/Desktop/AngularPractice"
}
],
"settings": {
"css.validate": false
}
}

How to get Grunt UnCss to compile based on the homepage

I am trying to get UnCss to produce a cut down version of my master CSS file, for now I only want to get this working on the homepage as a test.
I am using the following code:
uncss: {
dist: {
options: {
stylesheets : ['localhost/assets/css/master-2014.css'],
urls : ['localhost/en-gb/']
},
files: {
'css/app.clean.css': ['localhost/en-gb/']
}
}
}
What I am trying to do here is read master-2014.css from my local server (and eventually a remote url e.g. google.com), then look at the page that I have got the stylesheet from (my homepage localhost) and determine which style is needed. I finally want to then produce this into app.clean.css.
Currently I cannot get this to work for the life of me I have tried other variations like:
files: {
'css/app.clean.css': ['**/*.Master', '**/*.ascx']
}
This does not work.
I have also seen people try something like this:
files: {
'css/app.clean.css': ['index.html']
}
Where index.html is a blank html file. This is the only one that succeeds but it just creates me a css file which only contains css for html and body. The rest all throw the following error:
Running "uncss:dist" (uncss) task
Warning: Destination (css/app.clean.css) not written because src files were empty. Use --force to continue.
Aborted due to warnings.
All other examples that I can find are for WordPress which is PHP and this is a .Net site.
I would be very grateful for any help.

Phonegap: InAppBrowser insertCSS file

I'm trying to create an app that loads a website and then adds some custom CSS to adjust it to a mobile device.
I'm using window.open to load the page successfully, and I have a callback on loadstop where I'm calling browser.insertCSS, this is where the problem is.
If I do something like this:
browser.insertCSS({code:"body{background-color:red;}");
The style is applied correctly. However if I do this:
browser.insertCSS({file:"mobile-style.css");
And add the same CSS to the file, it doesn't get loaded
I have tried different paths (putting the file in the www folder, in the css folder, in the same folder as the JS file, and referencing it with "./mobile-style.css", "mobile-style.css", "/www/mobile-style.css", "/mobile-style.css" but none of them seem to load the file correctly.
I saw another post What should file paths fed to insertCSS() be relative to? where this same question was asked, but there is no accepted answer (I have tried the suggestion there and it doesn't work).
Any help would be greatly appreciated.
Thanks
Will
you have to wait until your inAppBrowser page loading finishes.
You must add an event listener:
var inApp = window.open('mypage.html', '_blank', 'location=no');
inApp.addEventListener('loadstop', function(){
inApp.insertCSS({
file: 'inAppStyle.css'
},onSuccess);
});
EDITED
Use this path for your android projects file:///android_asset/{your folder}
INFO: https://github.com/apache/cordova-plugin-file/blob/master/doc/index.md#android-file-system-layout
I couldn't find the right local path. Instead, I just uploaded the css file to the web and provided a regular URL
file: 'http://mywebsite.com/path-if-needed/my.css'
Not ideal to have an external dependency, but not a big deal since InAppBrowser itself requires internet access.
I probably know why it won't work, it is because your path isn't right, this css file should not put in www folder, neither the cordova project folder, u should put it into the server, for example, if ur browser is to visit http://192.168.1.1/admin, then the cordova only fetch this file when the browser is under the 192.168.1.1/admin, it fetch the file under the server directory.I don't know if u use any debug tool , if u use one, it's easy to find out what went wrong, ur console will log the error which path it fetch the css file and didn't get it.
If you want to add an external CSS file stored locally in the APP's sandbox and not around in the Internet, this is the only way, that is, you get the external file, you store it into a string variable, and then you insert such code into the Browser.
var inAppBrowserRef = cordova.InAppBrowser.open(url, "_blank", "location=no");
//when load stops call loadedCallbackFunction
inAppBrowserRef.addEventListener('loadstop', loadedCallbackFunction);
function loadedCallbackFunction() {
console.log("InAppBrowser Window loaded");
$.ajax({
type: "GET",
url: cordova.file.applicationDirectory + "www/css/myExternalCSS.css",
dataType: "text",
success: function (CSScode) {
inAppBrowserRef.insertCSS(
{ code: JScode},
function(){
console.log("CSS code Inserted Succesfully into inApp Browser Window");
});
},
error: function () {
console.error("Ajax Error");
}
});
}
You need the cordova-plugin-inappbrowser

Image path in css not working properly

I am trying to use images in css file in my laravel project that makes use of twitter bootstrap and Jason Lewis' Basset.
Now when I use a image in my css like
.div {
background: url('asset/img/photo.jpg');
}
I get the path to
http://localhost/asset/css/less/assets/img/photo.jpg
However the real path should be
http://localhost/~Username/laravelProject/public/asset/img/photo.jpg
The only way to achieve this is to use this url in my css
/../~Username/laravelProject/public/asset/img/photo.jpg
You guys would understand this is a no go if I have to move the site from local to server and have to change all the urls every time.. So Why is this not working properly? I am using this laravel starter site made by andrew13
startersite github
Last but not least.. this is the structure
The issue is that the path is bellow the css doc, relative file paths work by adding there files location to the beginning of the url, this means that it is looking for (Mypath)/asset/img/photo.jpg
(or: public/asset/css/asset/img/photo.jpg from what I can see)
Without a PHP server to return dynamic url's, sadly your only 2 options are:
Move the CSS to the root, or at least lower then the IMG
Use a absolute url
With php you have a few options, my favorite being a "Node" structure
How this works is placing a php file in the root folder that sets a constant of its location:
<?php
define('ROOTPATH', dirname(__FILE__));
?>
When ever you want to use this just include the file, and use ROOTPATH:
<?php
include 'TheFileName.php';
echo ROOTPATH,'/public/asset/img/photo.jpg';
?>
On most php servers this is already set to $_SERVER['DOCUMENT_ROOT'], but on a local host with will need to use a node.
Please note this is sudo code, some things may have to be changed

Resources