Reputation: 21359
I made an app using the ionic framework and would like to make it run on meteor.
The App is build on top of the sidemenu template you can create tying ionic start myApp sidemenu
.
Here is the Git of the port or just
> git clone https://github.com/Xample/sidemenu-meteor
> cd sidemenu-meteor/
> meteor
How to do so ?
Upvotes: 1
Views: 763
Reputation: 21359
Create both projects:
ionic start ionicProject sidemenu
meteor create meteorProject
Reorganise the files:
All the important files within a ionicframework comes into a www
folder start to reorganise them to fit with the meteor good practices.
ionicProject/www/css
files into the meteorProject/css
meteorProject/client
foldermeteorProject/public
folderionicProject/www/lib
will be replaced by a meteor package. Do not include it.meteorProject/server
folder will remain emptyNow we need to ensure meteor will load the app.js file before the other one.
meteorProject/client/lib
folderapp.js
file into that oneYou should have the following structure:
├── client
│ ├── controllers.js
│ ├── index.html
│ ├── lib
│ │ └── app.js
│ └── templates
│ ├── browse.html
│ ├── login.html
│ ├── menu.html
│ ├── playlist.html
│ ├── playlists.html
│ └── search.html
├── css
│ └── style.css
├── public
│ └── img
│ └── ionic.png
└── server
Import the meteor packages:
meteor add urigo:ionic
That one will include other dependent packages below:
added mquandalle:bower at version 0.1.11
added urigo:ionic at version 0.0.6
added urigo:angular at version 0.4.8
added urigo:angular-ui-router at version 0.6.1
added tinytest at version 1.0.3
ionicProject/www/lib
folder. Those are now included by default into your meteor project.Edit and port the files
index.html - On meteor the header and the body are parsed and generated back by the framework. In short, meteor packs everything and generate the script and style files for you. Conversely if you wanted to just include a css or a js file through a or tag within the header / body, they will be dismissed by meteor. This is the reason why we are using packages instead of adding our script by ourselves. This to say, that most of the content of the index.html is now useless and needs to be removed. Even the is not allowed by meteor because it will generate it for you as well…. Moreover, no attributes are allowed in the body. This might be problematic for bootstrapping our project with angularJS. The html files looks like this now:
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title>sidemenu-meteor</title>
</head>
<body>
<ion-nav-view></ion-nav-view>
</body>
The templates files:
All the .html
files not being into the server
, public
or private
folder are loaded and packed into one big html by meteor. As meteor will search for and pack all the .html
it will load but not include all the one within a <template>
tag. All the files into the meteorProject/client/templates
must be edited and encapsulated within a <template>
tag bearing the name
attribute such that we can easily find it back later on. For example the template browse.html will be packed such as:
<template name="browse.html">
... browse html file content ...
</template>
Repeat this step for all the templates.
app.js
Meteor.startup(function () { angular.bootstrap(document, ['starter']); });
Note: You need to do it once everything is loaded, for this reason we are doing it within the Meteor.startup function caller.
[[
and ]]
instead of the regular conflicting with meteor's handlebars {{
and }}
angular.module('starter', ['angular-meteor','ionic', 'starter.controllers'])
templateUrl
path url references to something we can use with the loaded by meteor templates. Remember, we are not storing the templates into the meteorProject/public
folder, therefore we cannot load them through templateUrl:'someUrl'
you might do it but I do not recommendtemplateUrl: "templates/menu.html",
becomes template:UiRouter.template('menu.html'),
Repeat this step for all the states in the state provider.
controller.js
$ionicModal.fromTemplateUrl('templates/login.html', {
to
$ionicModal.fromTemplateUrl('login.html', {
This is again to ensure the template is found correctly. Note that for some reason we have been able to load the templateUrl using the template name. It's still a mystery to me, probably a meteor package port have added this sugar…
playlists.html (but possibly other files)
Edit all the files and replace all the {{
occurrences to [[
and }}
to ]]
Basically in this example you will only have to edit playlists.html
Last step
At this stage you should be able to run the ionic sidemenu project under meteor. There is only one thing missing. As you can remember, we changed the delimiters {{}} -> [[]]. Unfortunately, some of the ionic directives are using the regular {{}} delimiters and expect them to be functional. Therefore while adding a <ion-item href="myPath">
this is compiled to something like <a href={{$href()}}>
so… now if you click on a menu, the href will be wrong and you will not be redirected to the right page… To fix this, a workaround is to embed the <ion-item>
within your own <a href="myRef">
tag. I'm still looking for a better solution…. Still to do so, just refactor all your ion-item such that:
<ion-item nav-clear menu-close href="#/app/search">
becomes encapsulated in
<a href="/#/app/search">
<ion-item nav-clear menu-close >
Search
</ion-item>
</a>
Dependencies
Last thing, meteor will try to minify your javascript during the deployment, doing so you might break the angular code if it is not using the array notation. Just refactor all your methods putting your methods into an array. Read the guide for more information. An alternative is to avoid meteor to minify the code deploying using --debug meteor deploy --debug your-project.meteor.com
To get this tutorial:
> git clone https://github.com/Xample/sidemenu-meteor
> cd sidemenu-meteor/
> meteor
Upvotes: 2