3 new revisions:

Revision: 72dea36cd84e
Branch:   default
Author:   Robot Framework Developers (robotframew...@gmail.com)
Date:     Tue Oct  9 02:19:42 2012
Log:      libdoc tests: moved reusable keywords to resource file
http://code.google.com/p/robotframework/source/detail?r=72dea36cd84e

Revision: b0b91fc5015f
Branch:   default
Author:   Robot Framework Developers (robotframew...@gmail.com)
Date:     Tue Oct  9 02:20:21 2012
Log:      libdoc.html: this isn't xhtml
http://code.google.com/p/robotframework/source/detail?r=b0b91fc5015f

Revision: 82cf631e12ac
Branch:   default
Author:   Robot Framework Developers (robotframew...@gmail.com)
Date:     Tue Oct  9 03:05:07 2012
Log:      libdoc: Initial support for alternative doc formats....
http://code.google.com/p/robotframework/source/detail?r=82cf631e12ac

==============================================================================
Revision: 72dea36cd84e
Branch:   default
Author:   Robot Framework Developers (robotframew...@gmail.com)
Date:     Tue Oct  9 02:19:42 2012
Log:      libdoc tests: moved reusable keywords to resource file
http://code.google.com/p/robotframework/source/detail?r=72dea36cd84e

Modified:
 /atest/robot/libdoc/internal_linking.txt
 /atest/robot/libdoc/libdoc_resource.txt

=======================================
--- /atest/robot/libdoc/internal_linking.txt    Thu Oct  4 14:17:56 2012
+++ /atest/robot/libdoc/internal_linking.txt    Tue Oct  9 02:19:42 2012
@@ -1,7 +1,7 @@
 *** Settings ***
 Force Tags       regression    pybot    jybot
 Resource         libdoc_resource.txt
-Suite Setup      Run Libdoc And Parse Model From HTML
+Suite Setup Run Libdoc And Parse Model From HTML ${TESTDATADIR}/InternalLinking.py
 Test Template    Doc Should Contain Link

 *** Test Cases ***
@@ -57,20 +57,16 @@


 *** Keywords ***
-
-Run Libdoc And Parse Model From HTML
-    Run Libdoc    ${TESTDATADIR}/InternalLinking.py ${OUT HTML}
-    ${MODEL} =    Get Libdoc Model From HTML    ${OUT HTML}
-    Set Suite Variable    ${MODEL}

 Doc Should Contain Link
     [Arguments]    ${object}    ${target}    ${text}
- Doc Should Contain ${object} <a href="#${target}" class="name">${text}</a> + Doc Should Contain ${object} <a href="#${target}" class="name">${text}</a>

 Doc Should Contain Name
     [Arguments]    ${object}    ${text}
-    Doc Should Contain    ${object}    <span class="name">${text}</span>
+    Doc Should Contain   ${object}    <span class="name">${text}</span>

 Doc Should Contain
-    [Arguments]    ${object}    ${expected}
-    Should Contain    ${object['doc']}    ${expected}
+    [Arguments]    ${object}    ${text}
+    Doc Should Contain In HTML    ${object}    ${text}
+
=======================================
--- /atest/robot/libdoc/libdoc_resource.txt     Fri Sep 14 05:01:48 2012
+++ /atest/robot/libdoc/libdoc_resource.txt     Tue Oct  9 02:19:42 2012
@@ -29,6 +29,16 @@
     ${output}=    Run Libdoc    ${args}
     ${expected}=    Catenate    SEPARATOR=\n    @{expected}
     Should Match    ${output}   ${expected}
+
+Run Libdoc And Parse Model From HTML
+    [Arguments]    ${args}
+    Run Libdoc    ${args} ${OUT HTML}
+    ${MODEL} =    Get Libdoc Model From HTML    ${OUT HTML}
+    Set Suite Variable    ${MODEL}
+
+Doc Should Contain In HTML
+    [Arguments]    ${object}    ${expected}
+    Should Contain    ${object['doc']}    ${expected}

 Name Should Be
     [Arguments]    ${name}

==============================================================================
Revision: b0b91fc5015f
Branch:   default
Author:   Robot Framework Developers (robotframew...@gmail.com)
Date:     Tue Oct  9 02:20:21 2012
Log:      libdoc.html: this isn't xhtml
http://code.google.com/p/robotframework/source/detail?r=b0b91fc5015f

