コード例 #1
0
    def depart_bullet_list(self, node):
        parent = node.parent
        for item in reversed(node):
            section_type = detect_section_type("list", item)
            if section_type:
                split_title_and_content(item)
                newnode = section_type.parse_node(item)
                node.remove(item)

                index = parent.index(node)
                parent.insert(index + 1, newnode)

        if len(node) == 0:
            parent.remove(node)
コード例 #2
0
    def test_detect_section_type(self):
        def node2title(title):
            section = nodes.section()
            section += nodes.title(text=title)
            return section

        title = 'Group Blog Posts'
        self.assertEqual(addnodes.ResourceGroup, detect_section_type("header", node2title(title)))
        self.assertEqual(None, detect_section_type("list", node2title(title)))

        title = '/posts/{id}'
        self.assertEqual(addnodes.Resource, detect_section_type("header", node2title(title)))
        self.assertEqual(None, detect_section_type("list", node2title(title)))

        title = 'Blog Posts [/posts/{id}]'
        self.assertEqual(addnodes.Resource, detect_section_type("header", node2title(title)))
        self.assertEqual(None, detect_section_type("list", node2title(title)))

        title = 'GET /posts/{id}'
        self.assertEqual(addnodes.ResourceAction, detect_section_type("header", node2title(title)))
        self.assertEqual(None, detect_section_type("list", node2title(title)))

        title = 'Blog Posts [GET /posts/{id}]'
        self.assertEqual(addnodes.ResourceAction, detect_section_type("header", node2title(title)))
        self.assertEqual(None, detect_section_type("list", node2title(title)))

        title = 'Model (text/plain)'
        self.assertEqual(None, detect_section_type("header", node2title(title)))
        self.assertEqual(addnodes.Model, detect_section_type("list", node2title(title)))

        title = 'Schema'
        self.assertEqual(None, detect_section_type("header", node2title(title)))
        self.assertEqual(addnodes.Schema, detect_section_type("list", node2title(title)))

        title = 'GET'
        self.assertEqual(addnodes.Action, detect_section_type("header", node2title(title)))
        self.assertEqual(None, detect_section_type("list", node2title(title)))

        title = 'Retrieve Blog Posts [GET]'
        self.assertEqual(addnodes.Action, detect_section_type("header", node2title(title)))
        self.assertEqual(None, detect_section_type("list", node2title(title)))

        title = 'Request Create Blog Post (application/json)'
        self.assertEqual(None, detect_section_type("header", node2title(title)))
        self.assertEqual(addnodes.Request, detect_section_type("list", node2title(title)))

        title = 'Response 201 (application/json)'
        self.assertEqual(None, detect_section_type("header", node2title(title)))
        self.assertEqual(addnodes.Response, detect_section_type("list", node2title(title)))

        title = 'Parameters'
        self.assertEqual(None, detect_section_type("header", node2title(title)))
        self.assertEqual(addnodes.Parameters, detect_section_type("list", node2title(title)))

        title = 'Attributes (object)'
        self.assertEqual(None, detect_section_type("header", node2title(title)))
        self.assertEqual(addnodes.Attributes, detect_section_type("list", node2title(title)))

        title = 'Headers'
        self.assertEqual(None, detect_section_type("header", node2title(title)))
        self.assertEqual(addnodes.Headers, detect_section_type("list", node2title(title)))

        title = 'Body'
        self.assertEqual(None, detect_section_type("header", node2title(title)))
        self.assertEqual(addnodes.Body, detect_section_type("list", node2title(title)))

        title = 'Data Structures'
        self.assertEqual(addnodes.DataStructures, detect_section_type("header", node2title(title)))
        self.assertEqual(None, detect_section_type("list", node2title(title)))

        title = 'Relation: task'
        self.assertEqual(None, detect_section_type("header", node2title(title)))
        self.assertEqual(addnodes.Relation, detect_section_type("list", node2title(title)))

        title = 'Unknown'
        self.assertEqual(None, detect_section_type("header", node2title(title)))
        self.assertEqual(None, detect_section_type("list", node2title(title)))

        http_methods = ["GET", "HEAD", "POST", "PUT", "DELETE", "CONNECT", "OPTIONS", "TRACE"]
        for method in http_methods:
            self.assertEqual(addnodes.Action, detect_section_type("header", node2title(method)))
            self.assertEqual(None, detect_section_type("list", node2title(method)))
コード例 #3
0
 def depart_section(self, node):
     section_type = detect_section_type("header", node)
     if section_type:
         newnode = section_type.parse_node(node)
         node.replace_self(newnode)