cinera.c: Correct template buffers

The template buffers no longer contain indentation spaces at the start
or a \n at the end. This removes any weirdness from template composition

Also remove the cleanup code added in 0.5.22
This commit is contained in:
Matt Mascarenhas 2018-01-08 22:59:36 +00:00
parent 6b1156292c
commit 93fa77b055
1 changed files with 15 additions and 40 deletions

View File

@ -14,7 +14,7 @@ typedef struct
version CINERA_APP_VERSION = { version CINERA_APP_VERSION = {
.Major = 0, .Major = 0,
.Minor = 5, .Minor = 5,
.Patch = 22 .Patch = 23
}; };
// TODO(matt): Copy in the DB 3 stuff from cinera_working.c // TODO(matt): Copy in the DB 3 stuff from cinera_working.c
@ -122,7 +122,6 @@ typedef struct
buffer IncludesIndex; buffer IncludesIndex;
buffer Search; buffer Search;
buffer Index; // NOTE(matt): This buffer is malloc'd separately, rather than claimed from the memory_arena buffer Index; // NOTE(matt): This buffer is malloc'd separately, rather than claimed from the memory_arena
buffer ScriptIndex;
buffer IncludesPlayer; buffer IncludesPlayer;
buffer Menus; buffer Menus;
buffer Player; buffer Player;
@ -2220,7 +2219,6 @@ HMMLToBuffers(buffers *CollationBuffers, template **BespokeTemplate, char *Filen
RewindBuffer(&CollationBuffers->Player); RewindBuffer(&CollationBuffers->Player);
RewindBuffer(&CollationBuffers->ScriptPlayer); RewindBuffer(&CollationBuffers->ScriptPlayer);
RewindBuffer(&CollationBuffers->IncludesIndex); RewindBuffer(&CollationBuffers->IncludesIndex);
RewindBuffer(&CollationBuffers->ScriptIndex);
*CollationBuffers->Title = '\0'; *CollationBuffers->Title = '\0';
*CollationBuffers->ProjectName = '\0'; *CollationBuffers->ProjectName = '\0';
@ -2395,14 +2393,14 @@ HMMLToBuffers(buffers *CollationBuffers, template **BespokeTemplate, char *Filen
int UniqueRefs = 0; int UniqueRefs = 0;
CopyStringToBuffer(&CollationBuffers->Menus, CopyStringToBuffer(&CollationBuffers->Menus,
" <div class=\"cineraMenus %s\">\n" "<div class=\"cineraMenus %s\">\n"
" <span class=\"episode_name\">", StringsDiffer(Config.Theme, "") ? Config.Theme : HMML.metadata.project); " <span class=\"episode_name\">", StringsDiffer(Config.Theme, "") ? Config.Theme : HMML.metadata.project);
CopyStringToBufferHTMLSafe(&CollationBuffers->Menus, HMML.metadata.title); CopyStringToBufferHTMLSafe(&CollationBuffers->Menus, HMML.metadata.title);
CopyStringToBuffer(&CollationBuffers->Menus, "</span>\n" CopyStringToBuffer(&CollationBuffers->Menus, "</span>\n"
" <span id=\"focus-warn\">⚠ Click here to regain focus ⚠</span>\n"); " <span id=\"focus-warn\">⚠ Click here to regain focus ⚠</span>\n");
CopyStringToBuffer(&CollationBuffers->Player, CopyStringToBuffer(&CollationBuffers->Player,
" <div class=\"cineraPlayerContainer\">\n" "<div class=\"cineraPlayerContainer\">\n"
" <div class=\"video_container\" data-videoId=\"%s\"></div>\n" " <div class=\"video_container\" data-videoId=\"%s\"></div>\n"
" <div class=\"markers_container %s\">\n", HMML.metadata.id, StringsDiffer(Config.Theme, "") ? Config.Theme : HMML.metadata.project); " <div class=\"markers_container %s\">\n", HMML.metadata.id, StringsDiffer(Config.Theme, "") ? Config.Theme : HMML.metadata.project);
@ -3014,7 +3012,7 @@ AppendedIdentifier:
if(HasFilterMenu) if(HasFilterMenu)
{ {
CopyStringToBuffer(&FilterState, "<script>\n" CopyStringToBuffer(&FilterState, "\n<script>\n"
" var filterInitState = {\n"); " var filterInitState = {\n");
for(int i = 0; i < Topics.Count; ++i) for(int i = 0; i < Topics.Count; ++i)
{ {
@ -3059,7 +3057,7 @@ AppendedIdentifier:
CopyStringToBuffer(&FilterState, CopyStringToBuffer(&FilterState,
" };\n" " };\n"
" </script>\n"); " </script>");
buffer URLPrefix; buffer URLPrefix;
ClaimBuffer(&URLPrefix, "URLPrefix", 1024); ClaimBuffer(&URLPrefix, "URLPrefix", 1024);
@ -3483,11 +3481,11 @@ AppendedIdentifier:
ConstructURLPrefix(&URLPrefix, INCLUDE_JS, PAGE_PLAYER); ConstructURLPrefix(&URLPrefix, INCLUDE_JS, PAGE_PLAYER);
CopyStringToBuffer(&CollationBuffers->IncludesPlayer, CopyStringToBuffer(&CollationBuffers->IncludesPlayer,
" <script type=\"text/javascript\" src=\"%scinera_player_pre.js\"></script>\n", " <script type=\"text/javascript\" src=\"%scinera_player_pre.js\"></script>",
URLPrefix.Location); URLPrefix.Location);
CopyStringToBuffer(&CollationBuffers->ScriptPlayer, CopyStringToBuffer(&CollationBuffers->ScriptPlayer,
" <script type=\"text/javascript\" src=\"%scinera_player_post.js\"></script>\n", "<script type=\"text/javascript\" src=\"%scinera_player_post.js\"></script>",
URLPrefix.Location); URLPrefix.Location);
DeclaimBuffer(&URLPrefix); DeclaimBuffer(&URLPrefix);
@ -3669,20 +3667,24 @@ BuffersToHTML(buffers *CollationBuffers, template *Template, char *OutputPath, i
CopyStringToBuffer(&Master, CopyStringToBuffer(&Master,
"<html>\n" "<html>\n"
" <head>\n"); " <head>\n"
" ");
CopyBuffer(&Master, PageType == PAGE_PLAYER ? &CollationBuffers->IncludesPlayer : &CollationBuffers->IncludesIndex); CopyBuffer(&Master, PageType == PAGE_PLAYER ? &CollationBuffers->IncludesPlayer : &CollationBuffers->IncludesIndex);
CopyStringToBuffer(&Master, "\n"); CopyStringToBuffer(&Master, "\n");
CopyStringToBuffer(&Master, CopyStringToBuffer(&Master,
" </head>\n" " </head>\n"
" <body>\n"); " <body>\n"
" ");
if(PageType == PAGE_PLAYER) if(PageType == PAGE_PLAYER)
{ {
CopyBuffer(&Master, &CollationBuffers->Menus); CopyBuffer(&Master, &CollationBuffers->Menus);
CopyStringToBuffer(&Master, "\n"); CopyStringToBuffer(&Master, "\n"
" ");
CopyBuffer(&Master, &CollationBuffers->Player); CopyBuffer(&Master, &CollationBuffers->Player);
CopyStringToBuffer(&Master, "\n"); CopyStringToBuffer(&Master, "\n"
" ");
CopyBuffer(&Master, &CollationBuffers->ScriptPlayer); CopyBuffer(&Master, &CollationBuffers->ScriptPlayer);
CopyStringToBuffer(&Master, "\n"); CopyStringToBuffer(&Master, "\n");
} }
@ -3899,31 +3901,6 @@ InsertIntoIndex(buffers *CollationBuffers, template **BespokeTemplate, char *Bas
break; break;
} }
// TODO(matt): Remove this little scope after 0.5.22 has been run once and all the searches are working correctly
if(IndexMetadataFileReadCode == RC_SUCCESS)
{
Index.Header = *(index_header *)Index.Metadata.Buffer.Ptr;
if(Index.Header.AppVersion.Major < 0 ||
Index.Header.AppVersion.Minor < 5 ||
Index.Header.AppVersion.Patch < 22)
{
CopyString(Index.File.Path, "%s/%s.index", Config.BaseDir, Config.ProjectID);
fprintf(stderr, "\e[1;31mRemoving %s and %s generated by Cinera version %d.%d.%d\n"
"prior to the index reinsertion fix implemented in version 0.5.22\e[0m\n",
Index.Metadata.Path, Index.File.Path,
Index.Header.AppVersion.Major,
Index.Header.AppVersion.Minor,
Index.Header.AppVersion.Patch);
FreeBuffer(&Index.Metadata.Buffer);
IndexMetadataFileReadCode = RC_ERROR_FILE;
remove(Index.Metadata.Path);
remove(Index.File.Path);
}
}
//
Index.File.Buffer.ID = "IndexFile"; Index.File.Buffer.ID = "IndexFile";
CopyString(Index.File.Path, "%s/%s.index", Config.BaseDir, Config.ProjectID); CopyString(Index.File.Path, "%s/%s.index", Config.BaseDir, Config.ProjectID);
@ -5114,7 +5091,6 @@ main(int ArgC, char **Args)
if(ClaimBuffer(&CollationBuffers.IncludesIndex, "IncludesIndex", Kilobytes(1)) == RC_ARENA_FULL) { goto RIP; }; if(ClaimBuffer(&CollationBuffers.IncludesIndex, "IncludesIndex", Kilobytes(1)) == RC_ARENA_FULL) { goto RIP; };
if(ClaimBuffer(&CollationBuffers.Search, "Search", Kilobytes(32)) == RC_ARENA_FULL) { goto RIP; }; if(ClaimBuffer(&CollationBuffers.Search, "Search", Kilobytes(32)) == RC_ARENA_FULL) { goto RIP; };
if(ClaimBuffer(&CollationBuffers.ScriptIndex, "ScriptIndex", 256) == RC_ARENA_FULL) { goto RIP; };
// NOTE(matt): Templating // NOTE(matt): Templating
// //
@ -5325,7 +5301,6 @@ NextFile:
DeclaimTemplate(IndexTemplate); DeclaimTemplate(IndexTemplate);
} }
DeclaimBuffer(&CollationBuffers.ScriptIndex);
DeclaimBuffer(&CollationBuffers.Search); DeclaimBuffer(&CollationBuffers.Search);
DeclaimBuffer(&CollationBuffers.IncludesIndex); DeclaimBuffer(&CollationBuffers.IncludesIndex);