Skip to content

Commit

Permalink
https://github.com/angelozerr/angularjs-eclipse/issues/70
Browse files Browse the repository at this point in the history
  • Loading branch information
angelozerr committed Jul 1, 2014
1 parent 1671f19 commit f8983a8
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,24 @@
import org.eclipse.angularjs.core.link.AngularLinkHelper;
import org.eclipse.angularjs.core.link.AngularLinkResource;
import org.eclipse.core.resources.IFile;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;
import org.w3c.dom.Node;

import tern.angular.AngularType;
import tern.angular.protocol.Controller;
import tern.angular.protocol.HTMLTernAngularHelper;
import tern.angular.protocol.TernAngularQuery;
import tern.eclipse.ide.core.scriptpath.ITernScriptPath;

public class AngularScopeHelper {

public static String getAngularValue(IDOMAttr attr, AngularType angularType) {
if (angularType == AngularType.controller) {
return Controller.getName(attr.getValue());
}
return attr.getValue();
}

public static ITernScriptPath populateScope(Node element, IFile file,
AngularType angularType, TernAngularQuery query) throws Exception {
ITernScriptPath scriptPath = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.eclipse.angularjs.core.AngularProject;
import org.eclipse.angularjs.core.utils.DOMUtils;
import org.eclipse.angularjs.core.utils.HyperlinkUtils;
import org.eclipse.angularjs.internal.ui.AngularScopeHelper;
import org.eclipse.angularjs.internal.ui.Trace;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
Expand Down Expand Up @@ -73,16 +74,19 @@ public IHyperlink[] detectHyperlinks(ITextViewer textViewer,
// the attribute is directive, try to open the
// angular
// element controller, module, etc.
hyperlink = new HTMLAngularHyperLink(attr.getOwnerElement(),
hyperlink = new HTMLAngularHyperLink(
attr.getOwnerElement(),
HyperlinkUtils.getValueRegion(attr), file,
ternProject, attr.getValue(),
ternProject, AngularScopeHelper.getAngularValue(attr,
directive.getType()),
directive.getType());

} else {
// Hyperlink on attr name, try to open the custom
// directive
if (directive.isCustom()) {
hyperlink = new HTMLAngularHyperLink(attr.getOwnerElement(),
hyperlink = new HTMLAngularHyperLink(
attr.getOwnerElement(),
HyperlinkUtils.getNameRegion(attr),
file, ternProject, directive.getName(),
AngularType.directive);
Expand All @@ -92,7 +96,7 @@ public IHyperlink[] detectHyperlinks(ITextViewer textViewer,
// Hyperlink on element name, try to open the custom
// directive
if (directive.isCustom()) {
IDOMElement element =(IDOMElement)node;
IDOMElement element = (IDOMElement) node;
hyperlink = new HTMLAngularHyperLink(element,
HyperlinkUtils.getElementRegion(element),
file, ternProject, directive.getName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ private String find(IDOMAttr attr, IFile file, IDETernProject ternProject,
final AngularType angularType) throws Exception {

TernAngularQuery query = new TernAngularTypeQuery(angularType);
query.setExpression(attr.getValue());
query.setExpression(AngularScopeHelper.getAngularValue(attr,
angularType));
ITernScriptPath scriptPath = AngularScopeHelper.populateScope(
attr.getOwnerElement(), file, angularType, query);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ private boolean find(IDOMAttr attr, IFile file, IDETernProject ternProject,
Exception {

TernAngularQuery query = new TernAngularTypeQuery(angularType);
query.setExpression(attr.getValue());
query.setExpression(AngularScopeHelper.getAngularValue(attr,
angularType));

ITernScriptPath scriptPath = AngularScopeHelper.populateScope(
attr.getOwnerElement(), file, angularType, query);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/
package org.eclipse.angularjs.internal.ui.validation;

import org.eclipse.angularjs.internal.ui.AngularScopeHelper;
import org.eclipse.angularjs.internal.ui.AngularUIMessages;
import org.eclipse.angularjs.internal.ui.Trace;
import org.eclipse.jface.text.BadLocationException;
Expand All @@ -24,7 +25,7 @@
public class ValidatorUtils {

public static LocalizedMessage createMessage(IDOMAttr attr, AngularType type) {
String textContent = attr.getValue();
String textContent = AngularScopeHelper.getAngularValue(attr, type);
int start = attr.getValueRegionStartOffset();
return createMessage(attr, start, textContent, type);
}
Expand Down
18 changes: 18 additions & 0 deletions samples/todos-controllerAs/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>todos-controllerAs</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>tern.eclipse.ide.core.ternBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>tern.eclipse.ide.core.ternnature</nature>
<nature>org.eclipse.angularjs.core.angularnature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
traceOnConsole=true
1 change: 1 addition & 0 deletions samples/todos-controllerAs/.tern-project
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"plugins":{"angular":{}},"libs":["browser","ecma5"],"ide":{}}
26 changes: 26 additions & 0 deletions samples/todos-controllerAs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!doctype html>
<html ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.12/angular.min.js"></script>
<script src="todo.js"></script>
<link rel="stylesheet" href="todo.css">
</head>
<body>
<h2>Todo</h2>
<div ng-controller="TodoCtrl">
<span>{{remaining()}} of {{todos.length}} remaining</span>
[ <a href="" ng-click="archive()">archive</a> ]
<ul class="unstyled">
<li ng-repeat="todo in todos">
<input type="checkbox" ng-model="todo.done">
<span class="done-{{todo.done}}">{{todo.text}}</span>
</li>
</ul>
<form ng-submit="addTodo()">
<input type="text" ng-model="todoText" size="30"
placeholder="add new todo here">
<input class="btn-primary" type="submit" value="add">
</form>
</div>
</body>
</html>
4 changes: 4 additions & 0 deletions samples/todos-controllerAs/todo.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.done-true {
text-decoration: line-through;
color: grey;
}
26 changes: 26 additions & 0 deletions samples/todos-controllerAs/todo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function TodoCtrl($scope) {
$scope.todos = [
{text:'learn angular', done:true},
{text:'build an angular app', done:false}];

$scope.addTodo = function() {
$scope.todos.push({text:$scope.todoText, done:false});
$scope.todoText = '';
};

$scope.remaining = function() {
var count = 0;
angular.forEach($scope.todos, function(todo) {
count += todo.done ? 0 : 1;
});
return count;
};

$scope.archive = function() {
var oldTodos = $scope.todos;
$scope.todos = [];
angular.forEach(oldTodos, function(todo) {
if (!todo.done) $scope.todos.push(todo);
});
};
}
2 changes: 2 additions & 0 deletions samples/todos/.settings/tern.eclipse.ide.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
traceOnConsole=true

0 comments on commit f8983a8

Please sign in to comment.