@@ -243,13 +243,7 @@ defmodule Phoenix.LiveView.HTMLAlgebra do
243243 end
244244
245245 group =
246- concat ( [
247- "<#{ name } " ,
248- build_attrs ( attrs , "" , context . attr_formatters , context . opts ) ,
249- ">" ,
250- doc ,
251- "</#{ name } >"
252- ] )
246+ concat ( [ format_tag_open ( name , attrs , context ) , doc , "</#{ name } >" ] )
253247 |> group ( )
254248
255249 { :block , group }
@@ -308,21 +302,11 @@ defmodule Phoenix.LiveView.HTMLAlgebra do
308302
309303 defp to_algebra ( { :tag_self_close , name , attrs } , context ) do
310304 doc =
311- case attrs do
312- [ attr ] ->
313- concat ( [
314- "<#{ name } " ,
315- render_attribute ( attr , context . attr_formatters , context . opts ) ,
316- " />"
317- ] )
318-
319- attrs ->
320- concat ( [
321- "<#{ name } " ,
322- build_attrs ( attrs , " " , context . attr_formatters , context . opts ) ,
323- "/>"
324- ] )
325- end
305+ concat ( [
306+ "<#{ name } " ,
307+ build_attrs ( attrs , " " , context . attr_formatters , context . opts ) ,
308+ "/>"
309+ ] )
326310
327311 { :inline , group ( doc ) }
328312 end
@@ -438,18 +422,32 @@ defmodule Phoenix.LiveView.HTMLAlgebra do
438422
439423 defp build_attrs ( [ ] , on_break , _formatters , _opts ) , do: on_break
440424
425+ defp build_attrs ( [ attr ] , on_break , formatters , opts ) do
426+ concat ( [ " " , render_attribute ( attr , formatters , opts ) , on_break ] )
427+ end
428+
441429 defp build_attrs ( attrs , on_break , formatters , opts ) do
442- attrs
443- |> Enum . sort_by ( & attrs_sorter / 1 )
444- |> Enum . reduce (
445- empty ( ) ,
446- & concat ( [ & 2 , break ( " " ) , render_attribute ( & 1 , formatters , opts ) ] )
447- )
448- |> nest ( 2 )
449- |> concat ( break ( on_break ) )
450- |> group ( )
430+ doc =
431+ attrs
432+ |> Enum . sort_by ( & attrs_sorter / 1 )
433+ |> Enum . reduce (
434+ empty ( ) ,
435+ & concat ( [ & 2 , break ( " " ) , render_attribute ( & 1 , formatters , opts ) ] )
436+ )
437+ |> nest ( 2 )
438+ |> concat ( break ( on_break ) )
439+
440+ if distinct_lines? ( attrs , - 1 ) do
441+ doc |> force_unfit ( ) |> group ( )
442+ else
443+ group ( doc )
444+ end
451445 end
452446
447+ defp distinct_lines? ( [ { _ , _ , % { line: line } } | _ ] , line ) , do: false
448+ defp distinct_lines? ( [ { _ , _ , % { line: line } } | tail ] , _line ) , do: distinct_lines? ( tail , line )
449+ defp distinct_lines? ( [ ] , _line ) , do: true
450+
453451 @ attrs_order % {
454452 ":let" => 1 ,
455453 ":for" => 2 ,
@@ -466,9 +464,6 @@ defmodule Phoenix.LiveView.HTMLAlgebra do
466464 end
467465 end
468466
469- defp format_tag_open ( name , [ attr ] , context ) ,
470- do: concat ( [ "<#{ name } " , render_attribute ( attr , context . attr_formatters , context . opts ) , ">" ] )
471-
472467 defp format_tag_open ( name , attrs , context ) ,
473468 do: concat ( [ "<#{ name } " , build_attrs ( attrs , "" , context . attr_formatters , context . opts ) , ">" ] )
474469
0 commit comments