?DEBUG и ?PRINT в Nitrogen (Erlang web-фреймворк)?

Начал изучать Erlang, скачал и установил веб-фреймворк Nitrogen, начал проходить туториал


Запустил страничку index.erl (были сложности, но разобрался сам)
%% -*- mode: nitrogen -*-
-module (index).
-compile(export_all).
-include_lib("nitrogen/include/wf.hrl").

main() -> #template { file="./site/templates/bare.html" }.

title() -> "Welcome to my Website".

body() ->
    #container_12 { body=[
        #grid_8 { alpha=true, prefix=2, suffix=2, omega=true, body=inner_body() }
    ]}.

inner_body() -> 
    [
        #h1 { text="Welcome to me" },
        #p{ },
        "
        If you can see this page, then your Nitrogen server is up and
        running. Click the button below to test postbacks.
        ",
        #p{}, 	
        #button { id=button, text="Click me!", postback=click },
        #p{},
        "
        Run <b>./bin/dev help</b> to see some useful developer commands.
        "
    ].
	
event(click) ->
    wf:replace(button, #panel { 
        body="You clicked the button!", 
        actions=#effect { effect=highlight }
    }).



дошёл в туториале до места
Debug Statements

Add ?DEBUG to index.erl. Then compile and reload. What happens?

Add ?PRINT(node()) to index.erl. Then compile and reload. What happens?



И как не пытаюсь их добавить, постоянно выдаёт ошибку компиляции. Гугление показало, что это макросы, но вот примеров их практического использования найти не смог.


Вопрос: как их добавить в код странички?
  • Вопрос задан
  • 3066 просмотров
Пригласить эксперта
Ответы на вопрос 1
VBart
@VBart
Например так:
event(click) ->
    ?DEBUG,
    wf:replace(button, #panel { 
        body="You clicked the button!", 
        actions=#effect { effect=highlight }
    }).

Будете кликать, будете получать debug-сообщение в консоль.

Или так:
inner_body() ->
    ?PRINT(node()),
    [
        #h1 { text="Welcome to my ERL-TASTIC WEBSITE!" },
        #p{},
        "
        If you can see this page, then your Nitrogen server is up and
        running. Click the button below to test postbacks.
        ",
        #p{}, 	
        #button { id=button, text="Click me!", postback=click },
        #p{},
        "
        Run <b>./bin/dev help</b> to see some useful developer commands.
        "
    ].


Будет сообщение в консоль при каждом открытии страницы, к тому же содержать название ноды.
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы