From 0028be5e4c6da0eae2abd2d22cda7558c4f4272d Mon Sep 17 00:00:00 2001 From: lime Date: Tue, 4 Mar 2014 23:33:39 +0800 Subject: [PATCH] fix issue #13 --- .gitignore | 3 +- .gitmodules | 3 + FileHeader.py | 19 +++- doc/_themes/plain | 1 + doc/conf.py | 265 ++++++++++++++++++++++++++++++++++++++++++++++ doc/index.rst | 77 ++++++++++++++ doc/make.bat | 242 ++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 605 insertions(+), 5 deletions(-) create mode 100644 .gitmodules create mode 160000 doc/_themes/plain create mode 100644 doc/conf.py create mode 100644 doc/index.rst create mode 100644 doc/make.bat diff --git a/.gitignore b/.gitignore index a549af9..fd7dad2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ *.swp *.pyc github.py - +doc/Makefile +doc/_build/ diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..3470e6f --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "doc/_themes/plain"] + path = doc/_themes/plain + url = git://github.com/hit9/sphinx-theme-rux.git diff --git a/FileHeader.py b/FileHeader.py index a2730ff..fb81032 100644 --- a/FileHeader.py +++ b/FileHeader.py @@ -3,7 +3,7 @@ # @Author: lime # @Date: 2013-10-28 13:39:48 # @Last Modified by: lime -# @Last Modified time: 2014-02-07 18:02:05 +# @Last Modified time: 2014-03-05 10:16:24 import os import sys @@ -17,6 +17,7 @@ import shutil import time import pickle +import filecmp from datetime import datetime @@ -27,6 +28,7 @@ PLUGIN_NAME = 'FileHeader' +INSTALLED_PLUGIN_NAME = '%s.sublime-package' % PLUGIN_NAME PACKAGES_PATH = sublime.packages_path() PLUGIN_PATH = os.path.join(PACKAGES_PATH, PLUGIN_NAME) HEADER_PATH = os.path.join(PLUGIN_PATH, 'template/header') @@ -37,10 +39,10 @@ sys.path.insert(0, PLUGIN_PATH) - def plugin_loaded(): '''ST3''' + global LOADED global PACKAGES_PATH global PLUGIN_PATH global HEADER_PATH @@ -48,6 +50,9 @@ def plugin_loaded(): global INSTALLED_PLGIN_PATH global IS_ST3 + PLUGIN_NAME = 'FileHeader' + INSTALLED_PLUGIN_NAME = '%s.sublime-package' % PLUGIN_NAME + PACKAGES_PATH = sublime.packages_path() PLUGIN_PATH = os.path.join(PACKAGES_PATH, PLUGIN_NAME) HEADER_PATH = os.path.join(PLUGIN_PATH, 'template/header') @@ -59,12 +64,16 @@ def plugin_loaded(): sys.path.insert(0, PLUGIN_PATH) if INSTALLED_PLGIN_PATH != PLUGIN_PATH: + _ = os.path.join(PLUGIN_PATH, INSTALLED_PLUGIN_NAME) + if os.path.exists(_) and filecmp.cmp(_, INSTALLED_PLGIN_PATH): + return + if os.path.exists(PLUGIN_PATH): try: shutil.rmtree(PLUGIN_PATH) except: pass - + if not os.path.exists(PLUGIN_PATH): os.mkdir(PLUGIN_PATH) @@ -73,6 +82,8 @@ def plugin_loaded(): z.extract(f, PLUGIN_PATH) z.close() + shutil.copyfile(INSTALLED_PLGIN_PATH, _) + def Window(): '''Get current active window''' @@ -554,7 +565,7 @@ def update_automatically(self, view, what): elif what == 'LAST_MODIFIED_TIME': strings = datetime.now().strftime(get_strftime()) elif what == 'FILE_NAME': - strings = 'undefined' if view.file_name() is None else view.file_name().split('/')[-1] + strings = 'undefined' if view.file_name() is None else os.path.basename(view.file_name()) spaces = (index - space_start) * ' ' strings = spaces + strings diff --git a/doc/_themes/plain b/doc/_themes/plain new file mode 160000 index 0000000..942fe15 --- /dev/null +++ b/doc/_themes/plain @@ -0,0 +1 @@ +Subproject commit 942fe1526ade359c9829f70667fc02725829a1dd diff --git a/doc/conf.py b/doc/conf.py new file mode 100644 index 0000000..6ff9d8b --- /dev/null +++ b/doc/conf.py @@ -0,0 +1,265 @@ +# -*- coding: utf-8 -*- +# +# FileHeader documentation build configuration file, created by +# sphinx-quickstart on Sat Jun 28 09:25:34 2014. +# +# This file is execfile()d with the current directory set to its +# containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import sys +import os + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +#sys.path.insert(0, os.path.abspath('.')) + +# -- General configuration ------------------------------------------------ + +# If your documentation needs a minimal Sphinx version, state it here. +#needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix of source filenames. +source_suffix = '.rst' + +# The encoding of source files. +#source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'FileHeader' +copyright = u'2014, Lime' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = '1.5.6' +# The full version, including alpha/beta/rc tags. +release = '1.5.6' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +#language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +#today = '' +# Else, today_fmt is used as the format for a strftime call. +#today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = ['_build'] + +# The reST default role (used for this markup: `text`) to use for all +# documents. +#default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +#add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +#add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +#show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# A list of ignored prefixes for module index sorting. +#modindex_common_prefix = [] + +# If true, keep warnings as "system message" paragraphs in the built documents. +#keep_warnings = False + + +# -- Options for HTML output ---------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +html_theme = 'default' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +#html_theme_options = {} + +# Add any paths that contain custom themes here, relative to this directory. +#html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +#html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +#html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +#html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +#html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# Add any extra paths that contain custom files (such as robots.txt or +# .htaccess) here, relative to this directory. These files are copied +# directly to the root of the documentation. +#html_extra_path = [] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +#html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +#html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +#html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +#html_additional_pages = {} + +# If false, no module index is generated. +#html_domain_indices = True + +# If false, no index is generated. +#html_use_index = True + +# If true, the index is split into individual pages for each letter. +#html_split_index = False + +# If true, links to the reST sources are added to the pages. +#html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +#html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +#html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +#html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +#html_file_suffix = None + +# Output file base name for HTML help builder. +htmlhelp_basename = 'FileHeaderdoc' + + +# -- Options for LaTeX output --------------------------------------------- + +latex_elements = { +# The paper size ('letterpaper' or 'a4paper'). +#'papersize': 'letterpaper', + +# The font size ('10pt', '11pt' or '12pt'). +#'pointsize': '10pt', + +# Additional stuff for the LaTeX preamble. +#'preamble': '', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + ('index', 'FileHeader.tex', u'FileHeader Documentation', + u'Lime', 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +#latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +#latex_use_parts = False + +# If true, show page references after internal links. +#latex_show_pagerefs = False + +# If true, show URL addresses after external links. +#latex_show_urls = False + +# Documents to append as an appendix to all manuals. +#latex_appendices = [] + +# If false, no module index is generated. +#latex_domain_indices = True + + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + ('index', 'fileheader', u'FileHeader Documentation', + [u'Lime'], 1) +] + +# If true, show URL addresses after external links. +#man_show_urls = False + + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + ('index', 'FileHeader', u'FileHeader Documentation', + u'Lime', 'FileHeader', 'One line description of project.', + 'Miscellaneous'), +] + +# Documents to append as an appendix to all manuals. +#texinfo_appendices = [] + +# If false, no module index is generated. +#texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +#texinfo_show_urls = 'footnote' + +# If true, do not generate a @detailmenu in the "Top" node's menu. +#texinfo_no_detailmenu = False + +sys.path.append(os.path.abspath('_themes')) +html_theme_path = ['_themes'] +html_theme = 'plain' +html_theme_options = { + 'github': 'shiyanhui' +} \ No newline at end of file diff --git a/doc/index.rst b/doc/index.rst new file mode 100644 index 0000000..13a81da --- /dev/null +++ b/doc/index.rst @@ -0,0 +1,77 @@ +**FileHeader** 是一个Sublime Text的File Templating插件。目前ST已经有几款File Templating插件了,像SublimeTmpl、Template​Ninja、File​Templates等,但是这些插件的功能太简单了,他们几乎都使用了ST的内置snippets来实现模板的渲染,并且支持的语言很有限(像SublimeTmpl仅支持Python、Ruby、JavaScript、PHP、HTML、CSS、XML),有的插件仅仅支持ST2(File​Templates),还有的使用起来及其不效率。 + +本插件与其他插件有很大的不同。 + +- 将一个模板文件分为header和body两部分。允许用户自定义自己的模板文件。 +- FileHeader能够自动的监测创建新文件动作,自动的添加模板。 +- 不仅支持创建已经使用模板初始化好的文件,而且支持将header添加到已经存在的文件头部,并且支持批量添加。 +- 使用了非常强大并且很容易使用的 `Jinja2 `_ 模板系统,在模板文件里你可以完成很多复杂的初始化。 +- 几乎支持所有的编程语言,并且支持用户自定义语言。 +- 能够自动的更新文件最后修改时间。 +- 能够自动的更新文件最后的修改者,这在协同开发中是一个很有用的功能。 +- 支持ST2/ST3。 + +安装 +------ + +可以通过 **Package Control** 搜索 **FileHeader** 安装。 + +或者: + +进入到你的"Packages"文件夹 **(Preferences / Browse Packages)** ,然后: + +.. code-block:: python + + git clone git@github.com:shiyanhui/FileHeader.git + +使用 +------ + +FileHeader非常容易使用。 + +创建新文件 +````````` + +FileHeader能够自动的监测创建新文件动作,自动的添加模板。因此你可以用别的插件创建新文件,FileHeader会自动的给你添加模板。 + +- Sidebar Menu + + .. image:: https://raw.github.com/shiyanhui/shiyanhui.github.io/master/images/FileHeader/new-file.gif + +- Shortcuts + + The default shortcuts is **super+alt+n** on OS X, **ctrl+alt+n** on Windows and Linux. + +- Context Menu + + Similar to **Sidebar Menu**. + + +添加文件头 +````````` + +- Sidebar Menu + + .. image:: https://raw.github.com/shiyanhui/shiyanhui.github.io/master/images/FileHeader/add-header.gif + +- Shortcuts + + The default shortcuts is **super+alt+a** on OS X, **ctrl+alt+a** on Windows and Linux. + +- Context Menu + + Similar to **Sidebar Menu**. + +批量添加文件头 +````````` + +.. image:: https://raw.github.com/shiyanhui/shiyanhui.github.io/master/images/FileHeader/add-header-dir.gif + + +自动更新文件修改时间和最后修改者 +````````` + +.. image:: https://raw.github.com/shiyanhui/shiyanhui.github.io/master/images/FileHeader/update.gif + + +详细设置及文档请看 `GitHub `_ 。 \ No newline at end of file diff --git a/doc/make.bat b/doc/make.bat new file mode 100644 index 0000000..cafda5e --- /dev/null +++ b/doc/make.bat @@ -0,0 +1,242 @@ +@ECHO OFF + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set BUILDDIR=_build +set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . +set I18NSPHINXOPTS=%SPHINXOPTS% . +if NOT "%PAPER%" == "" ( + set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% + set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% +) + +if "%1" == "" goto help + +if "%1" == "help" ( + :help + echo.Please use `make ^` where ^ is one of + echo. html to make standalone HTML files + echo. dirhtml to make HTML files named index.html in directories + echo. singlehtml to make a single large HTML file + echo. pickle to make pickle files + echo. json to make JSON files + echo. htmlhelp to make HTML files and a HTML help project + echo. qthelp to make HTML files and a qthelp project + echo. devhelp to make HTML files and a Devhelp project + echo. epub to make an epub + echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter + echo. text to make text files + echo. man to make manual pages + echo. texinfo to make Texinfo files + echo. gettext to make PO message catalogs + echo. changes to make an overview over all changed/added/deprecated items + echo. xml to make Docutils-native XML files + echo. pseudoxml to make pseudoxml-XML files for display purposes + echo. linkcheck to check all external links for integrity + echo. doctest to run all doctests embedded in the documentation if enabled + goto end +) + +if "%1" == "clean" ( + for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i + del /q /s %BUILDDIR%\* + goto end +) + + +%SPHINXBUILD% 2> nul +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 +) + +if "%1" == "html" ( + %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/html. + goto end +) + +if "%1" == "dirhtml" ( + %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. + goto end +) + +if "%1" == "singlehtml" ( + %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. + goto end +) + +if "%1" == "pickle" ( + %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the pickle files. + goto end +) + +if "%1" == "json" ( + %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the JSON files. + goto end +) + +if "%1" == "htmlhelp" ( + %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run HTML Help Workshop with the ^ +.hhp project file in %BUILDDIR%/htmlhelp. + goto end +) + +if "%1" == "qthelp" ( + %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run "qcollectiongenerator" with the ^ +.qhcp project file in %BUILDDIR%/qthelp, like this: + echo.^> qcollectiongenerator %BUILDDIR%\qthelp\FileHeader.qhcp + echo.To view the help file: + echo.^> assistant -collectionFile %BUILDDIR%\qthelp\FileHeader.ghc + goto end +) + +if "%1" == "devhelp" ( + %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. + goto end +) + +if "%1" == "epub" ( + %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The epub file is in %BUILDDIR%/epub. + goto end +) + +if "%1" == "latex" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "latexpdf" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + cd %BUILDDIR%/latex + make all-pdf + cd %BUILDDIR%/.. + echo. + echo.Build finished; the PDF files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "latexpdfja" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + cd %BUILDDIR%/latex + make all-pdf-ja + cd %BUILDDIR%/.. + echo. + echo.Build finished; the PDF files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "text" ( + %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The text files are in %BUILDDIR%/text. + goto end +) + +if "%1" == "man" ( + %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The manual pages are in %BUILDDIR%/man. + goto end +) + +if "%1" == "texinfo" ( + %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. + goto end +) + +if "%1" == "gettext" ( + %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The message catalogs are in %BUILDDIR%/locale. + goto end +) + +if "%1" == "changes" ( + %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes + if errorlevel 1 exit /b 1 + echo. + echo.The overview file is in %BUILDDIR%/changes. + goto end +) + +if "%1" == "linkcheck" ( + %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck + if errorlevel 1 exit /b 1 + echo. + echo.Link check complete; look for any errors in the above output ^ +or in %BUILDDIR%/linkcheck/output.txt. + goto end +) + +if "%1" == "doctest" ( + %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest + if errorlevel 1 exit /b 1 + echo. + echo.Testing of doctests in the sources finished, look at the ^ +results in %BUILDDIR%/doctest/output.txt. + goto end +) + +if "%1" == "xml" ( + %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The XML files are in %BUILDDIR%/xml. + goto end +) + +if "%1" == "pseudoxml" ( + %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. + goto end +) + +:end