UltimateBook: Pdf and html obtained from web

git-svn-id: svn://ultimatepp.org/upp/trunk@2473 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
koldo 2010-06-10 20:14:43 +00:00
parent 2f76a00894
commit 761b699ded
8 changed files with 362 additions and 0 deletions

View file

@ -0,0 +1,143 @@
#include <Core/Core.h>
#include "Functions4U/Functions4U.h"
using namespace Upp;
String CppAsQtf(const String& str)
{
static const char *cpp[] = {
"__asm", "else", "struct",
"enum", "switch", "auto", "__except", "template",
"explicit", "this",
"bool", "extern", "mutable", "thread",
"break", "false", "throw",
"case", "__fastcall", "namespace", "true",
"catch", "__finally", "new", "try",
"__cdecl", "float", "__try",
"char", "for", "operator", "typedef",
"class", "friend", "private", "typeid",
"const", "goto", "protected", "typename",
"const_cast", "if", "public", "union",
"continue", "inline", "register", "unsigned",
"__declspec", "__inline", "reinterpret_cast", "using",
"using", "default", "int", "return",
"delete", "__int8", "short", "__uuidof",
"dllexport", "__int16", "signed", "virtual",
"dllimport", "__int32", "sizeof", "void",
"do", "__int64", "static", "volatile",
"double", "__leave", "static_cast",
"dynamic_cast", "long", "__stdcall", "while",
"include", "define", "ifdef", "ifndef", "endif",
NULL
};
static Index<String> keyword;
if(keyword.GetCount() == 0)
for(const char **q = cpp; *q; q++)
keyword.Add(*q);
const char *s = str;
StringBuffer qtf;
qtf << "[l0r0<C1 ";
while(*s)
{
if(iscib(*s)) {
const char *b = s;
while(iscid(*s))
s++;
String id(b, s);
if(keyword.Find(id) >= 0)
qtf << "[@B " << DeQtf(id) << "]";
else
qtf << DeQtf(id);
}
else {
if(*s == '\t')
qtf << "____";
else
if(*s == '\n')
qtf << '&';
else
if((byte)*s >= 32)
if(strchr("!+-*^/%~&|=[]:?<>.#", *s))
qtf << "[@B `" << *s << "]";
else
qtf << '`' << *s;
s++;
}
}
return qtf;
}
void AddFiles(String& qtf, const String& dir, const char* ext, bool& b)
{
FindFile ff(AppendFileName(dir, "*." + String(ext)));
while(ff) {
qtf << "[A4* " << DeQtf(ff.GetName()) << "]&&"
<< CppAsQtf(LoadFile(AppendFileName(dir, ff.GetName())))
<< "&&&";
ff.Next();
b = true;
}
}
struct Isort {
bool operator()(const String& a, const String& b) const
{
return ToUpper(a) < ToUpper(b);
}
};
String MakeExamples(const char *webdir, const char *dir, const char *www, String language, GatherTpp &tt)
{
String ttxt;
FindFile ff(AppendFileName(dir, "*.*"));
ttxt << "{{1:3 ";
bool next = false;
Vector<String> ls;
while(ff) {
if(ff.IsFolder())
ls.Add(ff.GetName());
ff.Next();
}
Sort(ls, Isort());
for(int i = 0; i < ls.GetCount(); i++) {
String name = ls[i];
String link = String().Cat() << www << '$' << name << "$" << language << ".html";
Topic& topic = tt.AddTopic(link);
topic.title = name;
String fn = AppendFileName(
AppendFileName(
webdir,
String(www) + ".tpp"
),
topic.title + "$" + language + ".tpp"
);
String h = ReadTopic(LoadFile(fn)).text;
Package p;
p.Load(AppendFileName(AppendFileName(dir, name), name + ".upp"));
topic.text << "[R6* " << name << "]&&" << DeQtf(p.description) << "&";
if(h.GetCount())
topic.text << h;
topic.text << "[A2<l0r0 &&";
String d = AppendFileName(dir, name);
bool b = false;
AddFiles(topic.text, d, "h", b);
AddFiles(topic.text, d, "hpp", b);
AddFiles(topic.text, d, "cpp", b);
AddFiles(topic.text, d, "usc", b);
AddFiles(topic.text, d, "lay", b);
AddFiles(topic.text, d, "key", b);
AddFiles(topic.text, d, "brc", b);
AddFiles(topic.text, d, "sch", b);
AddFiles(topic.text, d, "xml", b);
if(b) {
if(next)
ttxt << "\n::^ ";
ttxt << "[^" << link << "^ " << DeQtf(topic.title) << "]::^ "
<< DeQtf(p.description);
next = true;
}
}
ttxt << "}}&&";
return ttxt;
}

