Browse Source

Level 3: conditions and operators.

Frederic G. MARAND 6 years ago
parent
commit
73a37e9cbb

+ 5 - 0
.idea/runConfigurations/PHP_Server.xml

@@ -0,0 +1,5 @@
+<component name="ProjectRunConfigurationManager">
+  <configuration default="false" name="PHP Server" type="PhpBuiltInWebServerConfigurationType" factoryName="PHP Built-in Web Server" singleton="true" document_root="$PROJECT_DIR$" port="8000">
+    <method />
+  </configuration>
+</component>

+ 75 - 17
.idea/workspace.xml

@@ -2,8 +2,11 @@
 <project version="4">
   <component name="ChangeListManager">
     <list default="true" id="a9e80a2a-c5a3-4f61-9674-b81f51dbb223" name="Default" comment="">
-      <change beforePath="" afterPath="$PROJECT_DIR$/src/jquery.coffee" />
+      <change beforePath="" afterPath="$PROJECT_DIR$/.idea/runConfigurations/PHP_Server.xml" />
+      <change beforePath="" afterPath="$PROJECT_DIR$/src/conditions.coffee" />
+      <change beforePath="" afterPath="$PROJECT_DIR$/src/operators.coffee" />
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
+      <change beforePath="$PROJECT_DIR$/index.html" afterPath="$PROJECT_DIR$/index.html" />
     </list>
     <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
     <option name="TRACKING_ENABLED" value="true" />
@@ -13,7 +16,18 @@
     <option name="LAST_RESOLUTION" value="IGNORE" />
   </component>
   <component name="FileEditorManager">
-    <leaf />
+    <leaf>
+      <file leaf-file-name="index.html" pinned="false" current-in-tab="true">
+        <entry file="file://$PROJECT_DIR$/index.html">
+          <provider selected="true" editor-type-id="text-editor">
+            <state relative-caret-position="150">
+              <caret line="10" column="0" lean-forward="true" selection-start-line="10" selection-start-column="0" selection-end-line="10" selection-end-column="0" />
+              <folding />
+            </state>
+          </provider>
+        </entry>
+      </file>
+    </leaf>
   </component>
   <component name="FileTemplateManagerImpl">
     <option name="RECENT_TEMPLATES">
@@ -31,8 +45,10 @@
         <option value="$PROJECT_DIR$/package.json" />
         <option value="$PROJECT_DIR$/hello.coffee" />
         <option value="$PROJECT_DIR$/src/hello.coffee" />
-        <option value="$PROJECT_DIR$/index.html" />
         <option value="$PROJECT_DIR$/src/jquery.coffee" />
+        <option value="$PROJECT_DIR$/index.html" />
+        <option value="$PROJECT_DIR$/src/conditions.coffee" />
+        <option value="$PROJECT_DIR$/src/operators.coffee" />
       </list>
     </option>
   </component>
@@ -45,7 +61,7 @@
   <component name="PhpServers">
     <servers />
   </component>
-  <component name="PhpWorkspaceProjectConfiguration" backward_compatibility_performed="true" interpreter_name="PHP 7.0 Brew" />
+  <component name="PhpWorkspaceProjectConfiguration" backward_compatibility_performed="true" interpreter_name="PHP 7.1 Brew" />
   <component name="ProjectFrameBounds">
     <option name="y" value="23" />
     <option name="width" value="1440" />
@@ -105,13 +121,13 @@
               <item name="coffee-codeschool" type="b2602c69:ProjectViewProjectNode" />
               <item name="coffee-codeschool" type="2a2b976b:PhpTreeStructureProvider$1" />
               <item name="lib" type="2a2b976b:PhpTreeStructureProvider$1" />
-              <item name="hello.js" type="620a8d5e:NestingTreeNode" />
+              <item name="conditions.js" type="620a8d5e:NestingTreeNode" />
             </path>
             <path>
               <item name="coffee-codeschool" type="b2602c69:ProjectViewProjectNode" />
               <item name="coffee-codeschool" type="2a2b976b:PhpTreeStructureProvider$1" />
               <item name="lib" type="2a2b976b:PhpTreeStructureProvider$1" />
