zambal / marker Goto Github PK
View Code? Open in Web Editor NEWSmall and performant library for writing HTML markup in Elixir using templates and components
License: Other
Small and performant library for writing HTML markup in Elixir using templates and components
License: Other
When a module use Marker.HTML
, all tag functions are included. How can I exclude one or more tags from the inclusion list?
Specifically, I want to write like this:
defmodule NanoPlanner.TopView do
use NanoPlanner.Web, :view
use Marker.HTML
def foo(list) do
div do
for item <- list do
span item, class: "item"
end
end
end
end
This causes a compilation error:
** (CompileError) web/templates/top/index.html.eex:2: function link/2 imported from both Phoenix.HTML.Link and Marker.HTML, call is ambiguous
I know that you assume that we use Marker
(not Marker.HTML
) and define templates for the Phoenix framework, but I want to define a normal function to generate HTML fragment within a view module.
I would like to use Marker in a Phoenix project, but it seems that it does not know how to deal with encoding the result of phoenix-generate html (i.e. helpers):
template :index do
form_for @conn, user_path(@conn, :create), [as: :search], fn f ->
label "Name: #{text_input f, :name}"
label "Age: #{select f, :age, 18..100}"
submit "Submit"
end
end
protocol String.Chars not implemented for {:safe, [60, "input", [[32, "id", 61, 34, "search_name", 34], [32, "name", 61, 34, "search[name]", 34], [32, "type", 61, 34, "text", 34]], 62]}. This protocol is implemented for: Atom, BitString, Date, DateTime, Decimal, Ecto.Date, Ecto.DateTime, Ecto.Time, Float, Hound.Element, Integer, List, NaiveDateTime, Postgrex.Copy, Postgrex.Query, Postgrex.Stream, Time, URI, Version, Version.Requirement
Since v1.6, Elixir features a code formatter. By default, it add parentheses to all functions or macro calls. The first Marker sample code would look like this once formatted:
use Marker.HTML
name = "Vincent"
html do
body do
div do
h3("Person")
p(name, class: "name")
p(2 * 19, class: "age")
end
end
end
It is however possible to declare locals_without_parens
in a .formatter.exs
to avoid this behaviour for DSL macros. For libraries like Marker, it is possible to export such configurations and import them in the user’s projects.
We should export all the Marker DSL macros as locals_without_parens
.
Hi,
I am trying to use marker to generate some html and it seems the generation is partial.
For instance, let say I have this component in MyTestComponent module
component :form_input do
custom_type = @type || "text" # default to text
# div class: "form-group" do
label @label, for: @id
input id: @id,
type: custom_type,
class: "a_class",
placeholder: @placeholder,
name: "name",
value: "a value"
# end
end
I use the component like this
use Marker
use Marker.HTML
require MyTestComponent
import MyTestComponent
form_input id: "label", label: "Label", placeholder: "My component name"
The output is missing the label element:
{ :safe, "<input id='label' type='text' class='pure-input-1' placeholder='My component name' name='name' value='a value'/>"}
If I uncomment the div element in the component definition, then I get the result:
I could live with this change but I tried the same for another component:
component :form_select do
div class: "form-group" do
label @label, for: @id
select @__content__, id: @id, class: "a_class"
end
end
And it did not work at all:
form_select id: "method", label: "Method", placeholder: "GET" do
option "GET", value: "GET"
option "PUT", value: "PUT"
option "POST", value: "POST"
option "DELETE", value: "DELETE"
end
output has no option at all:
"{ :safe, <div class='form-group'><label for='method'>Method</label><select id='method' class='a_class'></select></div>"}
Any idea what's wrong?
Thanks!
Howdy. This looks really neat. I already see your description that it integrates well with Phoenix...do you have an example "Hello World" project that does this?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.