Пример #1
0
 def testDefault(self):
     """
     Проверка того, что возвращается правильный путь до шаблона по умолчанию
     """
     style = Style()
     defaultStyle = style.getDefaultStyle()
     self.assertEqual(os.path.abspath(defaultStyle), os.path.abspath("styles/__default/__style.html"))
Пример #2
0
    def generateHtml (self, page):
        path = self.getHtmlPath (page)

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

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

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

            tpl = HtmlTemplate (style.getDefaultStyle())

        if page.autoLineWrap:
            text = HtmlImprover.run (page.content)
            text = re.sub ("\n<br>\n(<li>)|(<li>)", "\n<LI>", text)
        else:
            text = page.content

        result = tpl.substitute (content=text)

        with open (path, "wb") as fp:
            fp.write (result.encode ("utf-8"))

        return path
Пример #3
0
    def testSelfDefault(self):
        style = Style()

        page = self.rootwiki[u"Викистраница 1"]
        style.setPageStyle(page, style.getPageStyle(page))

        self.assertEqual(os.path.abspath(style.getPageStyle(page)), os.path.abspath(style.getDefaultStyle()))
Пример #4
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
Пример #5
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

        result = tpl.substitute(content=text,
                                title=page.display_title)

        result = self._changeContentByEvent(page,
                                            PostprocessingParams(result),
                                            self._application.onPostprocessing)
        return result
Пример #6
0
 def testDefault(self):
     """
     Проверка того, что возвращается правильный путь до шаблона по умолчанию
     """
     style = Style()
     defaultStyle = style.getDefaultStyle()
     self.assertEqual(os.path.abspath(defaultStyle),
                      os.path.abspath("src/styles/__default/__style.html"))
Пример #7
0
    def testSelfDefault(self):
        style = Style()

        page = self.wikiroot["Викистраница 1"]
        style.setPageStyle(page, style.getPageStyle(page))

        self.assertEqual(os.path.abspath(style.getPageStyle(page)),
                         os.path.abspath(style.getDefaultStyle()))
Пример #8
0
    def testFakeStyle(self):
        style = Style()
        page = self.rootwiki[u"Викистраница 1"]
        os.mkdir(os.path.join(page.path, self._styleFname))

        validStyle = os.path.abspath(style.getDefaultStyle())
        pageStyle = os.path.abspath(style.getPageStyle(page))

        self.assertEqual(pageStyle, validStyle)
Пример #9
0
    def testFakeStyle(self):
        style = Style()
        page = self.wikiroot["Викистраница 1"]
        os.mkdir(os.path.join(page.path, self._styleFname))

        validStyle = os.path.abspath(style.getDefaultStyle())
        pageStyle = os.path.abspath(style.getPageStyle(page))

        self.assertEqual(pageStyle, validStyle)
Пример #10
0
    def testStylePageDefault(self):
        """
        Проверка на то, что если у страницы нет файла стиля, то возвращается стиль по умолчанию
        """
        style = Style()
        defaultStyle = style.getDefaultStyle()
        style_page1 = style.getPageStyle(self.rootwiki[u"Викистраница 1"])
        style_page2 = style.getPageStyle(self.rootwiki[u"Html-страница 2"])

        self.assertEqual(style_page1, defaultStyle)
        self.assertEqual(style_page2, defaultStyle)
Пример #11
0
    def testStylePageDefault(self):
        """
        Проверка на то, что если у страницы нет файла стиля, то возвращается стиль по умолчанию
        """
        style = Style()
        defaultStyle = style.getDefaultStyle()
        style_page1 = style.getPageStyle(self.wikiroot["Викистраница 1"])
        style_page2 = style.getPageStyle(self.wikiroot["Html-страница 2"])

        self.assertEqual(style_page1, defaultStyle)
        self.assertEqual(style_page2, defaultStyle)
Пример #12
0
    def generateHtml (self, page):
        style = Style()
        stylepath = style.getPageStyle (page)
        generator = HtmlGenerator (page)

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

            html = generator.makeHtml (style.getDefaultStyle())

        return html
Пример #13
0
    def testSetStyle2(self):
        style = Style()
        page = self.rootwiki[u"Викистраница 1"]

        pageStyleFname = os.path.join(page.path, self._styleFname)
        pageStyleDir = os.path.join(page.path, self._styleDir)

        self.assertFalse(os.path.exists(pageStyleDir))
        self.assertFalse(os.path.exists(pageStyleFname))

        style.setPageStyle(page, self._exampleStyleDir)

        self.assertTrue(os.path.exists(pageStyleDir))
        self.assertTrue(os.path.exists(pageStyleFname))

        style.setPageStyle(page, style.getDefaultStyle())

        self.assertFalse(os.path.exists(pageStyleDir))
        self.assertFalse(os.path.exists(pageStyleFname))
Пример #14
0
    def testSetStyle2(self):
        style = Style()
        page = self.wikiroot["Викистраница 1"]

        pageStyleFname = os.path.join(page.path, self._styleFname)
        pageStyleDir = os.path.join(page.path, self._styleDir)

        self.assertFalse(os.path.exists(pageStyleDir))
        self.assertFalse(os.path.exists(pageStyleFname))

        style.setPageStyle(page, self._exampleStyleDir)

        self.assertTrue(os.path.exists(pageStyleDir))
        self.assertTrue(os.path.exists(pageStyleFname))

        style.setPageStyle(page, style.getDefaultStyle())

        self.assertFalse(os.path.exists(pageStyleDir))
        self.assertFalse(os.path.exists(pageStyleFname))
Пример #15
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
Пример #16
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