Modified:
 /src/robot/htmldata/libdoc/libdoc.html

=======================================
--- /src/robot/htmldata/libdoc/libdoc.html      Sun Oct  7 23:51:31 2012
+++ /src/robot/htmldata/libdoc/libdoc.html      Tue Oct  9 02:20:21 2012
@@ -114,7 +114,7 @@
 </script>
 <script type="text/x-jquery-tmpl" id="footer_template">
     <p class="footer">
-        Altogether ${keywords.length} keywords.<br />
+        Altogether ${keywords.length} keywords.<br>
Generated by <a href="http://code.google.com/p/robotframework/wiki/LibraryDocumentationTool";>libdoc</a>
         on ${generated}.
     </p>

==============================================================================
Revision: 82cf631e12ac
Branch:   default
Author:   Robot Framework Developers (robotframew...@gmail.com)
Date:     Tue Oct  9 03:05:07 2012
Log:      libdoc: Initial support for alternative doc formats.

Update issue 489
Status: Started
Owner: pekka.klarck
Cc: kontulai
Now it is possible to give documentation format from the CLI using --docformat
option. Supported formats are ROBOT (default), TEXT and HTML.

Plenty of stuff still to do:
- Support for reST.
- Documentation in --help.
- Documentation in User Guide.
- Read format from XML spec.
- Possibly support for specifying doc format alraedy in library source.
http://code.google.com/p/robotframework/source/detail?r=82cf631e12ac

Added:
 /atest/robot/libdoc/doc_format.txt
 /atest/testdata/libdoc/DocFormat.py
Modified:
 /atest/robot/libdoc/invalid_usage.txt
 /src/robot/libdoc.py
 /src/robot/libdocpkg/__init__.py
 /src/robot/libdocpkg/htmlwriter.py
 /src/robot/libdocpkg/model.py
 /src/robot/libdocpkg/xmlwriter.py

=======================================
--- /dev/null
+++ /atest/robot/libdoc/doc_format.txt  Tue Oct  9 03:05:07 2012
@@ -0,0 +1,48 @@
+*** Settings ***
+Force Tags       regression    pybot    jybot
+Resource         libdoc_resource.txt
+
+*** Variables ***
+${EXAMPLE URL}     http://example.com
+${EXAMPLE LINK}    <a href="${EXAMPLE URL}">${EXAMPLE URL}</a>
+
+*** Test Cases ***
+
+Robot format in HTML
+    Test Format in HTML    --docformat Robot
+    ...    <b>bold</b> or &lt;b&gt;bold&lt;/b&gt; ${EXAMPLE LINK}
+
+Text format in HTML
+    Test Format in HTML    --DocFormat TEXT
+    ...    *bold* or &lt;b&gt;bold&lt;/b&gt; ${EXAMPLE LINK}
+
+HTML format in HTML
+    Test Format in HTML    -F html
+    ...    *bold* or <b>bold</b> ${EXAMPLE URL}
+
+Robot format in XML
+    Test Format In XML    --DOCFORMAT RoBoT    ROBOT
+
+Text format in XML
+    Test Format In XML    -F text    TEXT
+
+HTML format in XML
+    Test Format In XML    --docfor HtMl    HTML
+
+
+*** Keywords ***
+
+Test Format In HTML
+    [Arguments]    ${options}    ${expected}
+ Run Libdoc And Parse Model From HTML ${options} ${TESTDATADIR}/DocFormat.py
+    Doc Should Contain In HTML    ${MODEL['keywords'][0]}    ${expected}
+
+Test Format In XML
+    [Arguments]    ${options}    ${expected}
+    Run Libdoc And Parse Output     ${options} ${TESTDATADIR}/DocFormat.py
+    Format should be    ${expected}
+    Keyword Doc Should Be    0    *bold* or <b>bold</b> http://example.com
+
+Format should be
+    [Arguments]    ${expected}
+    Element Attribute Should Be    ${LIBDOC}    format    ${expected}
=======================================
--- /dev/null
+++ /atest/testdata/libdoc/DocFormat.py Tue Oct  9 03:05:07 2012
@@ -0,0 +1,5 @@
+
+
+
+def keyword():
+    """*bold* or <b>bold</b> http://example.com""";
=======================================
--- /atest/robot/libdoc/invalid_usage.txt       Tue Feb 21 00:44:19 2012
+++ /atest/robot/libdoc/invalid_usage.txt       Tue Oct  9 03:05:07 2012
@@ -22,8 +22,11 @@
     --invalid         option --invalid not recognized

 Invalid format
