Skip to content
This repository

Rewrite page flow control #30

Merged
merged 13 commits into from over 1 year ago

2 participants

Paolo "Nusco" Perrotta Anthony Grimes
Paolo "Nusco" Perrotta

Raynes, this time around I tackled the JS code. I heavily refactored the page flow control and added a few minor features/fixes:

  • catering for non-happy-path behavior, like users using the "restart" command on the first screen;
  • changed the initial "tutorial" command to "next", so that the user doesn't have as many commands to remember;
  • added obvious undocumented aliases for commands, so that if the user types a wrong command (say, "previous" instead of "back"), the tutorial still works;
  • removed the "home" button (it was breaking "next"/"back", and the user can simply refresh the page instead);
  • added a final page in case the user types "next" on the last tutorial page;
  • added an undocumented "gopage x" command, useful to debug as we change the tutorial.

I also have a couple of bigger ideas about the project. Is it appropriate to open issues to discuss new ideas, or would you rather use email?

It was a nice night of hacking - I need more of that. :)

nusco added some commits
Paolo "Nusco" Perrotta nusco change text 62c2706
Paolo "Nusco" Perrotta nusco fix typo in <em> html tags
(they're styled out anyway, but that may change)
7327047
Paolo "Nusco" Perrotta nusco fix typo 3815723
Paolo "Nusco" Perrotta nusco merge master and new_text branches 57890f5
Paolo "Nusco" Perrotta nusco refactor page resolution to allow arbitrary page numbers 8bf5ac3
Paolo "Nusco" Perrotta nusco fix problems in screen flow a7e3cc8
Paolo "Nusco" Perrotta nusco add a few command alias
(Like 'previous' for back and 'reset' for 'restart'.)
I tended to forget the commands the first time I was using TryClojure. These aliases should help users as absent-minded as I am.
9ebd2ed
Paolo "Nusco" Perrotta nusco refactorings e1f13fe
Paolo "Nusco" Perrotta nusco add a final page
In case people type 'next' on the last tutorial page
b398f7b
Paolo "Nusco" Perrotta nusco remove 'home' button'
It broke 'next' and 'back'
If someone wants to go back to the beginning, she can either use 'restart' or just refresh the URL.
d2b277c
Paolo "Nusco" Perrotta nusco add undocumented 'gopage x' command (useful for debugging) 473e8e1
Paolo "Nusco" Perrotta nusco merge flow_refactoring branch back into latest master 73e9a0c
Paolo "Nusco" Perrotta nusco fix typo 4608432
Anthony Grimes Raynes merged commit 4608432 into from
Anthony Grimes
Owner

Merged!

I'm fine with either issues or emails. Whichever you feel more comfortable with!

Thank you so much for taking an interest in the project btw. I simply don't have time to do much with it these days, and was hoping a knight in shining armor would come save it from oblivion.

Paolo "Nusco" Perrotta

I don't think I qualify as a knight (I lack the good manners), but thank you anyways!

I don't know whether I'll have the time to keep working on the project - but hey, every incremental improvements counts. I think it's a very good thing to have for the Clojure community.

At the very least, expect a couple issues soon to discuss new ideas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 13 unique commits by 1 author.

Nov 24, 2012
Paolo "Nusco" Perrotta nusco change text 62c2706
Paolo "Nusco" Perrotta nusco fix typo in <em> html tags
(they're styled out anyway, but that may change)
7327047
Paolo "Nusco" Perrotta nusco fix typo 3815723
Nov 25, 2012
Paolo "Nusco" Perrotta nusco merge master and new_text branches 57890f5
Paolo "Nusco" Perrotta nusco refactor page resolution to allow arbitrary page numbers 8bf5ac3
Paolo "Nusco" Perrotta nusco fix problems in screen flow a7e3cc8
Paolo "Nusco" Perrotta nusco add a few command alias
(Like 'previous' for back and 'reset' for 'restart'.)
I tended to forget the commands the first time I was using TryClojure. These aliases should help users as absent-minded as I am.
9ebd2ed
Paolo "Nusco" Perrotta nusco refactorings e1f13fe
Paolo "Nusco" Perrotta nusco add a final page
In case people type 'next' on the last tutorial page
b398f7b
Paolo "Nusco" Perrotta nusco remove 'home' button'
It broke 'next' and 'back'
If someone wants to go back to the beginning, she can either use 'restart' or just refresh the URL.
d2b277c
Paolo "Nusco" Perrotta nusco add undocumented 'gopage x' command (useful for debugging) 473e8e1
Paolo "Nusco" Perrotta nusco merge flow_refactoring branch back into latest master 73e9a0c
Paolo "Nusco" Perrotta nusco fix typo 4608432
This page is out of date. Refresh to see the latest.
107 resources/public/javascript/tryclojure.js
... ... @@ -1,6 +1,19 @@
1   -var pageNum = -1;
2   -var page = null;
  1 +var currentPage = -1;
3 2 var pages = [
  3 + "page1",
  4 + "page2",
  5 + "page3",
  6 + "page4",
  7 + "page5",
  8 + "page6",
  9 + "page7",
  10 + "page8",
  11 + "page9",
  12 + "page10",
  13 + "page11",
  14 + "end"
  15 + ];
  16 +var pageExitConditions = [
4 17 {
5 18 verify: function(data) { return false; }
6 19 },
@@ -33,23 +46,26 @@ var pages = [
33 46 },
34 47 {
35 48 verify: function (data) { return false; }
  49 + },
  50 + {
  51 + verify: function (data) { return false; }
36 52 }
37 53 ];
38 54
39   -function showPage(n) {
40   - var res = pages[n];
41   - if (res) {
42   - pageNum = n;
43   - page = res;
44   -
45   - var block = $("#changer");
46   - block.fadeOut(function(e) {
47   - block.load("/tutorial", { 'n' : n+1 }, function() {
48   - block.fadeIn();
49   - changerUpdated();
50   - });
51   - });
52   - }
  55 +function goToPage(pageNumber) {
  56 + if (pageNumber == currentPage || pageNumber < 0 || pageNumber >= pages.length) {
  57 + return;
  58 + }
  59 +
  60 + currentPage = pageNumber;
  61 +
  62 + var block = $("#changer");
  63 + block.fadeOut(function(e) {
  64 + block.load("/tutorial", { 'page' : pages[pageNumber] }, function() {
  65 + block.fadeIn();
  66 + changerUpdated();
  67 + });
  68 + });
53 69 }
54 70
55 71 function setupLink(url) {
@@ -85,36 +101,28 @@ function html_escape(val) {
85 101 return result;
86 102 }
87 103
88   -function doCommand(input, report) {
89   - switch (input) {
90   - case 'tutorial':
91   - showPage(0);
92   - report();
93   - return true;
94   - case 'back':
95   - if (pageNum > 0) {
96   - showPage(pageNum - 1);
97   - report();
98   - return true;
99   - } else {
100   - return false;
101   - }
102   - case 'next':
103   - if (pageNum >= 0 && pageNum < pages.length - 1) {
104   - showPage(pageNum + 1);
105   - report();
106   - return true;
107   - } else {
108   - return false;
109   - }
  104 +function doCommand(input) {
  105 + if (input.match(/^gopage /)) {
  106 + goToPage(parseInt(input.substring("gopage ".length)));
  107 + return true;
  108 + }
  109 +
  110 + switch (input) {
  111 + case 'next':
  112 + case 'forward':
  113 + goToPage(currentPage + 1);
  114 + return true;
  115 + case 'previous':
  116 + case 'prev':
  117 + case 'back':
  118 + goToPage(currentPage - 1);
  119 + return true;
110 120 case 'restart':
111   - if (pageNum > 0) {
112   - showPage(0);
113   - report();
114   - return true;
115   - } else {
116   - return false;
117   - }
  121 + case 'reset':
  122 + case 'home':
  123 + case 'quit':
  124 + goToPage(0);
  125 + return true;
118 126 default:
119 127 return false;
120 128 }
@@ -128,7 +136,10 @@ function onHandle(line, report) {
128 136 var input = $.trim(line);
129 137
130 138 // handle commands
131   - if (doCommand(input, report)) return;
  139 + if (doCommand(input)) {
  140 + report();
  141 + return;
  142 + }
132 143
133 144 // perform evaluation
134 145 var data = eval_clojure(input);
@@ -139,8 +150,8 @@ function onHandle(line, report) {
139 150 }
140 151
141 152 // handle page
142   - if (page && page.verify(data)) {
143   - showPage(pageNum + 1);
  153 + if (currentPage >= 0 && pageExitConditions[currentPage].verify(data)) {
  154 + goToPage(currentPage + 1);
144 155 }
145 156
146 157 // display expr results
7 resources/public/tutorial/end.html
... ... @@ -0,0 +1,7 @@
  1 +<p>
  2 + Glad to know you're eager for more, but unfortunately this tutorial is over.
  3 +</p>
  4 +
  5 +<p>
  6 + Maybe you can click the 'links' button above for more resources?
  7 +</p>
11 src/tryclojure/views/home.clj
@@ -3,7 +3,7 @@
3 3 [hiccup.element :refer [javascript-tag link-to unordered-list]]
4 4 [hiccup.page :refer [include-css include-js html5]]))
5 5
6   -(defpartial links []
  6 +(defpartial links-html []
7 7 (unordered-list
8 8 [(link-to "http://clojure.org" "The official Clojure website")
9 9 (link-to "http://dev.clojure.org/display/doc/Getting+Started" "Getting started with Clojure")
@@ -22,10 +22,6 @@
22 22 "You won't be able to do everything in it that you could do in your local interpreter. "
23 23 "Also, the interpreter deletes the data that you enter if you define too many things, or after 15 minutes."]
24 24 [:p.bottom
25   - "You can find the site's source and such on its "
26   - (link-to "http://github.com/Raynes/tryclojure" "github")
27   - " page."]
28   - [:p.bottom
29 25 "TryClojure is written in Clojure and JavaScript with "
30 26 (link-to "http://webnoir.org" "Noir") ", "
31 27 (link-to "https://github.com/flatland/clojail" "clojail") ", and Chris Done's "
@@ -39,7 +35,7 @@
39 35 "You can see a Clojure interpreter above - we call it a <em>REPL</em>."
40 36 ]
41 37 [:p.bottom
42   - "Type \"tutorial\" in the REPL to begin."
  38 + "Type <code>next</code> in the REPL to begin."
43 39 ])
44 40
45 41 (defn root-html []
@@ -66,7 +62,6 @@
66 62 [:div#container
67 63 [:div#console.console]
68 64 [:div#buttons
69   - [:a#home.buttons "home"]
70 65 [:a#links.buttons "links"]
71 66 [:a#about.buttons.last "about"]]
72 67 [:div#changer (home-html)]]
@@ -93,4 +88,4 @@
93 88 (about-html))
94 89
95 90 (defpage "/links" []
96   - (links))
  91 + (links-html))
4 src/tryclojure/views/tutorial.clj
... ... @@ -1,5 +1,5 @@
1 1 (ns tryclojure.views.tutorial
2 2 (:require [noir.core :refer [defpage]]))
3 3
4   -(defpage [:post "/tutorial"] {n :n}
5   - (slurp (str "resources/public/tutorial/page" n ".html")))
  4 +(defpage [:post "/tutorial"] {page :page}
  5 + (slurp (str "resources/public/tutorial/" page ".html")))

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.