Skip to content

Commit

Permalink
Some efforts to minimize output code size with an html minimization l…
Browse files Browse the repository at this point in the history
…ibrary.
  • Loading branch information
BSVino committed Aug 16, 2014
1 parent 82e49e1 commit 54a6da8
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 146 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "html/copy/jquery-cookie"]
path = html/copy/jquery-cookie
url = https://github.com/carhartl/jquery-cookie.git
[submodule "htmlmin"]
path = htmlmin
url = https://github.com/mankyd/htmlmin.git
6 changes: 5 additions & 1 deletion compile.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import os
import shutil
import time
import sys

import opengl
import shared

sys.path.append("htmlmin")
import htmlmin

def create_directory(dir):
if not os.path.exists(dir):
os.makedirs(dir)
Expand Down Expand Up @@ -196,7 +200,7 @@ def spew_category(name, commands):
output_html = header_for_command + command_html + footer_for_command

output = open(output_dir + version_dir + "/" + command, "w")
output.write(output_html.encode('ascii', 'xmlcharrefreplace'))
output.write(htmlmin.minify(output_html, remove_comments=True, reduce_boolean_attributes=True, remove_all_empty_space=True).encode('ascii', 'xmlcharrefreplace'))
output.close()

written += 1
Expand Down
146 changes: 146 additions & 0 deletions html/copy/docs.gl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
function gl_printable_name(name) {
if (name == "es20")
return "OpenGL ES 2.0";
if (name == "es30")
return "OpenGL ES 3.0";
if (name == "es31")
return "OpenGL ES 3.1";
if (name == "gl21")
return "OpenGL 2.1";
if (name == "gl30")
return "OpenGL 3.0";
if (name == "gl31")
return "OpenGL 3.1";
if (name == "gl32")
return "OpenGL 3.2";
if (name == "gl33")
return "OpenGL 3.3";
if (name == "gl40")
return "OpenGL 4.0";
if (name == "gl41")
return "OpenGL 4.1";
if (name == "gl42")
return "OpenGL 4.2";
if (name == "gl43")
return "OpenGL 4.3";
if (name == "gl44")
return "OpenGL 4.4";
if (name == "gl45")
return "OpenGL 4.5";
return "OpenGL X";
}

window.last_gl_version = window.current_api.substring(0, 2);
window.api_version = "";

function set_api_version(version) {
window.api_version = version;

$( "#opengl_name" ).text(gl_printable_name(version));

$(".category").addClass("disabled");
$(".command").addClass("disabled");
$("." + version).removeClass("disabled");

version_directory = version.substring(0, 3);
$(".rewritelink").each(function() {
if ($(this).hasClass(version))
$(this).attr("href", "../" + version_directory + "/" + $(this).text());
else
{
highest = 0;
var classList = $(this).attr('class').split(/\s+/);
for (var i = 0; i < classList.length; i++) {
class_api = classList[i].substring(0, 2);
if (class_api != version.substring(0, 2))
continue;

if (class_api != 'gl' && class_api != 'es')
continue;

// Only consider versions <= the one the user has selected.
if (classList[i].substring(2, 3) <= version.substring(2, 3))
{
if (!highest)
highest = classList[i].substring(2, 3);

if (classList[i].substring(2, 3) > highest)
highest = classList[i].substring(2, 3);
}
}

if (!highest)
{
// No available versions <= the user's choice, so go with the highest one.
for (var i = 0; i < classList.length; i++) {
class_api = classList[i].substring(0, 2);
if (class_api != version.substring(0, 2))
continue;

if (class_api != 'gl' && class_api != 'es')
continue;

if (!highest)
highest = classList[i].substring(2, 3);

if (classList[i].substring(2, 3) > highest)
highest = classList[i].substring(2, 3);
}
}

$(this).attr("href", "../" + version.substring(0, 2) + highest + "/" + $(this).text());
}
});

if (window.last_gl_version != version.substring(0, 2))
{
// Remove functions from GL that ES doesn't have and vice versa.
hide_commands = function() {
$(this).addClass("hidden");

var classList = $(this).attr('class').split(/\s+/);
for (var i = 0; i < classList.length; i++) {
if (classList[i].substring(0, 2) === version.substring(0, 2)) {
$(this).removeClass("hidden");
break;
}
}
};

$(".command").each(hide_commands);
$(".category").each(hide_commands);

$("span.bonsai_inner").trigger('click');
$("span.bonsai_inner").trigger('click');

window.last_gl_version = version.substring(0, 2);
}
}

