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

Webmachine State Machine

General

  • Service available?
    • callback: service_available?
    • false: 503 Service Unavailable
  • Known method?
    • callback: known_methods
  • absent: 501 Not Implemented
% copied from Mochiweb's mochiweb_uitl.erl
-module(url_encoder).
-export([encode/1]).
-define(PERCENT, 37). % $\%
-define(FULLSTOP, 46). % $\.
-define(IS_HEX(C), ((C >= $0 andalso C =< $9) orelse
(C >= $a andalso C =< $f) orelse
(C >= $A andalso C =< $F))).
-define(QS_SAFE(C), ((C >= $a andalso C =< $z) orelse
-module(strre).
-author("Daniel Kwiecinski: lambder.com").
-purpose("string replace functionality").
-export([sub/3,gsub/3,test/0]).
sub(Str,Old,New) ->
RegExp = "\\Q"++Old++"\\E",
re:replace(Str,RegExp,New,[multiline, {return, list}]).
gsub(Str,Old,New) ->
%% @author Daniel Kwiecinski <[email protected]>
%% @copyright Daniel Kwiecinski author.
%% @doc Example of redirect webmachine_resource.
-module(redirect_resource).
-export([init/1, resource_exists/2, moved_temporarily/2, previously_existed/2]).
-include_lib("webmachine/include/webmachine.hrl").
init([]) -> {ok, undefined}.
-module(scroogle_scrapper).
-compile(export_all).
-define(SCROOGLE_URL, "https://ssl.scroogle.org/cgi-bin/nbbw.cgi").
-define(SCROOGLE_PEM, "[PATH_TO_SSL_SCROOGLE_ORG_PEM_CERTIFICATE]").
start() ->
inets:start(),
ssl:start().