EmberJS – Managing Dependencies ”; Previous Next Ember uses NPM and Bower for managing dependencies which are defined in package.json for NPM and bower.json for Bower. For instance, you may require installing SASS for your style sheets which is not installed by Ember while developing Ember app. To accomplish this, use the Ember Addons for sharing the reusable libraries. If you want to install any CSS framework or JavaScript datepicker dependencies, then use the Bower package manager. Addons The Ember CLI can be used to install the Ember Addons by using the following command − ember install ember-cli-sass The ember install command will save all the dependencies to the respective configuration file. Bower It is a package manager for the web which manages the components of HTML, CSS, JavaScript or image files. It basically maintains and monitors all packages and examines new updates. It uses the configuration file bower.json to keep track of applications placed at the root of the Ember CLI project. You can install the project dependencies by using the following command − bower install <dependencies> –save Assets You can place the third-party JavaScript in the vendor/ folder of your project which are not available as an Addon or Bower package and place the own assets such as robots.txt, favicon, etc. in the public/ folder of your project. The dependencies which are not installed by Ember while developing the Ember app, should be included by using the manifest file ember-cli-build.js. AMD JavaScript modules You can give the asset path as the first argument and the list of modules and exports as the second argument. You can include these assets in the ember-cli-build.js manifest file as − app.import(”bower_components/ic-ajax/dist/named-amd/main.js”, { exports: { ”ic-ajax”: [ ”default”, ”defineFixture”, ”lookupFixture”, ”raw”, ”request” ] } }); Environment Specific Assets The different assets can be used in different environments by defining object as first parameter which is an environment name and the value of an object should be used as asset in that environment. In the ember-cli-build.js manifest file, you can include as − app.import ({ development: ”bower_components/ember/ember.js”, production: ”bower_components/ember/ember.prod.js” }); Other Assets Once all the assets are placed in the public/ folder, they will get copied into the dist/ directory. For instance, if you copy a favicon placed at the public/images/favicon.ico folder, this will get copied into the dist/images/favicon.ico directory. The third-party assets can be added manually in the vendor/ folder or by using the Bower package manager via the import() option. The assets which are not added by using the import() option, will not be present in the final build. For instance, consider the following line of code which imports the assets into the dist/ folder. app.import(”bower_components/font-awesome/fonts/fontawesome-webfont.ttf”); The above line of code creates a font file in dist/font-awesome/fonts/fontawesomewebfont.ttf. You can also place the above file at a different path as shown below − app.import(”bower_components/font-awesome/fonts/fontawesome-webfont.ttf”, { destDir: ”assets” }); It will copy the font file in dist/assets/fontawesome-webfont.ttf. Print Page Previous Next Advertisements ”;
Category: emberjs
EmberJS – Application Concerns ”; Previous Next The Ember application can be extended by using the Ember.Application class which declares and configures the objects that are helpful in building your application. Application creates the Ember.ApplicationInstance class while running which is used for managing its aspects and it acts as owner for instantiated objects. In short, the Ember.Application class defines the application and the Ember.ApplicationInstance class manages its state. The following table lists down more details about models − S.No. Model Ways & Description 1 Dependency Injection It is a process of supplying dependencies of one object to another and used by an Ember application to declare and instantiates the objects and dependencies classes between them. 2 Initializers Initializers are used to configure an application as it boots. 3 Services Service is an Ember object which can be made available in the different parts of the application. 4 The Run Loop It is a region where most of the application”s internal code takes place. Print Page Previous Next Advertisements ”;
EmberJS – Installation
EmberJS – Installation ”; Previous Next It is easy to configure Ember.js in your system. By using the Ember CLI (Command Line Interface) utility, you can create and manage your Ember projects. The Ember CLI deals with different kinds of application asset management such as concatenation, minification and versioning and also provide generators to produce components, routes etc. To install Ember CLI, you need to have the following dependencies − Git − It is a open source version control system for tracking the changes made in the files. For more information, check the official website of git. Ember uses Git to manage its dependencies. Installing Git on Linux: Install the Git on Linux by using this link – http://git-scm.com/download/linux Installing Git on Mac: Install the Git on Mac OS by using this link – https://git-scm.com/download/mac Installing Git on Linux: Install the Git on Windows by using this link – https://git-scm.com/download/win Node.js and npm − Node.js is an open source, used for developing server side and networking applications. It is written in JavaScript. NPM is a node package manager used for installing, sharing and managing the dependencies in the projects. Ember CLI uses Node.js run time and npm to get the dependencies. Bower − It is used for managing the components such as HTML, CSS, JavaScript, image files etc and can be installed by using the npm. Watchman − This optional dependency can be used to watch the files or directories and execute some actions when they change. PhantomJS − This optional dependency can be used for running browser based unit tests to interact with web page. Installing Ember CLI Ember CLI integrates Ember patterns into development process and focuses easily on the developer productivity. It is used for creating Ember apps with Ember.js and Ember data. You can install Ember using npm as in the command given below − npm install -g ember-cli To install the beta version, use the following command − npm install -g [email protected] To check the successful installation of Ember, use the following command − ember -v After executing the above command, it will show something like this − ember-cli: 2.10.1 node: 0.12.7 os: win32 ia32 Print Page Previous Next Advertisements ”;
EmberJS – Creating and Running Application ”; Previous Next You can easily configure the Ember.js in your system. The installation of Ember.js is explained in the EmberJS Installation chapter. Creating Application Let us create one simple app using Ember.js. First create one folder where you create your applications. For instance, if you have created the “emberjs-app” folder, then navigate to this folder as − $ cd ~/emberjs-app Inside the “emberjs=app” folder, create a new project by using the new command − $ ember new demo-app When you create a project, new command provides the following directory structure with files and directories − |– app |– bower_components |– config |– dist |– node_modules |– public |– tests |– tmp |– vendor bower.json ember-cli-build.js package.json README.md testem.js app − It specifies the folders and files of models, routes, components, templates and styles. bower_components / bower.json − It is used for managing the components such as HTML, CSS, JavaScript, image files etc and can be installed by using the npm. The bower_components directory contains all the Bower components and bower.json contains the list of dependencies which are installed by Ember, Ember CLI Shims and QUnit. config − It contains the environment.js directory which is used for configuring the settings of an application. dist − It includes the output files which are deployed when building the app. node_modules / package.json − NPM is a node package manager for Node.js which is used for installing, sharing and managing the dependencies in the projects. The package.json file includes the current npm dependencies of an application and the listed packages get installed in the node_modules directory. public − It includes assets like images, fonts, etc. vendor − It is a directory in which the front-end dependencies such as JavaScript, CSS are not controlled by Bower go. tests / testem.js − The automated tests are stored under the tests folder and the test runner testem of Ember CLI”s is arranged in testem.js. tmp − It contains the temporary files of Ember CLI. ember-cli-build.js − It specifies how to build the app by using the Ember CLI. Running Application To run the application, navigate to the newly created project directory − $ cd demo-app We have created the new project and it is ready to run with the command given below − $ ember server Now open the browser and navigate to http://localhost:4200/. You will get the Ember Welcome page as shown in the image below − Print Page Previous Next Advertisements ”;
EmberJS – Core Concepts
EmberJS – Core Concepts ”; Previous Next Ember.js has the following core concepts − Router Templates Models Components Router and Route Handlers The URL loads the app by entering the URL in the address bar and user will click a link within the app. The Ember uses the router to map the URL to a route handler. The router matches the existing URL to the route which is then used for loading data, displaying the templates and setting up an application state. The Route handler performs the following actions − It provides the template. It defines the model that will be accessible to the template. If there is no permission for the user to visit a particular part of the app, then the router will redirect to a new route. Templates Templates are powerful UI for the end-users. Ember template provides user interface look of an application which uses the syntax of Handlebars templates. It builds the front-end application, which is like the regular HTML. It also supports the regular expression and dynamically updates the expression. Model The route handlers render the model that persists information to the web server. It manipulates the data stored in the database. The model is the simple class that extends the functionality of the Ember Data. Ember Data is a library that is tightly coupled with Ember.js to manipulate with the data stored in the database. Components The component controls the user interface behavior which includes two parts − a template which is written in JavaScript a source file which is written in JavaScript that provides behavior of the components. Print Page Previous Next Advertisements ”;