From 288e5cbd773c261a196ec2be4e80ca8c95d18d1f Mon Sep 17 00:00:00 2001 From: Radu Cotescu Date: Mon, 28 Jul 2014 23:05:08 +0300 Subject: [PATCH] initial commit --- .gitignore | 18 + .jshintrc | 21 + Gruntfile.js | 51 ++ LICENSE | 176 ++++ NOTICE | 4 + README.md | 45 + build.sh | 4 + main.js | 65 ++ package.json | 30 + pom.xml | 75 ++ sly-tests/BeanManagerTest.js | 67 ++ sly-tests/SightlyCodeHintTest.js | 130 +++ sly-tests/SightlyLanguageTest.js | 87 ++ sly-tests/resources/codehint-test.sly | 35 + sly-tests/resources/parse-test.sly | 8 + sly/BeanManager.js | 279 ++++++ sly/CRXDEFilePathProcessor.js | 55 ++ sly/Highlighter.js | 158 ++++ sly/Preview.js | 172 ++++ sly/ProjectUtils.js | 129 +++ sly/RemoteSyncManager.js | 308 +++++++ sly/SessionStorage.js | 31 + sly/SightlyCodeHint.js | 349 ++++++++ sly/SightlyLanguage.js | 252 ++++++ sly/bootstrap/default.json | 51 ++ sly/bootstrap/extensions/cq.json | 49 ++ sly/bootstrap/extensions/sling.json | 20 + sly/command/Commands.js | 38 + sly/menu/Menu.js | 50 ++ sly/nls/ro/strings.js | 55 ++ sly/nls/root/strings.js | 55 ++ sly/nls/strings.js | 16 + sly/node/Constants.js | 41 + sly/node/Filter.js | 96 +++ sly/node/FilterRule.js | 36 + sly/node/PackMgr.js | 233 +++++ sly/node/SlyDomain.js | 174 ++++ sly/node/VaultSyncManager.js | 864 +++++++++++++++++++ sly/preferences/Preferences.js | 166 ++++ sly/preferences/project-settings-dialog.html | 44 + sly/styles/sly.css | 48 ++ sly/toolbar/ToolBar.js | 69 ++ sly/toolbar/brackets_sightly_icons.svg | 40 + sly/toolbar/error.svg | 18 + sly/toolbar/ok.svg | 14 + sly/toolbar/sync.svg | 19 + sly/toolbar/toolbar-aem-indicator.html | 7 + sly/toolbar/toolbar-aem-sync-status.html | 33 + sly/toolbar/warn.svg | 20 + strings.js | 12 + unittests.js | 19 + 51 files changed, 4836 insertions(+) create mode 100644 .gitignore create mode 100644 .jshintrc create mode 100644 Gruntfile.js create mode 100644 LICENSE create mode 100644 NOTICE create mode 100644 README.md create mode 100755 build.sh create mode 100644 main.js create mode 100644 package.json create mode 100644 pom.xml create mode 100644 sly-tests/BeanManagerTest.js create mode 100644 sly-tests/SightlyCodeHintTest.js create mode 100644 sly-tests/SightlyLanguageTest.js create mode 100644 sly-tests/resources/codehint-test.sly create mode 100644 sly-tests/resources/parse-test.sly create mode 100644 sly/BeanManager.js create mode 100644 sly/CRXDEFilePathProcessor.js create mode 100644 sly/Highlighter.js create mode 100644 sly/Preview.js create mode 100644 sly/ProjectUtils.js create mode 100644 sly/RemoteSyncManager.js create mode 100644 sly/SessionStorage.js create mode 100644 sly/SightlyCodeHint.js create mode 100644 sly/SightlyLanguage.js create mode 100644 sly/bootstrap/default.json create mode 100644 sly/bootstrap/extensions/cq.json create mode 100644 sly/bootstrap/extensions/sling.json create mode 100644 sly/command/Commands.js create mode 100644 sly/menu/Menu.js create mode 100644 sly/nls/ro/strings.js create mode 100644 sly/nls/root/strings.js create mode 100644 sly/nls/strings.js create mode 100644 sly/node/Constants.js create mode 100644 sly/node/Filter.js create mode 100644 sly/node/FilterRule.js create mode 100644 sly/node/PackMgr.js create mode 100644 sly/node/SlyDomain.js create mode 100644 sly/node/VaultSyncManager.js create mode 100644 sly/preferences/Preferences.js create mode 100644 sly/preferences/project-settings-dialog.html create mode 100644 sly/styles/sly.css create mode 100644 sly/toolbar/ToolBar.js create mode 100644 sly/toolbar/brackets_sightly_icons.svg create mode 100644 sly/toolbar/error.svg create mode 100644 sly/toolbar/ok.svg create mode 100644 sly/toolbar/sync.svg create mode 100644 sly/toolbar/toolbar-aem-indicator.html create mode 100644 sly/toolbar/toolbar-aem-sync-status.html create mode 100644 sly/toolbar/warn.svg create mode 100644 strings.js create mode 100644 unittests.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2ee8538 --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +atlassian-ide-plugin.xml +node_modules +sling +target +.idea +.classpath +.project +.settings +.checkstyle +*.iml +*.ipr +*.iws +bin +.vlt +.vlt-sync-config.properties +.vlt-sync.log +.DS_Store +*.log diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..e001ae8 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,21 @@ +{ + "nonew" : true, + "curly" : true, + "latedef" : true, + "unused" : "vars", + "noarg" : true, + "indent" : 4, + "trailing": true, + "forin" : true, + "noempty" : true, + "quotmark": "single", + "node" : true, + "eqeqeq" : true, + "strict" : true, + "undef" : true, + "bitwise" : true, + "immed" : true, + "maxlen" : 140, + "freeze" : true, + "multistr": true +} diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..a79eece --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2014 Adobe Systems Incorporated. All rights reserved. + * + * Licensed under the Apache License 2.0. + * http://www.apache.org/licenses/LICENSE-2.0 + ******************************************************************************/ +module.exports = function (grunt) { + 'use strict'; + // Project configuration. + grunt.initConfig({ + pkg: grunt.file.readJSON('package.json'), + maven: { + options: { + goal: 'install' + } + }, + compress: { + main: { + options: { + archive: 'target/aem-sightly-brackets-extension-<%= pkg.version %>.zip' + }, + files: [ + { + src: [ + 'main.js', + 'strings.js', + 'package.json', + 'LICENSE', + 'NOTICE', + 'sly/**', + 'sling/*', + 'node_modules/adm-zip/**', + 'node_modules/fs-extra/**', + 'node_modules/glob/**', + 'node_modules/q/**', + 'node_modules/request/**', + 'node_modules/xmldom/**', + 'node_modules/xpath/**' + ] + } + ] + } + } + }); + + grunt.loadNpmTasks('grunt-maven-tasks'); + grunt.loadNpmTasks('grunt-contrib-compress'); + + // Default task(s). + grunt.registerTask('default', ['maven', 'compress']); +}; diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d9a10c0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,176 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..034d175 --- /dev/null +++ b/NOTICE @@ -0,0 +1,4 @@ +Copyright 2014 Adobe Systems Incorporated. All rights reserved. + +Licensed under the Apache License 2.0. +http://www.apache.org/licenses/LICENSE-2.0 \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..a6e1ed5 --- /dev/null +++ b/README.md @@ -0,0 +1,45 @@ +#Adobe Experience Manager - Sightly Brackets Extension + +[Sightly](Sightly|http://docs.adobe.com/content/docs/en/aem/6-0/develop/sightly.html "Sightly") is the new HTML templating system introduced +with Adobe Experience Manager 6.0. The AEM Sightly Brackets Extension provides a smoother development workflow for writing AEM components, +adding support for syntax-highlighting, code-completion, bi-directional synchronisation and +more. + +## Installation +1. Install [Brackets](http://brackets.io) +2. Open Brackets and go to `File` > `Extension Manager…` +3. Enter 'sightly' in the search bar and look for 'AEM Sightly Brackets Extension'. +4. Click `Install`. +5. Restart Brackets when asked. +6. Open a [content-package](http://docs.adobe.com/docs/en/aem/6-0/administer/content/package-manager.html "How to Work With Packages") + project and start hacking. + +## Features +1. Sightly syntax + * Sightly syntax highlighting + * Auto-completion for Sightly statements - `data-sly-*` + * Basic code completion for Sightly expressions - `${}` +2. Auto-sync to AEM + * `*.html` and `*.js` files are synced automatically to AEM upon saving them + * editing and saving a `.content.xml` file will trigger an automated sync of the file's parent folder +3. Project Preferences + * AEM server settings are available in the `Project Settings` dialog, accessible from the top-level `Sightly` menu (`⌘-Shift-P` on a Mac, + `Ctrl-Shift-P` on a PC) + * the project preferences are saved in the project's root in a `.brackets.json` file (you should commit this to your SCM system) +4. Support for `filter.xml` + * all content projects should have a `filter.xml` file in order to support bi-directional synchronisation; the filter file is relative to + the `jcr_root`folder of the project (`../META-INF/vault/filter.xml`) +5. Main toolbar notification icon in the right bottom corner + * after a sync operation the notification icon's colour changes to indicate the synchronisation status: + * green - all files have been synchronised successfully + * yellow sync - some of the files were not synchronised successfully + * red - none of the selected files were synchronised + * blue - a sync operation is in progress + * when hovering on the notification icon a tooltip will summarise the status of the last sync operation + * clicking on the notification icon will open the `Synchronisation Status` dialog with the status of the last sync operation +6. Synchronisation + * content can be synchronised from the project explorer through a contextual menu (`Export to Server` / `Import from Server`); the + contextual menu is disabled for files not belonging to a `jcr_root` + * in the top-level `Sightly` menu two entries allow synchronising the full content package (`Export Content Package` - `⌘-Shift-E` on a + Mac, `Ctrl-Shift-E` on a PC; `Import Content Package` - `⌘-Shift-I` on a Mac, `Ctrl-Shit-I` on a PC) + diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..bdcd944 --- /dev/null +++ b/build.sh @@ -0,0 +1,4 @@ +#!/bin/sh +mvn clean install > build.log +npm install >> build.log +grunt -v >> build.log diff --git a/main.js b/main.js new file mode 100644 index 0000000..90254eb --- /dev/null +++ b/main.js @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2014 Adobe Systems Incorporated. All rights reserved. + * + * Licensed under the Apache License 2.0. + * http://www.apache.org/licenses/LICENSE-2.0 + ******************************************************************************/ +/*global define, $, brackets, require */ +require.config({ + paths: { + 'text' : 'lib/text', + 'i18n' : 'lib/i18n' + }, + locale: brackets.getLocale() +}); + +define(function (require, exports, module) { + 'use strict'; + + // Load submodules + var Menu = require('sly/menu/Menu'), + SightlyLanguage = require('sly/SightlyLanguage'), + BeanManager = require('sly/BeanManager'), + SlyCodeHints = require('sly/SightlyCodeHint'), + Highlighter = require('sly/Highlighter'), + RemoteSyncMgr = require('sly/RemoteSyncManager'), + ToolBar = require('sly/toolbar/ToolBar'), + Preferences = require('sly/preferences/Preferences'), + SLYDefault = require('text!sly/bootstrap/default.json'), + SLYCQ = require('text!sly/bootstrap/extensions/cq.json'), + SLYSling = require('text!sly/bootstrap/extensions/sling.json'), + defaultJSON = JSON.parse(SLYDefault), + cqJSON = JSON.parse(SLYCQ), + slingJSON = JSON.parse(SLYSling), + SLYDictionary = $.extend(true, defaultJSON, cqJSON, slingJSON), + AppInit = brackets.getModule('utils/AppInit'), + ExtensionUtils = brackets.getModule('utils/ExtensionUtils'); + + AppInit.appReady(function () { + try { + Menu.load(SLYDictionary); + Preferences.load(SLYDictionary); + RemoteSyncMgr.load(SLYDictionary); + SightlyLanguage.load(SLYDictionary); + Highlighter.load(SLYDictionary); + BeanManager.load(SLYDictionary); + SlyCodeHints.load(SLYDictionary); + ToolBar.load(SLYDictionary); + brackets.getModule( + ['file/FilePathProcessor'], + function (fpp) { + var CRXDEFilePathProcessor = require('sly/CRXDEFilePathProcessor').CRXDEFilePathProcessor; + brackets.app.registerFilePathProcessor(new CRXDEFilePathProcessor()); + }, + function (err) { + var failed = err.requireModules && err.requireModules[0]; + console.log('Cannot load module ' + failed); + } + ); + ExtensionUtils.loadStyleSheet(module, 'sly/styles/sly.css').done(); + } catch (e) { + console.error('unable to correctly load sightly extension : ' + e); + } + }); + +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..dc5fd22 --- /dev/null +++ b/package.json @@ -0,0 +1,30 @@ +{ + "name" : "aem-sightly-brackets-extension", + "title" : "AEM Sightly Brackets Extension", + "description" : "Sightly is the new HTML templating system introduced with Adobe Experience Manager 6.0. The AEM Sightly Brackets Extension provides a smoother development workflow for writing AEM components, adding support for syntax-highlighting, code-completion, bi-directional synchronisation and more.", + "version" : "0.0.3", + "engines" : { + "brackets": ">=0.38.0" + }, + "author" : "Adobe Marketing Cloud (https://github.com/raducotescu)", + "homepage" : "https://github.com/adobe-marketing-cloud/aem-sightly-brackets-extension", + "repository" : "https://github.com/adobe-marketing-cloud/aem-sightly-brackets-extension.git", + "license" : "MIT License", + "keywords" : ["aem", "sightly", "templating"], + "categories": ["editing", "language", "external"], + "dependencies" : { + "request" : "~2.34.0", + "adm-zip" : "0.4.4", + "q" : "1.0.1", + "glob" : "3.2.9", + "fs-extra": "0.8.1", + "xmldom" : "0.1.19", + "xpath" : "0.0.7" + }, + "devDependencies": { + "grunt" : "~0.4.2", + "grunt-maven-tasks" : "~1.1.0", + "grunt-npm-install" : "~0.1.0", + "grunt-contrib-compress": "~0.8.0" + } +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..633045c --- /dev/null +++ b/pom.xml @@ -0,0 +1,75 @@ + + + + + 4.0.0 + com.adobe.aem + aem-sightly-brackets-extension + 0.0.3 + + Adobe Experience Manager - Brackets Sightly Extension + Builds the Brackets extension sling subfolder + + + + + org.codehaus.mojo + exec-maven-plugin + 1.2.1 + + + clean-sling + clean + + exec + + + rm + + -rf + ${project.basedir}/sling + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.8 + + + copy-java + package + + copy + + + + + com.adobe.aem + aem-sightly-ide-api + jar + ${project.basedir}/sling + + + + + + + + + + + + com.adobe.aem + aem-sightly-ide-api + 0.1.0-SNAPSHOT + + + diff --git a/sly-tests/BeanManagerTest.js b/sly-tests/BeanManagerTest.js new file mode 100644 index 0000000..073dacb --- /dev/null +++ b/sly-tests/BeanManagerTest.js @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2014 Adobe Systems Incorporated. All rights reserved. + * + * Licensed under the Apache License 2.0. + * http://www.apache.org/licenses/LICENSE-2.0 + ******************************************************************************/ + +/**/ +/* Sightly Language unit tests*/ +/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */ +/*global brackets,define, $, jasmine, spyOn, describe, beforeFirst, afterLast, afterEach, it, runs, waitsFor, expect, waitsForDone */ + +define(function (require, exports, module) { + "use strict"; + var beanManager = require("sly/BeanManager"), + SpecRunnerUtils = brackets.getModule("spec/SpecRunnerUtils"), + DocumentManager = brackets.getModule("document/DocumentManager"), + SLYDefault = require("text!sly/bootstrap/default.json"), + SLYCQ = require("text!sly/bootstrap/extensions/cq.json"), + SLYSling = require("text!sly/bootstrap/extensions/sling.json"), + defaultJSON = JSON.parse(SLYDefault), + cqJSON = JSON.parse(SLYCQ), + slingJSON = JSON.parse(SLYSling), + SLYDictionnary = $.extend(true, defaultJSON, cqJSON, slingJSON); + + + describe("Sightly Bean Manager", function () { + beanManager.load(SLYDictionnary); + + it("initializes a new set of beans at every refreshSlyDoc event", function () { + beanManager.__testonly__refreshBeans(); + expect(beanManager.getBeans()).toBeDefined(); + }); + it("registers a bean at the correct line (registerBean)"); + it("retrieves all bean classes except the private ones (getBeanClasses)"); + it("retrieves all beans available at given line (getAt)"); + it("removes all beans from changed line (and only them) (onChangedLine)", function () { + + beanManager.getBeans().remove = { + name : "remove", + members : "null", + start : {"line": 1, "ch": 12}, + end: {"line": 3, "ch": 21} + }; + beanManager.getBeans().removeAnother = { + name : "removeAnother", + members : "null", + start : {"line": 1, "ch": 43} + }; + beanManager.getBeans().dontremove = { + name : "dontremove", + members : "null", + start : {"line": 2, "ch": 12} + }; + var beanCount = Object.keys(beanManager.getBeans()).length; + beanManager.__testonly__onChangedLine(null, 1); + expect(Object.keys(beanManager.getBeans()).length).toBe(beanCount - 2); + expect(beanManager.getBeans().remove).not.toBeDefined(); + expect(beanManager.getBeans().dontremove).toBeDefined(); + }); + it("re registers list beans whith good scope when name is not changed", function () { + beanManager.__testonly__reRegisterBean("data-sly-list.remove", SLYDictionnary.constants.LIST.CLASS, {"line": 1, "ch": 12}); + expect(beanManager.getBeans().remove).toBeDefined(); + expect(beanManager.getBeans().remove.end).toBeDefined(); + }); + }); +}); \ No newline at end of file diff --git a/sly-tests/SightlyCodeHintTest.js b/sly-tests/SightlyCodeHintTest.js new file mode 100644 index 0000000..5d828c7 --- /dev/null +++ b/sly-tests/SightlyCodeHintTest.js @@ -0,0 +1,130 @@ +/******************************************************************************* + * Copyright (c) 2014 Adobe Systems Incorporated. All rights reserved. + * + * Licensed under the Apache License 2.0. + * http://www.apache.org/licenses/LICENSE-2.0 + ******************************************************************************/ + +/**/ +/* Sightly Code Hint unit tests*/ +/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */ +/*global beanManager, brackets, define, describe, beforeEach, afterEach, it, runs, waits, waitsForDone, expect, $, beforeFirst, afterLast */ + +define(function (require, exports, module) { + "use strict"; + var codehint = require("sly/SightlyCodeHint"), + beanManager = require("sly/BeanManager"), + HTMLUtils = brackets.getModule("language/HTMLUtils"), + SpecRunnerUtils = brackets.getModule("spec/SpecRunnerUtils"), + Editor = brackets.getModule("editor/Editor").Editor, + CodeHintManager = brackets.getModule("editor/CodeHintManager"), + TokenUtils = brackets.getModule("utils/TokenUtils"), + SLYDefault = require("text!sly/bootstrap/default.json"), + SLYCQ = require("text!sly/bootstrap/extensions/cq.json"), + SLYSling = require("text!sly/bootstrap/extensions/sling.json"), + defaultJSON = JSON.parse(SLYDefault), + cqJSON = JSON.parse(SLYCQ), + slingJSON = JSON.parse(SLYSling), + SLYDictionnary = $.extend(true, defaultJSON, cqJSON, slingJSON), + defaultContent = require("text!sly-tests/resources/codehint-test.sly"); + + + describe("Sightly Code Hint", function () { + + codehint.load(SLYDictionnary); + beanManager.load(SLYDictionnary); + var testEditorAndDoc, + hintProvider = new codehint.SLYHints(); + + beforeEach(function () { + testEditorAndDoc = SpecRunnerUtils.createMockEditor(defaultContent, "html"); + $(testEditorAndDoc.doc).on("change", hintProvider.__test_only__onChange); + beanManager.__testonly__refreshBeans(); + }); + + afterEach(function () { + SpecRunnerUtils.destroyMockEditor(testEditorAndDoc.doc); + }); + + // Ask provider for hints at current cursor position; expect it to return some + function expectHints() { + expect(hintProvider.hasHints(testEditorAndDoc.editor, null)).toBe(true); + var hintsObj = hintProvider.getHints(null); + expect(hintsObj).toBeTruthy(); + return hintsObj.hints; // return just the array of hints + } + + // Ask provider for hints at current cursor position + function expectNoHints() { + expect(hintProvider.hasHints(testEditorAndDoc.editor, null)).toBe(false); + } + + //after given choice, expect given completion, with char | as the new cursor position + function expectCompletion(initialText, choice, completion, atTypeTime) { + var ctx, + pos = testEditorAndDoc.editor.getCursorPos(), + completions = completion.split('|'), + expectedPos = { + line: pos.line, + ch: pos.ch + completions[0].length - initialText.length + }; + hintProvider.editor = testEditorAndDoc.editor; + hintProvider.insertHint(choice); + expect(testEditorAndDoc.editor.getCursorPos().ch).toBe(expectedPos.ch); + expect(testEditorAndDoc.editor.getCursorPos().line).toBe(expectedPos.line); + ctx = TokenUtils.getInitialContext(testEditorAndDoc.editor._codeMirror, expectedPos); + expect(ctx.token.string).toBe(completions[0]); + if (completions.length > 1 && completions[1].length > 0) { + expect(TokenUtils.moveNextToken(ctx)).toBe(true); + expect(ctx.token.string).toBe(completions[1]); + } + } + + it("proposes data-sly-* attributes when entering sly", function () { + testEditorAndDoc.editor.setCursorPos({line: 4, ch: 14}); + expectHints(); + }); + it("proposes data-sly-* attributes when entering data-sly", function () { + testEditorAndDoc.editor.setCursorPos({line: 9, ch: 22}); + expectHints(); + }); + it("completes with attribute only when attribute is of type none, " + + "while typing the attribute", function () { + testEditorAndDoc.editor.setCursorPos({line: 9, ch: 22}); + expectCompletion("data-sly-", "data-sly-unwrap", "data-sly-unwrap|"); + }); + it("completes with attribute only when attribute is of type optional, " + + "while typing the attribute", function () { + testEditorAndDoc.editor.setCursorPos({line: 9, ch: 22}); + expectCompletion("data-sly-", "data-sly-list", "data-sly-list|"); + }); + + it("completes with attribute appended with '=${|}' when attribute is " + + "of type expression and mandatory", function () { + testEditorAndDoc.editor.setCursorPos({line: 9, ch: 22}); + expectCompletion("data-sly-", "data-sly-resource", "data-sly-resource=\"${|}\""); + }); + it("completes with '${}' when typing = and attribute is " + + "of type expression or optional", function () { + var pos = {line: 14, ch: 26}; + testEditorAndDoc.editor.setCursorPos(pos); + testEditorAndDoc.doc.replaceRange("=", pos); + var line = testEditorAndDoc.doc.getLine(14); + expect(line.indexOf("data-sly-list=\"{}\"") > 0).toBe(true); + expect(testEditorAndDoc.editor.getCursorPos().line).toBe(14); + expect(testEditorAndDoc.editor.getCursorPos().ch).toBe(29); + }); + it("proposes some beans within an empty expression", function () { + testEditorAndDoc.editor.setCursorPos({line: 20, ch: 14}); + expectHints(); + }); + it("proposes some members within after resources.", function () { + testEditorAndDoc.editor.setCursorPos({line: 25, ch: 23}); + expectHints(); + }); + it("doesn't propose anything when a full expression is entered", function () { + testEditorAndDoc.editor.setCursorPos({line: 30, ch: 27}); + expectNoHints(); + }); + }); +}); \ No newline at end of file diff --git a/sly-tests/SightlyLanguageTest.js b/sly-tests/SightlyLanguageTest.js new file mode 100644 index 0000000..1980196 --- /dev/null +++ b/sly-tests/SightlyLanguageTest.js @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2014 Adobe Systems Incorporated. All rights reserved. + * + * Licensed under the Apache License 2.0. + * http://www.apache.org/licenses/LICENSE-2.0 + ******************************************************************************/ + +/**/ +/* Sightly Language unit tests*/ +/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */ +/*global brackets,define, $, jasmine, spyOn, describe, beforeFirst, afterLast, afterEach, it, runs, waitsFor, expect, waitsForDone */ + +define(function (require, exports, module) { + "use strict"; + var language = require("sly/SightlyLanguage"), + SpecRunnerUtils = brackets.getModule("spec/SpecRunnerUtils"), + FileUtils = brackets.getModule("file/FileUtils"), + DocumentManager = brackets.getModule("document/DocumentManager"), + SLYDefault = require("text!sly/bootstrap/default.json"), + SLYCQ = require("text!sly/bootstrap/extensions/cq.json"), + SLYSling = require("text!sly/bootstrap/extensions/sling.json"), + defaultJSON = JSON.parse(SLYDefault), + cqJSON = JSON.parse(SLYCQ), + slingJSON = JSON.parse(SLYSling), + SLYDictionnary = $.extend(true, defaultJSON, cqJSON, slingJSON); + + + describe("Sightly Language", function () { + language.load(SLYDictionnary); + var resourcesPath = FileUtils.getNativeModuleDirectoryPath(module) + "/resources/"; + + it("registers all specified sightly extension as of html language"); + it("extracts correctly a variable bean name from an attribute declaration, null if not or wrongly defined", function () { + expect(language.extractBeanVarName("data-sly-use.blah")).toBe("blah"); + expect(language.extractBeanVarName("data-sly-use.")).toBeNull(); + expect(language.extractBeanVarName("data-sly-use")).toBeNull(); + }); + it("sends parsedSlyBlock event with open tag info & end position when parsing a tag block containing sly attributes"); + it("sends parsedSlyOperator event with start and end of the operator when parsing an operator"); + it("sends parsedSlyValue event with start and end of the value when parsing an value"); + it("sends parsedSlyExpression event with start and end of the expression when parsing an expression"); + it("sends correct number of event for a given file (parse)", function () { + var promise, doc, + parseTestPath = resourcesPath + "parse-test.sly", + eventSpy = jasmine.createSpyObj("eventSpy", ['expr', 'operator', 'value', 'block']); + $(language).on("parsedSlyExpression", eventSpy.expr); + $(language).on("parsedSlyValue", eventSpy.value); + $(language).on("parsedSlyOperator", eventSpy.operator); + $(language).on("parsedSlyBlock", eventSpy.block); + + runs(function () { + waitsForDone(DocumentManager.getDocumentForPath(parseTestPath).done(function (_doc) { + doc = _doc; + }), "get document"); + }); + + runs(function () { + expect(language.__testonly__parse(doc)).toBe(true); + expect(eventSpy.expr.callCount).toBe(6); + expect(eventSpy.value.callCount).toBe(4); + expect(eventSpy.operator.callCount).toBe(3); + expect(eventSpy.block.callCount).toBe(4); + }); + }); + it("sends parsedSlyAttributeName with start & end of the attribute when parsing a line"); + it("sends correct number of events when a line only is changed (propagateLineChanges)", function () { + var promise, + changedLine = "