vic

vic

Asdf Core Team

Deco - minimal function decorators with around advice

Yep, yet another library for function decorators in Elixir. This one however, is smaller and simple

   defp is_authorized(decorated, conn, params) do
      if conn.assigns.user do
        decorated.(conn, params)
      else
        conn
        |> send_resp(401, "unauthorized")
        |> halt()
      end
   end

   deco {Deco.around(is_authorized)} in
   def create(conn, params) do
     ...
   end

Most Liked

tmbb

tmbb

Very cool :smiling_face_with_sunglasses:

Not in the sense thatbI’d ever use it, but in the sence that it makes me want to use it, even though I probably shouldn’t…

I’ve written a similar thing, which I’ve named Doktor. It’s like you regular old Doc, but younger, cooler and more radiKal. Because it had a K. It allows you to write this:

defmodule My.Module do
  use Doktor, "dok/docstrings_for_my_module.md"
  @moduledok "My.Module"

  @dok "hey/0"
  def hey(), do: "Hey!"

  @dok "hello/1"
  def hello(name), do: "Hello #{name}!"
end

Basically, Doktor takes up an Markdown (MD - :joy:) file annotated in a special way and, extracts docstrings from that file and documents the functions with those docstrings. This kan help deKlutter your modules, because it moves the doKstrings somewhere else. I’m still not sure on how useful this is (or whether it is even a good thing at all), but it’s just so KOOL xD

The way it works is by overwriting the @ operator inside the use macro so that it treats the @dok, @moduledok and @typedok` In a special way. Although it’s completely different, it reminded me of this somehow.

vic

vic

Asdf Core Team

haha you got me, I’m always looking at what things I’m able to do with the Elixir syntax, and yeah, the formatter doesnt like it that much, maybe in could be treated just like do and allow a new line after it.

Hey Doktor looks awesome, I’ve been using just @moduledoc File.read!("README.md") but your tool looks nice. One thing I’ve noticed while running tests from an .md file is, I need to modify the .ex file importing it for the new tests to take place, otherwise it’s already compiled with no changes. How you’d handle that in doktor.

:slight_smile:

OvermindDL1

OvermindDL1

I like this trick of linking with in here! I wonder how the formatter formats that though, hmm…

Testing…

iex(1)> Code.format_string!("""
...(1)>    deco {Deco.around(is_authorized)} in
...(1)>    def create(conn, params) do
...(1)>      ...
...(1)>    end
...(1)> """) |> IO.puts()
deco {Deco.around(is_authorized)} in def(create(conn, params)) do
  ...
end

Aww that’s sad, and no way to fix the formatter for this either currently…

Last Post!

tmbb

tmbb

I’ve released Doktor (not public on hex yet, or maybe ever): Doktor: extract docs from external files

It now has a much better design. It still doesn’t use the @external_resource thing. I should add it…

Where Next?

Popular in Announcing Top

zorbash
I created Kitto a framework for dashboards inspired by Dashing. The distributed characteristics of Elixir and the low memory footprint...
New
bryanjos
Hi, I just published version 0.23.0 of Elixirscript. https://github.com/bryanjos/elixirscript/blob/master/CHANGELOG.md Most of the chan...
New
tmbb
I’ve published the first version of my Makeup library. It’s a syntax highlighter for Elixir in the spirit of Pygments, Currently it highl...
New
josevalim
Yes, yet another parser combinator library! Most of the parser combinators in the ecosystem are either compile-time, often using AST tra...
159 19951 141
New
wfgilman
I’ve cleaned up and open sourced three financial libraries I was using for my company. They are bindings for the APIs of these three comp...
New
nikokozak
Hello all, I’ve been working on Svonix - a library for quickly integrating Svelte components into Phoenix views. It’s a much-needed succ...
New
trisolaran
Hi! :waving_hand: I would like to present LiveSelect, a little library that I wrote to easily add a dynamic selection input to your LV f...
198 11283 107
New

Other popular topics Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31586 112
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49266 226
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New

We're in Beta

About us Mission Statement