- -f XXX BuiltIn out.html Format must be either 'HTML' or 'XML', got 'XXX'. - BuiltIn out.ext Format must be either 'HTML' or 'XML', got 'EXT'.
+    -f XXX BuiltIn out.html    Format must be 'HTML' or 'XML', got 'XXX'.
+    BuiltIn out.ext            Format must be 'HTML' or 'XML', got 'EXT'.
+
+Invalid doc format
+ --docformat inv BuiltIn out Doc format must be 'ROBOT', 'TEXT' or 'HTML', got 'INV'.

 Non-existing library
NonExistingLib out.html Importing test library 'NonExistingLib' failed: *
=======================================
--- /src/robot/libdoc.py        Fri Sep 14 05:01:11 2012
+++ /src/robot/libdoc.py        Tue Oct  9 03:05:07 2012
@@ -37,6 +37,7 @@
  -f --format HTML|XML     Specifies whether to generate HTML or XML output.
                           If this options is not used, the format is got
                           from the extension of the output file.
+ -F --docformat ROBOT|HTML|TEXT|REST     TODO
-n --name newname Sets the name of the documented library or resource.
  -v --version newversion  Sets the version of the documented library or
                           resource.
@@ -110,7 +111,7 @@
 if 'robot' not in sys.modules and __name__ == '__main__':
     import pythonpathsetter

-from robot.utils import Application
+from robot.utils import Application, seq2str
 from robot.errors import DataError
 from robot.libdocpkg import LibraryDocumentation, ConsoleViewer

@@ -127,20 +128,29 @@
raise DataError('Only two arguments allowed when writing output.')
         return options, arguments

-    def main(self, args, name='', version='', format=None):
+    def main(self, args, name='', version='', format=None, docformat=None):
         lib_or_res, output = args[:2]
-        libdoc = LibraryDocumentation(lib_or_res, name, version)
+        libdoc = LibraryDocumentation(lib_or_res, name, version,
+                                      self._get_doc_format(docformat))
         if ConsoleViewer.handles(output):
             ConsoleViewer(libdoc).view(output, *args[2:])
         else:
-            libdoc.save(output, self._get_format(format, output))
+            libdoc.save(output, self._get_output_format(format, output))
             self.console(os.path.abspath(output))

-    def _get_format(self, format, output):
-        format = (format or os.path.splitext(output)[1][1:]).upper()
-        if format not in ['HTML', 'XML']:
- raise DataError("Format must be either 'HTML' or 'XML', got '%s'."
-                            % format)
+    def _get_doc_format(self, format):
+        return self._verify_format('Doc format', format or 'ROBOT',
+                                   ['ROBOT', 'TEXT', 'HTML'])
+
+    def _get_output_format(self, format, output):
+        default = os.path.splitext(output)[1][1:]
+ return self._verify_format('Format', format or default, ['HTML', 'XML'])
+
+    def _verify_format(self, type, format, valid):
+        format = format.upper()
+        if format not in valid:
+            raise DataError("%s must be %s, got '%s'."
+ % (type, seq2str(valid, lastsep=' or '), format))
         return format


=======================================
--- /src/robot/libdocpkg/__init__.py    Tue Mar 13 07:57:23 2012
+++ /src/robot/libdocpkg/__init__.py    Tue Oct  9 03:05:07 2012
@@ -23,11 +23,13 @@
 from .consoleviewer import ConsoleViewer


-def LibraryDocumentation(library_or_resource, name=None, version=None):
+def LibraryDocumentation(library_or_resource, name=None, version=None,
+                         doc_format='ROBOT'):
     builder = DocumentationBuilder(library_or_resource)
     libdoc = builder.build(library_or_resource)
     if name:
         libdoc.name = name
     if version:
         libdoc.version = version
+    libdoc.doc_format = doc_format
     return libdoc
