diff --git a/Gruntfile.js b/Gruntfile.js index cf4909c3e..fa472be3e 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,4 +1,5 @@ module.exports = function(grunt) { + var path = require('path'); var cfg = require('./package.json'); grunt.initConfig({ jst: { @@ -62,6 +63,10 @@ module.exports = function(grunt) { dest: 'css/converse.min.css', src: ['css/converse.css'] } + }, + touch: { + npm: ['stamp-npm'], + bower: ['stamp-bower'] } }); grunt.loadNpmTasks('grunt-contrib-cssmin'); @@ -69,6 +74,7 @@ module.exports = function(grunt) { grunt.loadNpmTasks('grunt-contrib-jst'); grunt.loadNpmTasks('grunt-json'); grunt.loadNpmTasks('grunt-contrib-requirejs'); + grunt.loadNpmTasks('grunt-touch'); grunt.registerTask('test', 'Run Tests', function () { var done = this.async(); @@ -107,23 +113,26 @@ module.exports = function(grunt) { var child_process = require('child_process'); var exec = child_process.exec; var callback = function (err, stdout, stderr) { + grunt.log.write(stdout); if (err) { grunt.log.write('build failed with error code '+err.code); grunt.log.write(stderr); - } - grunt.log.write(stdout); - done(); + done(false); + } else + done(); }; - exec('./node_modules/requirejs/bin/r.js -o src/build.js && ' + - './node_modules/requirejs/bin/r.js -o src/build.js optimize=none out=builds/converse.js && ' + - './node_modules/requirejs/bin/r.js -o src/build-no-jquery.js &&' + - './node_modules/requirejs/bin/r.js -o src/build-no-jquery.js optimize=none out=builds/converse.nojquery.js && ' + - './node_modules/requirejs/bin/r.js -o src/build-no-locales-no-otr.js && ' + - './node_modules/requirejs/bin/r.js -o src/build-no-locales-no-otr.js optimize=none out=builds/converse-no-locales-no-otr.js && ' + - './node_modules/requirejs/bin/r.js -o src/build-no-otr.js &&' + - './node_modules/requirejs/bin/r.js -o src/build-no-otr.js optimize=none out=builds/converse-no-otr.js && ' + - './node_modules/requirejs/bin/r.js -o src/build-website-no-otr.js &&' + - './node_modules/requirejs/bin/r.js -o src/build-website.js', callback); + var rjsext = (process.platform === 'win32') ? '.cmd' : ''; + var rjs = path.resolve('./node_modules/.bin/r.js' + rjsext); + exec(rjs + ' -o src/build.js && ' + + rjs + ' -o src/build.js optimize=none out=builds/converse.js && ' + + rjs + ' -o src/build-no-jquery.js &&' + + rjs + ' -o src/build-no-jquery.js optimize=none out=builds/converse.nojquery.js && ' + + rjs + ' -o src/build-no-locales-no-otr.js && ' + + rjs + ' -o src/build-no-locales-no-otr.js optimize=none out=builds/converse-no-locales-no-otr.js && ' + + rjs + ' -o src/build-no-otr.js &&' + + rjs + ' -o src/build-no-otr.js optimize=none out=builds/converse-no-otr.js && ' + + rjs + ' -o src/build-website-no-otr.js &&' + + rjs + ' -o src/build-website.js', callback); // XXX: It might be possible to not have separate build config files. For example: // 'r.js -o src/build.js paths.converse-dependencies=src/deps-no-otr paths.locales=locale/nolocales out=builds/converse-no-locales-no-otr.min.js' }); diff --git a/Makefile b/Makefile index 6c081b1f3..3ce775767 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,14 @@ # You can set these variables from the command line. -BOWER ?= ./node_modules/.bin/bower -BUILDDIR = ./docs -PAPER = +BOWER ?= node_modules/.bin/bower +BUILDDIR = ./docs +PAPER = PHANTOMJS ?= ./node_modules/.bin/phantomjs -SPHINXBUILD ?= ./bin/sphinx-build -SPHINXOPTS = -PO2JSON ?= ./node_modules/.bin/po2json -SASS ?= sass +SPHINXBUILD ?= ./bin/sphinx-build +SPHINXOPTS = +PO2JSON ?= ./node_modules/.bin/po2json +SASS ?= sass GRUNT ?= ./node_modules/.bin/grunt +HTTPSERVE ?= ./node_modules/.bin/http-server # Internal variables. ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) ./docs/source @@ -19,18 +20,27 @@ I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) ./docs/source all: dev help: - @echo "Please use \`make ' where is one of" - @echo " dev to set up the development environment" + @echo "Please use \`make ' where is one of the following" @echo " build create minified builds containing converse.js and all its dependencies" - @echo " gettext to make PO message catalogs of the documentation" - @echo " html to make standalone HTML files of the documentation" - @echo " pot to generate a gettext POT file to be used for translations" - @echo " po to generate gettext PO files for each i18n language" - @echo " po2json to generate JSON files from the language PO files" - @echo " release to make a new minified release" - @echo " linkcheck to check all documentation external links for integrity" - @echo " epub to export the documentation to epub" - @echo " changes to make an overview of all changed/added/deprecated items added to the documentation" + @echo " changes make an overview of all changed/added/deprecated items added to the documentation" + @echo " css generate CSS from the Sass files" + @echo " dev set up the development environment" + @echo " epub export the documentation to epub" + @echo " gettext make PO message catalogs of the documentation" + @echo " html make standalone HTML files of the documentation" + @echo " linkcheck check all documentation external links for integrity" + @echo " cssmin minify the CSS files" + @echo " po generate gettext PO files for each i18n language" + @echo " po2json generate JSON files from the language PO files" + @echo " pot generate a gettext POT file to be used for translations" + @echo " release make a new minified release" + @echo " serve serve this directory via a webserver on port 8000" + +######################################################################## +## Miscellaneous + +serve: dev + $(HTTPSERVE) -p 8000 ######################################################################## ## Translation machinery @@ -49,12 +59,6 @@ po2json: ######################################################################## ## Release management -jsmin: - ./node_modules/requirejs/bin/r.js -o src/build.js && ./node_modules/requirejs/bin/r.js -o src/build-no-locales-no-otr.js && ./node_modules/requirejs/bin/r.js -o src/build-no-otr.js && ./node_modules/requirejs/bin/r.js -o src/build-website.js - -cssmin: - $(GRUNT) cssmin - release: sed -i s/Project-Id-Version:\ Converse\.js\ [0-9]\.[0-9]\.[0-9]/Project-Id-Version:\ Converse.js\ $(VERSION)/ locale/converse.pot sed -i s/\"version\":\ \"[0-9]\.[0-9]\.[0-9]\"/\"version\":\ \"$(VERSION)\"/ bower.json @@ -86,14 +90,20 @@ clean:: dev: clean npm install - ${BOWER} update; + $(BOWER) update; bundler install --path=. ######################################################################## ## Builds css:: - ${SASS} sass/converse.scss > css/converse.css + $(SASS) sass/converse.scss > css/converse.css + +jsmin: + ./node_modules/requirejs/bin/r.js -o src/build.js && ./node_modules/requirejs/bin/r.js -o src/build-no-locales-no-otr.js && ./node_modules/requirejs/bin/r.js -o src/build-no-otr.js && ./node_modules/requirejs/bin/r.js -o src/build-website.js + +cssmin: + $(GRUNT) cssmin build:: $(GRUNT) jst diff --git a/Makefile.win b/Makefile.win new file mode 100644 index 000000000..1082d6842 --- /dev/null +++ b/Makefile.win @@ -0,0 +1,63 @@ +# You can set these variables from the command line. +GRUNT ?= node_modules\.bin\grunt.cmd +BOWER ?= node_modules\.bin\bower +PHANTOMJS ?= node_modules\.bin\phantomjs +SASS ?= sass +RMRF ?= rmdir /q /s +RMF ?= del /q +HTTPSERVE ?= ./node_modules/.bin/http-server + +.PHONY: all help clean css minjs build + +all: dev + +help: + @echo "Please use \`make ' where is one of the following" + @echo " dev to set up the development environment" + @echo " build create minified builds containing converse.js and all its dependencies" + @echo " serve to serve this directory via a webserver on port 8000" + +######################################################################## +## Miscellaneous + +serve: + $(HTTPSERVE) -p 8000 + +######################################################################## +## Install dependencies + +stamp-npm: package.json + npm install + $(GRUNT) touch:npm + +stamp-bower: stamp-npm bower.json + $(BOWER) install + $(GRUNT) touch:bower + +clean:: + @if EXIST stamp-npm $(RMF) stamp-npm + @if EXIST stamp-bower $(RMF) stamp-bower + @if EXIST node_modules\. $(RMRF) node_modules + @if EXIST components\. $(RMRF) components + +dev: clean + npm install + $(BOWER) update + bundler install --path=. + +######################################################################## +## Builds + +css:: + $(SASS) sass/converse.scss > css/converse.css + +build:: + $(GRUNT) jst + $(GRUNT) minify + +######################################################################## +## Tests + +check:: stamp-npm + $(PHANTOMJS) node_modules/phantom-jasmine/lib/run_jasmine_test.coffee tests.html + diff --git a/bower.json b/bower.json index 477d417c4..0efce266b 100644 --- a/bower.json +++ b/bower.json @@ -22,7 +22,7 @@ "requirejs-text": "~2.0.12", "requirejs-tpl-jcbrand": "*", "momentjs": "~2.6.0", - "jquery.browser": "https://raw.githubusercontent.com/jcbrand/jquery-browser-plugin/ae5e88aa7a26f583e8865c3961ba857918c4c9c1/dist/jquery.browser.js", + "jquery.browser": ">=0.0.7", "jquery-easing-original": "https://raw.githubusercontent.com/jcbrand/jquery.easing/7de3458b1845a72c1f407debf6b223c8446396bf/jquery.easing.1.3.js", "bootstrap": "~3.2.0", "bootstrapJS": "https://raw.githubusercontent.com/jcbrand/bootstrap/7d96a5f60d26c67b5348b270a775518b96a702c8/dist/js/bootstrap.js", diff --git a/converse.js b/converse.js index 6b1ed2b45..b08faa920 100644 --- a/converse.js +++ b/converse.js @@ -170,8 +170,8 @@ var converse = this; // Logging - Strophe.log = function (level, msg) { console.log(level+' '+msg); }; - Strophe.error = function (msg) { console.log('ERROR: '+msg); }; + Strophe.log = function (level, msg) { converse.log(level+' '+msg, level); }; + Strophe.error = function (msg) { converse.log(msg, 'error'); }; // Add Strophe Namespaces Strophe.addNamespace('CHATSTATES', 'http://jabber.org/protocol/chatstates'); @@ -4257,7 +4257,7 @@ this.XMPPStatus = Backbone.Model.extend({ initialize: function () { this.set({ - 'status' : this.get('status') || 'online' + 'status' : this.getStatus() }); this.on('change', $.proxy(function (item) { if (this.get('fullname') === undefined) { @@ -4277,12 +4277,14 @@ }, this)); }, - sendPresence: function (type) { - if (type === undefined) { + sendPresence: function (type, status_message) { + if (typeof type === 'undefined') { type = this.get('status') || 'online'; } - var status_message = this.get('status_message'), - presence; + if (typeof status_message === 'undefined') { + status_message = this.get('status_message'); + } + var presence; // Most of these presence types are actually not explicitly sent, // but I add all of them here fore reference and future proofing. if ((type === 'unavailable') || @@ -4316,8 +4318,12 @@ this.save({'status': value}); }, + getStatus: function() { + return this.get('status') || 'online'; + }, + setStatusMessage: function (status_message) { - converse.connection.send($pres().c('show').t(this.get('status')).up().c('status').t(status_message)); + this.sendPresence(this.getStatus(), status_message); this.save({'status_message': status_message}); if (this.xhr_custom_status) { $.ajax({ diff --git a/docs/CHANGES.rst b/docs/CHANGES.rst index 5e41423df..cd264d389 100644 --- a/docs/CHANGES.rst +++ b/docs/CHANGES.rst @@ -12,6 +12,9 @@ Changelog * #292 Better support for XEP-0085 Chat State Notifications. [jcbrand] * #295 Document "allow_registration". [gbonvehi] * #304 Added Polish translations. [ser] +* New Makefile.win to build in Windows environments. [gbonvehi] +* Strophe.log and Strophe.error now uses converse.log to output messages. [gbonvehi] +* #305 presence/show text in XMPP request isn't allowed by specification. [gbonvehi] 0.8.6 (2014-12-07) ------------------ diff --git a/docs/source/_templates/layout.html b/docs/source/_templates/layout.html index 6a3b3c971..5da06ba3e 100644 --- a/docs/source/_templates/layout.html +++ b/docs/source/_templates/layout.html @@ -3,7 +3,7 @@ {# Custom CSS overrides #} {% set bootswatch_css_custom = ['_static/style.css', "../../css/converse.min.css"] %} -{% set script_files = script_files + ["../../builds/converse.min.js"] %} +{% set script_files = script_files + ["../../builds/converse.min.js", "../../analytics.js"] %} {# Add some extra stuff before and use existing with 'super()' call. #} {% block footer %} diff --git a/docs/source/builds.rst b/docs/source/builds.rst index aff47468a..3892a35f9 100644 --- a/docs/source/builds.rst +++ b/docs/source/builds.rst @@ -1,6 +1,8 @@ -====================== -Creating custom builds -====================== +.. _builds: + +=============== +Creating builds +=============== .. contents:: Table of Contents :depth: 3 @@ -10,31 +12,53 @@ Creating custom builds .. warning:: There current documentation in this section does not adequately explain how to create custom builds. +.. note:: Please make sure to read the section :doc:`development` and that you have installed + all development dependencies (long story short, you should be able to just run ``make dev``) + +Creating builds +=============== + +We use `require.js `_ to keep track of *Converse.js* and +its dependencies and to to bundle them together in a single file fit for +deployment to a production site. + +To create the bundles, simply run:: + + make build + +This command does the following: + +* It creates different Javascript bundles of Converse.js. + The individual javascript files will be bundled and minified with `require.js`_'s + optimization tool, using `almond `_. + You can `read more about require.js's optimizer here `_. + +* It bundles the HTML templates in ``./src/templates/`` into a single file called ``templates.js``. + This file can then be included via the `` - + diff --git a/package.json b/package.json index 9a496c492..ed22b5907 100755 --- a/package.json +++ b/package.json @@ -40,6 +40,8 @@ "grunt-contrib-jst": "~0.6.0", "grunt-contrib-requirejs": "~0.4.3", "grunt-json": "^0.1.3", + "grunt-touch": "^0.1.0", + "http-server": "^0.7.4", "less": "~1.7.0", "phantom-jasmine": "0.1.8", "phantomjs": "~1.9.7-1", diff --git a/spec/xmppstatus.js b/spec/xmppstatus.js new file mode 100644 index 000000000..560489af9 --- /dev/null +++ b/spec/xmppstatus.js @@ -0,0 +1,29 @@ +(function (root, factory) { + define([ + "jquery", + "mock", + "test_utils" + ], function ($, mock, test_utils) { + return factory($, mock, test_utils); + } + ); +} (this, function ($, mock, test_utils) { + return describe("The XMPPStatus model", $.proxy(function(mock, test_utils) { + beforeEach($.proxy(function () { + window.localStorage.clear(); + window.sessionStorage.clear(); + }, converse)); + it("won't send online when setting a custom status message", $.proxy(function () { + this.xmppstatus.save({'status': 'online'}); + spyOn(this.xmppstatus, 'setStatusMessage').andCallThrough(); + spyOn(converse.connection, 'send'); + this.xmppstatus.setStatusMessage("I'm also happy!"); + runs (function () { + expect(converse.connection.send).toHaveBeenCalled(); + var $stanza = $(converse.connection.send.argsForCall[0][0].tree()); + expect($stanza.children().length).toBe(1); + expect($stanza.children('show').length).toBe(0); + }); + }, converse)); + }, converse, mock, test_utils)); +})); diff --git a/tests/main.js b/tests/main.js index 4a47fcb29..daca682cc 100644 --- a/tests/main.js +++ b/tests/main.js @@ -67,7 +67,8 @@ require([ "spec/chatroom", "spec/minchats", "spec/profiling", - "spec/register" + "spec/register", + "spec/xmppstatus" ], function () { // Make sure this callback is only called once. delete converse.callback;