I am doing a simple web app, where i am using a external lib called (html-to-pdf). The idea is to create a pdf with the html and css generated on the frontend. The lib receives a html document, so i need to have something like this representation:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>cv-maker</title>
</head>
<style>
styles go here
</style>
<body>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
at the moment I am using vue to do the job, since it gives me less headeaches with other stuff. What I need is to convert a component based templated, like this:
<template>
<div class="wrapper">
<button #click="sendRequest()"></button>
</div>
</template>
to the above example, so I can extract the component styles and the generated html for the specific component, is there any way to do this?
Currently I am thinking about webpack plugin, but i don't want to build my bundle each time i do a request to the server, is this the good way to do that?
edit: resuming the behaviour i want, basicly i want to extract the html is inside the template witht the class wrapper, and get the styles on the current component and create a single html file with the extracted html from the component and the style embeded on the component with the style tag.
Thanks
Related
I have created simple custom elements in angular in one project and created bundle using npx-build-plus and generated files as shown in the picture below,
out of these files i took out main.js file.
I created another angular cli project and included generated js file in root folder like the below
and in index.html i used like this
<!doctype html>
<html lang="en">
<head>
<title>Custom Angular Element</title>
</head>
<body>
<script src="elements/main.f23021e9a099929ed5cb.js"></script>
<h1 id="result" style="text-align: center"> Angular elements !!!</h1>
<value-button text="Value Button" value="1"></value-button>
</body>
</html>
But the element is not displaying.
I tried to give in app component html also but not working there as well
Should i give any configuraration in package.json ? Can you please tell help me?
You can try following this article https://medium.com/swlh/build-micro-frontends-using-angular-elements-the-beginners-guide-75ffeae61b58
Also if try building it without an hash so that it is easy to always read that.Also you should be adding the custom element in the index.html (e.g. ).
The article talks about setting these things up in more detail.
My project is on angularjs and php. I have been placed in a project that has been previously done by a group of 3 and the documentation was not clear. What I observe from that code is that whenever I declare any bootstrap class or id
without explicitly linking it in that html file
Eg:
<html>
<head>
<title>some title</title>
<!-- No CSS file linked here -->
</head>
<body>
<button class="btn btn-primary">Here</button>
</body>
For above document bootstrap classes "btn btn-primary" are applied. However, they have included that bootstrap file in a folder named "css" but DID NOT include/import that in that html file.
How does my html file know where to search for suitable css file?
Does it search all the available css files?
Is that a good practice or do I need to change that?
when I go to inspect -> sources
<html lang="en" ng-app="quiz">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/bootstrap.min.css">
<script src="js/jquery-3.2.1.slim.min.js"></script>
<script src="js/popper.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="script/angular.min.js"></script>
<script src="script/angular-route.min.js"></script>
<script src="app.js"></script>
<script src="controllers/displayController.js"></script>
<script src="controllers/quizController.js"></script>
<script src="controllers/welcomeController.js"></script>
<script src="controllers/csvController.js"></script>
<script src="controllers/loginController.js"></script>
<script src="controllers/adminController.js"></script>
<style>
body
{
background-color: bisque;
background-repeat: no-repeat;
background-size: cover;
/*border: 1px solid red;*/
}
</style>
</head>
<body>
<div ng-view>
</div>
</body>
</html>
This is the default html for every page, now if I add anyother .js(In js file) or .css( In css file) it doesn't show up here or adds in my html. This came to notice when I added HTML2CANVAS file for one particular html file and it is saying "html2canvas is not defined" in console
Edit:
Thanks for the help JkAlombro, I found that this project uses angular router($routeprovider) So I traced default html file(index.html in this case) and added my js scripts and css links. To know whether your project uses $routeprovider, goto app.js file and check for app.config(function($routeProvider). Just so it helps anyone.
The reason why you can't see any css/js imports to your other HTML files is because that app using an angular router (most probably $routeProvider) and I can confirm that in your index html file.
See that <div ng-view> in your index? That's where all of your other html files are being displayed depending on what route is being pointed. Other proofs that you are using angular router is this script
<script src="script/angular-route.min.js"></script>
Why you don't have to import your css and js in the rest of your html file?
Because everything is being rendered to your index.html (or whatever your default html file is named) so you only need to include all of your scripts and css links there and it will be used all over your app. That's how a Single Page Application works (at least for AngularJS).
If you wanna trace where the router is being configured, most probably you can find it in your app.js or displayController.js.
Make a common header and footer file. Include all your css file in header and javaScript file in footer.
eg:
header.file
- Only push your content here -
footer.file
This way the css and js will be common for every other file.
I am having a bit of an issue in vuejs.
The thing is that i am trying to load more than one template in my vue project. Each component has to load his own css files.
To do that, all i could think of is to put each template css in a folder inside the static folder.
this is the index html
<div id="app"></div>
and in each component i loaded the head tag with css from the static folder
<template>
<html>
<head>
<title> site </title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,height=device-height,initial-scale=1,maximum-scale=1">
<link rel="shortcut icon" href="static/search/favicon.ico">
<link rel="apple-touch-icon-precomposed" href="static/search/favicon.ico">
<link rel="stylesheet" id="brk-direction-bootstrap" href="static/search/css/bootstrap.css">
<!-- etc etc -->
</head>
<body>
<!-- ... -->
</body>
</html>
</template>
And that's how i solved loading different css templates in one project.
But that made the page loading have an issue, it looks completely off before the css finish loading.
I ma not sure how i can fix! calling all the css files in the index.html does not work.
As #puddi says, use the <style> tags in your component. What would seem to suit your needs best would be to use scoped style, <style scoped> which means the css you include there only applies to that component, not globally.
Depending on how adventurous you want to get, you could build your project in Nuxt.js (a wrapper for vue) which allows you to define layouts that would do exactly what you're asking.
http://www.abeautifulsite.net/whipping-file-inputs-into-shape-with-bootstrap-3/
In the "See in Action" section you can see the whole code is separated into 3 parts (HTML,CSS and JS). I'm new in working with asp.net. I know I can put css and js codes inside different files and have a web form which contains html and asp.net tags, But really I do not know how I can assemble the codes are shown in above page to get the correct output.
Any help please?
Simple straightforward example for a way they can all come together:
<html>
<head>
<style>
/* PUT YOUR CSS HERE */
</style>
</head>
<body>
<!-- PUT YOUR HTML HERE -->
<script>
// PUT YOUR JS HERE
</script>
</body>
</html>
This way they all come together at one page, and can affect each other (Css can affect HTML, and JS can affect html & style (which means, it can also change the Css).
Note - the only one you really need in an HTML page is the HTML itself. you could add links to other resources you have written in other files instead of copypasting scripts if you already have the files pre-made, which is probably the better, more orginised approach to this - however the one I've written is more easy to understand if you're a novice, and is probably the best if it's your first time trying all these together. Good luck, new web dev, may the force be with you. (:
Here is the file structure I usually use:
/
|_index.html
|
|_assets/
|_css/
| |_style.css
|
|_ js/
|_script.js
And my index.html generally looks like this:
<!doctype html>
<html>
<head>
<title>Test page</title>
<link rel="stylesheet" href="assets/css/style.css">
</head>
<body>
<h1>Hello world!</h1>
<script src="assets/js/script.js"></script>
</body>
</html>
Why is the CSS linked in the head tag?
Because I want the CSS to be loaded as soon as it can, so the user doesn't see an unstyled version of my page when it loads.
Why is the script called at the bottom of the page?
Because that way, I'm sure the whole document is loaded and parsed when I execute my script.
I've come into a wall : Basically, Javascript doesn't seem to be working in my play pages.
So I have a view main.scala.html as a template for other views.
This file looks like that :
#(page : String, title: String)(content: Html)
<!DOCTYPE html>
<html lang="en">
<head>
<title>#title</title>
<link rel="stylesheet" media="screen" href="#routes.Assets.at("stylesheets/bootstrap.min.css")">
<link rel="stylesheet" media="screen" href="#routes.Assets.at("stylesheets/main.css")">
<link rel="shortcut icon" type="image/png" href="#routes.Assets.at("images/favicon.png")">
<script src="#routes.Assets.at("javascripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
<script src="#routes.Assets.at("javascripts/bootstrap.min.js")" type="text/javascript"></script>
</head>
<body>
<!--some stuff-->
#content
</body>
</html>
So I tried putting a simple thing in the body of the views.
-First in the main.scala.html template
-Then in a view that used this template
-Finally in a thing.html, with no links what so ever with Play! Framework, that I opened in my browser:
<html lang="en">
<head>
<title>title</title>
</head>
<body>
truc
</body>
Only the third option return the wanted result : A popup with thing in it.
My question is : Why is my javascript not handled by play? Do I have to "import" some global javascript feature in order to use it?
Thanks for your help, if you need more info, tell me.
Play produces normal HTML code - browser doesn't care what kind of soft produced it, so I suspect, that you have some mistake in path to some JS file in your head, so it avoids running other scripts, Use some kind of inspector in your browser, to validate, that all resources are downloaded properly. Also check JS console, most probably there are some errors shown.
On the other hand, placing simple JS directly in the views most often works correctly, however, keep in mind that, view's renderer may consider some JS typical syntax as a Play's tag, or something, therefore you need to control still if after rendering your JS is not 'damaged' by this process. For views where you want to use more advanced JS it's absolutely safer (and more comfortable) to include JS from static file(s) the same way as you are using for jquery.js or bootstrap.js
May be you forgot to write
#main(title = "my title") {
<h1>Other html<h1>
<p>My js here</p>
truc
}
P.S:
If it is helpfull don't forget that you shouldn't white head , html and body tags any more, it is included already. Otherwise you will have not valid html, and it will render bad in all browsers