Skip to content

Instantly share code, notes, and snippets.

Make each module and each site an Erlang (library) app.
This means that each module should be structured like this:
├── dispatch
├── ebin
├── lib
│   ├── css
│   ├── images
├── src
│   ├── actions

The main idea is to split off Zotonic's functionality in a set of OTP apps. Each site will become its own app. Modules are treated specially. They are also erlang apps, containing a simple-one-for-one supervisor, in which each child process is an actual running instance of the module for a specific site.

The most powerful feature of zotonic is its extensibility and flexibility. Zotonic consists of one or more sites, each of which use functionality which is contained in modules. In the site context, tools exist to communicate between these through notifications: a prioritized publish/subscribe mechanism for the exchange of messages through maps and folds.

The z_core app will consist of functions for starting/stopping sites and modules, broadcasting notifications within sites, and code for the indexing of the module files (e.g. for template finding; z_module_indexer). For sites and modules, behaviours will be created to reduce the amount of boilerplate code when implementing sites/modules.

% My attempt to document all the Erlang-isms that I come across
% mostly from the wonderful book by Joe Armstrong (which I highly recommend)
% Extracting values from tuples
Point = {point, 10, 45}.
{point, X, Y} = Point.
X. % Will return 10
Y. % Will return 45.
% Extracting elements from a list
% Write a ring benchmark. Create N processes in a ring. Send a message
% round the ring M times so that a total of N * M messages get sent.
% Time how long this takes for different values of N and M.
% -- Joe Armstrong, "Programming Erlang"
% Copyright (c) 2008-2010 Ivan Fomichev
%
% 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
-module(urlget).
% Hacked by Roland and Erik Aug 1997
%% Joe Armstrong
%% get_http(Fun, URL, OPts, Proxy, Timeout) ->
%% ok{URL', Header, Body} | error{What}
%% URL' is the actual URL that was gotten
@chinnurtb
chinnurtb / Erlang Inets POST Request
Created August 9, 2013 12:37
Erlang Inets POST Request
$ erl
Erlang R16B01 (erts-5.10.2) [source] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
Eshell V5.10.2 (abort with ^G)
1> inets:start().
ok
2> httpc:request(post, {"http://www.google.com/",[],"application/x-www-form-urlencoded", "hl=en&q=erlang&btnG=Google+Search&meta="},[], []).
{ok,{{"HTTP/1.1",405,"Method Not Allowed"},
[{"date","Fri, 09 Aug 2013 12:32:09 GMT"},
{"server","gws"},
@chinnurtb
chinnurtb / Erlang OTP Release Version
Created August 9, 2013 12:38
Erlang OTP Release Version
$ erl
Erlang R16B01 (erts-5.10.2) [source] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
Eshell V5.10.2 (abort with ^G)
1> erlang:system_info(otp_release).
"R16B01"

Webmachine State Machine

General

  • Service available?
    • callback: service_available?
    • false: 503 Service Unavailable
  • Known method?
    • callback: known_methods
  • absent: 501 Not Implemented
@chinnurtb
chinnurtb / dragon_resource.erl
Created August 16, 2013 12:11
A Content-less PUT that returns 201 or 409 This webmachine resource accepts a PUT request to create a new resource. No content and no content headers are required in the request. A successful request returns 201, and the new resource is accessible at the same url as the PUT. If the resource already exists a 409 is returned.
-module(dragon_resource).
-export([init/1,
allowed_methods/2,
content_types_accepted/2,
accept_content/2,
resource_exists/2
]).
-include_lib("webmachine/include/webmachine.hrl").
@chinnurtb
chinnurtb / CURL view Response Headers
Created August 16, 2013 12:31
CURL view Response Headers
curl -i http://127.0.0.1:8000