From ef9818e9cff70687410836a29101d1d3b6c78247 Mon Sep 17 00:00:00 2001 From: Yevgen Muntyan <17531749+muntyan@users.noreply.github.com> Date: Fri, 27 Oct 2017 18:58:48 -0700 Subject: [PATCH] Generate help with cmake --- CMakeLists.txt | 7 +- api/CMakeLists.txt | 4 +- api/gendocbook.py | 15 ++- doc/CMakeLists.txt | 155 ++++++++++++++++++++++++++++ doc/genhelpsectionsh.py | 25 +++-- doc/trim.py | 19 ++++ moo/plugins/support/moolineview.cpp | 2 +- 7 files changed, 214 insertions(+), 13 deletions(-) create mode 100644 doc/CMakeLists.txt create mode 100644 doc/trim.py diff --git a/CMakeLists.txt b/CMakeLists.txt index b726eb1c..a85c73d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -204,7 +204,7 @@ set(MOO_PYTHON "${PYTHON_EXECUTABLE}") set(MOO_ENABLE_PYTHON TRUE CACHE BOOL "Use python") -add_definitions(-DHAVE_CONFIG_H=1 -DXDG_PREFIX=_moo_edit_xdg -DG_LOG_DOMAIN=\"Moo\") +add_definitions(-DHAVE_CONFIG_H=1 -DXDG_PREFIX=_moo_edit_xdg "-DG_LOG_DOMAIN=\"Moo\"") #add_definitions(-DGDK_DISABLE_DEPRECATED=1) #add_definitions(-DGTK_DISABLE_DEPRECATED=1) @@ -218,7 +218,10 @@ endif(WIN32) # zzz SUBDIRS = po po-gsv api doc moo add_subdirectory(api) -# add_subdirectory(doc) + +add_subdirectory(doc) +include_directories("${CMAKE_BINARY_DIR}/doc") +add_definitions(-DMOO_ENABLE_HELP) #set(ENABLE_NLS TRUE) #add_subdirectory(po) diff --git a/api/CMakeLists.txt b/api/CMakeLists.txt index bafc5aa8..8350d18c 100644 --- a/api/CMakeLists.txt +++ b/api/CMakeLists.txt @@ -294,11 +294,11 @@ SET(source_files ../moo/mooutils/moowin32/ms/unistd.h ../moo/mooutils/moowindow.c ../moo/mooutils/moowindow.h - ../moo/plugins/support/moocmdview.c + ../moo/plugins/support/moocmdview.cpp ../moo/plugins/support/moocmdview.h ../moo/plugins/support/mooeditwindowoutput.c ../moo/plugins/support/mooeditwindowoutput.h - ../moo/plugins/support/moolineview.c + ../moo/plugins/support/moolineview.cpp ../moo/plugins/support/moolineview.h ../moo/plugins/support/moooutputfilter.c ../moo/plugins/support/moooutputfilter.h diff --git a/api/gendocbook.py b/api/gendocbook.py index cad1b0f6..2a0b80ae 100644 --- a/api/gendocbook.py +++ b/api/gendocbook.py @@ -1,5 +1,6 @@ #! /usr/bin/env python +import os import sys import optparse @@ -10,6 +11,7 @@ op = optparse.OptionParser() op.add_option("--python", action="store_true") op.add_option("--lua", action="store_true") op.add_option("--template", action="store") +op.add_option("-o", "--output", action="store") op.add_option("-i", "--import", action="append", dest="import_modules") (opts, args) = op.parse_args() @@ -28,4 +30,15 @@ if opts.import_modules: mod = Module.from_xml(args[0]) for im in import_modules: mod.import_module(im) -Writer(mode, opts.template, sys.stdout).write(mod) + +def write(out): + Writer(mode, opts.template, out).write(mod) + +if opts.output: + with open(opts.output + '.tmp', 'w') as out: + write(out) + if os.path.exists(opts.output): + os.remove(opts.output) + os.rename(opts.output + '.tmp', opts.output) +else: + write(sys.stdout) diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt new file mode 100644 index 00000000..5c4888e0 --- /dev/null +++ b/doc/CMakeLists.txt @@ -0,0 +1,155 @@ +find_program(XSLTPROC_COMMAND xsltproc) + +configure_file(medit-defines.ent.in ${CMAKE_CURRENT_SOURCE_DIR}/built/medit-defines.ent @ONLY) + +set(gendocbook_files + ${CMAKE_SOURCE_DIR}/api/gendocbook.py + ${CMAKE_SOURCE_DIR}/api/mpi/__init__.py + ${CMAKE_SOURCE_DIR}/api/mpi/module.py + ${CMAKE_SOURCE_DIR}/api/mpi/docbookwriter.py +) + +set(script_docbook_sources + ${CMAKE_CURRENT_SOURCE_DIR}/built/medit-defines.ent + ${CMAKE_CURRENT_SOURCE_DIR}/built/script-python.docbook + ${CMAKE_CURRENT_SOURCE_DIR}/built/script-lua.docbook + ${CMAKE_CURRENT_SOURCE_DIR}/built/script-lua-gtk.docbook +) + +add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/built/script-python.docbook + COMMAND ${MOO_PYTHON} ARGS + ${CMAKE_SOURCE_DIR}/api/gendocbook.py --python + --template ${CMAKE_CURRENT_SOURCE_DIR}/script-python.tmpl.docbook + --output ${CMAKE_CURRENT_SOURCE_DIR}/built/script-python.docbook + ${CMAKE_SOURCE_DIR}/api/moo.xml + MAIN_DEPENDENCY script-python.tmpl.docbook + DEPENDS apixml ${gendocbook_files} ${CMAKE_SOURCE_DIR}/api/moo.xml +) + +add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/built/script-lua.docbook + COMMAND ${MOO_PYTHON} ARGS + ${CMAKE_SOURCE_DIR}/api/gendocbook.py --lua + --template ${CMAKE_CURRENT_SOURCE_DIR}/script-lua.tmpl.docbook + --import ${CMAKE_SOURCE_DIR}/api/gtk.xml + --output ${CMAKE_CURRENT_SOURCE_DIR}/built/script-lua.docbook + ${CMAKE_SOURCE_DIR}/api/moo.xml + MAIN_DEPENDENCY script-lua.tmpl.docbook + DEPENDS apixml ${gendocbook_files} ${CMAKE_SOURCE_DIR}/api/moo.xml +) + +add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/built/script-lua-gtk.docbook + COMMAND ${MOO_PYTHON} ARGS + ${CMAKE_SOURCE_DIR}/api/gendocbook.py --lua + --template ${CMAKE_CURRENT_SOURCE_DIR}/script-lua-gtk.tmpl.docbook + --output ${CMAKE_CURRENT_SOURCE_DIR}/built/script-lua-gtk.docbook + ${CMAKE_SOURCE_DIR}/api/gtk.xml + MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/script-lua.tmpl.docbook + DEPENDS ${gendocbook_files} ${CMAKE_SOURCE_DIR}/api/gtk.xml +) + +add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/help/script/index.html + COMMAND ${XSLTPROC_COMMAND} ARGS + --xinclude script-book.xsl script.docbook + MAIN_DEPENDENCY script.docbook + DEPENDS ${script_docbook_sources} script-book.xsl + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +) + +add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/help/medit.css + COMMAND ${CMAKE_COMMAND} ARGS + -E copy ${CMAKE_CURRENT_SOURCE_DIR}/medit.css ${CMAKE_CURRENT_SOURCE_DIR}/help/medit.css + MAIN_DEPENDENCY medit.css +) + +add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/built/lgpl.no-fancy-chars + COMMAND ${MOO_PYTHON} ARGS ${CMAKE_CURRENT_SOURCE_DIR}/trim.py + --input ${CMAKE_SOURCE_DIR}/COPYING + --output ${CMAKE_CURRENT_SOURCE_DIR}/built/lgpl.no-fancy-chars + MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/COPYING +) + +set(docbook_files + medit.docbook + prefs.docbook + regex.docbook + user-tools.docbook + license.docbook +) + +set(docbook_sources + ${docbook_files} + built/lgpl.no-fancy-chars + built/medit-defines.ent +) + +add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/help/index.html + COMMAND ${XSLTPROC_COMMAND} ARGS + --xinclude medit.xsl medit.docbook + MAIN_DEPENDENCY medit.docbook + DEPENDS ${docbook_sources} medit.xsl medit-common.xsl + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +) + +add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/help/help.html + COMMAND ${XSLTPROC_COMMAND} ARGS + --xinclude --output help/help.html medit-single.xsl medit.docbook + MAIN_DEPENDENCY medit.docbook + DEPENDS ${docbook_sources} medit-single.xsl medit-common.xsl + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +) + +add_custom_command(OUTPUT toc.xml + COMMAND ${XSLTPROC_COMMAND} ARGS + --output toc.xml --xinclude + --stringparam chunk.first.sections 1 + http://docbook.sourceforge.net/release/xsl/current/html/maketoc.xsl ${CMAKE_CURRENT_SOURCE_DIR}/medit.docbook + MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/medit.docbook + DEPENDS ${docbook_sources} +) + +add_custom_command(OUTPUT moo-help-sections.h + COMMAND ${MOO_PYTHON} ARGS + ${CMAKE_CURRENT_SOURCE_DIR}/genhelpsectionsh.py --toc=toc.xml + --output=moo-help-sections.h + --srcdir=${CMAKE_CURRENT_SOURCE_DIR} ${docbook_files} + MAIN_DEPENDENCY toc.xml + DEPENDS ${docbook_files} genhelpsectionsh.py +) + +set(dest_png_files + ${CMAKE_CURRENT_SOURCE_DIR}/help/img/prefs-file-filters.png + ${CMAKE_CURRENT_SOURCE_DIR}/help/img/prefs-file-selector.png +) +add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/help/img/prefs-file-filters.png + COMMAND ${CMAKE_COMMAND} ARGS -E copy ${CMAKE_CURRENT_SOURCE_DIR}/img/prefs-file-filters.png ${CMAKE_CURRENT_SOURCE_DIR}/help/img/prefs-file-filters.png + MAIN_DEPENDENCY img/prefs-file-filters.png +) +add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/help/img/prefs-file-selector.png + COMMAND ${CMAKE_COMMAND} ARGS -E copy ${CMAKE_CURRENT_SOURCE_DIR}/img/prefs-file-selector.png ${CMAKE_CURRENT_SOURCE_DIR}/help/img/prefs-file-selector.png + MAIN_DEPENDENCY img/prefs-file-selector.png +) + +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/help DESTINATION ${MOO_DOC_DIR}) + +#EXTRA_DIST = help built/moo-help-sections.h built/medit.1 + +#install-data-local: +# $(MKDIR_P) $(DESTDIR)$(MOO_HELP_DIR)/img $(DESTDIR)$(MOO_HELP_DIR)/script +# cd $(srcdir) && $(INSTALL_DATA) help/*.html help/*.css $(DESTDIR)$(MOO_HELP_DIR) +# cd $(srcdir) && $(INSTALL_DATA) help/script/*.html $(DESTDIR)$(MOO_HELP_DIR)/script +# cd $(srcdir) && $(INSTALL_DATA) help/img/*.png $(DESTDIR)$(MOO_HELP_DIR)/img + +#uninstall-local: +# rm -f $(DESTDIR)$(MOO_HELP_DIR)/*.html \ +# $(DESTDIR)$(MOO_HELP_DIR)/*.css \ +# $(DESTDIR)$(MOO_HELP_DIR)/script/*.html \ +# $(DESTDIR)$(MOO_HELP_DIR)/img/*.png + +add_custom_target(docs ALL DEPENDS + ${CMAKE_CURRENT_SOURCE_DIR}/help/help.html + ${CMAKE_CURRENT_SOURCE_DIR}/help/index.html + ${CMAKE_CURRENT_SOURCE_DIR}/help/script/index.html + ${CMAKE_CURRENT_SOURCE_DIR}/help/medit.css + moo-help-sections.h + ${dest_png_files} +) diff --git a/doc/genhelpsectionsh.py b/doc/genhelpsectionsh.py index 90a9bafc..98cce832 100644 --- a/doc/genhelpsectionsh.py +++ b/doc/genhelpsectionsh.py @@ -8,6 +8,7 @@ import optparse op = optparse.OptionParser() op.add_option("--toc", action="store") op.add_option("--srcdir", action="store") +op.add_option("--output", action="store") (opts, args) = op.parse_args() srcdir = opts.srcdir or '.' @@ -62,10 +63,20 @@ for section in map_hsection_to_id: map_hsection_to_html['PREFS_PLUGINS'] = map_hsection_to_html['PREFS_DIALOG'] map_hsection_to_html['PREFS_VIEW'] = map_hsection_to_html['PREFS_DIALOG'] -print '#ifndef MOO_HELP_SECTIONS_H' -print '#define MOO_HELP_SECTIONS_H' -print '' -for section in sorted(map_hsection_to_html.keys()): - print '#define HELP_SECTION_%s "%s"' % (section, map_hsection_to_html[section]) -print '' -print '#endif /* MOO_HELP_SECTIONS_H */' +def write(out): + out.write('#ifndef MOO_HELP_SECTIONS_H\n') + out.write('#define MOO_HELP_SECTIONS_H\n') + out.write('\n') + for section in sorted(map_hsection_to_html.keys()): + out.write('#define HELP_SECTION_%s "%s"\n' % (section, map_hsection_to_html[section])) + out.write('\n') + out.write('#endif /* MOO_HELP_SECTIONS_H */\n') + +if opts.output: + with open(opts.output + '.tmp', 'w') as out: + write(out) + if os.path.exists(opts.output): + os.remove(opts.output) + os.rename(opts.output + '.tmp', opts.output) +else: + write(sys.stdout) diff --git a/doc/trim.py b/doc/trim.py new file mode 100644 index 00000000..a4438a4e --- /dev/null +++ b/doc/trim.py @@ -0,0 +1,19 @@ +#! /usr/bin/env python + +import os +import optparse + +op = optparse.OptionParser() +op.add_option("-o", "--output", action="store") +op.add_option("-i", "--input", action="store") +(opts, args) = op.parse_args() + +assert len(args) == 0 +assert opts.input and opts.output + +with open(opts.input) as inp: + with open(opts.output + '.tmp', 'w') as out: + out.write(inp.read().replace('\014', '')) +if os.path.exists(opts.output): + os.remove(opts.output) +os.rename(opts.output + '.tmp', opts.output) diff --git a/moo/plugins/support/moolineview.cpp b/moo/plugins/support/moolineview.cpp index 5033b407..25c4853e 100644 --- a/moo/plugins/support/moolineview.cpp +++ b/moo/plugins/support/moolineview.cpp @@ -14,7 +14,7 @@ */ /** - * class:MooLineView: (parent MooTextView) (constructable) (moo.private 1) + * class:MooLineView: (parent MooTextView) (constructable) **/ #include "moolineview.h"