diff --git a/htdocs/index.html b/htdocs/index.html index de5dc4b..089ace3 100644 --- a/htdocs/index.html +++ b/htdocs/index.html @@ -18,13 +18,13 @@
//harmonious
+ //harmonious
//harmonious
+ - To ignore within a particular block of code, wrap the code in the following:
+
//harmonious
...your code...
//harmonious_end
diff --git a/htdocs/style.css b/htdocs/style.css
index 69e5010..fea3b5e 100644
--- a/htdocs/style.css
+++ b/htdocs/style.css
@@ -23,7 +23,8 @@ div#loading {
}
table {
- border-left: solid #aaa 1px
+ border-left: solid #aaa 1px;
+ margin-bottom: 10px;
}
td, th {
@@ -34,7 +35,8 @@ td {
padding: 0 3px
}
-td.token {
+td.token,
+td.module {
text-align: center;
font-weight: bold
}
diff --git a/src/CodeVersionInformation.hx b/src/CodeVersionInformation.hx
index b5b02f7..62fa48d 100644
--- a/src/CodeVersionInformation.hx
+++ b/src/CodeVersionInformation.hx
@@ -178,12 +178,7 @@ class CodeVersionInformation {
this.all_modules.push(source);
}
- this.all_modules.sort(function(a, b) {
- if (a == "PHP") { return -1; }
- if (b == "PHP") { return -1; }
- if (a == b) { return 0; }
- return (a < b) ? -1 : 1;
- });
+ this.all_modules.sort(CodeVersionInformation.module_name_sorter);
for (source in start_maximum_versions.keys()) {
this.maximum_versions.set(source, get_lowest_version(start_maximum_versions.get(source)));
@@ -195,6 +190,10 @@ class CodeVersionInformation {
this.final_versions.set("maximum", maximum_versions);
}
+ /**
+ Return true if the minimum and maximum module versions within this
+ CodeVersionInformation object will produce runnable code.
+ **/
public function is_valid() {
for (source in this.maximum_versions.keys()) {
var versions = [ this.maximum_versions.get(source), this.minimum_versions.get(source) ];
@@ -205,4 +204,14 @@ class CodeVersionInformation {
}
return true;
}
+
+ /**
+ Sort module names, making sure PHP is first in the list.
+ **/
+ public static function module_name_sorter(a : String, b : String) : Int {
+ if (a.toLowerCase() == "php") { return -1; }
+ if (b.toLowerCase() == "php") { return 1; }
+ if (a == b) { return 0; }
+ return (a < b) ? -1 : 1;
+ }
}
\ No newline at end of file
diff --git a/src/JavaScriptTarget.hx b/src/JavaScriptTarget.hx
index 14463b8..52d6cf2 100644
--- a/src/JavaScriptTarget.hx
+++ b/src/JavaScriptTarget.hx
@@ -1,8 +1,12 @@
+/**
+ The JavaScript functionality of Harmonious Code.
+**/
class JavaScriptTarget {
static public var code_parser : CodeParser;
static public var current_results : Array;
static public var show_only_modules : Hash;
static public var ignored_modules : Hash;
+ static public var manually_ignored_modules : Hash;
static public function main() {
var function_token = new FunctionToken("a","a");
@@ -12,6 +16,7 @@ class JavaScriptTarget {
show_only_modules = new Hash();
ignored_modules = new Hash();
+ manually_ignored_modules = new Hash();
#if js
var loading_div = js.Lib.document.getElementById("loading");
@@ -22,11 +27,18 @@ class JavaScriptTarget {
#end
}
+ /**
+ Parse a String and get the token results and ignored modules.
+ **/
static public function get_results(s : String) {
current_results = code_parser.parse(s);
ignored_modules = code_parser.ignored_modules;
+ manually_ignored_modules = new Hash();
}
+ /**
+ Enable/disable a particular Result from the version calculations.
+ **/
static public function change_result(index_id : Int, state : Bool) : Bool {
if (index_id < current_results.length) {
current_results[index_id].is_enabled = state;
@@ -35,6 +47,9 @@ class JavaScriptTarget {
return false;
}
+ /**
+ Toggle the visibility of module functions.
+ **/
static public function toggle_module(module : String) {
if (!show_only_modules.exists(module)) {
show_only_modules.set(module, false);
@@ -42,15 +57,21 @@ class JavaScriptTarget {
show_only_modules.set(module, !show_only_modules.get(module));
}
+ /**
+ Set the ignore state on a module.
+ **/
static public function change_module_ignore(module : String, state : Bool) {
- ignored_modules.set(module, state);
+ manually_ignored_modules.set(module, state);
}
- static public function toggle_ignore_module(module: String) {
- if (!ignored_modules.exists(module)) {
- ignored_modules.set(module, false);
+ /**
+ Toggle ignoring a module.
+ **/
+ static public function toggle_ignore_module(module : String) {
+ if (!manually_ignored_modules.exists(module)) {
+ manually_ignored_modules.set(module, false);
}
- ignored_modules.set(module, !ignored_modules.get(module));
+ manually_ignored_modules.set(module, !manually_ignored_modules.get(module));
}
#if js
@@ -75,11 +96,71 @@ class JavaScriptTarget {
output += "";
- for (module in minimum.keys()) {
- output += "- " + module + ": " + minimum.get(module) + "
";
+ var all_modules_hash = new Hash();
+
+ for (module in minimum.keys()) { all_modules_hash.set(module, true); }
+ for (module in ignored_modules.keys()) { all_modules_hash.set(module, true); }
+ for (module in manually_ignored_modules.keys()) { all_modules_hash.set(module, true); }
+
+ var all_modules = new Array();
+
+ for (module in all_modules_hash.keys()) { all_modules.push(module); }
+
+ all_modules.sort(CodeVersionInformation.module_name_sorter);
+
+ var ignored_tokens = new Array();
+ var ignored_modules_array = new Array();
+ for (module in manually_ignored_modules.keys()) {
+ if (manually_ignored_modules.get(module) == true) {
+ ignored_modules_array.push("@" + module);
+ }
}
- output += "
";
+ output += "";
+ output += "Module Ignore? Version ";
+
+ for (module in all_modules) {
+ var is_ignored = false;
+ var is_ignored_in_source = false;
+ var show_checkbox = true;
+ var is_checked = false;
+
+ if (ignored_modules.exists(module) == true) {
+ is_ignored = true;
+ is_ignored_in_source = true;
+ show_checkbox = false;
+ }
+ if (manually_ignored_modules.get(module) == true) {
+ is_ignored = true;
+ is_checked = true;
+ }
+
+ output += "" + module + " ";
+
+ if (show_checkbox && (module.toLowerCase() != "php")) {
+ output += " ";
+ } else {
+ output += " ";
+ }
+
+ if (is_ignored) {
+ if (is_ignored_in_source) {
+ output += "(ignored in source) ";
+ } else {
+ output += "(ignored) ";
+ }
+ } else {
+ if (minimum.exists(module)) {
+ output += "" + minimum.get(module) + " ";
+ } else {
+ output += " ";
+ }
+ }
+
+ output += " ";
+ }
+
+ output += "
";
var maximum = version_info.final_versions.get("maximum");
var printed_message = false;
@@ -109,13 +190,14 @@ class JavaScriptTarget {
classes.push("is-filtering");
}
}
- output += "" + module + " ";
+
+ if (manually_ignored_modules.get(module) != true) {
+ output += "" + module + " ";
+ }
}
output += "";
- var ignored_tokens = new Array();
-
var id_index = 0;
for (result in current_results) {
var ok_to_show = true;
@@ -156,31 +238,45 @@ class JavaScriptTarget {
+ ((!result.is_enabled) ? " checked" : "") + " />";
for (module in version_info.all_modules) {
- output += "";
- if (max_versions.exists(module)) {
- output += max_versions.get(module);
- } else {
- output += " ";
+ if (manually_ignored_modules.get(module) != true) {
+ output += " ";
+ if (max_versions.exists(module)) {
+ output += max_versions.get(module);
+ } else {
+ output += " ";
+ }
+ output += " ";
}
- output += "";
}
output += "";
- id_index++;
}
+ id_index++;
}
output += "";
output += "";
- var permanent_ignore_div = js.Lib.document.getElementById('permanent-ignore');
- if (ignored_tokens.length > 0) {
- var spans = js.Lib.document.getElementsByTagName("span");
- for (span_index in 0...spans.length) {
- if (spans[span_index].className == "ignore-code-holder") {
- spans[span_index].innerHTML = ignored_tokens.join(" ");
- }
+ var permanent_ignore_div = js.Lib.document.getElementById("permanent-ignore");
+
+ if ((ignored_modules_array.length > 0) || (ignored_tokens.length > 0)) {
+ var ignored_modules_string = ignored_modules_array.join(" ");
+ var ignored_tokens_string = ignored_tokens.join(" ");
+
+ var global_span = js.Lib.document.getElementById("ignore-code-holder-global");
+ global_span.innerHTML = ignored_modules_string + " " + ignored_tokens_string;
+
+ var permanent_ignore_block_li = js.Lib.document.getElementById("permanent-ignore-block");
+
+ if (ignored_tokens.length > 0) {
+ var block_span = js.Lib.document.getElementById("ignore-code-holder-block");
+ block_span.innerHTML = ignored_tokens_string;
+
+ permanent_ignore_block_li.style.display = "";
+ } else {
+ permanent_ignore_block_li.style.display = "none";
}
+
permanent_ignore_div.style.display = "";
} else {
permanent_ignore_div.style.display = "none";
diff --git a/src/TestCodeVersionInformation.hx b/src/TestCodeVersionInformation.hx
index 27b1c76..19f1abb 100644
--- a/src/TestCodeVersionInformation.hx
+++ b/src/TestCodeVersionInformation.hx
@@ -1,5 +1,11 @@
+/**
+ Test the CodeVersionInformation object.
+**/
class TestCodeVersionInformation extends haxe.unit.TestCase {
- function testIsInvalid() {
+ /**
+ Test is_invalid()
+ **/
+ function test_is_invalid() {
var valid_results = [
new Result(ResultType.Function, "one", "PHP 4, PHP 5"),
new Result(ResultType.Function, "two", "PHP 4 <= 4.2.0")
@@ -17,7 +23,10 @@ class TestCodeVersionInformation extends haxe.unit.TestCase {
assertFalse(code_version_info.is_valid());
}
- function testBreakdownVersionString() {
+ /**
+ Test breakdown_version_string()
+ **/
+ function test_breakdown_version_string() {
assertEquals("[PHP, 4]", CodeVersionInformation.breakdown_php_version_string("PHP 4").toString());
assertEquals("[PHP, 5.2.0]", CodeVersionInformation.breakdown_php_version_string("PHP 5 >= 5.2.0").toString());
assertEquals("[xmlwriter, 2.0.4]", CodeVersionInformation.breakdown_php_version_string("xmlwriter 2.0.4").toString());
@@ -25,7 +34,10 @@ class TestCodeVersionInformation extends haxe.unit.TestCase {
assertEquals("[xmlwriter, 0.1]", CodeVersionInformation.breakdown_php_version_string("xmlwriter 0.1-2.0.4").toString());
}
- function testVersionCompare() {
+ /**
+ Test version_compare()
+ **/
+ function test_version_compare() {
assertEquals(-1, CodeVersionInformation.version_compare("4", "5"));
assertEquals(1, CodeVersionInformation.version_compare("5", "4"));
assertEquals(-1, CodeVersionInformation.version_compare("4", "4.5"));
@@ -34,26 +46,38 @@ class TestCodeVersionInformation extends haxe.unit.TestCase {
assertEquals(-1, CodeVersionInformation.version_compare("4.5", "4.10"));
}
- function testGetHighestVersion() {
+ /**
+ Test get_highest_version()
+ **/
+ function test_get_highest_version() {
assertEquals("5.2.0", CodeVersionInformation.get_highest_version(["5.2.0"]));
assertEquals("5.2.0", CodeVersionInformation.get_highest_version(["5.1.0", "5.2.0"]));
assertEquals("5", CodeVersionInformation.get_highest_version(["4", "4.1", "5"]));
}
- function testGetLowestVersion() {
+ /**
+ Test get_lowest_version()
+ **/
+ function test_get_lowest_version() {
assertEquals("5.2.0", CodeVersionInformation.get_lowest_version(["5.2.0"]));
assertEquals("5.1.0", CodeVersionInformation.get_lowest_version(["5.1.0", "5.2.0"]));
assertEquals("4", CodeVersionInformation.get_lowest_version(["4", "4.1", "5"]));
assertEquals("4.0.6", CodeVersionInformation.get_lowest_version(["4.0.6", "5"]));
}
+ /**
+ Test get_version_lower_than()
+ **/
function testGetVersionLowerThan() {
assertEquals(null, CodeVersionInformation.get_version_lower_than("PHP 5"));
assertEquals(null, CodeVersionInformation.get_version_lower_than("PHP 5 >= 5.2.0"));
assertEquals("4.0.4", CodeVersionInformation.get_version_lower_than("PHP 4 <= 4.0.4"));
}
- function testCreate() {
+ /**
+ Test instantiating a CodeVersionInformation object
+ **/
+ function test_create() {
var valid_results = [
new Result(ResultType.Function, "one", "PHP 4, PHP 5"),
new Result(ResultType.Function, "two", "PHP 4 >= 4.0.6, PHP 5"),
@@ -68,13 +92,19 @@ class TestCodeVersionInformation extends haxe.unit.TestCase {
assertEquals("4", v.minimum_versions.get("PHP"));
}
- function testGetVersionStringSplit() {
+ /**
+ Test split_version_string()
+ **/
+ function test_get_version_string_split() {
assertEquals("{xmlwriter => 2.0.4, PHP => 4}", CodeVersionInformation.split_version_string("PHP 4, xmlwriter 2.0.4").toString());
assertEquals("{xmlwriter => 2.0.4, PHP => 4.0.3}", CodeVersionInformation.split_version_string("PHP 4 >= 4.0.3, xmlwriter 2.0.4").toString());
assertEquals("{PHP => 4}", CodeVersionInformation.split_version_string("PHP 5, PHP 4").toString());
}
- function testGetModuleInformation() {
+ /**
+ Test getting module information
+ **/
+ function test_get_module_information() {
var valid_results = [
new Result(ResultType.Function, "one", "PHP 4, zmod 5"),
new Result(ResultType.Function, "two", "PHP 4 >= 4.0.6, xmod 5"),
@@ -84,7 +114,10 @@ class TestCodeVersionInformation extends haxe.unit.TestCase {
assertEquals("[PHP, xmod, zmod]", v.all_modules.toString());
}
- function testIgnoreModules() {
+ /**
+ Test ignoring modules
+ **/
+ function test_ignore_modules() {
var valid_results = [
new Result(ResultType.Function, "one", "PHP 4, zmod 5"),
new Result(ResultType.Function, "two", "PHP 4 >= 4.0.6, xmod 5"),
@@ -96,4 +129,15 @@ class TestCodeVersionInformation extends haxe.unit.TestCase {
assertEquals("[PHP, zmod]", v.all_modules.toString());
}
+
+ /**
+ Test module name sorting
+ **/
+ function test_module_name_sorting() {
+ var module_names = [ "zmod", "xmod", "PHP" ];
+
+ module_names.sort(CodeVersionInformation.module_name_sorter);
+
+ assertEquals("[PHP, xmod, zmod]", module_names.toString());
+ }
}
\ No newline at end of file
diff --git a/src/TestJavaScriptTarget.hx b/src/TestJavaScriptTarget.hx
index 9aa083c..dde4b3a 100644
--- a/src/TestJavaScriptTarget.hx
+++ b/src/TestJavaScriptTarget.hx
@@ -15,10 +15,10 @@ class TestJavaScriptTarget extends haxe.unit.TestCase {
JavaScriptTarget.toggle_module("zip");
assertEquals("{zip => true}", JavaScriptTarget.show_only_modules.toString());
- assertEquals("{}", JavaScriptTarget.ignored_modules.toString());
+ assertEquals("{}", JavaScriptTarget.manually_ignored_modules.toString());
JavaScriptTarget.change_module_ignore("zip", true);
- assertEquals("{zip => true}", JavaScriptTarget.ignored_modules.toString());
+ assertEquals("{zip => true}", JavaScriptTarget.manually_ignored_modules.toString());
JavaScriptTarget.change_module_ignore("zip", false);
- assertEquals("{zip => false}", JavaScriptTarget.ignored_modules.toString());
+ assertEquals("{zip => false}", JavaScriptTarget.manually_ignored_modules.toString());
}
}
\ No newline at end of file