Skip to content

Commit

Permalink
0.10.1 - fix erlydtl use of gettext
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-rubio committed May 4, 2024
1 parent 75f10b7 commit 19cac06
Show file tree
Hide file tree
Showing 16 changed files with 418 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/lambdapad/generate/pages.ex
Expand Up @@ -50,6 +50,8 @@ defmodule Lambdapad.Generate.Pages do
|> Map.put("name", name)
|> Map.update(:env, %{"language" => atom_lang}, &Map.put(&1, "language", atom_lang))

config = Map.put(config, "language", language)

pages =
page_data
|> Sources.get_files(workdir)
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Expand Up @@ -6,7 +6,7 @@ defmodule Lambdapad.MixProject do
name: "Lambdapad",
description: "Static website generator",
app: :lambdapad,
version: "0.10.0",
version: "0.10.1",
elixir: "~> 1.11",
start_permanent: Mix.env() == :prod,
deps: deps(),
Expand Down
5 changes: 5 additions & 0 deletions samples/blogerl/assets/bootstrap.min.css

Large diffs are not rendered by default.

78 changes: 78 additions & 0 deletions samples/blogerl/assets/styles.css
@@ -0,0 +1,78 @@
body {
padding-top: 20px;
padding-bottom: 60px;
}

h2 {
font-size: 28px;
}

.jumbotron {
margin: 0 0 40px;
padding: 20px 10px 30px;
text-align: center;
}

.jumbotron h1 {
font-size: 52px;
line-height: 1;
}
.jumbotron .lead {
font-size: 24px;
line-height: 1.25;
}
.jumbotron .btn {
font-size: 21px;
padding: 14px 24px;
}
.marketing {
margin: 60px 0;
}
.marketing p + h4 {
margin-top: 28px;
}

.navbar .navbar-inner {
padding: 0;
}
.navbar .nav {
margin: 0;
display: table;
width: 1%;
}
.navbar .nav li {
display: table-cell;
width: 1%;
float: none;
}
.navbar .nav li a {
font-weight: bold;
text-align: center;
border-left: 1px solid rgba(255,255,255,.75);
border-right: 1px solid rgba(0,0,0,.1);
}
.navbar .nav li:first-child a {
border-left: 0;
border-radius: 3px 0 0 3px;
}
.navbar .nav li:last-child a {
border-right: 0;
border-radius: 0 3px 3px 0;
}

.body {
padding: 0 10px;
}

.recent-posts tr {
vertical-align: top;
}

.recent-posts td {
padding-right: 10px;
padding-bottom: 5px;
}

.post-info {
font-style: italic;
}
7 changes: 7 additions & 0 deletions samples/blogerl/blog.config
@@ -0,0 +1,7 @@
#{
title => "My Life With LambdaPad",
description => "
Tales of daily life using the amazing LambdaPad
for my every site generating need.",
url => "http://localhost:8080/"
}.
80 changes: 80 additions & 0 deletions samples/blogerl/index.erl
@@ -0,0 +1,80 @@
-module(index).

-define(SITE_ROOT, "/").

config(_Args) ->
#{
blog => {eterm, "blog.config"}
}.

assets(_Config) ->
#{
files => {"assets/*.css", "site/css"}
}.

widgets(_Config) ->
#{
"recent posts" => {
template, "recent-posts.html",
{posts, "posts/**/*.md"},
#{
env => #{
site_root => ?SITE_ROOT
}
}
}
}.

pages(Config) ->
Blog = get_value("blog", Config),
Workdir = get_value("workdir", Blog),
#{
"/" => {
template, "index.html",
{about, "snippets/about.md"},
#{
env => #{
site_root => ?SITE_ROOT
}
}
},
"/posts" => {
template, "posts.html",
{posts, "posts/**/*.md"},
#{
env => #{
site_root => ?SITE_ROOT
}
}
},
"/posts/{{ post.id }}" => {
template_map, "post.html",
{post, "posts/**/*.md"},
#{
env => #{
site_root => ?SITE_ROOT
}
}
},
"/examples" => {
template, "example.html",
undefined,
#{
env => #{
site_root => ?SITE_ROOT,
example_file_content => get_current_file(Workdir),
example_file => "index.erl"
}
}
}
}.

