alecStewart1
Hello there!
So I’ve been wanting to jump in Phoenix and I thought I’d try making it more difficult for myself with introducing Earmark into the equation.
I would say setting up like a blog, however I would find the CRUD way of doing things to be somewhat silly for me because…well it’s only me creating posts with Markdown.
I do have a few questions:
-
Should I bother with Ecto?
I’m more wondering what the best way to store everything. I think I should store both the Markdown itself and the generated HTML, in separate tables with a shared key like ID or something. Though I’m not the most experience with databases.
-
Potentially extending Earmark?
The two things I’d like to do is:
-
Have frontmatter in Markdown for posts
-
Components of sorts
Mainly just for use with things like code blocks and such.
Though maybe, for now, it would just be worth..somehow using remark? Though that sounds like it be a bit more of a headache.
-
-
ElixirLS to ignore certain folders.
I like that ElixirLS exists, however I wish I could tell it to not look in every directory in my project, slowing itself down and Emacs. Is it possible to have ElixirLS ignore some folders, or is that yet to be added in it’s functionality? Potentially specifying a
.gitignore?
Thank you for any answers you give!
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
kokolegorille
Hello and welcome,
This post might give You some idea…
alecStewart1
Oh I like that so far!
Thank you!
I feel like
Could maybe be abstracted better in some way, though. As opposed to this…mutlimethod(?) of sorts. Maybe.
kokolegorille
Ouch, this is typical Elixir code… and it’s hard to be more descriptive than this.
Maybe later You’ll enjoy this kind of code, when You’ll start to like pattern matching in function header
alecStewart1
Is there not some kind of metaprogramming facility that allows to us to abstract this away? Or simply pattern matching with
caseorwith?Like…oh
Or something?
kokolegorille
Using abstraction and multi methods suggests You are still thinking in OOP, but in FP You don’t have methods, just Module, Function and Arguments…
Of course You can simplify this, but using metaprogramming add complexity, or use a case.
But most will try to avoid this case, and use multiple header function.
In the end, it’s only one function
alecStewart1
Oh, I kind of get it. Because there’s functions like
fun/1andfun/2. The functions defined are based on their name and arity, right?kokolegorille
Yes, if You mean Elixir will treat them as 2 distincts functions. But what You described is just one.
Compare with this code…
It’s repetitive, but descriptive too.
srowley
You could be a little more terse with:
That does the same thing as your first example except that it will not throw an error if something other than
:title,:author,:description,:bodyor:tagsis passed as the first argument to that function. In that case it just returnsString.trim(value). You could make it throw an error by using a guard (see the example below), and not defining a function clause that matches the first argument on anything.The code below is what I think you intended to do with your second example, but there are two differences between this and that example:
valueif the first argument is:body(the second example would returnString.trim(value))String.trim(value)if the first argument is anything other than:tags).The third clause in that
caseblock will never match because:errorwould match on the second clause.As the other poster said, this is pretty idiomatic Elixir code. I felt like it would be confusing when I started learning Elixir, but now I find it much easier to read and reason about than one or more control flow blocks.
kokolegorille
You can do it with macros, but first rule is… don’t use macros.
It’s just harder to read.
RobertDober
… and easy to change!