Merge branch 'master' into pr/298

This commit is contained in:
Paul Tagliamonte 2013-10-10 17:30:03 -04:00
commit 8377097a36
5 changed files with 85 additions and 73 deletions

View File

@ -2,6 +2,8 @@
Hacking on hy
===============
.. highlight:: bash
Join our hyve!
==============
@ -21,24 +23,39 @@ Hack!
Do this:
1. create a `Python virtual environment
<https://pypi.python.org/pypi/virtualenv>`_
2. (optional) go to https://github.com/paultag/hy and fork it
3. get the source code::
1. create a `virtual environment
<https://pypi.python.org/pypi/virtualenv>`_::
$ git clone git://github.com/paultag/hy.git
$ virtualenv venv
(or use your fork)
4. install for hacking::
and activate it::
$ python setup.py develop
$ . venv/bin/activate
5. install other develop-y requirements::
or use `virtualenvwrapper <http://virtualenvwrapper.readthedocs.org/en/latest/#introduction>`_
to create and manage your virtual environment::
$ mkvirtualenv hy
$ workon hy
2. get the source code::
$ git clone https://github.com/hylang/hy.git
or use your fork::
$ git clone git@github.com:<YOUR_USERNAME>/hy.git
3. install for hacking::
$ cd hy/
$ pip install -e .
4. install other develop-y requirements::
$ pip install -r requirements-dev.txt
6. do awesome things; make someone shriek in delight/disgust at what
you have wrought
5. do awesome things; make someone shriek in delight/disgust at what
you have wrought.
Test!
@ -60,7 +77,7 @@ Document!
Documentation is located in ``docs/``. We use `Sphinx
<http://sphinx-doc.org/>`_.
To build the docs in html::
To build the docs in HTML::
$ cd docs
$ make html

View File

@ -24,8 +24,8 @@ languages.
* UTF-8 entities will be encoded using
`punycode <http://en.wikipedia.org/wiki/Punycode>`_ and prefixed with
`hy_`. For instance, `⚘` will become `hy_w7h`, and `♥` will become
`hy_g6h`.
`hy_`. For instance, `⚘` will become `hy_w7h`, `♥` will become `hy_g6h`,
and `i♥u` will become `hy_iu_t0x`.
* Symbols that contain dashes will have them replaced with underscores. For
example, `render-template` will become `render_template`.

54
hy/contrib/meth.hy Normal file
View File

@ -0,0 +1,54 @@
;;; Meth
;; based on paultag's meth library to access a Flask based application
(defmacro route [name path params code]
"Default get request"
`(let [[deco (.route app ~path)]]
(with-decorator deco
(defn ~name ~params ~@code))))
(defmacro route-with-methods [name path params code methods]
"Same as route but with an extra methods array to specify HTTP methods"
`(let [[deco (kwapply (.route app ~path)
{"methods" ~methods})]]
(with-decorator deco
(defn ~name ~params ~@code))))
;; Some macro examples
(defmacro post-route [name path params code]
"Post request"
`(route-with-methods ~name ~path ~params ~code ["POST"]))
(defmacro put-route [name path params code]
"Put request"
`(route-with-methods ~name ~path ~params ~code ["PUT"]))
(defmacro delete-route [name path params code]
"Delete request"
`(route-with-methods ~name ~path ~params ~code ["DELETE"]))
;;; Simple example application
;;; Requires to have Flask installed
;; (import [flask [Flask]])
;; (setv app (Flask "__main__"))
;; (require methy)
;; (print "setup / with GET")
;; (route get-index "/" [] (str "Hy world!"))
;; (print "setup /post with POST")
;; (post-route post-index "/post" [] (str "Hy post world!"))
;; (route-with-methods both-index "/both" []
;; (str "Hy to both worlds!") ["GET" "POST"])
;; (.run app)
;;; Now you can do:
;;; curl 127.0.0.1:5000
;;; curl -X POST 127.0.0.1:5000/post
;;; curl -X POST 127.0.0.1:5000/both
;;; curl 127.0.0.1:5000/both

View File

@ -1,58 +0,0 @@
# Copyright (c) 2013 Paul Tagliamonte <paultag@debian.org>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
from hy.models.expression import HyExpression
from hy.models.symbol import HySymbol
from hy.models.string import HyString
from hy.models.list import HyList
from hy.models.dict import HyDict
from hy.macros import macro
def router(tree, rkwargs=None):
tree = HyExpression(tree)
name = tree.pop(0)
path = tree.pop(0)
tree.insert(0, HySymbol("fn"))
tree = HyExpression([HySymbol("def"), name, tree])
route = HyExpression([HySymbol(".route"), HySymbol("app"), path])
if rkwargs:
route = HyExpression([HySymbol("kwapply"), route,
HyDict({HyString("methods"): rkwargs})])
return HyExpression([HySymbol("with_decorator"), route, tree])
@macro("route")
def route_macro(*tree):
return router(tree)
@macro("post_route")
def post_route_macro(*tree):
return router(tree, rkwargs=HyList([HyString("POST")]))
@macro("get_route")
def get_route_macro(*tree):
return router(tree, rkwargs=HyList([HyString("GET")]))

View File

@ -24,7 +24,6 @@ class HyObject(object):
Generic Hy Object model. This is helpful to inject things into all the
Hy lexing Objects at once.
"""
pass
def replace(self, other):
if isinstance(other, HyObject):