本文整理汇总了Python中xierpa3.toolbox.transformer.TX类的典型用法代码示例。如果您正苦于以下问题:Python TX类的具体用法?Python TX怎么用?Python TX使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TX类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _get_expression
def _get_expression(self):
expressions = []
if self.min:
expressions.append('(min-width:%s)' % TX.px(self.min))
if self.max:
expressions.append('(max-width:%s)' % TX.px(self.max))
if self.device or expressions:
return (self.device or 'all') + ' and ' + ' and '.join(expressions)
return None # Raising error, style as media needs a defined expression
开发者ID:simons-design,项目名称:Xierpa3,代码行数:9,代码来源:style.py
示例2: buildResource
def buildResource(self, site):
u"""The url refers to a xierpa3 resource, try to find it and answer the result
with the appropriate mime type."""
path = TX.path2ParentDirectory(TX.module2Path(xierpa3)) + site.e.request.path
if os.path.exists(path):
f = open(path, 'rb')
result = f.read()
f.close()
return result, self.C.MIMETYPE_PNG
return '', self.C.MIMETYPE_HTML
开发者ID:petrvanblokland,项目名称:Xierpa3,代码行数:10,代码来源:baseclient.py
示例3: updateArticle
def updateArticle(self, id, path):
u"""Update the article from *id* and *path*. Set the modification time, so we know
when the file is updated."""
data = None
wiki = self.readWikiFile(path)
if wiki is not None:
data = self.compileArticle(wiki)
data.id = id
data.source = wiki
data.ranking = TX.asInt(data.ranking) or 0 # Make sure we can sort on the ranking field.
data.blogresponse = TX.asBool(data.blogresponse)
data.path = path # Keep the source path is case POST needs to save to the file.
data.modificationTime = os.path.getmtime(path) # @@@ TODO: Should be DateTime instance.
self.cacheArticle(data)
return data
开发者ID:thongnv,项目名称:Xierpa3,代码行数:15,代码来源:textilefileadapter.py
示例4: getColClass
def getColClass(self, col):
u"""Answer the colClass, based on the numeric <i>col</i> value and if the component is the
last in the parent list of child components."""
colClass = TX.col2Class(col)
if self.parent.isLast(self):
colClass = (colClass, C.CLASS_LAST)
return colClass
开发者ID:simons-design,项目名称:Xierpa3,代码行数:7,代码来源:component.py
示例5: baseComponents
def baseComponents(self):
u"""Create the component instances"""
# Import current example site, as anchor for the article files.
from xierpa3.sites.examples import textilearticles
# Root path where to find the article Simples wiki file for this example page.
articleRoot = TX.module2Path(textilearticles) + '/files/articles/'
adapter = ArticleAdapter(articleRoot) # Preferred adapter class for articles in this site.
# Create navigation instance, to choose between the available articles.
menu = Menu(adapter=adapter)
menuContainer = Container(components=menu)
# Create the article component to contain articles answered by the adapter.
#article = SimplexArticle(adapter=adapter)
article = Article(width=Perc(70), adapter=adapter, showPoster=True, splitChapters=False)
articleSideBar = ArticleSideBar(width=Perc(22), adapter=adapter)
featuredArticles = FeaturedByImage(width=Perc(22), adapter=adapter,
# Example to overwrite the default BluePrint parameter titleColor
titleColor=Color('red'))
#featuredByImage = FeaturedByText(widht=Perc(22), adapter=adapter)
# Make main page container for the article column
container = Container(components=(
#article,
articleSideBar,
#featuredArticles,
#featuredByImage
))
# The class is also the page name in the url.
homePage = Page(class_=self.C.TEMPLATE_INDEX, name=self.C.TEMPLATE_INDEX,
fonts=self.URL_FONTS, title=self.TITLE, css=self.C.URL_CSS,
components=(menuContainer, container))
return [homePage]
开发者ID:petrvanblokland,项目名称:Xierpa3,代码行数:30,代码来源:make.py
示例6: write_attribute
def write_attribute(self, key, value):
u"""
Auxiliary function to write each attribute to @[email protected] If the *key* is defined in
@[email protected] then only output the single key name (even if this breaks XML
validation). By default the @[email protected] is empty, but it can be redefined by the
inheriting application class.
If the *key* is in @[email protected] and the *value* is tuple or
a list, then join the *value*, separated by spaces. This feature is especially used to build flexible
cascading *class_* attributes.
If the attribute has no value, then the output is skipped.
"""
line = None
if key == 'class_':
key = 'class'
value = self.class2SpaceString(value)
if key in self.SINGLE_ATTRIBUTES:
line = u' ' + key
elif isinstance(value, (list, tuple)):
if key in self.CASCADING_ATTRIBUTES:
value = TX.flatten2Class(value)
if isinstance(value, basestring):
value = value.replace('"', '"');
if value:
line = u' %s="%s"' % (key, value)
else:
raise ValueError('[XmlTagBuilder.write_attribute] No list attribute value allowed for %s="%s"' % (key, `value`))
elif value:
if isinstance(value, basestring):
value = value.replace('"', '"');
line = u' %s="%s"' % (key, value)
if line:
self.output(line)
开发者ID:thongnv,项目名称:Xierpa3,代码行数:32,代码来源:xmltagbuilderpart.py
示例7: script
def script(self, charset='UTF-8', type='text/javascript', **args):
"""
The <code>br</code> tag inserts a single line break.<br/>
Defines a script, such as a JavaScript. Note that if @src is used, then no <code>self._script()</code> must be used.
The count attribute is not standard XHTML. It indicates the number of <code>br</code> to repeat.<br/>
<seealso><www href="http://www.w3schools.com/tags/tag_script.asp" target="external"/></seealso>
<python>
self.script()<br/>
...<br/>
self._script()
</python>
"""
#
# Build script. Note that if @src is used, then no self._script()
# must be used.
#
r = self.result.peek()
r.write(u'<script')
# Make sure to write "UTF-8" instead of "utf-8" since FireFox 2.0.0.4 will
# ignore the script otherwise.
r.write(u' charset="%s"' % charset.upper())
r.write(u' type="%s"' % type)
language = args.get(u'language')
if language is not None:
r.write(u' language="%s"' % language)
for key, value in args.items():
r.write(u' %s="%s"' % (TX.dataAttribute2Html5Attribute(key), value))
src = args.get(u'src')
if src is not None:
r.write(u'></script>\n')
else:
self._pushTag(u'script')
r.write(u'>\n')
开发者ID:thongnv,项目名称:Xierpa3,代码行数:33,代码来源:htmlbuilderpart.py
示例8: makeDirectory
def makeDirectory(self, path):
u"""Make sure that the directory of path (as file) exists. Otherwise create it.
Answer the directory path for convenience of the caller."""
dirPath = TX.path2Dir(path)
if not os.path.exists(dirPath):
os.makedirs(dirPath)
return dirPath
开发者ID:petrvanblokland,项目名称:Xierpa3,代码行数:7,代码来源:builder.py
示例9: baseComponents
def baseComponents(self):
# Import current example site, as anchor for the article files.
from xierpa3.sites import doingbydesign
# Root path where to find the article Simples wiki file for this example page.
articleRoot = TX.module2Path(doingbydesign) + '/files/articles/'
adapter = DbDAdapter(articleRoot) # Preferred adapter class for articles in this site.
logo = Logo(text='Doing by Design', fontFamily='Impact', color=Color('#888'), fontSize=Em(1.8))
menu = Menu()
mobileNavigation = DbDMobileNavigation()
article = Article()
featuredByImage = FeaturedByImage(start=0, width=Perc(65.4), showTitle=False,
showHeadline=False, showTopic=False)
featuredByText = FeaturedByText(start=0, width=Perc(30.75))
# Containers
top = Top(components=(logo, menu), media=Media(max=self.C.M_MOBILE_MAX, display=self.C.NONE))
featured = Featured(components=(featuredByImage, featuredByText), backgroundColor=Color('#262c37'))
section = Section(components=(featuredByImage,))
mainContent = MainContent(components=article)
footer = Footer(components=(menu))
homePage = Page(name=self.C.TEMPLATE_INDEX,
components=(mobileNavigation, top, featured, section, mainContent, footer),
css=self.C.URL_CSS, fonts=self.C.URL_FONTS, js=self.URL_JAVASCRIPT,
favicon=self.C.URL_FAVICON, adapter=adapter)
articlePage = Page(name=self.C.TEMPLATE_ARTICLE,
comoonents=(mobileNavigation, top, article, footer),
css=self.C.URL_CSS, fonts=self.C.URL_FONTS, js=self.URL_JAVASCRIPT,
favicon=self.C.URL_FAVICON, adapter=adapter)
return [homePage, articlePage]
开发者ID:petrvanblokland,项目名称:Xierpa3,代码行数:34,代码来源:doingbydesign.py
示例10: baseComponents
def baseComponents(self):
# Create the article adapter
# Import articles from the doingbydesign site, sharing the article files.
from xierpa3.sites import doingbydesign
# Root path where to find the article Simplex wiki file for this example page.
articleRoot = TX.module2Path(doingbydesign) + '/files/articles/'
adapter = SimpleSiteAdapter(articleRoot)
# Header
logo = Logo()
menu = Menu()
header = Header(components=(logo,menu), mobileContainerDisplay=self.C.NONE,
doc_mobileContainerDisplay=u'Header is not visible for mobile')
mobileNavigation = MobileNavigation() # Is container by itself. Change??
# Create the component instances
article = Article(width=Perc(68))
featuredByImage = FeaturedByImage(count=1, width=Perc(30))
featuredByText = FeaturedByText(start=1, count=3, width=Perc(30))
# Create the single page instance, containing the number of components
mainHome = Container(components=(article, featuredByImage, featuredByText))
# Footer
footer = Footer(components=(menu,), containerBackgroundColor=self.FOOTERBGCOLOR)
# The class is also the page name in the url.
homePage = Page(class_=self.C.TEMPLATE_INDEX, name=self.C.TEMPLATE_INDEX, adapter=adapter,
#components=(mobileNavigation, header, mainHome, footer),
#components=(header, mainHome, footer),
components=Container(header),
fonts=self.URL_FONTS, title=self.TITLE, css=self.C.URL_CSS)
return [homePage]
开发者ID:thongnv,项目名称:Xierpa3,代码行数:32,代码来源:make.py
示例11: make
def make(self, root=None):
u"""The instance of this class builds CSS and HTML files at the optional path *root*.
If not defined, then @[email protected] is used, as in general builders
are associated where output should go to.
E.g. the default @[email protected] is defined as to the user extended
path of @~/Desktop/Xierpa3Examples/[component.name]@.
And for @[email protected] it is @~/Desktop/Xierpa3Examples/[component.name]/css/[email protected]"""
if root is None:
root = TX.asDir(self.C.PATH_EXAMPLES) # Expand user path to full directory path.
# C S S
# Create the main CSS builder instance to build the CSS part of the site.
cssBuilder = CssBuilder()
# Compile (=build) the SCSS to CSS.
self.build(cssBuilder)
# Save the file in "css/style.css".
cssBuilder.save(self, root=root)
# H T M L
# Create the main HTML builder instance to build the HTML part of the site.
htmlBuilder = HtmlBuilder()
# Compile the site instance and its components into HTML code.
self.build(htmlBuilder)
# Save the resulting HTML file in "helloWorld.html"
# Answer the file path, so we can directly open the file with a browser.
return htmlBuilder.save(self, root=root)
开发者ID:petrvanblokland,项目名称:Xierpa3,代码行数:25,代码来源:make.py
示例12: buildBlock
def buildBlock(self, b):
colClass = TX.col2Class('graph')
s = self.style
b.block(self)
b.div(class_=colClass, float=s.graphFloat or self.LEFT, width=s.graphWidth or Perc(100))
b._div(comment=colClass)
b._block(self)
开发者ID:petrvanblokland,项目名称:Xierpa3,代码行数:7,代码来源:graph.py
示例13: image
def image(self, component, class_=None):
u"""
"""
if component.style:
width = component.style.width_html # Take explicit HTML width/height if defined in component.
height = component.style.height_html
else:
width = None
height = None
if height is None and width is None:
width = '100%'
elif height is not None:
width = None
alt = component.alt or TX.path2Name(component.url)
self.img(src=component.url, width_html=width, height_html=height, alt=alt,
class_=TX.flatten2Class(class_, component.getPrefixClass()))
开发者ID:thongnv,项目名称:Xierpa3,代码行数:16,代码来源:htmlbuilder.py
示例14: getFilePath
def getFilePath(self, site):
u"""
Answers the file path, based on the URL. Add '/files' to hide Python sources from view.
The right 2 slash-parts of the site path are taken for the output (@@@ for now)
"""
if site.e is not None:
return TX.class2Path(site) + "/files/" + "/".join(site.e.path.split("/")[-2:])
return None
开发者ID:simons-design,项目名称:Xierpa3,代码行数:8,代码来源:baseclient.py
示例15: __init__
def __init__(self, col, format="hex", bw=None, bwrgb=None):
self.alpha = 1
self.bwlevel = bw or BWLEVEL
self.bwrgb = bwrgb or BWRGBWEIGHT
if isinstance(col, (long, float, int)):
col = hex(col)
elif isinstance(col, Color):
col = col.hex
if format in ('cmyk', 'rgb', 'hex', 'uhex'):
self.format = format
else:
raise ValueError('[Color] Wrong format "%s". Should be in %s' % (format, repr(('cmyk', 'rgb', 'hex', 'uhex'))))
try:
if isinstance(col, basestring):
# Convert unreliable HTML/CSS color name to hex value and process from there.
col = COLOR_NAMES.get(col, col)
if ',' in col:
self.c = TX.list2IntFloatList(col)
elif HEXTUPLE.match(col):
if len(col) == 4:
col = '#%s%s%s' % (col[1]*2, col[2]*2, col[3]*2)
self.c = col
elif UHEXTUPLE.match(col):
col = col[2:]
if len(col) == 4:
col = '#%s%s%s' % (col[1]*2, col[2]*2, col[3]*2)
self.c = col
elif RGBTUPLE.match(col):
mrgb = RGBTUPLE.match(col)
self.c = (int(mrgb.group(1)), int(mrgb.group(2)), int(mrgb.group(3)))
elif RGBATUPLE.match(col):
mrgb = RGBTUPLE.match(col)
self.c = (int(mrgb.group(1)), int(mrgb.group(2)), int(mrgb.group(3)))
self.alpha = float(mrgb.group(4))
elif CMYKTUPLE.match(col):
mcmyk = CMYKTUPLE.match(col)
self.c = (int(mcmyk.group(1)), int(mcmyk.group(2)), int(mcmyk.group(3)), int(mcmyk.group(4)))
else:
ValueError('[Color] Unknown color format "%s"' % color)
else:
self.c = col
if len(self.c) == 3 and sum(self.c) <= 3:
# Test for 0-1 values - RGB values should be 0-255
self.c = list(self.c)
for i in range(3):
if self.c[i] <= 1 and self.c[i] / 2 == float(self.c[i]) / 2:
self.c[i] *= 255
self.c[i] = int(self.c[i])
self.c = tuple(self.c)
except:
raise ValueError('[Color] Wrong color format "%s"' % color)
rgbint = color.rgb(self.c)
self.r, self.g, self.b = color._int2rgbtuple(rgbint)
self.h, self.l, self.s = _rgb2hls(self.r, self.g, self.b)
开发者ID:thongnv,项目名称:Xierpa3,代码行数:58,代码来源:coloring.py
示例16: getFilePath
def getFilePath(self, site):
u"""
Answers the file path, based on the URL. Add '/files' to hide Python sources from view.
"""
fileName = site.e.path.split('/')[-1:]
if fileName:
fileName = '/'.join(file)
else:
fileName = 'index'
return TX.class2Path(site) + '/files/' + fileName
开发者ID:math-u,项目名称:Xierpa3,代码行数:10,代码来源:shop.py
示例17: save
def save(self, path, makeDirectory=False):
u"""Save the file in path. If <i>makeDirectory</i> is <b>True</b> (default is <b>False</b>)
then create the directories in the path if they don’t exist."""
if makeDirectory:
dirPath = TX.path2Dir(path)
if not os.path.exists(dirPath):
os.makedirs(dirPath)
f = open(path, 'wb')
f.write(self.getResult())
f.close()
开发者ID:math-u,项目名称:Xierpa3,代码行数:10,代码来源:builder.py
示例18: buildBlock
def buildBlock(self, b):
s = self.style
data = self.adapter.getMenu(id='home') # Get data for home page from adapter.
b.block(self) # div.mobileNavigation
b.div(class_=(self.C.CLASS_CONTAINER, self.className), display=s.display,
backgroundcolor=s.backgroundColor, width=s.width,
marginleft=s.marginLeft, marginright=s.marginRight,
paddingleft=s.paddingLeft, paddingright=s.paddingRight,
media=(
Media(max=self.C.M_MOBILE_MAX, display=s.displayMobile),
)
)
b.snippet(self, 'navigation-mobile') # Allow PHP to create a snippet file from this block.
colClass = self.getColClass(s.colWidth)
#b.text(data.loop) # In case there is PHP looping code. Skip for CSS
b.div(class_=colClass, width=self.C.AUTO, float=self.C.NONE, marginleft=Em(0.5),
marginright=Em(0.5), paddingleft=Em(0.5), paddingright=Em(0.5))
b.div(id=self.C.ID_MOBILENAVWRAP, width=s.navWidth, display=s.navDisplay, zindex=s.navZIndex)
b.div(id=self.C.ID_MENUICON, class_=self.C.CLASS_MENU, color=Color(self.C.WHITE),
height=26, width=56, paddingtop=Em(0.6), cursor='pointer',
display=self.C.INLINEBLOCK, marginright=0, top=0, left=0, fontsize=Px(13))
b.img(src=s.menuIconUrl,
padding=0, margin=0, verticalalign=self.C.MIDDLE, maxwidth=Perc(50), height=self.C.AUTO)
b._div(comment='#'+self.C.ID_MENUICON) # #menu-icon
if data.menuItems is None:
b.error('No items in the adapter')
else:
b.ul(id=self.C.ID_NAV, backgroundcolor=s.menuListBackgroundColor,
display=self.C.NONE, clear=self.C.BOTH, position=self.C.ABSOLUTE, top=s.menuHeight-5,
width=Perc(100), zindex=Z(2000), padding=0, margin=0, liststyletype=self.C.NONE, left=0,
textalign=self.C.CENTER)
homeArticle = self.adapter.getArticle(id='home')
for menuId in TX.commaSpaceString2WordList(homeArticle.menu):
menuArticle = self.adapter.getArticle(id=menuId)
url = menuArticle.url
if url is None:
url = '/%s-%s' % (self.C.PARAM_ARTICLE, menuId)
b.li(fontsize=s.listFontSize, paddingtop=Em(1.2), width=Perc(100), liststyletype=self.C.NONE,
borderbottom=Border('1 solid white'), height=36, backgroundcolor=Color('#4890BC'))
b.a(href=url, color=Color('#E8E8E8'))
b.text(menuArticle.name or 'Untitled') # Show full name, otherwise use b.text(menu.tag or menu.name)
b._a()
b._li()
b._ul()
b._div(comment=self.C.ID_MOBILENAVWRAP)
#b.a(href='/home', color='#E8E8E8')
#b.text('Doing by Design')
#b._a()
b._div(comment=self.C.CLASS_12COL)
#b.text(data._loop) # In case there is PHP looping code. Skip for CSS
b._snippet(self) # In case PHP saved this block as snippet.
b._div() # Final comment is automatic from component.selector
b._block(self) # div.mobileNavigation
开发者ID:thongnv,项目名称:Xierpa3,代码行数:55,代码来源:navigation.py
示例19: get_attribute_exceptions
def get_attribute_exceptions(self, key, value):
u"""
The <code>get_attribute_exceptions</code> method writes the attribute, and checks on naming differences between
the Xierpa attributes and HTML attributes.
"""
# Boolean attributes.
key = TX.dataAttribute2Html5Attribute(key)
if key in self.BOOLEAN_ATTRIBUTES:
if TX.value2Bool(value): # Can be boolean or text boolean
self.write_attribute(key, self.BOOLEAN_ATTRIBUTES[key])
else:
# Some exceptions.
if key.startswith('html'):
key = key[3:]
if key == 'class_':
key = 'class'
# elif key == 'src':
# value = self.e.getPath(value)
elif key == 'rowspan':
if int(value) <= 1:
return
elif key == 'colspan':
if int(value) <= 1:
return
elif key == 'xmllang':
key = 'xml:lang'
elif key == 'httpequiv':
key = 'http-equiv'
elif key == 'usemap':
if not value.startswith(u'#'):
value = u'#' + value
# Handle Angular.org attributes that contain underscores, translate them to hyphens
elif key.startswith('ng_'):
key = key.replace('_', '-')
self.write_attribute(key, value)
开发者ID:thongnv,项目名称:Xierpa3,代码行数:38,代码来源:htmlbuilderpart.py
示例20: image
def image(self, component, class_=None):
u"""
"""
if component.style:
width = component.style.width_html
height = component.style.height_html
else:
width = None
height = None
if height is None and width is None:
width = '100%'
elif height is not None:
width = None
self.img(src=component.url, width_html=width, height_html=height, alt=component.alt,
class_=TX.flatten2Class(class_, component.getPrefixClass()))
开发者ID:simons-design,项目名称:Xierpa3,代码行数:15,代码来源:htmlbuilder.py
注:本文中的xierpa3.toolbox.transformer.TX类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论