Binary file not shown.

View file

@ -0,0 +1,46 @@
#include <Core/Core.h>
#include "Functions4U/Functions4U.h"
using namespace Upp;
String FolderLinks(const String uppsrc, const String package, const String group, const String lang, GatherTpp &tt)
{
String qtf;
FindFile ff(AppendFileName(AppendFileName(AppendFileName(uppsrc, package), group + ".tpp"), "*.tpp"));
while(ff) {
if(ff.IsFile()) {
if (ff.GetName().Find(lang) >= 0) {
String title;
String tl = "topic://" + package + '/' + group + '/' + GetFileTitle(ff.GetName());
tt.GatherTopics(tl, title);
qtf << "________[^" << tl << "^ " << DeQtf(Nvl(title, tl)) << "]&";
}
}
ff.Next();
}
return qtf;
}
void SrcDocs(Index<String> &x, String& qtf, String uppsrc, const char *folder, String lang, GatherTpp &tt)
{
if(x.Find(folder) >= 0)
return;
x.Add(folder);
String srcdoc = FolderLinks(uppsrc, folder, "srcdoc", lang, tt);
String src = FolderLinks(uppsrc, folder, "src", lang, tt);
Package p;
p.Load(AppendFileName(uppsrc, AppendFileName(folder, GetFileName(folder) + ".upp")));
if(srcdoc.GetLength() || src.GetLength()) {
qtf << "&&&[*4@b " << folder << "]&";
if(!IsNull(p.description))
qtf << "[2 " << p.description << "]&";
if(srcdoc.GetCount()) {
qtf << "&[3/* " + Format(t_("Using %s"), folder) << "]&";
qtf << srcdoc;
}
if(src.GetCount()) {
qtf << "&[3/* " << Format(t_("%s reference"), folder) << "]&";
qtf << src;
}
}
}

View file

@ -1,3 +1,27 @@
description "Ultimate++ website generation and export.\377";
uses
Web,
RichText,
plugin\gif,
CtrlLib,
CtrlLib,
plugin\png,
plugin\ftp,
Sql,
Controls4U,
GridCtrl,
ide;
options(GCC) -DNOWSTRING;
file
MakeExamples.cpp,
SrcDocs.cpp,
www.cpp,
book.lay,
srcdoc.tpp;
mainconfig
"" = "GUI";

View file

@ -0,0 +1,12 @@
LAYOUT(main, 412, 156)
ITEM(Option, doPdf, SetLabel(t_("Do .pdf")).LeftPosZ(8, 64).BottomPosZ(105, 19))
ITEM(Option, doHtml, SetLabel(t_("Do .html")).LeftPosZ(8, 64).BottomPosZ(125, 19))
ITEM(EditFile, pdfFile, HSizePosZ(140, 8).BottomPosZ(105, 19))
ITEM(Label, dv___3, SetLabel(t_("Html folder:")).LeftPosZ(80, 60).BottomPosZ(125, 19))
ITEM(Label, dv___4, SetLabel(t_("Pdf file:")).LeftPosZ(80, 60).BottomPosZ(105, 19))
ITEM(EditFolder, htmlFolder, HSizePosZ(140, 8).BottomPosZ(125, 19))
ITEM(Button, go, SetLabel(t_("Go")).RightPosZ(8, 72).BottomPosZ(8, 24))
ITEM(Label, action, HSizePosZ(4, 8).TopPosZ(64, 19))
ITEM(ProgressIndicator, progress, LeftPosZ(4, 400).TopPosZ(88, 24))
END_LAYOUT

Binary file not shown.

After

Width:  |  Height:  |  Size: 6 B

View file

@ -1,3 +1,13 @@
#ifndef _UltimateBook_icpp_init_stub
#define _UltimateBook_icpp_init_stub
#include "Web/init"
#include "RichText/init"
#include "plugin\gif/init"
#include "CtrlLib/init"
#include "plugin\png/init"
#include "plugin\ftp/init"
#include "Sql/init"
#include "Controls4U/init"
#include "GridCtrl/init"
#include "ide/init"
#endif

