示例#1
0
文件: aml.py 项目: p/shpaml-jinja
def convert_text(text):
    ''' Converts text to html. Text must be in aml template format (at).
    
    Aml templates are mostly comprised of shpaml syntax with shortcuts
    added for jinja. Please refer to install_jinja_shortcuts for syntax
    details.
    
    Whitespace removal is enabled; please refer to install_whitespace_removal
    for details on what whitespace is removed. Whitespace removal is not
    necessary to generate valid html from aml templates.
    
    Whitespace removal is an experimental feature.
    
    Indentation in aml is significant, and only spaces are allowed for
    indentation. If tabs are found in text at the beginning of any lines,
    IndentError will be raised.
    '''
    
    if not configuration.configured:
        raise NotConfiguredError
    
    text = configuration.active_shortcuts.convert_text_pre(text)
    text = shpaml.convert_text(text)
    text = configuration.active_shortcuts.convert_text_post(text)
    return text
示例#2
0
def cb_end(request):
    """Generates a overview of all articles."""
    
    request = deepcopy(request)
    request = tools.run_callback('prepare',
                    request) # needed for entry's url
    
    config = request._config
    data = request._data
    layout = os.path.join(config.get('layout_dir', 'layouts'), 'articles.html')
    tt_articles = Template(convert_text(open(layout).read()))
    articles = defaultdict(list)
    
    for entry in sorted(data['entry_list'], key=lambda k: k.date, reverse=True):
        url, title, year = entry['url'], entry['title'], entry.date.year
        
        articles[year].append((entry.date, url, title))
        
    articlesdict = config.copy()
    articlesdict.update({'articles': articles,
                 'num_entries': len(data['entry_list'])})
                 
    html = tt_articles.render(articlesdict)
    path = os.path.join(config.get('output_dir', 'out'), 'articles', 'index.html')
    
    tools.mk_file(html, {'title': 'articles/index.html'}, path)
    
    return request
示例#3
0
def fromSHPAML(shpamlTemplate):
    """
        Returns a parsable dictionary representation of the interface:
            shpaml - a string containing a shpaml representation of the interface
    """
    xmlStructure = minidom.parseString(shpaml.convert_text(shpamlTemplate))
    return __createTemplateFromXML(xmlStructure.childNodes[0])
示例#4
0
def cb_end(request):
    
    tt_atom_entry = Template(convert_text(ATOM_ENTRY))
    tt_atom_body = Template(convert_text(ATOM_BODY))
    tt_rss_entry = Template(convert_text(RSS_ENTRY))
    tt_rss_body = Template(convert_text(RSS_BODY))
    config = request._config
    data = request._data
    
    data['type'] = 'feed'
    count = 25
    
    # last preparations
    request = tools.run_callback(
            'prepare',
            request)
    
    dict = request._config
    rss_list = []
    atom_list = []
    for entry in data['entry_list'][:25]:
        entry['body'] = cgi.escape(entry['body'].replace('­', ''))
        entrydict = dict.copy()
        entrydict.update(entry)
        atom_list.append(tt_atom_entry.render( entrydict ))
        rss_list.append(tt_rss_entry.render( entrydict ))
    
    # atom
    dict.update( {'entry_list': '\n'.join(atom_list),
                  'date': data['entry_list'][0].date } )
    xml = tt_atom_body.render( dict )
    directory = os.path.join(config.get('output_dir', 'out'), 'atom')
    path = os.path.join(directory, 'index.xml')
    tools.mk_file(xml, {'title': 'atom/index.xml'}, path)
    
    # rss
    dict.update( {'entry_list': '\n'.join(rss_list),
                  'date': data['entry_list'][0].date } )
    xml = tt_rss_body.render( dict )
    directory = os.path.join(config.get('output_dir', 'out'), 'rss')
    path = os.path.join(directory, 'index.xml')
    tools.mk_file(xml, {'title': 'rss/index.xml'}, path)
    
    return request
    
示例#5
0
 def load_template_source(self, template_name, *args, **kwargs):
     if not template_name.endswith('.shpaml'):
         raise TemplateDoesNotExist(template_name)
     shpaml_source, template_path = super(Loader,
                                          self).load_template_source(
                                              template_name, *args,
                                              **kwargs)
     html = shpaml.convert_text(shpaml_source)
     return html, template_path
示例#6
0
文件: show.py 项目: esehara/hogegift
	def output(self):
		template_string = shpaml.convert_text(open("template/show.haml",encoding="UTF-8").read())
		template_string = (template_string
							.replace("{whatisgift}",self.configure["giftname"].rstrip())
							.replace("{whatisgiftjp}",self.configure["giftnamejp"].rstrip())
							.replace("{name}",self.configure["yourname"].rstrip())
							.replace("{twitter}",self.configure["twitter"].rstrip())
							.replace("{yourinfo}",self.configure["yourinfo"].rstrip())
							.replace("{descript}",self.configure["descript"].rstrip())
							.replace("{filename}",self.configure["filename"].rstrip())
							.replace("{url}",self.nowurl())
							)
		print(template_string)
