Did I find the right examples for you? yes no

All Samples(12)  |  Call(9)  |  Derive(0)  |  Import(3)

        def generate_code(**kw):
    resource_to_name = {}
    resources = []
    for name, resource in kw.items():
        resource_to_name[(resource.library, resource.relpath)] = name
        resources.append(resource)

    # libraries with the same name are the same libraries
    libraries = {}
    for resource in resources:
        libraries[resource.library.name] = resource.library
        for mode_name, mode_resource in resource.modes.items():
            libraries[mode_resource.library.name] = mode_resource.library
    libraries = sorted(libraries.values(), key=lambda library: library.name)

    result = []
    # import on top
    result.append("from fanstatic import Library, Resource")
    result.append("")
    result.append("# This code is auto-generated and not PEP8 compliant")
    result.append("")
    # define libraries
    for library in libraries:
        result.append("%s = Library('%s', '%s')" %
                      (library.name, library.name, library.rootpath))
    result.append("")

    # sort resources in the order we want them to be
    resources = sort_resources_topological(resources)

    # now generate resource code
    for resource in resources:
        s = "%s = Resource(%s, '%s'" % (
            resource_to_name[(resource.library, resource.relpath)],
            resource.library.name,
            resource.relpath)
        if resource.depends:
            depends_s = ', depends=[%s]' % ', '.join(
                [resource_to_name[(d.library, d.relpath)] for d in resource.depends])
            s += depends_s
        if resource.supersedes:
            supersedes_s = ', supersedes=[%s]' % ', '.join(
                [resource_to_name[(i.library, i.relpath)] for i in resource.supersedes])
            s += supersedes_s
        if resource.modes:
            items = []
            for mode_name, mode in resource.modes.items():
                items.append((mode_name,
                              generate_inline_resource(mode, resource)))
            items = sorted(items)
            modes_s = ', %s' % ', '.join(["%s=%s" % (name, mode) for
                                          (name, mode) in items])
            s += modes_s
        s += ')'
        result.append(s)
    return '\n'.join(result)
        


src/f/a/fanstatic-1.0a5/tests/test_codegen.py   fanstatic(Download)
from fanstatic import generate_code, Library, Resource
 
 
def test_generate_source():
    foo = Library('foo', '')
    i5 = Resource(foo, 'i5.js', depends=[i3])
 
    assert generate_code(i1=i1, i2=i2, i3=i3, i5=i5) == '''\
from fanstatic import Library, Resource
 
    non_inlinable = Resource(foo, 'j3.js', debug=Resource(bar,
                                                          'j4.js'))
    generated = generate_code(j1=j1, j2=j2, giantj=giantj,
                              non_inlinable=non_inlinable)
    assert generated.startswith('''\
    i2 = Resource(foo, 'i2.js', depends=[i1])
 
    assert generate_code(hoi=i1) == '''\
from fanstatic import Library, Resource
 
hoi = Resource(foo, 'i1.js')'''
 
    assert generate_code(hoi=i1, i2=i2) == '''\
from fanstatic import Library, Resource
 

src/f/a/fanstatic-tools-0.2/fanstatic/test_codegen.py   fanstatic-tools(Download)
from fanstatic import generate_code, Library, Resource
 
 
def test_generate_source():
    foo = Library('foo', '')
    i5 = Resource(foo, 'i5.js', depends=[i3])
 
    assert generate_code(i1=i1, i2=i2, i3=i3, i5=i5) == '''\
from fanstatic import Library, Resource
 
    non_inlinable = Resource(foo, 'j3.js', debug=Resource(bar,
                                                          'j4.js'))
    assert generate_code(j1=j1, j2=j2, giantj=giantj,
                         non_inlinable=non_inlinable) == '''\
from fanstatic import Library, Resource
    i2 = Resource(foo, 'i2.js', depends=[i1])
 
    assert generate_code(hoi=i1) == '''\
from fanstatic import Library, Resource
 
hoi = Resource(foo, 'i1.js')'''
 
    assert generate_code(hoi=i1, i2=i2) == '''\
from fanstatic import Library, Resource
 

src/j/s/js.yui-2.8.2-1/js/yui/prepare.py   js.yui(Download)
import json
 
from fanstatic import Library, Resource, generate_code
 
YUI_VERSION = '2.8.2'
 
    # now generate code
    return generate_code(**inclusion_map)
 
def load_json(version):