$(function() {
$( "#command_categories" ).bonsai()

$( "#versions_dropdown" ).selectmenu({
change: function( event, ui ) {
set_api_version(ui.item.value);
}
});

set_api_version(window.current_api);

$("#style_light").click(function() {
$("#pagestyle").attr("href", "../style_light.css");
$.cookie("pagestyle", "light");
});

$("#style_dark").click(function() {
$("#pagestyle").attr("href", "../style_dark.css");
$.cookie("pagestyle", "dark");
});

if ($.cookie("pagestyle") == 'light')
$("#style_light").click();

if ($.cookie("pagestyle") == 'dark')
$("#style_dark").click();
});
148 changes: 3 additions & 145 deletions html/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,152 +18,10 @@
<link id="pagestyle" href="../style_light.css" rel="stylesheet" type="text/css" />

<script>
function gl_printable_name(name) {
if (name == "es20")
return "OpenGL ES 2.0";
if (name == "es30")
return "OpenGL ES 3.0";
if (name == "es31")
return "OpenGL ES 3.1";
if (name == "gl21")
return "OpenGL 2.1";
if (name == "gl30")
return "OpenGL 3.0";
if (name == "gl31")
return "OpenGL 3.1";
if (name == "gl32")
return "OpenGL 3.2";
if (name == "gl33")
return "OpenGL 3.3";
if (name == "gl40")
return "OpenGL 4.0";
if (name == "gl41")
return "OpenGL 4.1";
if (name == "gl42")
return "OpenGL 4.2";
if (name == "gl43")
return "OpenGL 4.3";
if (name == "gl44")
return "OpenGL 4.4";
if (name == "gl45")
return "OpenGL 4.5";
return "OpenGL X";
}

window.last_gl_version = ("{$current_api}").substring(0, 2);
window.api_version = "";

function set_api_version(version) {
window.api_version = version;

$( "#opengl_name" ).text(gl_printable_name(version));

$(".category").addClass("disabled");
$(".command").addClass("disabled");
$("." + version).removeClass("disabled");

version_directory = version.substring(0, 3);
$(".rewritelink").each(function() {
if ($(this).hasClass(version))
$(this).attr("href", "../" + version_directory + "/" + $(this).text());
else
{
highest = 0;
var classList = $(this).attr('class').split(/\s+/);
for (var i = 0; i < classList.length; i++) {
class_api = classList[i].substring(0, 2);
if (class_api != version.substring(0, 2))
continue;

if (class_api != 'gl' && class_api != 'es')
continue;

// Only consider versions <= the one the user has selected.
if (classList[i].substring(2, 3) <= version.substring(2, 3))
{
if (!highest)
highest = classList[i].substring(2, 3);

if (classList[i].substring(2, 3) > highest)
highest = classList[i].substring(2, 3);
}
}

if (!highest)
{
// No available versions <= the user's choice, so go with the highest one.
for (var i = 0; i < classList.length; i++) {
class_api = classList[i].substring(0, 2);
if (class_api != version.substring(0, 2))
continue;

if (class_api != 'gl' && class_api != 'es')
continue;

if (!highest)
highest = classList[i].substring(2, 3);

if (classList[i].substring(2, 3) > highest)
highest = classList[i].substring(2, 3);
}
}

$(this).attr("href", "../" + version.substring(0, 2) + highest + "/" + $(this).text());
}
});

if (window.last_gl_version != version.substring(0, 2))
{
// Remove functions from GL that ES doesn't have and vice versa.
hide_commands = function() {
$(this).addClass("hidden");

var classList = $(this).attr('class').split(/\s+/);
for (var i = 0; i < classList.length; i++) {
if (classList[i].substring(0, 2) === version.substring(0, 2)) {
$(this).removeClass("hidden");
break;
}
}
};

$(".command").each(hide_commands);
$(".category").each(hide_commands);

$("span.bonsai_inner").trigger('click');
$("span.bonsai_inner").trigger('click');

window.last_gl_version = version.substring(0, 2);
}
}

$(function() {
$( "#command_categories" ).bonsai()

$( "#versions_dropdown" ).selectmenu({
change: function( event, ui ) {
set_api_version(ui.item.value);
}
});

set_api_version("{$current_api}");

$("#style_light").click(function() {
$("#pagestyle").attr("href", "../style_light.css");
$.cookie("pagestyle", "light");
});

$("#style_dark").click(function() {
$("#pagestyle").attr("href", "../style_dark.css");
$.cookie("pagestyle", "dark");
});

if ($.cookie("pagestyle") == 'light')
$("#style_light").click();
window.current_api = "{$current_api}"
</script>
<script src="../docs.gl.js"></script>

if ($.cookie("pagestyle") == 'dark')
$("#style_dark").click();
});
</script>

</head>
Expand Down
1 change: 1 addition & 0 deletions htmlmin
Submodule htmlmin added at 9b8f44

0 comments on commit 54a6da8

Please sign in to comment.