示例#7
0
def load_template_source(template_name, template_dirs=None):
    tried = []
    print "load_template_source.shpaml_loader", template_name, template_dirs
    for filepath in get_template_sources(template_name, template_dirs):
        try:
            (text, url) = (convert_text(open(filepath).read().decode(settings.FILE_CHARSET)), filepath)
            return Template(text)
        except IOError:
            tried.append(filepath)
    if tried:
        error_msg = "Tried %s" % tried
    else:
        error_msg = "Your TEMPLATE_DIRS setting is empty. Change it to point to at least one template directory."
    raise TemplateDoesNotExist, error_msg
示例#8
0
def minaml (value):
    if trace:
        print
        print 'BEFORE:', value

    result = convert_text (value)

    if trace:
        print
        print 'AFTER:', result

    #if settings.DEBUG:
    #    result += '<!-- \n\nBEFORE:\n%s\n\nAFTER:\n%s\n\n -->' % (value, result)

    return result
示例#9
0
    def fromShpaml(self, file, tabs=''):
        if (not file):
            return ""
        
        results = []
        path = self._shpamlDir + file + '.shpaml'
        
        with open(path) as f:
            for line in f:
                exploded = self._shpamlVars.sub(self.runMethod, line)
                parse = self._shpamlExec.match(exploded)
                if (parse):
                    fullTabs = tabs + parse.group('tabbed')
                    exploded = self.fromShpaml(parse.group('file'), fullTabs)

                results.append(tabs + exploded)
        
        s = "".join(results)
        
        return convert_text(s)
示例#10
0
	def on_post_save(self, view):

		current_file_path = view.file_name() 
		path = ""

		if current_file_path:
			path, current_file_name = os.path.split(current_file_path)
		else:
			return

		if current_file_name.endswith(".shpaml"):

			if ".html" in current_file_name or ".xml" in current_file_name:
				new_file_name = current_file_name.replace(".shpaml", "")
			else:
				new_file_name = current_file_name.replace(".shpaml", ".html")

			with open(current_file_path, "r") as f:
				read_data = f.read()
			
			with open(os.path.join(path, new_file_name), "w") as f:
				f.write(shpaml.convert_text(read_data))
示例#11
0
 def __init__(self, f, **kwargs):
     html = shpaml.convert_text(f.read())
     html = html.replace('<html', html_begin)
     html_f = StringIO(html)
     MarkupTemplate.__init__(self, html_f, **kwargs)
示例#12
0
	def action(source, dest):
		with open(source, 'r') as s:
			if not os.path.exists(os.path.dirname(dest)):
				os.makedirs(os.path.dirname(dest))
			with open(dest, 'w') as d:
				d.write(shpaml.convert_text(s.read()))
示例#13
0
文件: loader.py 项目: alekam/shpaml
 def load_template_source(self, *args, **kwargs):
     src = super(InnerLoader, self).load_template_source(*args, **kwargs)
     return (shpaml.convert_text(src[0]), src[1])
示例#14
0
 def _shpaml(self, caller):
     return convert_text(caller())
示例#15
0
    def _shpaml(self, caller):
        from shpaml import convert_text

        return convert_text(caller())
示例#16
0
 def action(source, dest):
     with open(source, 'r') as s:
         if not os.path.exists(os.path.dirname(dest)):
             os.makedirs(os.path.dirname(dest))
         with open(dest, 'w') as d:
             d.write(shpaml.convert_text(s.read()))
示例#17
0
文件: loaders.py 项目: alekam/shpaml
 def load_template_source(self, template_name, *args, **kwargs):
     if not template_name.endswith('.shpaml'):
         raise TemplateDoesNotExist(template_name)
     shpaml_source, template_path = super(Loader, self).load_template_source(template_name, *args, **kwargs)
     html = shpaml.convert_text(shpaml_source)
     return html, template_path
示例#18
0
 def load_template_source(self, *args, **kwargs):
     src = super(InnerLoader, self).load_template_source(
         *args, **kwargs)
     return (shpaml.convert_text(src[0]), src[1])
示例#19
0
文件: haml.py 项目: esehara/pysimb
def output(string):
    return shpaml.convert_text(string)
示例#20
0
文件: run.py 项目: shon/cowspa
 def render(self, context):
     source = file(pathjoin(srcroot, self.src)).read()
     out = shpaml.convert_text(source)
     self.add_env(context)
     return template_env.from_string(out).render(**context)