Skip to content

Commit

Permalink
Add Surface formatter plugin and format
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagoefmoraes committed Sep 14, 2024
1 parent 7aade00 commit d0326d3
Show file tree
Hide file tree
Showing 41 changed files with 139 additions and 144 deletions.
5 changes: 4 additions & 1 deletion .formatter.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Used by "mix format"
[
import_deps: [:phoenix, :surface],
plugins: [Phoenix.LiveView.HTMLFormatter],
plugins: [
Phoenix.LiveView.HTMLFormatter,
Surface.Formatter.Plugin
],
line_length: 115,
inputs: [
"{mix,.formatter}.exs",
Expand Down
2 changes: 1 addition & 1 deletion lib/surface/components/form.ex
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ defmodule Surface.Components.Form do
~F"""
<!-- XXX -->
<.form :let={form} for={@for} action={@action} {...@opts}>
<#slot {@default, form: form} context_put={__MODULE__, form: form}/>
<#slot {@default, form: form} context_put={__MODULE__, form: form} />
</.form>
"""
end
Expand Down
2 changes: 1 addition & 1 deletion lib/surface/components/form/field.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ defmodule Surface.Components.Form.Field do
def render(assigns) do
~F"""
<div class={class_value(@class)}>
<#slot context_put={__MODULE__, field: @name}/>
<#slot context_put={__MODULE__, field: @name} />
</div>
"""
end
Expand Down
2 changes: 1 addition & 1 deletion lib/surface/components/form/field_context.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ defmodule Surface.Components.Form.FieldContext do
slot default, required: true

def render(assigns) do
~F[<#slot context_put={Field, field: @name}/>]
~F[<#slot context_put={Field, field: @name} />]
end
end
2 changes: 1 addition & 1 deletion lib/surface/components/form/input.ex
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ defmodule Surface.Components.Form.Input do
field = Context.get(assigns, Surface.Components.Form.Field, :field)

~F"""
<#slot {@default, form: @assigns[:form] || form, field: @assigns[:field] || field}/>
<#slot {@default, form: @assigns[:form] || form, field: @assigns[:field] || field} />
"""
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/surface/components/form/inputs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ defmodule Surface.Components.Form.Inputs do
def render(assigns) do
~F"""
<.inputs_for :let={nested_form} field={@form[@for || @field]} {...@opts}>
<#slot {@default, form: nested_form, index: nested_form.index } context_put={Form, form: nested_form} />
<#slot {@default, form: nested_form, index: nested_form.index} context_put={Form, form: nested_form} />
</.inputs_for>
"""
end
Expand Down
2 changes: 1 addition & 1 deletion lib/surface/components/form/label.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ defmodule Surface.Components.Form.Label do
assigns = assign(assigns, opts: opts)

~F"""
<label :attrs={input_id(@form, @field) ++ @opts}>
<label {...input_id(@form, @field) ++ @opts}>
<#slot>{@text || Phoenix.Naming.humanize(@field)}</#slot>
</label>
"""
Expand Down
2 changes: 1 addition & 1 deletion lib/surface/components/form/telephone_input.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ defmodule Surface.Components.Form.TelephoneInput do

assigns = assign(assigns, opts: opts)

~F[{telephone_input(@form, @field, @opts)}]
~F[{telephone_input(@form, @field, @opts)}]
end
end
2 changes: 1 addition & 1 deletion lib/surface/components/link/button.ex
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ defmodule Surface.Components.Link.Button do
assigns = assign(assigns, to: to, opts: events ++ opts)

~F"""
<button id={@id} class={@class} :attrs={@opts}><#slot>{@label}</#slot></button>
<button id={@id} class={@class} {...@opts}><#slot>{@label}</#slot></button>
"""
end

Expand Down
6 changes: 3 additions & 3 deletions priv/catalogue/surface/components/form/example01.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ defmodule Surface.Components.Form.Example01 do
~F"""
<Form for={%{}} as={:user} change="change" submit="submit" opts={autocomplete: "off"}>
<Field class="field" name="name">
<Label class="label"/>
<Label class="label" />
<div class="control">
<TextInput class="input" value={@user["name"]}/>
<TextInput class="input" value={@user["name"]} />
</div>
</Field>
<Field class="field" name="email">
<Label class="label">E-mail</Label>
<div class="control">
<TextInput class="input" value={@user["email"]}/>
<TextInput class="input" value={@user["email"]} />
</div>
</Field>
</Form>
Expand Down
6 changes: 1 addition & 5 deletions priv/catalogue/surface/components/form/textarea/example01.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ defmodule Surface.Components.Form.TextArea.Example01 do

def render(assigns) do
~F"""
<TextArea
rows="4"
class="textarea"
opts={placeholder: "4 lines of textarea"}
/>
<TextArea rows="4" class="textarea" opts={placeholder: "4 lines of textarea"} />
"""
end
end
4 changes: 2 additions & 2 deletions test/surface/components/context_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defmodule Surface.Components.ContextTest do
~F"""
<Inputs for={:children}>
<Field name={:name}>
<TextInput/>
<TextInput />
</Field>
</Inputs>
"""
Expand All @@ -25,7 +25,7 @@ defmodule Surface.Components.ContextTest do
render_surface do
~F"""
<Form for={%{}} as={:parent} opts={csrf_token: "test"}>
<InputsWithNestedField/>
<InputsWithNestedField />
</Form>
"""
end
Expand Down
4 changes: 2 additions & 2 deletions test/surface/components/field_context_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule Surface.Components.FieldContextTest do
render_surface do
~F"""
<FieldContext name="my_field">
<TextInput form="my_form"/>
<TextInput form="my_form" />
</FieldContext>
"""
end
Expand All @@ -21,7 +21,7 @@ defmodule Surface.Components.FieldContextTest do
render_surface do
~F"""
<FieldContext name={:my_field}>
<TextInput form="my_form"/>
<TextInput form="my_form" />
</FieldContext>
"""
end
Expand Down
2 changes: 1 addition & 1 deletion test/surface/components/field_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ defmodule Surface.Components.FieldTest do
render_surface do
~F"""
<Field name="my_field">
<TextInput form="my_form"/>
<TextInput form="my_form" />
</Field>
"""
end
Expand Down
14 changes: 7 additions & 7 deletions test/surface/components/form/checkbox_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ defmodule Surface.Components.Form.CheckboxTest do
html =
render_surface do
~F"""
<Checkbox form="user" field="admin" checked_value="admin"/>
<Checkbox form="user" field="admin" checked_value="admin" />
"""
end

Expand All @@ -88,7 +88,7 @@ defmodule Surface.Components.Form.CheckboxTest do
html =
render_surface do
~F"""
<Checkbox value={true}/>
<Checkbox value />
"""
end

Expand All @@ -97,7 +97,7 @@ defmodule Surface.Components.Form.CheckboxTest do
html =
render_surface do
~F"""
<Checkbox value={false}/>
<Checkbox value={false} />
"""
end

Expand All @@ -108,7 +108,7 @@ defmodule Surface.Components.Form.CheckboxTest do
html =
render_surface do
~F"""
<Checkbox hidden_input={true}/>
<Checkbox hidden_input />
"""
end

Expand All @@ -117,7 +117,7 @@ defmodule Surface.Components.Form.CheckboxTest do
html =
render_surface do
~F"""
<Checkbox hidden_input={false}/>
<Checkbox hidden_input={false} />
"""
end

Expand Down Expand Up @@ -199,7 +199,7 @@ defmodule Surface.Components.Form.CheckboxConfigTest do
html =
render_surface do
~F"""
<Checkbox/>
<Checkbox />
"""
end

Expand All @@ -213,7 +213,7 @@ defmodule Surface.Components.Form.CheckboxConfigTest do
html =
render_surface do
~F"""
<Checkbox/>
<Checkbox />
"""
end

Expand Down
10 changes: 5 additions & 5 deletions test/surface/components/form/color_input_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ defmodule Surface.Components.Form.ColorInputTest do
html =
render_surface do
~F"""
<ColorInput form="user" field="color" class="input"/>
<ColorInput form="user" field="color" class="input" />
"""
end

Expand All @@ -57,7 +57,7 @@ defmodule Surface.Components.Form.ColorInputTest do
html =
render_surface do
~F"""
<ColorInput form="user" field="color" class="input primary"/>
<ColorInput form="user" field="color" class="input primary" />
"""
end

Expand Down Expand Up @@ -126,7 +126,7 @@ defmodule Surface.Components.Form.ColorInputConfigTest do
html =
render_surface do
~F"""
<ColorInput/>
<ColorInput />
"""
end

Expand All @@ -139,7 +139,7 @@ defmodule Surface.Components.Form.ColorInputConfigTest do
html =
render_surface do
~F"""
<ColorInput/>
<ColorInput />
"""
end

Expand All @@ -153,7 +153,7 @@ defmodule Surface.Components.Form.ColorInputConfigTest do
html =
render_surface do
~F"""
<ColorInput/>
<ColorInput />
"""
end

Expand Down
10 changes: 5 additions & 5 deletions test/surface/components/form/date_input_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ defmodule Surface.Components.Form.DateInputTest do
html =
render_surface do
~F"""
<DateInput form="user" field="birthday" class="input"/>
<DateInput form="user" field="birthday" class="input" />
"""
end

Expand All @@ -57,7 +57,7 @@ defmodule Surface.Components.Form.DateInputTest do
html =
render_surface do
~F"""
<DateInput form="user" field="birthday" class="input primary"/>
<DateInput form="user" field="birthday" class="input primary" />
"""
end

Expand Down Expand Up @@ -126,7 +126,7 @@ defmodule Surface.Components.Form.DateInputConfigTest do
html =
render_surface do
~F"""
<DateInput/>
<DateInput />
"""
end

Expand All @@ -139,7 +139,7 @@ defmodule Surface.Components.Form.DateInputConfigTest do
html =
render_surface do
~F"""
<DateInput/>
<DateInput />
"""
end

Expand All @@ -153,7 +153,7 @@ defmodule Surface.Components.Form.DateInputConfigTest do
html =
render_surface do
~F"""
<DateInput/>
<DateInput />
"""
end

Expand Down
17 changes: 3 additions & 14 deletions test/surface/components/form/date_select_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,7 @@ defmodule Surface.Components.Form.DateSelectTest do
html =
render_surface do
~F"""
<DateSelect
form="user"
field="born_at"
year={prompt: "Year"}
month={prompt: "Month"}
day={prompt: "Day"}
/>
<DateSelect form="user" field="born_at" year={prompt: "Year"} month={prompt: "Month"} day={prompt: "Day"} />
"""
end

Expand All @@ -118,7 +112,7 @@ defmodule Surface.Components.Form.DateSelectTest do
"Month: ",
b.(:month, class: "month"),
"Day: ",
b.(:day, class: "day"),
b.(:day, class: "day")
]
end}
/>
Expand Down Expand Up @@ -157,12 +151,7 @@ defmodule Surface.Components.Form.DateSelectTest do
html =
render_surface do
~F"""
<DateSelect
form="user"
field="born_at"
id="born_at"
name="born_at"
/>
<DateSelect form="user" field="born_at" id="born_at" name="born_at" />
"""
end

Expand Down
10 changes: 5 additions & 5 deletions test/surface/components/form/datetime_local_input_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ defmodule Surface.Components.Form.DateTimeLocalInputTest do
html =
render_surface do
~F"""
<DateTimeLocalInput form="order" field="completed_at" class="input"/>
<DateTimeLocalInput form="order" field="completed_at" class="input" />
"""
end

Expand All @@ -44,7 +44,7 @@ defmodule Surface.Components.Form.DateTimeLocalInputTest do
html =
render_surface do
~F"""
<DateTimeLocalInput form="order" field="completed_at" class="input primary"/>
<DateTimeLocalInput form="order" field="completed_at" class="input primary" />
"""
end

Expand Down Expand Up @@ -113,7 +113,7 @@ defmodule Surface.Components.Form.DateTimeLocalInputConfigTest do
html =
render_surface do
~F"""
<DateTimeLocalInput/>
<DateTimeLocalInput />
"""
end

Expand All @@ -126,7 +126,7 @@ defmodule Surface.Components.Form.DateTimeLocalInputConfigTest do
html =
render_surface do
~F"""
<DateTimeLocalInput/>
<DateTimeLocalInput />
"""
end

Expand All @@ -140,7 +140,7 @@ defmodule Surface.Components.Form.DateTimeLocalInputConfigTest do
html =
render_surface do
~F"""
<DateTimeLocalInput/>
<DateTimeLocalInput />
"""
end

Expand Down
Loading

0 comments on commit d0326d3

Please sign in to comment.