<plugin> <groupId>com.github.searls</groupId> <artifactId>jasmine-maven-plugin</artifactId> <version>1.2.0.0</version> <extensions>true</extensions> <executions> <execution> <goals> <goal>test</goal> </goals> </execution> </executions> <configuration> <jsSrcDir>${project.basedir}/src/main/webapp/js</jsSrcDir> <jsTestSrcDir>${project.basedir}/src/test/js</jsTestSrcDir> <browserVersion>FIREFOX_3</browserVersion> <!--use require js in specs--> <specRunnerTemplate>REQUIRE_JS</specRunnerTemplate> <preloadSources> <source>libs/jasmine/jasmine-jquery-1.3.1.js</source> </preloadSources> <!--customize path to require.js--> <scriptLoaderPath>libs/require/require.js</scriptLoaderPath> </configuration> </plugin>
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.1</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin>
<plugin> <artifactId>maven-resources-plugin</artifactId> <executions> <execution> <id>copy-js-files</id> <phase>generate-test-resources</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/jasmine</outputDirectory> <resources> <resource> <directory>src/main/webapp</directory> <filtering>false</filtering> </resource> </resources> </configuration> </execution> </executions> </plugin>
. βββ README.md βββ pom.xml //Maven βββ src // ( Maven) βββ main // ( Maven) β βββ webapp // ( Maven) β βββ css β β βββ bootstrap.css β β βββ style.css β β βββ styles.css β βββ imgs β β βββ 334.gif β βββ index.html // ( ) β βββ js β β βββ app.js // Backbone β β βββ libs // β β β βββ backbone β β β β βββ backbone-min.js β β β βββ handlebars β β β β βββ handlebars.js β β β βββ jasmine β β β β βββ jasmine-jquery-1.3.1.js β β β βββ jquery β β β β βββ jquery-min.js β β β β βββ jquery-serialize.js β β β βββ require β β β β βββ require.js β β β β βββ text.js β β β βββ underscore β β β βββ underscore-min.js β β βββ main.js // JS - RequireJS app.js β β βββ router.js // β β βββ views //Backbone View β β βββ layout β β βββ EmptyContent.js β β βββ EmptyFooter.js β β βββ NavigationHeader.js β β βββ PageLayoutView.js β βββ templates // html β βββ layout β βββ emptyContentTemplate.html β βββ footerTemplate.html β βββ navigationTemplate.html β βββ simpleTemplate.html βββ test // ( Maven) βββ js //Jasmine βββ layout βββ AboutLayout.js
//RequireJS define([ 'jquery', 'underscore', 'backbone', // html handlebars 'text!templates/layout/emptyContentTemplate.html', // Handlebars 'handlebars' ], function($, _, Backbone,emptyContentTemplate){ var EmptyContent = Backbone.View.extend({ }); return EmptyContent;
<div class="item"> <a href="#/description?id={{id}}">{{title}}</a> </div>
define([ 'jquery', 'underscore', 'backbone', 'views/layout/NavigationHeader', 'views/layout/EmptyContent', 'views/layout/EmptyFooter', 'text!templates/layout/simpleTemplate.html' , 'handlebars' ], function($, _, Backbone,NavigationHeader,EmptyContent,EmptyFooter,simpleTemplate){ var PageLayoutView = Backbone.View.extend({ template : Handlebars.compile(simpleTemplate), //defaults to NavigationHeader view function headerContent : NavigationHeader, //defaults to EmptyContent view function mainContent : EmptyContent, //defaults to EmptyFooter view function footerContent : EmptyFooter, initialize : function(options) { //instantiate appropriate views based on component functions if (options.mainContent != undefined && options.mainContent != null) { this.mainContent = options.mainContent; } if (options.headerContent != undefined && options.headerContent != null) { this.headerContent = options.headerContent; } if (options.footerContent != undefined && options.footerContent != null) { this.footerContent = options.footerContent; } }, render: function(){ //compile handlebars template with appropriate markup of components var html = this.template(); //append appropriate content to root element right away after compilation $(this.el).html(html); this.headerView = new this.headerContent({el : '#header'}); this.mainView = new this.mainContent({el : '#mian'}); this.footerView = new this.footerContent({el : '#footer'}); this.headerView.render(); this.mainView.render(); this.footerView.render(); return this; } }); return PageLayoutView; });
Source: https://habr.com/ru/post/165085/
All Articles