-              <item name="jquery.js" type="620a8d5e:NestingTreeNode" />
+              <item name="operators.js" type="620a8d5e:NestingTreeNode" />
             </path>
             <path>
               <item name="coffee-codeschool" type="b2602c69:ProjectViewProjectNode" />
@@ -155,6 +171,12 @@
       </list>
     </option>
   </component>
+  <component name="RunManager" selected="Node.js.Coffee watch">
+    <list size="2">
+      <item index="0" class="java.lang.String" itemvalue="Node.js.Coffee watch" />
+      <item index="1" class="java.lang.String" itemvalue="PHP Built-in Web Server.PHP Server" />
+    </list>
+  </component>
   <component name="ShelveChangesManager" show_recycled="false">
     <option name="remove_strategy" value="false" />
   </component>
@@ -168,22 +190,23 @@
       <workItem from="1519329235294" duration="254000" />
       <workItem from="1519329561859" duration="14000" />
       <workItem from="1519329585238" duration="4143000" />
-      <workItem from="1519580966069" duration="4000" />
+      <workItem from="1519580966069" duration="1963000" />
     </task>
     <servers />
   </component>
   <component name="TimeTrackingManager">
-    <option name="totallyTimeSpent" value="4415000" />
+    <option name="totallyTimeSpent" value="6374000" />
   </component>
   <component name="ToolWindowManager">
     <frame x="0" y="23" width="1440" height="877" extended-state="6" />
+    <editor active="true" />
     <layout>
-      <window_info id="Project" active="true" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.1702432" sideWeight="0.5" order="5" side_tool="false" content_ui="combo" />
+      <window_info id="Project" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.1702432" sideWeight="0.5" order="5" side_tool="false" content_ui="combo" />
       <window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="10" side_tool="false" content_ui="tabs" />
       <window_info id="Docker" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="11" side_tool="false" content_ui="tabs" />
       <window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="true" content_ui="tabs" />
       <window_info id="Database" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
-      <window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.19053708" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
+      <window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.19053708" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
       <window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
       <window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.16380544" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
       <window_info id="Mongo Explorer" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
@@ -220,13 +243,6 @@
     </entry>
     <entry file="file://$PROJECT_DIR$/hello.js" />
     <entry file="file://$PROJECT_DIR$/hello.coffee" />
-    <entry file="file://$PROJECT_DIR$/index.html">
-      <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="105">
-          <caret line="7" column="21" lean-forward="false" selection-start-line="7" selection-start-column="21" selection-end-line="7" selection-end-column="21" />
-        </state>
-      </provider>
-    </entry>
     <entry file="file://$PROJECT_DIR$/src/hello.coffee">
       <provider selected="true" editor-type-id="text-editor">
         <state relative-caret-position="195">
@@ -239,6 +255,7 @@
       <provider selected="true" editor-type-id="text-editor">
         <state relative-caret-position="270">
           <caret line="18" column="0" lean-forward="true" selection-start-line="18" selection-start-column="0" selection-end-line="18" selection-end-column="0" />
+          <folding />
         </state>
       </provider>
     </entry>
@@ -246,6 +263,7 @@
       <provider selected="true" editor-type-id="text-editor">
         <state relative-caret-position="300">
           <caret line="20" column="0" lean-forward="true" selection-start-line="20" selection-start-column="0" selection-end-line="20" selection-end-column="0" />
+          <folding />
         </state>
       </provider>
     </entry>
@@ -257,5 +275,45 @@
         </state>
       </provider>
     </entry>
