def setUp(self):
        self.filesPath = u"../test/samplefiles/"
        self.__createWiki()

        files = [u"image.jpg", u"dir"]
        self.wikicommands = [
            TestFooterWikiCommand,
            TestHeadWikiCommand,
        ]

        fullFilesPath = [
            os.path.join(self.filesPath, fname) for fname in files
        ]

        self.attach_page2 = Attachment(self.wikiroot[u"Страница 2"])

        # Прикрепим к двум страницам файлы
        Attachment(self.testPage).attach(fullFilesPath)

        self.wikitext = u"""Бла-бла-бла
        %thumb maxsize=250%Attach:image.jpg%%
        Бла-бла-бла"""

        self.testPage.content = self.wikitext

        self.__htmlconfig = HtmlRenderConfig(Application.config)
        self.__setDefaultConfig()

        self.resultPath = os.path.join(self.testPage.path, PAGE_RESULT_HTML)

        Application.onWikiParserPrepare += self.__onWikiParserPrepare
Beispiel #2
0
    def _makeHtml(self, page):
        style = Style()
        stylepath = style.getPageStyle(page)

        try:
            tpl = HtmlTemplate(readTextFile(stylepath))
        except EnvironmentError:
            tpl = HtmlTemplate(readTextFile(style.getDefaultStyle()))

        content = self._changeContentByEvent(page,
                                             PreprocessingParams(page.content),
                                             self._application.onPreprocessing)

        if page.autoLineWrap:
            content = self._changeContentByEvent(
                page, PreHtmlImprovingParams(content),
                self._application.onPreHtmlImproving)

            config = HtmlRenderConfig(self._application.config)
            improverFactory = HtmlImproverFactory(self._application)
            text = improverFactory[config.HTMLImprover.value].run(content)
        else:
            text = content

        userhead = u"<title>{}</title>".format(page.title)
        result = tpl.substitute(content=text, userhead=userhead)

        result = self._changeContentByEvent(page, PostprocessingParams(result),
                                            self._application.onPostprocessing)
        return result
Beispiel #3
0
    def __init__(self, application):
        self._unicodeEncoding = "unicode_escape"

        self._application = application
        self._mainConfig = self._application.config
        self._wikiConfig = WikiConfig(self._mainConfig)
        self._htmlConfig = HtmlRenderConfig(self._mainConfig)
Beispiel #4
0
    def setUp(self):
        self.initApplication()

        self.filesPath = "testdata/samplefiles/"
        self.__createWiki()

        files = ["image.jpg", "dir"]

        fullFilesPath = [
            os.path.join(
                self.filesPath,
                fname) for fname in files]

        self.attach_page2 = Attachment(self.wikiroot["Страница 2"])

        # Прикрепим к двум страницам файлы
        Attachment(self.testPage).attach(fullFilesPath)

        self.wikitext = """Бла-бла-бла
        %thumb maxsize=250%Attach:image.jpg%%
        Бла-бла-бла"""

        self.testPage.content = self.wikitext

        self.__htmlconfig = HtmlRenderConfig(self.application.config)
        self.__setDefaultConfig()
Beispiel #5
0
    def __init__(self, parent):
        super(type(self), self).__init__(parent)

        self.config = HtmlRenderConfig(Application.config)

        self._createGuiElements()
        self._do_layout()
Beispiel #6
0
    def __init__(self, parent, application):
        super(type(self), self).__init__(parent)

        self._application = application

        self.config = HtmlRenderConfig(self._application.config)

        self._createGuiElements()
        self._do_layout()
        self.SetupScrolling()
Beispiel #7
0
    def __init__(self, template):
        """
        template - текст шаблона

        Шаблон должен иметь содержание которого оформлено в стиле,
        описанном в http://docs.python.org/library/string.html#template-strings
        за исключением того, что в шаблоне $$ не заменяется на $
        """
        self.config = HtmlRenderConfig(Application.config)

        self.fontsize = self.config.fontSize.value
        self.fontfamily = self.config.fontName.value
        self.userStyle = self.config.userStyle.value

        self.template = MyTemplate(template)
Beispiel #8
0
    def makeHtml(self, stylepath):
        # Get content
        content = (self.page.content
                   if self.page.content
                   else EmptyContent(Application.config).content)

        content = self._changeContentByEvent(self.page,
                                             PreprocessingParams(content),
                                             Application.onPreprocessing)

        # Create parser
        factory = ParserFactory()
        parser = factory.make(self.page, Application.config)

        config = HtmlRenderConfig(Application.config)

        # Parse wiki content
        html = parser.toHtml(content)
        if parser.footer:
            html += u'\n' + parser.footer

        # Improve HTML
        html = self._changeContentByEvent(self.page,
                                          PreHtmlImprovingParams(html),
                                          Application.onPreHtmlImproving)

        improverFactory = HtmlImproverFactory(Application)
        text = improverFactory[config.HTMLImprover.value].run(html)
        head = parser.head

        # Create final HTML file
        tpl = HtmlTemplate(readTextFile(stylepath))
        result = tpl.substitute(content=text,
                                userhead=head,
                                title=self.page.display_title)

        result = self._changeContentByEvent(self.page,
                                            PostprocessingParams(result),
                                            Application.onPostprocessing)

        return result
Beispiel #9
0
    def generateHtml(self, page):
        path = self.getHtmlPath()

        if page.readonly and os.path.exists(path):
            # Если страница открыта только для чтения и html-файл уже существует, то покажем его
            return readTextFile(path)

        style = Style()
        stylepath = style.getPageStyle(page)

        try:
            tpl = HtmlTemplate(readTextFile(stylepath))
        except:
            MessageBox(_(u"Page style Error. Style by default is used"),
                       _(u"Error"), wx.ICON_ERROR | wx.OK)

            tpl = HtmlTemplate(readTextFile(style.getDefaultStyle()))

        content = self._changeContentByEvent(self.page,
                                             PreprocessingParams(page.content),
                                             Application.onPreprocessing)

        if page.autoLineWrap:
            content = self._changeContentByEvent(
                self.page, PreHtmlImprovingParams(content),
                Application.onPreHtmlImproving)

            config = HtmlRenderConfig(Application.config)
            improverFactory = HtmlImproverFactory(Application)
            text = improverFactory[config.HTMLImprover.value].run(content)
        else:
            text = content

        userhead = u"<title>{}</title>".format(page.title)
        result = tpl.substitute(content=text, userhead=userhead)

        result = self._changeContentByEvent(self.page,
                                            PostprocessingParams(result),
                                            Application.onPostprocessing)
        return result
Beispiel #10
0
 def setUp(self):
     self.initApplication()
     self.config = HtmlRenderConfig(self.application.config)
     self.__clearConfig()
     self.maxDiff = None