Commits

Tetsuya Morimoto committed e3f0409

added fanstatic samples

  • Participants
  • Parent commits 09c2903

Comments (0)

Files changed (7)

File fanstatic_sample/myapp/foo/__init__.py

Empty file added.

File fanstatic_sample/myapp/foo/main.py

+# -*- coding: utf-8 -*-
+from fanstatic import Fanstatic
+from static import resources as static_resources
+
+def app(environ, start_response):
+    start_response('200 OK', [])
+    static_resources.need()
+    html = """
+    <html>
+      <head></head>
+      <body>
+        <button type="button" id="sample_btn">Click Me!</button>
+      </body>
+    </html>
+    """
+    return [html]
+
+if __name__ == "__main__":
+    from wsgiref.simple_server import make_server
+    fapp = Fanstatic(app)
+    server = make_server('0.0.0.0', 8080, fapp)
+    server.serve_forever()

File fanstatic_sample/myapp/foo/static.py

+from fanstatic import Group, Library, Resource
+from js.jquery import jquery
+
+_resources = [jquery]
+
+lib_foo = Library("foo", "static")
+foo_js = Resource(lib_foo, "base.js", depends=[jquery], bottom=True)
+_resources.append(foo_js)
+
+foo_css = Resource(lib_foo, "base.css", bottom=True)
+_resources.append(foo_css)
+
+resources = Group(_resources)

File fanstatic_sample/myapp/foo/static/base.css

+/*
+ * base.css
+ */
+
+button {
+    border-color: #666666;
+    background-color: #E8E6E1;
+    font-size: large;
+    padding: 10px;
+}

File fanstatic_sample/myapp/foo/static/base.js

+$(function() {
+
+    $("#sample_btn").click(function() {
+        alert("Hello World");
+    });
+
+});

File fanstatic_sample/myapp/setup.py

+# -*- coding: utf-8 -*-
+from setuptools import setup
+
+setup(
+    name="myapp",
+    version="0.1",
+    install_requires=["fanstatic", "js.jquery"],
+    entry_points={
+        "fanstatic.libraries": [
+            "foo = foo.static:lib_foo",
+        ],
+    },
+)

File fanstatic_sample/quick.py

+# -*- coding: utf-8 -*-
+from fanstatic import Fanstatic
+from js.jquery import jquery
+
+def app(environ, start_response):
+    start_response('200 OK', [])
+    jquery.need()
+    return ['<html><head></head><body>Hello World</body></html>']
+
+if __name__ == "__main__":
+    from wsgiref.simple_server import make_server
+    fanstatic_app = Fanstatic(app)
+    server = make_server('0.0.0.0', 8080, fanstatic_app)
+    server.serve_forever()