dox_view 3.2.0
dox_view: ^3.2.0 copied to clipboard
A template engine for the Dox framework, like Edge.js: layouts with components and slots, @if, @each and escaped output in .dox.html files.
3.2.0 #
- Fix:
dox add viewnow makesresources/views/emails/when the app has dox_mailer. Before, withdox add mailerrun first, the folder was never made, because the mailer only makes it when dox_view is there. - New:
dox add view(theview:installcommand). It adds the provider,resources/views/and a samplewelcome.dox.html. It never overwrites a file. New dependency:dox_annotation. - Ships an AI agent skill (dox-view-guide). Install it in your app with
dart run skills@ get. - New: with
bladeOutput, a number in$attributesprints like{{ }}.1.0istitle="1"and0.5stays0.5. With the option off, nothing changes:1.0istitle="1.0". - Fix:
@empty (none)alone on its line threw@empty has no @end. Now a tag with a body and a space before the(, like@isset (x)or@empty (x), is a tag only when its own@endcomes after it, on any line. The@endof a block around it does not count. Else the text stays as it is. Templates that worked before still work the same. - Fix: many nested tags with a space before the
(, like@isset (x), made the parse very slow. Each extra level took about twice as long, so 40 levels would take days. Now the parser counts the@endtags once, so the time grows in a straight line. - Fix: text like
@empty (none)or@class (see docs)threw an error since 3.1.0. The new rule is for a tag with a space before the(, in the middle of a line. It is a tag only when its args are a valid expression.@isset,@emptyand@envalso need an@endafter them. Else the text stays as it is. A tag with no space works as before. Templates that worked on 3.1.0 still work. - New:
$attributes.except(['variant'])leaves out props that are only for the logic of a component. It can go beforemerge(). - Fix: spaces after the last tag at the end of a file stayed in the output. A tag alone on its line now removes them, like it removes the line break.
- New: layouts with
@extends('layouts/app'),@section('name') ... @endand@yield('name').@yield('title', 'Home')has a default.@section('title', 'Home')is the short form. A layout can extend another layout. In a page with@extends, text outside a section is not printed. - New:
@stack('scripts')prints what@push('scripts') ... @endand@prepend('scripts') ... @endadd. Pushes work from the page, its layout, includes and components. A@stackthat comes before the@pushstill prints it. A@stackinside a@pushworks too. - New:
@csrfprints the hidden_tokenfield. It must be alone on its line. With no session it throws aViewException.@method('PUT')prints the hidden_methodfield. - New: your own tags.
View.directive('datetime', DateTimeDirective())adds@datetime(...). The class implementsViewDirective. The output is escaped, but aSafeStringis not.ViewConfigandViewEnginetakedirectivestoo. The name of a built-in tag throws aViewException.Scopeis now exported. - Note:
@extends(...),@section(...),@yield(...),@stack(...),@push(...),@prepend(...)and@method(...)were plain text before. Now they are tags. With no( )they stay text. With a space before the(, they are tags only when the first argument is text in quotes, so text likegit @push (force)stays text.@csrfis a tag only alone on its line. A component with the same name still wins. To print one as text, write@@push(...). - Docs: a
$authkey in the data ofView.rendermakes@authtrue there. Do not pass data from the user as$auth. - New:
@include('card', { title: 'Hi' })gives more variables to the template. The map wins over the variables of the page, and the page does not see it after the include.@includeIftakes the map as a third argument. A value that is not a map throws aViewException. - New:
@includeWhen(condition, 'name')includes a template when the condition is true. It does the same as@includeIf, which did not change. - New:
$loopalso hasiteration,count,remaining,even,odd,depthandparent. The first round is odd.index,first,lastandlengthare the same as before. - New:
@json(value)prints a value as JSON.<,>,&,'and the line separators U+2028 and U+2029 are written as\uXXXX, so it is safe inside a<script>block and inside an attribute in single quotes. Thejson(value)function gives the same text for{{ }}. In Dart it isSafeString.json(value). A value that can not be JSON throws aViewException. - New:
@error('email') ... @endshows its body whenerrorshas a message for the field.messageis the first message. A name with dots reads the key'user.email'first, thenemailinsideuser. With no errors it prints nothing. - New: a warning for Blade names that are not Dox tags:
{!! !!},@foreach,@forelse,@for,@while,@switch,@php,@show,@parent,@stop, and@endifwith the other@end...names. They are still printed as text. The warning goes tostderr, one time each, with the template, the line and the Dox way.ViewConfig(bladeWarnings: false)turns it off.ViewEnginetakeswarningSinkto send the warnings somewhere else. - New: three options in
ViewConfigandViewEngine. All three are off by default, so the output of an app does not change. Turn each one on inViewConfig.strictVariables: a variable that does not exist throws aViewExceptionwith its name.@isset(x),@empty(x),x ?? 'default'andx?.namedo not throw.stringZeroIsFalse: the text'0'is false in a condition.bladeOutput:trueprints1,falseprints nothing, and10.0prints10. - Note:
@includeWhen(...),@json(...)and@error(...)were plain text before. Now they are tags. With no( )they stay text.@jsonand@includeWhenare tags only with the(right after the name, so text likethe @json (format)stays text. With a space before the(,@erroris a tag only when the first argument is text in quotes, so text likean @error (see log)stays text. A component with the same name still wins. A directive of the app can not use these three names. - Note: with the
(right after the name, these three are always tags. So old text like@json(foo bar),@error(see log)or@includeWhen(x)printed as text before, and can now stop the render with aViewException. To print it as text, write@@json(...). - Note: every template now has a
jsonfunction. A variable namedjsonin your data or your globals still wins.{{ $loop }}as a whole now prints the new fields too.
3.1.0 #
- New tags:
@isset,@empty,@auth,@guest,@env,@production,@once,@verbatim,@class,@checked,@selectedand@disabled. A component with the same name still wins. With no( ),@isset,@empty,@env,@class,@checked,@selectedand@disabledstay plain text.@auth,@guest,@production,@onceand@verbatimare tags only alone on their line, so text like@once upon a timestays text.@envand@productionignore case, like the cache default. ViewEnginetakesenvironmentfor@envand@production. By default it isAPP_ENV.- Components get
$attributes: the props as HTML attributes, withmerge()for default attributes. The values are escaped. - Components get
$slot, the same as$slots.main. Before,$slots.mainwas missing when the component had no body. Now both are always there, as empty text. So{{ $slots.main ?? 'x' }}no longer printsxfor an empty body. - An empty
SafeString(no text at all) is now false in@if, like empty text. So a named slot with no text is false. A named slot with only spaces is still true. - Fix: an app global named
errorswas hidden by the emptyerrorsthat every view gets. Now the global shows when there are no validation errors. - Fix:
{{ errors.email }}threw an error when there was no session, and inView.render. Nowerrorsis always there: an empty map when there is no session, so the template prints nothing. - Fix: the
toJson()of an object was kept for the life of the object. A change to the object (for example a global) did not show in later renders. Now the cache lasts only one render.
3.0.0 #
- The first stable release.
3.0.0-rc.1 #
- Fix:
View.configure()dropped the globals added before it withView.global(). Now it keeps them. The globals of the config win on the same name.
3.0.0-alpha.3 #
ViewProvider(was a DoxService): extend it in your app,shutdown()is optional.
3.0.0-alpha.2 #
- Components and layouts now see the request helpers of
view():request,csrfField(),csrfToken(),errors,old()andsession(). Before, a form inside a layout failed withcan not read "path" of null. ViewEngine.rendertakes a third map,shared: data that components see too.- README: credits to Edge.js.
3.0.0-alpha.1 #
- First version.
- Templates in
.dox.htmlfiles, rendered withview(req, name, data)orView.render(name, data). {{ }}escapes HTML,{{{ }}}does not.{{-- --}}comments.@if,@elseif,@else,@unless,@each(with index, key,$loopand@else),@let,@assign,@includeand@includeIf.- Components with props and slots, for layouts too. A template in
components/is also a tag, like@button(...). - Expressions with fields, math, logic,
??,?:, functions and methods. Objects withtoJson()work, like Dox models. - With a session:
csrfField(),csrfToken(),errors,old()andsession().route()andrequestin every view. - Parsed templates are cached, but not when
APP_ENVisdevelopmentorlocal. - Errors name the template and the line.