diff --git a/.gitignore b/.gitignore
index 7663424..3c8288c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,10 @@
+static/css/*
+!lib
+
+*.swp
.sass-cache
+.DS_Store
+.my.cnf
# github premade rules
*.py[cod]
@@ -18,7 +24,6 @@ var
sdist
develop-eggs
.installed.cfg
-lib
lib64
__pycache__
@@ -37,3 +42,15 @@ nosetests.xml
.mr.developer.cfg
.project
.pydevproject
+
+# Maven
+target
+
+# Ruby
+!parsers/ruby/lib
+
+# Ctags
+*/tags
+logs
+Gemfile.lock
+parsing.jar
diff --git a/LICENSE b/LICENSE
index edcb6e5..feaf8b8 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT)
-Copyright (c) 2014 Ben Kurtovic
+Copyright (c) 2014 Benjamin Attal, Ben Kurtovic, Severyn Kozak
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,4 @@ 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.
\ No newline at end of file
+SOFTWARE.
diff --git a/README.md b/README.md
index e6de751..6e8bacd 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,44 @@
bitshift
========
-bitshift is an online code snippet exchange.
+bitshift is a semantic search engine for source code developed by Benjamin
+Attal, Ben Kurtovic, and Severyn Kozak. This README is intended for developers
+only. For a user overview of the project:
+
+ * read our [about page](http://bitshift.it/)
+ * watch our [demo video](https://vimeo.com/98697078)
+
+Branches
+--------
+
+- `master`: working, tested, version-numbered code - no direct commits; should
+ only accept merges from `develop` when ready to release
+- `develop`: integration branch with unreleased but mostly functional code -
+ direct commits allowed but should be minor
+- `feature/*`: individual components of the project with untested, likely
+ horribly broken code - branch off from and merge into `develop` when done
+
+Style
+-----
+bitshift uses [SASS][SASS] for styling; compile the stylesheets to CSS with
+`sass --watch static/sass/:static/css`.
+
+Documentation
+-------------
+
+To build documentation, run `make html` from the `docs` subdirectory. You can
+then browse from `docs/build/html/index.html`.
+
+To automatically update the API documentation structure (necessary when adding
+new modules or packages, but *not* when adding functions or changing
+docstrings), run `sphinx-apidoc -fo docs/source/api bitshift` from the project
+root. Note that this will revert any custom changes made to the files in
+`docs/source/api`, so you might want to update them by hand instead.
+
+[SASS]: http://sass-lang.com/guide
+
+Releasing
+---------
+
+- Update `__version__` in `bitshift/__init__.py`, `version` in `setup.py`, and
+ `version` and `release` in `docs/conf.py`.
diff --git a/app.py b/app.py
index a7508c4..f05ba67 100644
--- a/app.py
+++ b/app.py
@@ -2,21 +2,67 @@
Module to contain all the project's Flask server plumbing.
"""
-from flask import Flask
-from flask import render_template, session
+from json import dumps
-from bitshift import *
+from flask import Flask, make_response, render_template, request
-app = Flask(__name__)
+from bitshift import assets
+from bitshift.database import Database
+from bitshift.languages import LANGS
+from bitshift.query import parse_query, QueryParseException
+
+app = Flask(__name__, static_folder="static", static_url_path="")
app.config.from_object("bitshift.config")
app_env = app.jinja_env
app_env.line_statement_prefix = "="
-app_env.globals.update(assets = assets)
+app_env.globals.update(assets=assets)
+
+database = Database()
@app.route("/")
def index():
- return render_template("index.html")
+ return render_template("index.html", autocomplete_languages=LANGS)
+
+@app.route("/search.json")
+def search():
+ def reply(json):
+ resp = make_response(dumps(json))
+ resp.mimetype = "application/json"
+ return resp
+
+ query = request.args.get("q")
+ if not query:
+ return reply({"error": "No query given"})
+ try:
+ tree = parse_query(query)
+ except QueryParseException as exc:
+ return reply({"error": exc.args[0]})
+
+ page = request.args.get("p", 1)
+ try:
+ page = int(page)
+ except ValueError:
+ return reply({"error": u"Invalid page number: %s" % page})
+
+ highlight = request.args.get("hl", "0")
+ highlight = highlight.lower() not in ["0", "false", "no"]
+
+ count, codelets = database.search(tree, page)
+ results = [clt.serialize(highlight) for clt in codelets]
+ return reply({"count": count, "results": results})
+
+@app.route("/about")
+def about():
+ return render_template("about.html")
+
+@app.route("/docs")
+def docs():
+ return render_template("docs.html")
+
+@app.errorhandler(404)
+def error404(error):
+ return render_template("error404.html"), 404
if __name__ == "__main__":
- app.run()
+ app.run(debug=True)
diff --git a/bitshift/__init__.py b/bitshift/__init__.py
index d51957e..0bd031c 100644
--- a/bitshift/__init__.py
+++ b/bitshift/__init__.py
@@ -1 +1,8 @@
-__all__ = ["config", "assets"]
+# -*- coding: utf-8 -*-
+
+__author__ = "Benjamin Attal, Ben Kurtovic, Severyn Kozak"
+__copyright__ = "Copyright (c) 2014 Benjamin Attal, Ben Kurtovic, Severyn Kozak"
+__license__ = "MIT License"
+__version__ = "0.1.dev"
+
+from . import assets, codelet, config, crawler, database, parser, query
diff --git a/bitshift/assets.py b/bitshift/assets.py
index 4754036..c7b7c11 100644
--- a/bitshift/assets.py
+++ b/bitshift/assets.py
@@ -1,22 +1,46 @@
"""
-Module contains helper functions to be used inside the project's Jinja
-templates.
+:synopsis: Helper functions for use inside the project's Jinja templates.
"""
+import re
+
from flask import Markup
ASSET_HTML_TEMPLATES = {
- 'css': "",
- 'js': ""
+ 'css': "",
+ 'js': ""
}
def tag(filename):
"""
- Return HTML tag for asset named filename.
+ Generate an HTML tag for a CSS/JS asset, based on its file extension.
+
+ :param filename: The filename of the asset to create a tag for.
+
+ :type filename: str
- Return either a
= endblock
= block body
-