Пример #1
0
    def preview_ttl(self):
        """
        Convert tabulated files to turtle according to the type of the columns set by the user
        """
        self.log.debug("preview_ttl")
        data = {}

        body = self.request.json_body
        file_name = body["file_name"]
        col_types = body["col_types"]
        disabled_columns = body["disabled_columns"]

        sfc = SourceFileConvertor(self.settings, self.request.session)

        src_file = sfc.get_source_file(file_name)
        src_file.set_forced_column_types(col_types)
        src_file.set_disabled_columns(disabled_columns)

        cont_ttl = '\n'.join(src_file.get_turtle(preview_only=True))
        data = textwrap.dedent("""
        {header}

        #############
        #  Content  #
        #############

        {content_ttl}

        #################
        #  Abstraction  #
        #################

        {abstraction_ttl}

        ######################
        #  Domain knowledge  #
        ######################

        {domain_knowledge_ttl}
        """).format(header=sfc.get_turtle_template(cont_ttl),
                    content_ttl=cont_ttl,
                    abstraction_ttl=src_file.get_abstraction(),
                    domain_knowledge_ttl=src_file.get_domain_knowledge())

        formatter = HtmlFormatter(cssclass='preview_field',
                                  nowrap=True,
                                  nobackground=True)
        return highlight(data, TurtleLexer(), formatter)  # Formated html
Пример #2
0
    def get_preview_ttl(self):
        """
        Return the first 100 lines of a ttl file,
        text is formated with syntax color
        """

        head = ''

        with open(self.path, 'r', encoding="utf-8", errors="ignore") as fp:
            for x in range(1,100):
                head += fp.readline()

        ttl = textwrap.dedent("""
        {content}
        """).format(content=head)

        formatter = HtmlFormatter(cssclass='preview_field', nowrap=True, nobackground=True)
        return highlight(ttl, TurtleLexer(), formatter) # Formated html
Пример #3
0
}

pfxs = []

for (key,val) in namespaces.copy().iteritems():
	pfxs.append("@prefix %s: <%s> ." % (key, val))
pfxstr = '\n'.join(pfxs)

fh = codecs.open('index-turtle-not-highlight.html', 'r', 'utf-8')
data = fh.read()
fh.close()
data = data.replace('\r\n', '\n')
dom = etree.HTML(data)
egs = dom.xpath('//pre[@class="example nohighlight turtle"]')

ttl = TurtleLexer()
fmt = HtmlFormatter(cssclass="turtle")

css = fmt.get_style_defs('.turtle')
css = css.replace(".turtle  { background: #f8f8f8; }", "")
css = "<style>%s</style>" % css
data = data.replace("<style>", css + "<style>")

x=1

for eg in egs:
	# print "afas"
	egdata = eg.xpath('./text()')[0]
	egdata = egdata.strip()
	if not egdata:
		continue
Пример #4
0
def turtle_lexer():
    yield TurtleLexer()