Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

z #9

Open
wants to merge 100 commits into
base: data_franca_work_branch
Choose a base branch
from
Open

z #9

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
13ab57b
Completed data_franca library.
simonask Jun 6, 2014
d422081
First steps to migrating old Node/MutableNode code to use data_franca.
simonask Jun 6, 2014
93cd50d
Finished transition to data_franca API
simonask Jun 9, 2014
bc255f7
Consolidated all serialization/deserialization (including DB interact…
simonask Jun 9, 2014
25c67bf
Updated TODO
simonask Jun 9, 2014
ac2fd05
Nullability for RecordPtr data_franca Adapter
simonask Jun 9, 2014
751770d
Fixed some minor bugs in data_franca
simonask Jun 9, 2014
8bd88b1
BelongsTo<T>::operator=
simonask Jun 9, 2014
61da57e
assign_attributes, create
simonask Jun 9, 2014
8e98a84
String utility: split
simonask Jun 9, 2014
b367322
Put POST params in Request.params
simonask Jun 9, 2014
263e75b
Include string support library in build
simonask Jun 11, 2014
0a91318
Monad interface for PrimaryKey
simonask Jun 11, 2014
91580ca
persistence: INSERT support
simonask Jun 11, 2014
5f39c88
Better error message
simonask Jun 11, 2014
e5d7602
Made tests compile again
simonask Jun 11, 2014
b542beb
Spelunker -> Spectator
simonask Jun 11, 2014
28c506a
Devirtualized a bit of the RecordType interface, and removed a number…
simonask Jun 11, 2014
a467ce7
Refactored Associations interface to support better introspection, an…
simonask Jun 14, 2014
6180c59
New belongs_to/has_many/has_one API, and implementation of HasMany::load
simonask Jun 14, 2014
bb68e4f
URI::decode now correctly changes '+' to ' '.
simonask Jun 14, 2014
44a191e
Renamed find_by_primary_key to find.
simonask Jun 15, 2014
a5a5d56
ProjectionReader -> Adapter<Projection>
simonask Jun 15, 2014
23ed511
Fixed a number of datetime bugs (not all)
simonask Jun 15, 2014
153d48f
Send headers and body when making a HTTP request.
simonask Jun 15, 2014
d88bc22
Let Spectator create an owning reader when passed an rvalue reference.
simonask Jun 15, 2014
fd1be91
"Magically" set created_at for new records, if the property exists.
simonask Jun 15, 2014
584f816
Updated blog example.
simonask Jun 15, 2014
38c7834
Brought DateTime into feature-parity with POSIX time functions, and t…
simonask Jun 15, 2014
3adc985
Synth binding: Support length/count for lists.
simonask Jun 15, 2014
3c08e2f
Improved safety of DateTime API
simonask Jun 16, 2014
0864b9f
Removed unnecessary load()
simonask Jun 19, 2014
cec5f8a
Removed unused header, added some missing includes.
simonask Jun 23, 2014
c7ed54b
Any class, and some fixes to the monad library.
simonask Jun 23, 2014
e1e7bab
Merge branch 'master' of github.com:simonask/w
simonask Jun 24, 2014
8a36de2
Maybe-specialization for reference types.
simonask Jun 24, 2014
68aa2c7
Any, AnyRef, AnyConstRef
simonask Jun 24, 2014
9e4c3cc
Missing includes.
simonask Jun 24, 2014
ec2670d
Any: Provide access to type info.
simonask Jun 25, 2014
bbd3070
TypeInfo: Add "get_id" member that returns the result of typeid(T)
simonask Jun 25, 2014
59a6f90
Overhaul of monad types Either, Maybe, and Result, and monad::fmap
simonask Jun 25, 2014
9d25e96
IType provides access to TypeInfo
simonask Jun 25, 2014
c726c57
Use AnyRef instead of DataRef everywhere.
simonask Jun 25, 2014
6ca1462
Removed DataRef class
simonask Jun 25, 2014
d6fdccb
Refactored persistence::insert into different isolatable steps. Combi…
simonask Jun 25, 2014
9d51a20
wayward::monad: Support monads with multiple parameters.
simonask Jun 26, 2014
33a6be4
Introduced trait "IsPointerLike" that's used by Maybe to implement a
simonask Jun 26, 2014
3573fc5
ISQLTypeMapper for mapping values to SQL literals.
simonask Jun 26, 2014
db82ee9
Moved IType and get_type into Wayward Support.
simonask Jun 26, 2014
30421da
Related Any-types can now convert to each other.
simonask Jun 26, 2014
220ff25
Updated SConstruct
simonask Jun 26, 2014
0886588
Some insertion checks progress.
simonask Jun 26, 2014
423e66f
Revert "Moved IType and get_type into Wayward Support."
simonask Jun 26, 2014
5d79916
Moved PostgreSQL adapter into its own directory.
simonask Jun 26, 2014
e6bd72f
Moved responsibility for converting values to SQL literals into ISQLT…
simonask Jun 26, 2014
16c62c5
Updated SConstruct
simonask Jun 26, 2014
3bcf5fb
Ripped out TypeMapper interface.
simonask Jun 26, 2014
cb31dbd
Fixed a bug in Any.
simonask Jun 26, 2014
ac6dd20
Fixed BelongsToType::make_literal
simonask Jun 27, 2014
1c60b39
Better Result API
simonask Jun 27, 2014
d6a6271
Added some static asserts to Any
simonask Jun 27, 2014
5e1a474
Use save_or_throw
simonask Jun 27, 2014
976e040
Stub ValidationErrors class.
simonask Jun 28, 2014
fbdf9d4
Initial work on session support.
simonask Jun 28, 2014
0394aab
Unified serialization/deserialization/reflection API.
simonask Jun 29, 2014
b1372e2
persistence: Using DataVisitor API for Projection, moved a lot of cod…
simonask Jun 29, 2014
c84dfa8
Removed an unnecessary cast.
simonask Jun 29, 2014
64d6f63
Moved private implementation things into detail namespace
simonask Jun 29, 2014
30e6fbc
persistence: Moved a lot of code into projection.cpp instead of proje…
simonask Jun 29, 2014
91f61aa
Use C++1y
simonask Jun 29, 2014
4ffe25d
Merge branch 'master' of github.com:simonask/w
simonask Jun 30, 2014
b08ddd0
Use DataVisitor in assign_attributes.
simonask Jul 9, 2014
d616955
Fixed BelongsTo
simonask Jul 9, 2014
432cda1
Initial efforts with some documentation.
simonask Jul 21, 2014
1019970
A little more documentation.
simonask Jul 21, 2014
ef67e75
UTF8-aware String/Char classes.
simonask Jul 23, 2014
55d042c
Documentation for data_franca.
simonask Jul 23, 2014
72ec002
Benchmark library.
simonask Jul 23, 2014
2d4b2cd
Fixed a potential bug where type coercion would prefer a weaker conve…
simonask Jul 23, 2014
ab81d5f
Some more docs.
simonask Jul 23, 2014
8bebe60
Added info from README to docs.
simonask Jul 23, 2014
7e8d45d
Commit to C++14.
simonask Jul 23, 2014
3e685f6
Updated .gitignore
simonask Jul 23, 2014
0ed97e2
"w_dev new" command.
simonask Jul 24, 2014
7c96748
Added TODO.
simonask Jul 24, 2014
f405284
Updated docs to reflect new w_dev functionality.
simonask Jul 24, 2014
e6b4555
Updated .gitignore
simonask Jul 24, 2014
f347f15
docs typo
simonask Jul 24, 2014
7195f57
Merge branch 'master' of github.com:simonask/w
simonask Aug 12, 2014
b8a198c
String trim.
simonask Aug 16, 2014
aa47e19
persistence: shorter form of referring to columns by member pointers
simonask Aug 16, 2014
ec93b8d
Initial work on w::respond_to
simonask Aug 16, 2014
df26d60
Support for implicit "format" parameter.
simonask Aug 16, 2014
d810170
Fixed build with newer Synth.
simonask Oct 17, 2014
2fa87c7
Changed synth submodule to my fork.
simonask Oct 17, 2014
b96c83a
Fixed synth submodule
simonask Oct 17, 2014
0b5029e
.gitignore
simonask Oct 17, 2014
7ed6366
scons install support
simonask Oct 17, 2014
a961412
Including shorthand headers in install by default.
simonask Oct 17, 2014
bff797f
Merge branch 'master' of github.com:simonask/w
simonask Oct 31, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ w_dev
*.os
*.o
.sconsign.dblite
site
*.pyc
wayward_synth.plugin
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
url = https://github.com/simonask/libevhtp.git
[submodule "3rdparty/synth"]
path = 3rdparty/synth
url = https://github.com/ajg/synth.git
url = https://github.com/simonask/synth.git
2 changes: 1 addition & 1 deletion 3rdparty/synth
Submodule synth updated 142 files
142 changes: 130 additions & 12 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ from wayward_build import *
import os

wayward_support_sources = Split("""
wayward/support/any.cpp
wayward/support/benchmark.cpp
wayward/support/format.cpp
wayward/support/uri.cpp
wayward/support/node.cpp
wayward/support/json.cpp
wayward/support/datetime/datetime.cpp
wayward/support/datetime/clock.cpp
wayward/support/datetime/interval.cpp
wayward/support/datetime/type.cpp
wayward/support/logger.cpp
wayward/support/error.cpp
wayward/support/command_line_options.cpp
Expand All @@ -17,42 +19,156 @@ wayward_support_sources = Split("""
wayward/support/http.cpp
wayward/support/teamwork.cpp
wayward/support/plugin.cpp
wayward/support/mutable_node.cpp
wayward/support/data_franca/spectator.cpp
wayward/support/data_franca/mutator.cpp
wayward/support/data_franca/object.cpp
wayward/support/string.cpp
wayward/support/types.cpp
3rdparty/libevhtp/evhtp.c
3rdparty/libevhtp/htparse/htparse.c
3rdparty/libevhtp/evthr/evthr.c
""")

wayward_support_headers = Split("""
wayward/support/uri.hpp
wayward/support/types.hpp
wayward/support/type_info.hpp
wayward/support/type.hpp
wayward/support/thread_local.hpp
wayward/support/teamwork.hpp
wayward/support/string.hpp
wayward/support/result.hpp
wayward/support/plugin.hpp
wayward/support/options.hpp
wayward/support/monad.hpp
wayward/support/meta.hpp
wayward/support/maybe.hpp
wayward/support/logger.hpp
wayward/support/json.hpp
wayward/support/intrusive_list.hpp
wayward/support/http.hpp
wayward/support/format.hpp
wayward/support/fiber.hpp
wayward/support/event_loop.hpp
wayward/support/error.hpp
wayward/support/either.hpp
wayward/support/datetime.hpp
wayward/support/data_visitor.hpp
wayward/support/data_franca.hpp
wayward/support/command_line_options.hpp
wayward/support/cloning_ptr.hpp
wayward/support/bitflags.hpp
wayward/support/benchmark.hpp
wayward/support/any.hpp
wayward/support/data_franca/adapter.hpp
wayward/support/data_franca/adapters.hpp
wayward/support/data_franca/mutator.hpp
wayward/support/data_franca/node.hpp
wayward/support/data_franca/object.hpp
wayward/support/data_franca/reader.hpp
wayward/support/data_franca/spectator.hpp
wayward/support/data_franca/types.hpp
wayward/support/data_franca/writer.hpp
wayward/support/datetime/clock.hpp
wayward/support/datetime/datetime.hpp
wayward/support/datetime/duration_units.hpp
wayward/support/datetime/interval.hpp
wayward/support/datetime/timezone.hpp
wayward/support/datetime/type.hpp
""")

wayward_sources = Split("""
wayward/app.cpp
wayward/render.cpp
wayward/log.cpp
wayward/template_engine.cpp
wayward/respond_to.cpp
wayward/content_type.cpp
""")

wayward_headers = Split("""
wayward/content_type.hpp
wayward/respond_to.hpp
wayward/routes.hpp
wayward/session.hpp
wayward/template_engine.hpp
wayward/w.hpp
w
""")

w_util_sources = Split("""
w_util/server.cpp
w_util/recompiler.cpp
w_util/main.cpp
w_util/init.cpp
""")

wayward_testing_sources = Split("""
wayward/testing/time_machine.cpp
""")

wayward_testing_headers = Split("""
wayward/testing/time_machine.hpp
""")

persistence_sources = Split("""
persistence/connection_provider.cpp
persistence/connection_retainer.cpp
persistence/adapter.cpp
persistence/data_store.cpp
persistence/connection_pool.cpp
persistence/p.cpp
persistence/postgresql.cpp
persistence/postgresql_renderers.cpp
persistence/adapters/postgresql/connection.cpp
persistence/adapters/postgresql/renderers.cpp
persistence/primary_key.cpp
persistence/relational_algebra.cpp
persistence/types.cpp
persistence/datetime.cpp
persistence/insert.cpp
persistence/property.cpp
persistence/data_as_literal.cpp
persistence/projection.cpp
persistence/column.cpp
persistence/assign_attributes.cpp
""")

persistence_headers = Split("""
persistence/adapters/postgresql/connection.hpp
persistence/adapters/postgresql/renderers.hpp
persistence/adapter.hpp
persistence/assign_attributes.hpp
persistence/association.hpp
persistence/ast.hpp
persistence/belongs_to.hpp
persistence/column.hpp
persistence/column_abilities.hpp
persistence/column_traits.hpp
persistence/connection.hpp
persistence/connection_pool.hpp
persistence/connection_provider.hpp
persistence/connection_retainer.hpp
persistence/context.hpp
persistence/create.hpp
persistence/data_as_literal.hpp
persistence/data_store.hpp
persistence/datetime.hpp
persistence/destroy.hpp
persistence/has_many.hpp
persistence/has_one.hpp
persistence/insert.hpp
persistence/p.hpp
persistence/persistence_macro.hpp
persistence/primary_key.hpp
persistence/projection.hpp
persistence/projection_as_structured_data.hpp
persistence/property.hpp
persistence/record.hpp
persistence/record_as_structured_data.hpp
persistence/record_ptr.hpp
persistence/record_type.hpp
persistence/record_type_builder.hpp
persistence/relational_algebra.hpp
persistence/result_set.hpp
persistence/validation_errors.hpp
p
""")

wayward_synth_sources = Split("""
Expand All @@ -61,14 +177,14 @@ wayward_synth_sources = Split("""

env = WaywardEnvironment(DefaultEnvironment())

wayward_support = WaywardLibrary(env, 'wayward_support', wayward_support_sources)
wayward_support = WaywardLibrary(env, 'wayward_support', wayward_support_sources, wayward_support_headers)
env_with_ws = env.Clone()
env_with_ws.Append(LIBS = [wayward_support])
wayward = WaywardLibrary(env_with_ws, 'wayward', wayward_sources)
wayward_testing = WaywardLibrary(env_with_ws, 'wayward_testing', wayward_testing_sources)
wayward = WaywardLibrary(env_with_ws, 'wayward', wayward_sources, wayward_headers)
wayward_testing = WaywardLibrary(env_with_ws, 'wayward_testing', wayward_testing_sources, wayward_headers)

env_for_synth = env.Clone()
env_for_synth.Append(CPPPATH = Split('3rdparty/synth'))
env_for_synth.Append(CPPPATH = Split('3rdparty/synth 3rdparty/synth/external/boost'))
wayward_synth = WaywardPlugin(env_for_synth, 'wayward_synth', wayward_synth_sources)

if platform.system() == 'Linux':
Expand All @@ -79,13 +195,15 @@ else:

persistence_env.Append(CCFLAGS = Split(libpq_cflags))
persistence_env.Append(LINKFLAGS = Split(libpq_libs))
persistence = WaywardLibrary(persistence_env, 'persistence', persistence_sources)
persistence = WaywardLibrary(persistence_env, 'persistence', persistence_sources, persistence_headers)

WaywardAddDefaultLibraries([wayward, persistence, wayward_support])

w_dev = WaywardProgram(env_with_ws, 'w_dev', w_util_sources, rpaths = ['.'])

Export('env', 'wayward', 'wayward_support', 'persistence', 'wayward_testing', 'WaywardProgram', 'WaywardLibrary', 'WaywardEnvironment')
env.Alias('install', ['install-bin', 'install-lib', 'install-inc'])

Export('env', 'wayward', 'wayward_support', 'persistence', 'wayward_testing', 'WaywardProgram', 'WaywardInternalProgram', 'WaywardLibrary', 'WaywardEnvironment')

build_tests = ARGUMENTS.get('build_tests', 'yes')
if build_tests == 'yes':
Expand Down
3 changes: 1 addition & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ Persistence
Wayward
-------

- Params de-/restructuralization
- Dictionary class that returns Maybe<T> for non-existing values.
- Make sure that plugin architecture (and Synth) is working on Linux.

Wayward Support
Expand All @@ -24,3 +22,4 @@ Wayward Support
- Path utility functions (maybe a path class).
- A string class that does proper UTF-8 handling.
- A HTML class representing a string that is unescaped HTML.
- Find better names for everything in data_franca.
70 changes: 70 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Wayward Overview

[GitHub](https://github.com/simonask/w)

Did your dad ever tell you: "Writing web apps in C++ is dangerous and stupid! You should know better!"?

Well he's not the boss of you! You can do whatever you want!

Wayward ("`<w>`") is a web framework for writing HTTP-aware apps in C++. It uses [libevent](http://libevent.org/) behind
the scenes to create a compact HTTP server that can act as the backend for your app.

`<w>` is heavily inspired by the Ruby framework Sinatra, and aims to keep things as simple as possible.
It uses the C++ Standard Template Library extensively.

***WARNING!*** Wayward is as of yet still in early alpha, and should not, I repeat *NOT* be used in production just yet. Several big pieces are missing, and the rest is a semi-explosive mess that is probably unfit for human *and* animal consumption. Don't say you weren't warned. If you're looking for production-quality code, come back in a few releases, I'm sure we'll have something cooking for you.


## Getting Started

Wayward is both a library and a command-line utility, named `w_dev`. Wayward apps can exist without `w_dev`, but it does make life for developers a lot easier. `w_dev` creates projects, generates standardized components in projects, and has a built-in development server that automatically rebuilds and restarts your app when you make changes to it, allowing for live "Rails-style" coding.

### Building `w_dev`

1. Make sure dependencies are installed (git, scons, clang, libevent).
2. `git clone --recursive https://github.com/simonask/w.git`
3. `cd w`
4. `scons -j8 w_dev` (This will only build the necessary components for `w_dev`. Running with `-jN` makes scons run tasks in parallel.)

### Creating a Project

1. `cd ~/your/path/to/projects`
2. `path/to/w_dev new my_project`
3. Wait for `w_dev` to finish installing dependencies in your project dir.
4. You now have a project named `my_project` in `~/your/path/to/projects`.

### Building and Running

1. `cd my_project`
3. `path/to/w_dev server my_project`
4. Browse to `localhost:3000`. The first request in the lifetime of the project will take some time.

On the first request to the app server, `w_dev` will build your app. This may take about a minute the very first time because it also needs to build Wayward and dependencies, but subsequent requests will only cause a rebuild of the things that have changed in your own project. Normal turnaround for an incremental build should be very short.


## Sample "Hello World"

#include <w>

int main(int argc, char** argv) {
w::App app { argc, argv };

app.get("/", [](w::Request& req) {
return w::render_text("Hello, World!");
});

return app.run();
}

## Dependencies

Dependency management in C++ apps is a pain, so `<w>` tries to keep it to a minimum.

- [libevent 2.0.x](http://libevent.org/)
- [Clang](http://clang.llvm.org/) and [libc++](http://libcxx.llvm.org/) — GCC will be supported in the future, but there are some disagreements between Clang++ and g++ that are holding back that development
- SCons 2.3.0 or newer.
- For Persistence: `libpq` (from PostgreSQL).

`<w>` has been tested on the following platforms:

- OS X 10.9.2 with Apple Clang-503.0.40
1 change: 1 addition & 0 deletions docs/persistence.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Persistence ORM Framework
Empty file added docs/wayward/advanced_routes.md
Empty file.
37 changes: 37 additions & 0 deletions docs/wayward/overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Wayward Web Framework

Wayward lives in the namespace `wayward`, which by default is aliased as `w`. To disable this, compile your app with `WAYWARD_NO_SHORTHAND_NAMESPACE` defined. Every time you see `w::`, it can be substituted for `wayward::`.

The core of a Wayward app is an instance of `App`, which is used to define the routes and bring up a listening HTTP server.

The simplest Wayward app looks like this:

#include <w>

int main(int argc, char** argv) {
w::App app { argc, argv };

app.get("/", [](w::Request& req) {
return w::render_text("Hello, World!");
});

return app.run();
}

A slightly more advanced example could include a parameter in the route definition:

#include <w>

int main(int argc, char** argv) {
w::App app { argc, argv };

app.get("/hello/:person", [](w::Request& req) {
return w::render_text("Hello, {0}!", req.params["person"]);
});
}

Going to `/hello/Steve` will then render the text "Hello, Steve!" in the browser.

See the documentation for [Routing](routing.md) for more ways to define routes.

See the [Advanced Routes](advanced_routes.md) for ways to define more complex route handlers.
9 changes: 9 additions & 0 deletions docs/wayward/request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Requests

All route handlers get called with a reference to a `w::Request` object. The `Request` object is a simple structure representing an HTTP request.

See also: [Wayward Support: HTTP Library](support/http.md)

From the perspective of a route handler, the most interesting parts of a request are the headers, the params, the [URI](support/uri.md), and the request body, if one is provided.

Params defined in the route with the `:` syntax will appear in the `params` member, as well as any GET and POST parameters passed from the client.
23 changes: 23 additions & 0 deletions docs/wayward/response.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Rendering Responses

Wayward comes with a number of predefined ways to render a quick HTTP response.

## w::not_found

Returns a generic 404 Not Found with Content-Type `text/plain`.

## w::render_text

Invoke: `render_text(format, ...)`

Returns a 200 OK response with Content-Type `text/plain`. The body of the response is the interpolation of the arguments. `w::render_text` treats its arguments equivalent to [`w::format`](support/format.md).

## w::redirect

Invoke: `redirect(new_url, [status])`

Returns a 302 Found response (or a different status code, if `status` is set), with the `Location` header set to `new_url`.

## w::render

See: [Templates](templates.md)
Loading