I've successfully precompiled handlebars into one file using grunt-ember-templates, however, when including source in html file:
<script src="templates/app/compiledTemplates.js" type="text/javascript"></script>
It says this:
Resource interpreted as Script but transferred with MIME type text/plain: "file:///Users/jaime/voyant-svn/voyant-blocks/dev/blocks-web/src/main/webapp/templates/app/compiledTemplates.devjs".
What is the proper way of including precompiled handlebar templates?
I combine the compiled templates with my other scripts (jQuery/ember/ember-data/my app code) using grunt. Then in my index.html I simply include the single js script (helps cut down on the number of http requests also).
I'm currently using grunt for this, a simple "build" step might look something like the below. To use this you would need to install nodejs. Next you would npm install the following
grunt
grunt-cli
grunt-ember-template-compiler
grunt-contrib-concat
Once you have these installed you can run the build below from your root if you put the js into a file called "Gruntfile.js" -then simply execute "grunt" and it will output a deps.min.js (w/ your script and templates combined)
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-ember-template-compiler');
grunt.initConfig({
concat: {
dist: {
src: [
'website/static/website/script/vendor/handlebars-v1.2.1.js',
'website/static/website/script/vendor/ember.min.js',
'website/static/website/script/my-app.js’,
'website/static/website/script/dist/tmpl.min.js'],
dest: 'website/static/website/script/dist/deps.min.js'
}
},
emberhandlebars: {
compile: {
options: {
templateName: function(sourceFile) {
var newSource = sourceFile.replace('website/static/website/script/app/templates/', '');
return newSource.replace('.handlebars', '');
}
},
files: ['website/static/website/script/app/templates/**/*.handlebars'],
dest: 'website/static/website/script/dist/tmpl.min.js'
}
}
});
grunt.task.registerTask('default', ['emberhandlebars', 'concat:dist']);
};
This is how I do it in my app:
<script type="text/javascript" charset="utf-8" src="dist/templates.js"></script>
You can see the whole index.html file here:
https://github.com/joachimhs/WarmCroc-Ember/blob/master/index.html
In, fact, I just wrote this code today during a live-coding presentation on Ember.js. The talk is recorded as a screencast, and is available from http://emberjstraining.com
This talks should give you the pointers you need to get everything set up properly :)
Related
I have developed a aws lex chatbot .Now ,I want to integrate in my website on EC2 instance using pre-built UI component libraries as an embeddable iframe that is already available in github.This is the link to it: https://github.com/aws-samples/aws-lex-web-ui#iframe.Below is the code for the iframe from the github:
<html>
<head>
<title>My Parent Page</title>
</head>
<body>
<h1>Welcome to my parent page</h1>
<!-- loader script -->
<script src="./lex-web-ui-loader.js"></script>
<script>
/*
The loader library creates a global object named ChatBotUiLoader
It includes the IframeLoader constructor
An instance of IframeLoader has the load function which kicks off
the load process
*/
// options for the loader constructor
var loaderOptions = {
// you can put the chatbot UI config in a JSON file
configUrl: './chatbot-ui-loader-config.json',
// the full page chatbot UI that will be iframed
iframeSrcPath: './chatbot-index.html#/?lexWebUiEmbed=true'
};
// The following statement instantiates the IframeLoader
var iframeLoader = new ChatBotUiLoader.IframeLoader(loaderOptions);
// chatbot UI config
// The loader can also obtain these values from other sources such
// as a JSON file or events. The configUrl variable in the
// loaderOptions above can be used to put these config values in a file
// instead of explicitly passing it as an argument.
var chatbotUiConfig = {
ui: {
// origin of the parent site where you are including the chatbot UI
// set to window.location.origin since hosting on same site
parentOrigin: window.location.origin,
},
iframe: {
// origin hosting the HTML file that will be embedded in the iframe
// set to window.location.origin since hosting on same site
iframeOrigin: window.location.origin,
},
cognito: {
// Your Cognito Pool Id - this is required to provide AWS credentials
poolId: xxx
},
lex: {
// Lex Bot Name in your account
botName: yyy
}
};
// Call the load function which returns a promise that is resolved
// once the component is loaded or is rejected if there is an error
iframeLoader.load(chatbotUiConfig)
.then(function () {
console.log('iframe loaded');
})
.catch(function (err) {
console.error(err);
});
</script>
</body>
</html>
When I integrated this code and hosted my website,I could just see "Welcome to my parent page".I am not able to see my lex components here.I placed my index.html and lex-web-ui folder in same directory as two seperate files.Should I change my script src location?I am not sure where I am wrong
Sample:
cd /var/www/html
ls
index.html lex-web-ui(github folder)
The problem is that this inline javascript (in your html file) requires the loader.js file to run some of the functions it is calling.
<!-- loader script -->
<script src="./lex-web-ui-loader.js"></script>
This line right here is telling the html file where to find that javascript loader file. The ./ before the file name means that the file should be in the same parent folder as this html file.
So you have a couple choices, both very simple:
Either
(1) change the code to point to the folder actually holding the js loader file.
or
(2) move the html file into the same parent folder as the js loader file.
For the first option, just change the ./ to ./lex-web-ui/
<!-- loader script -->
<script src="./lex-web-ui/lex-web-ui-loader.js"></script>
For the second option, you can move around the files and folders however you'd like, just make sure that the .html file is in the same folder as the loader.js file. This way you don't need to change any code.
[www]
|
|--[html]
|
|--[lex-web-ui]
|
|--lex-web-ui-loader.js
|--index.html
|--(other lex-web-ui files)
Note: Do one OR the other, do not do both.
How to use fontawesome in ionic 2 rc0 as there is no gulp/grunt file so I can add file into build process?
Here's an article i came across while searching on this same topic.
https://chriztalk.com/ionic-2-font-awesome-using-sass/
Here's a gist:
Make a new config directory the root of your ionic 2 project:
$ mkdir config
Find the copy.config.js and sass.config.js files into this folder: /node_modules/#ionic/app-scripts/config/ and copy them into the folder you just created.
Add these lines to the new copy.config.js in config directory you just created.
...
copyFontAwesomeCSS: {
src: '{{ROOT}}/node_modules/font-awesome/css/font-awesome.min.css',
dest: '{{WWW}}/assets/css/'
},
copyFontAwesome: {
src: '{{ROOT}}/node_modules/font-awesome/fonts/**/*',
dest: '{{WWW}}/fonts/'
},
...
Add these lines to the includePaths[] block of the sass.config.js file in the config directory you just created:
...
includePaths: [
...
'node_modules/font-awesome/scss',
...
],
...
Add a config block in your package.json file with the following references:
...
"config": {
"ionic_copy": "./config/copy.config.js",
"ionic_sass": "./config/sass.config.js"
},
....
Import font-awesome in your app.scss file:
...
#import 'font-awesome';
...
Finally, use font awesome like you would in any html file:
<h1><i class="fa fa-flag" aria-hidden="true"></i> Font Awesome</h1>
There is still a lot of confusion on what is a best practice when it comes to adding FontAwesome to an ionic2 app, so I wrote an article about it to mitigate some of that confusion. I hope this helps anybody else looking for a correct answer
http://luiscabrera.site/tech/2017/01/09/fontawesome-in-ionic2.html
Simply add cdn css link of font awesome to your index.html
Or you can use #import of sass to add it to your project
#import 'lib/fa.css'
The problem is that my index.html won't load a css file from a sister folder. I've tried a variety of Browsersync options and none worked.
Into my second day trying to figure this out. I'm working in the Flask framework for Python which works something like Laravel, etc. My task manager is Gulp, front end framework is Foundation 6. I'm new to Flask and Gulp. I used to use Grunt and Livereload with Laravel some years ago and had scss and browser reload working then. Memory fades though.
My file structure is supposed to be typical Flask, just the relevant folders here:
-root
-app
-static
-css
-js
-templates (html files)
-foundation (scss files and framework)
Browsersync seems to be designed so you have to have css under the html files. I've tested this with an index.html in the /root and /app folders and it works. However, I need / want the html in /templates.
In /app/templates/index.html:
<link rel="stylesheet" href="../static/css/app.css">
I'm using both command line for Browsersync and Gulp.js files in the root and in /foundation.
The Browsersync server will serve html from /templates if I set it up with "app/templates" but then it can't find the css. If I move /static/css into /templates the proper index.html file is rendered nicely in the browser. So Browsersync works with the old pre-app framework layout. It just can't deal with paths to sister folders.
gulp.task('serve', ['scss'], function() {
browserSync({
server: "app"
});
gulp.watch(src.css, ['scss']);
gulp.watch(src.html).on('change', reload);
});
I've considered their proxy option but so far can't find a solution with that. I haven't found many setup examples online and none were useful.
For now I'm just doing desktop layout of the app's html pages with Foundation 6 and haven't set up a dev server, just a folder on my MBP.
Any ideas? Please :-)
You can provide multiple base directories from which to serve static files
server: {
baseDir: ["app/templates", "static"]
}
this will server app/templates/index.html by default and then in your html just use
<link rel="stylesheet" href="/css/app.css">
This is my final working gulpfile.js in the site root and setup to work with Flask or most other application frameworks plus Foundation 6. Hope this example saves someone a day or more of figuring this out. I'll add js files later.
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var browserSync = require('browser-sync');
var sass = require('gulp-sass');
var reload = browserSync.reload;
var src = {
scss: 'foundation/scss/*.scss',
css: 'app/static/css/app.css',
allscss: 'foundation/scss/**/*.scss',
cssdest: 'app/static/css',
html: 'app/templates/*.html'
};
var sassPaths = [
'foundation/bower_components/foundation-sites/scss'
//'foundation/bower_components/motion-ui/src'
];
gulp.task('serve', ['sass'], function() {
browserSync({
open: false,
server: {
baseDir: ["app/templates", "app/static"]
}
});
gulp.watch([src.scss, src.allscss], ['sass'])
gulp.watch(src.html).on('change', reload);
gulp.watch(src.css).on('change', reload);
});
gulp.task('sass', function() {
return gulp.src(src.scss)
.pipe($.sass({
includePaths: sassPaths
})
.on('error', $.sass.logError))
.pipe($.autoprefixer({
browsers: ['last 2 versions', 'ie >= 9']
}))
.pipe(gulp.dest(src.cssdest))
});
gulp.task('default', ['serve']);
When using grunt is it possible to alter the references within a html file.
For example as part of my build process I am altering the filename from style.css to style.min.css.
What I would like to do is within my index.html file alter the reference to the stylesheet to use the minified version.
Yes, have a look at grunt-usemin. The README is pretty exhaustive. :)
https://github.com/yeoman/grunt-usemin
Another possible solution, which avoids defining block comments in your html markup, is to install the plugin named: grunt-text-replace
installing the plugin via npm:
$ npm install grunt-text-replace --save-dev
and then and add the following to your Gruntfile:
Gruntfile.js:
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
/* UPDATES CSS SRC REFERENCED IN YOUR THE HTML FILE */
replace: {
cssLink: {
src: ['./src/index.html'], //<--- The path to your html file
overwrite: true,
replacements: [{
// Subsitute src="css/ below with the path to your CSS file.
from: 'src="css/style.css',
// Subsitute src="css/ above with the path to your minified CSS file.
to: 'src="css/style.min.css'
}]
}
}
});
grunt.loadNpmTasks('grunt-text-replace');
grunt.registerTask('default', [
'replace:cssLink'
]);
};
I have a Bootstrap theme from https://wrapbootstrap.com/ that I want to use in my MeteorJS application. The issue is it has script tags like:
<!--[if !lte IE 6]><!-->
<!-- Link to Google CDN's jQuery + jQueryUI; fall back to local -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/libs/jquery.min.js"><\/script>')</script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script>window.jQuery.ui || document.write('<script src="js/libs/jquery.ui.min.js"><\/script>')</script>
script src="http://maps.google.com/maps/api/js?sensor=true" type="text/javascript"></scrip>
<!-- RECOMMENDED: For (IE6 - IE8) CSS3 pseudo-classes and attribute selectors -->
<!--[if lt IE 9]>
<script src="js/include/selectivizr.min.js"></script>
<![endif]-->
<script src="js/libs/jquery.ui.touch-punch.min.js"></script> <!-- REQUIRED: A small hack that enables the use of touch events on mobile -->
which don't work when added to MeteorJS. I know tags don't work, but how would you acoomodate this designed page to MeteorJS?
Later edit:
I added the script src="http://maps.google.com/maps/api/js?sensor=true" type="text/javascript"></script> above. All the above scripts are added in the <body>. The google.maps library is used in lib/main.js and it doesn't work with MeteorJS because it raises ReferenceError. Outside of Meteor it works fine.
Any ideas on how to add that Google Maps script from the Bootstrap Template?
Later edit:
The Bootstrap template has a lib/main.js file which is the last javascript file imported. Nevertheless, when I add it to Meteor, it seems to be run, but its effects are not seen in UI. For example, it executes this line $(".chzn-select").select2(); but only when I execute it from the Console I can see the UI changes. This file is loaded last by Meteor. I also tried with
function load_scripts() {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "lib/main.js";
document.body.appendChild(script);
}
if (Meteor.is_client) {
window.onload = load_scripts;
}
with no success.
These external themes might not be compatible with the default bootstrap included with meteor, so you should remove meteor's bootstrap package:
Remove default bootstrap:
meteor remove bootstrap
Add your theme:
Place your css files in your project's css directory, say /client/css
Place the themes javascript files in /client/lib
Don't worry about the script tags, or linking any of them or anything, meteor should take care of all of that.
Also
Meteor includes JQuery by default so you don't have to worry about including it in your project. To add jquery if for some odd reason you're meteor project might not have it use:
meteor add jquery
External Apis
e.g FB/Google Mapis API/Tracking scripts. Add them in the <head> section of your html file as normal.
Hopefully you find all of this cool!!