get_value(String, Config) when is_list(String) ->
get_value(list_to_binary(String), Config);
get_value(Binary, Config) ->
maps:get(Binary, Config).

get_current_file(Workdir) ->
Filename = iolist_to_binary([Workdir, "/index.erl"]),
{ok, Content} = file:read_file(Filename),
Content.
98 changes: 98 additions & 0 deletions samples/blogerl/posts/first-impressions.md
@@ -0,0 +1,98 @@
id : first-impressions
title : My First Impressions Of LambdaPad
date : 2014-08-09
author : Stan The Martian
excerpt: How the Erlang based site generator strikes my fancy.

Having used LambdaPad for my awesome blog, here is my first impression.

The good:

- It's explicit - very little magic
- Great [Django template](https://docs.djangoproject.com/en/dev/ref/templates/)
support
- Great [Markdown](http://daringfireball.net/projects/markdown/) support with
[multimarkdown](http://fletcherpenney.net/multimarkdown/)
- Seems pretty fast, with nice "re-generate only what's changed" (some bugs
though)
- Believe it or not, the Erlang site definition is actually pretty damn easy to
read and maintain

The less-than-good:

- Documentation is pretty much non-existent
- Bug with re-generating content depending on template ``extends`` and
``includes`` directives
- Would be nice to have a "watch" feature where the site is automatically
updated as underlying sources are changed
- Not sure how I can include content from within a markdown source (Sphinx has
this feature and it's indispensable)

## Being Explicit

I've worked a lot with [Hyde](http://hyde.github.io) --- it's a terrific static
site generator written in Python. However, I'm routinely confused and surprised
by what it does and have I have a hard time tracking down answers. It uses a
lot of cleverness, which may be powerful in one respect, but it's also hard to
follow.

LambdaPad has [*one* configuration file](../examples/index.erl.html), which
defines the site structure and the data that feeds the generators.

## Django Templates

The
[Django template language](https://docs.djangoproject.com/en/dev/ref/templates/)
is remarkably useful for defining site content. Just take a look at the
templates used for this blog! With the ``extends`` tag you can defined
base-level templates that provide overall site look-and-feel and structure and
then customize each page as needed within that structure. With the ``include``
tag you can include template snippets. This is great for frequently used
content that doesn't appear in a base template --- e.g. the "Recent Posts"
section listed on this page an include.

## Multimarkdown

Multimarkdown is a very functional and fast markdown processor. Check out
[the feature list](http://fletcherpenney.net/multimarkdown/features/) --- it's
all available (I think, well, at least the Markdown-to-HTML support) in
LambdaPad!

## Smart Content Generation

LambdaPad keeps track of sources that effect generated content. For the most
part, this works very well --- when you rebuild a site, content is generated
only when the underlying sources have changed. This is pretty damn nice. And
fast!

LambdaPad does have a bug where it fails to track templates that are included
or inherited from. So if you change a base template or an included snippet, you
won't get the right content re-generated. You can work around this of course by
manually deleting the effected targets, but this is a pain and this bug should
be fixed.

## Erlang Syntax

Check out [the site definition for this blog](../examples/index.erl.html) and
judge for yourself!

## Things To Look Forward To

LambdaPad is pretty function today, but it still has a ways to go. There are
some bugs but those will get fixed if the Calculus has anything to say about
it. Documentation will be a major effort, but that will fall into place (it's
pretty easy already to write a blog in LambdaPad --- docs can't be that far
behind).

I can imagine a feature where LambdaPad runs in a continual "watch" mode and
just re-generates content immediately when something changes. This would be
uber productive and stupendous and great.

From the look of my own ``index.erl`` for this blog, I wonder if some of the
syntax could possibly be improved. I know that functions can be used to express
things clearly --- and I've tried to do that --- but I wonder how this will
look to me over time. And when I'm drinking.

Keep an eye out for complexity and weirdness. This approach to site generation
could go horribly wrong if the LP authors aren't careful. Keep it simple --- as
simple as possible!
33 changes: 33 additions & 0 deletions samples/blogerl/posts/why-erlang.md
@@ -0,0 +1,33 @@
id : why-erlang
title : Why Erlang?
date : 2014-08-08
author : Stan The Martian
excerpt: Why on Earth was Erlang chosen as the language for LambdaPad?

Every site generator seems to be written in Ruby, Python, or Node.js these
days. Screw that. We want something *functional*. We want something
*awesome*. So the Propositional Calculus [^calculus] answered our prayers and gave us
*LambdaPad*.

There are a few principles that show up in this tool, which are inspired by
patterns in function programming:

- Magic is a pariah --- the goal is that behavior be up front and obvious
- Site data and structure is returned itself as data and is acted on by
LambdaPad --- transformation and other actions are provided as needed, but
they're not called directly by the site itself

Of course, none of these require *Erlang*. They're just principles and
patterns.

If you use LambdaPad, you'll learn a little a little Erlang --- in the same way
you'll learn a little Python if you use [Hyde](http://hyde.github.io). That's a
good thing. While LambdaPad is not a massively scalable server (heck, it
doesn't even spawn processes, yet --- though parallel execution could be on the
road map!) it's a nice example of an Erlang application. If you're inclined to
dig deeper, your knowledge of Erlang will improve.

That's the idea.

[^calculus]: Refer to this video for more on the Calculus:
<p><iframe width="420" height="345" src="https://www.youtube.com/embed/zY-IueSMAPc"></iframe></p>
11 changes: 11 additions & 0 deletions samples/blogerl/snippets/about.md
@@ -0,0 +1,11 @@
title: About
author: Garrett Smith

LambdaPad is static site generator written in Erlang. You might think that
sounds crazy, because you think everything cool should be written in Go,
Node.js, or --- if you're an old school hipster --- Ruby.

But LambdaPad doesn't care about being cool. It cares about being
*awesome*. And it is... *awesome*.

This blog is a record of my experiences with LambdaPad.
42 changes: 42 additions & 0 deletions samples/blogerl/templates/base.html
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>{{ blog.title }}</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="{{ blog.description }}">
<meta name="author" content="{{ blog.author }}">
<link href="{{site_root}}css/bootstrap.min.css" rel="stylesheet">
<link href="{{site_root}}css/bootstrap-responsive.min.css" rel="stylesheet">
<link href="{{site_root}}css/styles.css" rel="stylesheet">
</head>

<body>

<div class="container">
<div class="row">
<div class="col-md-1"></div>
<div class="col-md-10">
<div class="masthead">
<div class="navbar">
<div class="navbar-inner">
<div class="container">
<ul class="nav">
<li class="active"><a href="{{site_root}}index.html">Home</a></li>
<li><a href="{{site_root}}posts/index.html">Posts</a></li>
</ul>
</div>
</div>
</div><!-- /.navbar -->
</div>

<div class="body">
{% block body %}{% endblock %}
</div>

</div>
<div class="col-md-1"></div>
</div>
</div>
</body>
</html>
6 changes: 6 additions & 0 deletions samples/blogerl/templates/example.html
@@ -0,0 +1,6 @@
{% extends "base.html" %}

{% block body %}
<h1>{{ example_file }}</h1>
<pre>{{ example_file_content }}</pre>
{% endblock %}
10 changes: 10 additions & 0 deletions samples/blogerl/templates/index.html
@@ -0,0 +1,10 @@
{% extends "base.html" %} {% block body %} {% include "jumbotron.html" %}

<div class="container">
<div class="row">
<div class="col-md-7">{{ about.content | safe }}</div>
{% widget "recent posts" %}
</div>
</div>

{% endblock %}
4 changes: 4 additions & 0 deletions samples/blogerl/templates/jumbotron.html
@@ -0,0 +1,4 @@
<div class="jumbotron">
<h1>{{ blog.title }}</h1>
<p class="lead">{{ blog.description }}</p>
</div>

0 comments on commit 19cac06

Please sign in to comment.