+    <entry file="file://$PROJECT_DIR$/src/conditions.coffee">
+      <provider selected="true" editor-type-id="text-editor">
+        <state relative-caret-position="210">
+          <caret line="14" column="0" lean-forward="false" selection-start-line="14" selection-start-column="0" selection-end-line="14" selection-end-column="0" />
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/lib/conditions.js">
+      <provider selected="true" editor-type-id="text-editor">
+        <state relative-caret-position="390">
+          <caret line="26" column="0" lean-forward="true" selection-start-line="26" selection-start-column="0" selection-end-line="26" selection-end-column="0" />
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/src/operators.coffee">
+      <provider selected="true" editor-type-id="text-editor">
+        <state relative-caret-position="268">
+          <caret line="34" column="22" lean-forward="true" selection-start-line="34" selection-start-column="22" selection-end-line="34" selection-end-column="22" />
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/lib/operators.js">
+      <provider selected="true" editor-type-id="text-editor">
+        <state relative-caret-position="358">
+          <caret line="82" column="45" lean-forward="false" selection-start-line="82" selection-start-column="45" selection-end-line="82" selection-end-column="45" />
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/index.html">
+      <provider selected="true" editor-type-id="text-editor">
+        <state relative-caret-position="150">
+          <caret line="10" column="0" lean-forward="true" selection-start-line="10" selection-start-column="0" selection-end-line="10" selection-end-column="0" />
+          <folding />
+        </state>
+      </provider>
+    </entry>
   </component>
 </project>

+ 1 - 1
index.html

@@ -5,6 +5,6 @@
     <title>CoffeeScript playground</title>
   </head>
   <body>
-    <script src="lib/hello.js"></script>
+    <script src="lib/conditions.js"></script>
   </body>
 </html>

+ 26 - 0
lib/conditions.js

@@ -0,0 +1,26 @@
+var age, ref;
+
+age = prompt("How old are you?", 0);
+
+if (age >= 18) {
+  alert('Adult');
+} else {
+  alert('Under 18');
+}
+
+if (age < 15) {
+  alert('Under 15');
+}
+
+if (age < 16) {
+  alert("Under age");
+} else {
+  alert("Of age");
+}
+
+// Doesn't do what one would expect. At all. Look at the JS.
+console.log((ref = age < 15) != null ? ref : {
+  "Minor": "Elder"
+});
+
+//# sourceMappingURL=conditions.js.map

+ 13 - 0
lib/conditions.js.map

@@ -0,0 +1,13 @@
+{
+  "version": 3,
+  "file": "conditions.js",
+  "sourceRoot": "..",
+  "sources": [
+    "src/conditions.coffee"
+  ],
+  "names": [],
+  "mappings": "AAAA,IAAA,GAAA,EAAA;;AAAA,GAAA,GAAM,MAAA,CAAO,kBAAP,EAA2B,CAA3B;;AAEN,IAAG,GAAA,IAAO,EAAV;EACE,KAAA,CAAM,OAAN,EADF;CAAA,MAAA;EAGE,KAAA,CAAM,UAAN,EAHF;;;AAKA,IAAoB,GAAA,GAAM,EAA1B;EAAA,KAAA,CAAM,UAAN,EAAA;;;AAEA,IAAG,GAAA,GAAM,EAAT;EAAiB,KAAA,CAAM,WAAN,EAAjB;CAAA,MAAA;EAAwC,KAAA,CAAM,QAAN,EAAxC;CATA;;;AAYA,OAAO,CAAC,GAAR,kCAA0B;EAAA,OAAA,EAAU;AAAV,CAA1B",
+  "sourcesContent": [
+    "age = prompt \"How old are you?\", 0\n\nif age >= 18\n  alert 'Adult'\nelse\n  alert 'Under 18'\n\nalert 'Under 15' if age < 15\n\nif age < 16 then alert \"Under age\" else alert \"Of age\"\n\n# Doesn't do what one would expect. At all. Look at the JS.\nconsole.log ((age < 15) ? \"Minor\" : \"Elder\")\n\n"
+  ]
+}

+ 91 - 0
lib/operators.js