=======================================
--- /src/robot/libdocpkg/htmlwriter.py  Thu Oct  4 14:17:56 2012
+++ /src/robot/libdocpkg/htmlwriter.py  Tue Oct  9 03:05:07 2012
@@ -38,7 +38,8 @@
         self._output.write('</script>' + os.linesep)

     def write_data(self):
-        formatter = DocFormatter(self._libdoc.doc, self._libdoc.keywords)
+        formatter = DocFormatter(self._libdoc.keywords, self._libdoc.doc,
+                                 self._libdoc.doc_format)
         libdoc = JsonConverter(formatter).convert(self._libdoc)
         JsonWriter(self._output).write_json('libdoc = ', libdoc)

@@ -76,10 +77,12 @@
     _header_regexp = re.compile(r'<h2>(.+?)</h2>')
     _name_regexp = re.compile('`(.+?)`')

-    def __init__(self, introduction, keywords):
-        self._targets = self._get_targets(introduction, keywords)
+    def __init__(self, keywords, introduction, doc_format='ROBOT'):
+        self._doc_to_html = DocToHtml(doc_format)
+        self._targets = self._get_targets(keywords, introduction,
+                                          doc_format == 'ROBOT')

-    def _get_targets(self, introduction, keywords):
+    def _get_targets(self, keywords, introduction, robot_format):
         targets = utils.NormalizedDict({
             'introduction': 'introduction',
             'library introduction': 'introduction',
@@ -88,10 +91,11 @@
             'shortcuts': 'shortcuts',
             'keywords': 'keywords'
         })
-        for header in self._yield_header_targets(introduction):
-            targets[header] = header
         for kw in keywords:
             targets[kw.name] = kw.name
+        if robot_format:
+            for header in self._yield_header_targets(introduction):
+                targets[header] = header
         return targets

     def _yield_header_targets(self, introduction):
@@ -101,7 +105,7 @@
                 yield line[1:-1].strip()

     def html(self, doc, intro=False):
-        doc = utils.html_format(doc)
+        doc = self._doc_to_html(doc)
         if intro:
             doc = self._header_regexp.sub(r'<h2 id="\1">\1</h2>', doc)
         return self._name_regexp.sub(self._link_keywords, doc)
@@ -111,3 +115,20 @@
         if name in self._targets:
return '<a href="#%s" class="name">%s</a>' % (self._targets[name], name)
         return '<span class="name">%s</span>' % name
+
+
+class DocToHtml(object):
+
+    def __init__(self, format):
+        self._formatter =  {'ROBOT': utils.html_format,
+                            'TEXT': self._format_text,
+                            'HTML': self._format_html}[format]
+
+    def _format_text(self, doc):
+ return '<p style="white-space: pre-wrap">%s</p>' % utils.html_escape(doc)
+
+    def _format_html(self, doc):
+        return '<div style="margin: 0">%s</div>' % doc
+
+    def __call__(self, doc):
+        return self._formatter(doc)
=======================================
--- /src/robot/libdocpkg/model.py       Tue May 29 06:52:32 2012
+++ /src/robot/libdocpkg/model.py       Tue Oct  9 03:05:07 2012
@@ -23,13 +23,14 @@
 class LibraryDoc(object):

     def __init__(self, name='', doc='', version='', type='library',
-                 scope='', named_args=False):
+                 scope='', named_args=False, doc_format='ROBOT'):
         self.name = name
         self.doc = doc
         self.version = version
         self.type = type
         self.scope = scope
         self.named_args = named_args
+        self.doc_format = doc_format
         self.inits = []
         self.keywords = []

=======================================
--- /src/robot/libdocpkg/xmlwriter.py   Tue Jun  5 22:28:35 2012
+++ /src/robot/libdocpkg/xmlwriter.py   Tue Oct  9 03:05:07 2012
@@ -20,6 +20,7 @@
     def write(self, libdoc, outfile):
         writer = XmlWriter(outfile, encoding='UTF-8')
writer.start('keywordspec', {'name': libdoc.name, 'type': libdoc.type,
+                                     'format': libdoc.doc_format,
'generated': get_timestamp(millissep=None)})
         writer.element('version', libdoc.version)
         writer.element('scope', libdoc.scope)

Reply via email to