127
bazaar/UltimateBook/www.cpp Normal file
View file

@ -0,0 +1,127 @@
#include <CtrlLib/CtrlLib.h>
#include <Controls4U/Controls4U.h>
using namespace Upp;
#define LAYOUTFILE <UltimateBook/book.lay>
#include <CtrlCore/lay.h>
String MakeExamples(const char *webdir, const char *dir, const char *www, String language, GatherTpp &tt);
void SrcDocs(Index<String> &x, String& qtf, String uppsrc, const char *folder, String lang, GatherTpp &tt);
class Main : public Withmain<TopWindow> {
typedef Main CLASSNAME;
public:
Main();
~Main();
void DoGo();
void Xmlize(XmlIO xml) {
xml
("HtmlFolder", htmlFolder)
("PdfFile", pdfFile)
("DoPdf", doPdf)
("DoHtml", doHtml)
;
}
private:
EditString grFolder;
String configFile;
String indexFile;
bool SetProgress(int value, int total);
};
Main::Main() {
CtrlLayout(*this, "Ultimate Book");
Sizeable().Zoomable();
go.WhenAction = THISBACK(DoGo);
progress.Set(0, 1);
configFile = GetHomeDirFile("ultimatebook.xml");
LoadFromXMLFile(*this, configFile);
}
Main::~Main() {
StoreAsXMLFile(*this, NULL, configFile);
}
GUI_APP_MAIN {
Main main;
main.Execute();
}
bool Main::SetProgress(int value, int total) {
progress.Set(value, total);
Ctrl::ProcessEvents();
return false;
}
void Main::DoGo()
{
GatherTpp tpp;
String uppfolder = "C:/Desarrollo/Upp_Extra/upp-mirror/";
String uppsrc = uppfolder + "uppsrc";
tpp.AddFolder(uppfolder + "uppbox/uppweb");
tpp.AddFolder(uppsrc);
tpp.AddFolder(uppfolder + "bazaar");
action = "Loading pages";
tpp.Load(uppsrc + "uppbox/uppweb/www.tpp/index$en-us.tpp", THISBACK(SetProgress));
{ // Make examples pages
int id = tpp.FindTopic("topic://uppweb/www/examples$en-us");
if (id == -1) {
Exclamation("Error gathering examples");
return;
}
tpp.GetTopic(id).text << MakeExamples(uppfolder + "uppbox/uppweb", uppfolder + "examples",
"examples", "en-us", tpp);
tpp.GetTopic(id).text << ReadTopic(LoadFile(uppfolder + "uppbox/uppweb/www.tpp/reference$en-us.tpp")).text;
tpp.GetTopic(id).text << MakeExamples(uppfolder + "uppbox/uppweb", uppfolder + "reference",
"reference", "en-us", tpp);
}
{ // Make documentation pages
int id = tpp.FindTopic("topic://uppweb/www/documentation$en-us");
if (id == -1) {
Exclamation("Error gathering documentation");
return;
}
Index<String> x;
x.Clear();
String qtf;
SrcDocs(x, qtf, uppsrc, "Core", "en-us", tpp);
SrcDocs(x, qtf, uppsrc, "Draw", "en-us", tpp);
SrcDocs(x, qtf, uppsrc, "CtrlCore", "en-us", tpp);
SrcDocs(x, qtf, uppsrc, "CtrlLib", "en-us", tpp);
SrcDocs(x, qtf, uppsrc, "RichText", "en-us", tpp);
SrcDocs(x, qtf, uppsrc, "RichEdit", "en-us", tpp);
FindFile ff(AppendFileName(uppfolder + "uppsrc", "*.*"));
while(ff) {
if(ff.IsFolder())
SrcDocs(x, qtf, uppsrc, ff.GetName(), "en-us", tpp);
ff.Next();
}
tpp.GetTopic(id).text << qtf;
}
if (doHtml) {
action = "Making html";
tpp.MakeHtml(~htmlFolder, THISBACK(SetProgress));
}
if (doPdf) {
action = "Making pdf";
tpp.MakePdf(~pdfFile, THISBACK(SetProgress));
}
action = "";
}