@@ -0,0 +1,91 @@
+/*
+
+Operators
+---------
+
+  CoffeScript           JavaScript
+  == is                 ===
+  != isnt               !==
+  not                   !
+  and                   &&
+  or                    ||
+  true yes on           true
+  false no off          false
+
+*/
+var Decaf, addCaffeine, base, base1, base2, coffee, cupsOfCoffee, level, message, paid, pour;
+
+paid = coffee = pour = function() {};
+
+if (paid() && coffee() === true) {
+  pour();
+}
+
+addCaffeine = Decaf = function() {};
+
+if (!Decaf()) {
+  addCaffeine();
+}
+
+if (!Decaf()) {
+  addCaffeine();
+}
+
+// Combined range checks
+level = 4;
+
+if ((2 < level && level < 5)) {
+  alert("In range");
+}
+
+// Functional switch.
+message = (function() {
+  switch (cupsOfCoffee) {
+    case 0:
+      return 'Asleep';
+    case 1:
+      return 'Eyes open';
+    case 2:
+      return 'Buzzed';
+    default:
+      return 'Dangerous';
+  }
+})();
+
+// Existential check: not undefined and not null.
+if (typeof cupsOfCoffee !== "undefined" && cupsOfCoffee !== null) {
+  alert('Exists');
+}
+
+if (typeof cupsOfCoffee !== "undefined" && cupsOfCoffee !== null) {
+  alert('Exists');
+}
+
+// Not strictly identical to the two shorter forms below.
+if (typeof cupsOfCoffee === "undefined" || cupsOfCoffee === null) {
+  cupsOfCoffee = 0;
+}
+
+if (cupsOfCoffee == null) {
+  cupsOfCoffee = 0;
+}
+
+if (cupsOfCoffee == null) {
+  cupsOfCoffee = 0;
+}
+
+if (typeof coffeePot !== "undefined" && coffeePot !== null) {
+  coffeePot.brew();
+}
+
+if (typeof vehicle.start_engine === "function") {
+  if (typeof (base = vehicle.start_engine()).shift_gear === "function") {
+    if (typeof (base1 = base.shift_gear()).crank === "function") {
+      if (typeof (base2 = base1.crank()).press_gas === "function") {
+        base2.press_gas();
+      }
+    }
+  }
+}
+
+//# sourceMappingURL=operators.js.map

File diff suppressed because it is too large
+ 8 - 0
lib/operators.js.map


+ 14 - 0
src/conditions.coffee

@@ -0,0 +1,14 @@
+age = prompt "How old are you?", 0
+
+if age >= 18
+  alert 'Adult'
+else
+  alert 'Under 18'
+
+alert 'Under 15' if age < 15
+
+if age < 16 then alert "Under age" else alert "Of age"
+
+# Doesn't do what one would expect. At all. Look at the JS.
+console.log ((age < 15) ? "Minor" : "Elder")
+

+ 53 - 0
src/operators.coffee

@@ -0,0 +1,53 @@
+###
+
+Operators
+---------
+
+  CoffeScript           JavaScript
+  == is                 ===
+  != isnt               !==
+  not                   !
+  and                   &&
+  or                    ||
+  true yes on           true
+  false no off          false
+
+###
+
+paid = coffee = pour = ->
+
+if paid() and coffee() is on then pour()
+
+addCaffeine = Decaf = ->
+
+addCaffeine() if not Decaf()
+addCaffeine() unless Decaf()
+
+# Combined range checks
+level = 4
+if 2 < level < 5
+  alert "In range"
+
+# Functional switch.
+message = switch cupsOfCoffee
+  when 0 then 'Asleep'
+  when 1 then 'Eyes open'
+  when 2 then 'Buzzed'
+  else 'Dangerous'
+
+# Existential check: not undefined and not null.
+if cupsOfCoffee?
+  alert('Exists')
+alert 'Exists' if cupsOfCoffee?
+
+# Not strictly identical to the two shorter forms below.
+if not cupsOfCoffee?
+  cupsOfCoffee = 0
+
+cupsOfCoffee = 0 unless cupsOfCoffee?
+cupsOfCoffee ?= 0
+
+coffeePot?.brew()
+
+# Like Ruby "try"
+vehicle.start_engine?().shift_gear?().crank?().press_gas?()

Some files were not shown because too many files changed in this diff