Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Various fixes, new yql sample

  • Loading branch information...
commit 619960757ae66de341543119cee43ca7fbee660e 1 parent 169f140
@zefhemel zefhemel authored
View
1  editor/MoBL-Colorer.esv
@@ -32,6 +32,7 @@ colorer
_.Num : darkgreen
environment _.Javascript : darkgreen
+ environment _.JavascriptFor : darkgreen
action = _ 224 224 224
View
2  editor/java/mobl/strategies/InteropRegisterer.java
@@ -9,6 +9,6 @@
public class InteropRegisterer extends JavaInteropRegisterer {
public InteropRegisterer() {
- super(new Strategy[] { deltree_0_0.instance, uglify_0_0.instance, path_to_dataurl_0_0.instance });
+ super(new Strategy[] { deltree_0_0.instance, uglify_0_0.instance, path_to_dataurl_0_0.instance, confirm_dialog_0_0.instance });
}
}
View
43 editor/java/mobl/strategies/confirm_dialog_0_0.java
@@ -0,0 +1,43 @@
+package mobl.strategies;
+
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.swt.widgets.Shell;
+import org.spoofax.interpreter.terms.IStrategoTerm;
+import org.strategoxt.lang.Context;
+import org.strategoxt.lang.Strategy;
+
+public class confirm_dialog_0_0 extends Strategy {
+
+ public static confirm_dialog_0_0 instance = new confirm_dialog_0_0();
+
+ @Override
+ public IStrategoTerm invoke(Context context, IStrategoTerm current) {
+ String message = uglify_0_0.getStringFromTerm(current);
+
+ final MessageDialog messageDialog = new org.eclipse.jface.dialogs.MessageDialog(null, null, null, message, MessageDialog.CONFIRM,new String[] {"Yes", "No"}, 0);
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ messageDialog.open();
+ }
+ });
+
+ if(messageDialog.getReturnCode() == MessageDialog.OK) {
+ return current;
+ } else {
+ return null;
+ }
+/*
+
+ final InputDialog d = new InputDialog(null, title, message, value, null);
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ d.open();
+ }
+ });
+
+ return context.getFactory().makeString(d.getValue());*/
+ }
+}
View
1  release.nix
@@ -126,6 +126,7 @@ let
#irc_server = moblc { name = "irc"; app = "server.mobl"; stdlib = "${mobl}/stdlib-server-override"; } ;
shopping = moblc { name = "shopping"; app = "shopping.mobl"; } ;
tipcalculator = moblc { name = "tipcalculator"; app = "tipcalculator.mobl"; } ;
+ yql = moblc { name = "yql"; app = "demo.mobl"; } ;
todo = moblc { name = "todo"; app = "todo.mobl"; } ;
i18n = moblc { name = "i18n"; app = "demo.mobl"; } ;
#znake_client = moblc { name = "znake"; app = "znake.mobl"; } ;
View
132 samples/yql/demo.mobl
@@ -0,0 +1,132 @@
+application demo
+
+import mobl::ui::generic
+import mobl::yql
+import mobl::reflect
+
+style blogArticleStyle {
+ background: white;
+ margin: 0;
+ padding: 10px;
+}
+
+screen root() {
+ header("YQL Demos")
+ group {
+ item(onclick={ showFeed("http://mobl-lang.org/feed"); }) { "Feed reader" }
+ item(onclick={ pictureSearch(); }) { "Picture search" }
+ item(onclick={ queryInspector(); }) { "Query inspector" }
+ }
+ link("http://developer.yahoo.com/yql/") { "Learn about YQL" }
+}
+
+screen showFeed(url : String) {
+ var result = async(YQL.query("select * from feednormalizer where url='" + url + "' and output='atom_1.0'"))
+ var title = "Hang on..."
+ header(title) {
+ backButton()
+ }
+ whenLoaded(result) {
+ script {
+ title = result.feed.title;
+ }
+ group {
+ list(entry in result.feed.entry) {
+ item(onclick={ showEntry(entry); }) { label(entry.title) }
+ }
+ }
+ }
+}
+
+screen showEntry(e : JSON) {
+ header(e.title) {
+ backButton()
+ }
+ block(blogArticleStyle) {
+ html(e.content.content)
+ }
+}
+
+screen pictureSearch() {
+ var phrase = "elephant"
+ var result = async(YQL.query("select thumbnail_url from search.images where query=\"" + phrase + "\" and mimetype like \"%jpeg%\"").result)
+ header("Picture search") {
+ backButton()
+ }
+ searchBox(phrase, onsearch={
+ result = YQL.query("select thumbnail_url from search.images where query=\"" + phrase + "\" and mimetype like \"%jpeg%\"").result;
+ })
+ whenLoaded(result) {
+ group {
+ list(entry in result) {
+ image(entry.thumbnail_url)
+ }
+ }
+ }
+}
+
+
+screen queryInspector() {
+ var query = "select * from feednormalizer where url='http://rss.news.yahoo.com/rss/topstories' and output='atom_1.0'"
+ header("Query") {
+ backButton()
+ }
+ group {
+ item { textField(query, label="YQL Query:") }
+ }
+ button("Execute", onclick={
+ var result = YQL.query(query);
+ inspectJSON("result", result);
+ })
+ <h2>"Sample queries"</h2>
+ group {
+ item {
+ "All countries in Europe"
+ sideButton("Set", onclick={
+ query = "select * from geo.countries where place=\"Europe\"";
+ })
+ }
+ item {
+ "Web search: 'mobl'"
+ sideButton("Set", onclick={
+ query = "select title,abstract,url from search.web where query=\"mobl\"";
+ })
+ }
+ item {
+ "Pictures of elephants"
+ sideButton("Set", onclick={
+ query = "select * from search.images where query=\"elephant\" and mimetype like \"%jpeg%\"";
+ })
+
+ }
+ }
+}
+
+screen inspectJSON(path: String, obj : JSON) {
+ header("Inspector") {
+ backButton()
+ }
+ "Path: " <code>label(path)</code>
+ when(Reflector.isArray(obj)) {
+ list(i in range(0, obj.length)) {
+ item(onclick={ inspectJSON(path+"["+i+"]", Reflector.get(obj, ""+i));}) {
+ label(i)
+ }
+ }
+ } else {
+ when(Reflector.isBool(obj) || Reflector.isNum(obj) || Reflector.isString(obj)) {
+ group {
+ item { label(obj) }
+ }
+ } else {
+ group {
+ list(prop in Reflector.getProperties(obj)) {
+ item(onclick={ inspectJSON(path+"."+prop, Reflector.get(obj, prop));}) {
+ label(prop)
+ }
+ }
+ }
+ }
+ }
+ <textarea databind=JSON.stringify(obj) style="width: 100%;" rows="7"/>
+}
2  stdlib
@@ -1 +1 @@
-Subproject commit 3608ac0d4d3b72510eaed587d8ffe9d97f9e5506
+Subproject commit a3b1d04813c8618ed80652133552bdc60366df1b
View
18 trans/editor/editor.str
@@ -74,6 +74,7 @@ rules
rules
external deltree(|)
+ external confirm-dialog(|)
generate-artifacts:
(selected, position, ast, path, project-path) -> None() //(filename-html, result-html)
@@ -134,13 +135,16 @@ rules
with
rules ( ProjectPath := project-path )
; setup-paths
- ; if <file-exists> <OutputPath> then
- <deltree> <OutputPath>
- end
- ; if <file-exists> <ReleaseOutputPath> then
- <deltree> <ReleaseOutputPath>
- end
- ; <refresh-workspace-file> <ProjectPath>
+ ; try(
+ //<confirm-dialog> "Are you sure you want to clean the project, this will remove the output directories."
+ if <file-exists> <OutputPath> then
+ <deltree> <OutputPath>
+ end
+ ; if <file-exists> <ReleaseOutputPath> then
+ <deltree> <ReleaseOutputPath>
+ end
+ ; <refresh-workspace-file> <ProjectPath>
+ )
editor-rebuild-project :
(selected, position, ast, path, project-path) -> None()
View
17 trans/generation/ui.str
@@ -213,8 +213,15 @@ rules
[] -> ""
tag-arg-to-js(|tg, node) :
+ HtmlArg(name, True()) -> $[[node].attr('[name]', true);
+]
+ tag-arg-to-js(|tg, node) :
+ HtmlArg(name, False()) -> $[[node].attr('[name]', false);
+]
+
+ tag-arg-to-js(|tg, node) :
HtmlArg(name, String(s)) -> $[[node].attr('[name]', [s]);
- ]
+]
tag-arg-to-js(|tg, node) :
HtmlArg(name, e) -> $[
@@ -222,17 +229,13 @@ rules
if([r].get() !== null) {
[node].attr('[name]', [r].get());
subs__.addSub([r].addEventListener('change', function(_, ref, val) {
- if(ref === [r]) {
- [node].attr('[name]', val);
- } else {
- console.log("Garbage!");
- }
+ [node].attr('[name]', val);
}));
[subscriptions]
}
subs__.addSub([r].rebind());
]
- where not(String(_) := e)
+ where not(String(_) := e <+ True() := e <+ False() := e)
; not(SimpleType(QId("mobl", "Callback")) := <type-of> e <+ GenericType(QId("mobl", "Function0"), _) := <type-of> e)
with es := <ref-expression-to-js> e
; r := <newname> "ref"
Please sign in to comment.
Something went wrong with that request. Please try again.