Skip to content

Small bug, updated #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 45 additions & 3 deletions sourcemakeup.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
$extensions = 'js,php,css';
$filter = '.min.js';
$dev = false;

$trimCommentBlockLen = 2;
$trimInlineCommentLen = 3;

// ## The Source

Expand Down Expand Up @@ -97,7 +100,7 @@

// Load the file and create an array of all lines:

$data = file_get_contents($file);
$data = file_get_contents($dir.$file);
$lines = explode("\n", $data);

// Create some variables we need later:
Expand All @@ -106,6 +109,8 @@
$iscomment = false;
$currentblock = 0;
$linenumber = 0;
$blockCommentMode = false;
$trimCommentLength = 0;

// Step through all lines and combine them into codeblocks. Each codeblock can have following contents:
//
Expand All @@ -116,12 +121,49 @@
foreach($lines as $line){

$linenumber++;

// Check for a comment block mode at the first character. It will
// not catch a comment trailing text.

$startBlockCommentMode = (substr(trim($line),-2,2) == '/*');

// Check for a comment block mode at the end of the line. It will
// not catch a terminating comment followed by code.

$endBlockCommentMode = (substr(trim($line),-2,2) == '*/');

// If the line enters and exists a comment block mode then replace,
// replace with a regular comment.
// If the line enters with a block comment, set the mode

if ($startBlockCommentMode){
if ($endBlockCommentMode){
$line = '// '.substr(trim($line),2);
} else{
$blockCommentMode = true;
}
}

// If the line exists a comment block mode at the end of the line,
// then set single line tags and toggle blockCommentMode off.

if ($endBlockCommentMode) {
$line = '// '.substr(trim($line),0,-2);
$blockCommentMode = false;
}

// Check for comment tags or comment block mode

if (substr(trim($line),0,2) == '//'){
if (substr(trim($line),0,2) == '//' || $blockCommentMode){
if (!$iscomment){
$currentblock++;
}
$blocks[$currentblock]['comment'] .= "\n".substr(trim($line),3);

$trimCommentLength = ($blockCommentMode)
? $trimCommentBlockLen
: $trimInlineCommentLen;

$blocks[$currentblock]['comment'] .= "\n".trim(substr(trim($line), $trimCommentLength));
$blocks[$currentblock]['code'] .= "";
$iscomment = true;
if (substr(trim(substr(trim($line),3)),0,3) == '{!}'){
Expand Down
96 changes: 96 additions & 0 deletions sourcemakeup.staticfiles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

<title>sourceMakeup - File <?php echo $file; ?></title>

<meta name="viewport" content="width=1280, initial-scale=1, maximum-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />

<link rel="shortcut icon" type="image/x-icon" href="http://jquery-jkit.com/favicon.ico" />

<script src="js/jquery-1.9.1.min.js"></script>
<script src="js/jquery.easing.1.3.js"></script>
<script src="js/jquery.jkit.1.1.29.min.js"></script>
<script src="js/sourcemakeup.js"></script>

<script type="text/javascript" src="libs/google-code-prettify/prettify.js"></script>
<link href="libs/google-code-prettify/prettify.css" type="text/css" rel="stylesheet" />

<link href="css/sourcemakeup.css" type="text/css" rel="stylesheet" />
<style>
p.selected {
font-weight: bold;
}

#filelist {
left: 0px;
position: fixed;
width: 300px;
bottom: 0px;
top: 0px;
overflow-y: scroll;
}

#filelist div {
padding: 20px;
}

#filelist p {
margin-bottom: 10px;
}

body > table {
margin-left: 300px;
}

hr {
display: none;
}
</style>

</head>
<body>

<div id="options" data-jkit="[tooltip:text=Show compiler instructions?]"><input type="checkbox" id="showinstructions" value="1"></div>
<div id="search" data-jkit="[filter:global=yes;by=text;affected=tr.docu;loader=#spinner]"><input class="jkit-filter" placeholder="search ..." type="text" value=""></div>
<div id="overview" data-jkit="[summary:what=headers;linked=yes;from=table.container;scope=all;style=select;indent=yes]"></div>
<div id="filelist"><div>

<?php foreach($files as $f):

$selected = ($_GET['file']==$f)
?'selected'
:'';

$url = $_SERVER['PHP_SELF'].'?file='.$f;
?>

<p class="<?php echo $selected;?>">
<a href="<?php echo $url;?>"><?php echo $f;?></a></p>

<?php endforeach; ?>

</div></div>

<table class="container" cellpadding="0" cellspacing="0">
<thead>
<tr>
<th class="comment">

</th>
<th class="code">
Code
</th>
</tr>
</thead>
<tbody>
<?=$output?>
</tbody>
</table>

<div id="spinner"><img src="imgs/spinner.gif"></div>

</body>
</html>