패키지, 저장소 및 앱 카테고리 검색

패키지 상세v0.7.2

jinja

Dart용 Jinja2 템플릿 엔진. 변수, 표현식, 제어 구조 및 템플릿 상속.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
4.9만
좋아요
48
Pub 점수
160

패키지 설치

flutter pub add jinja

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

Jinja는 Jinja2 템플릿 엔진의 Dart 구현으로, 변수, 표현식, 제어 구조 및 템플릿 상속을 통해 동적 콘텐츠 생성을 가능하게 합니다. 서버 사이드 렌더링을 지원하며 웹 프레임워크와 잘 통합됩니다. 백엔드 서비스 및 웹 애플리케이션에서 사용하도록 설계되어 강력한 템플릿 기능을 통해 로직과 표시를 분리할 수 있습니다. 이 패키지는 모바일, 웹, 데스크톱을 포함한 모든 주요 플랫폼에서 실행됩니다.

사용 사례

  • 서버 사이드 렌더링
  • 동적 HTML 생성
  • 템플릿 기반 콘텐츠 생성
  • 웹 애플리케이션 레이아웃
  • API 기반 템플릿
  • 다중 플랫폼 템플릿

주요 기능

  • 변수 및 표현식 지원
  • 제어 구조 (if, for)
  • 템플릿 상속
  • 크로스 플랫폼 호환성
  • 경량이고 빠름
  • Dart 앱과의 간편한 통합

적합한 대상

  • 백엔드 개발자
  • 풀스택 웹 개발자
  • 템플릿 기반 애플리케이션
  • 서버 렌더링 웹 애플리케이션
  • 다트 기반 웹 프레임워크

고려 사항

  • 클라이언트 측 렌더링을 위한 것이 아님
  • 제한된 문서
  • Jinja2 구문에 대한 이해가 필요합니다
  • 서버 환경에 가장 적합
  • 내장된 보안 필터 없음
  • 사용자 입력에 대한 추가 검증이 필요할 수 있습니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

jinja

Pub Package Test Status CodeCov

Jinja (3.x) server-side template engine port for Dart 3. Variables, expressions, control structures and template inheritance.

Documentation

It is mostly similar to Jinja templates documentation, differences provided below.

work in progress.

Differences with Python version

  • Auto-escaping and related statements, filters and tests have been removed due to the impossibility of extending String. Use the escape filter manually or escape values before passing them to the template.
  • The default filter compares values with null.
  • The defined and undefined tests compare values with null.
  • The map filter also compares values with null. Use attribute and item filters for object.attribute and object[item] expressions.
  • If Environment({getAttribute}) is not passed, the getItem method will be used. This allows you to use {{ map.key }} as an expression equivalent to {{ map['key'] }}.
  • String slices and negative indexes are not supported (list slicing [start:stop] with non-negative integers is supported).
  • Macro arguments without default values are required.
  • No FilterArgumentError error class.
  • No *args and **kwargs arguments.
  • No Template module.
  • work in progress

Dynamically invoked members (can increase the size of the JS output)

  • [], +, -, *, /, ~/, % operators
  • object.length getter
  • object.call getter
  • Function.apply(function, ...)

Example

import 'package:jinja/jinja.dart';

// ...

var environment = Environment(blockStart: '...', blockEnd: '...');
var template = environment.fromString('...source...');
print(template.render({'key': value}));
// or write directly to StringSink (IOSink, HttpResponse, ...)
template.renderTo(stringSink, {'key': value});

See also examples with conduit and reflectable.

Status:

TODO:
  • Informative error messages
    • Template name 🔥
    • Source span 🔥
  • Template class:
    • generate method
    • stream method
  • Relative template paths
  • Async Support
  • Template Inheritance
    • Super Blocks
      • {{ super.super() }}
  • List of Control Structures
    • Extends
      • Execute non-block statements and expressions
        {% extends 'base.html' %}
        {% set title = 'Index' %}
        {% macro header() %}
          <h1>{{ title }}</h1>
        {% endmacro %}      ```
        {% block body %}
          {{ header() }}
        {% endblock %}
        
  • Expressions
    • Dart Methods and Properties
      • !./?.
  • Loaders
    • PackageLoader (VM)
    • ...
  • List of Global Functions
    • lipsum
    • cycler
    • joiner
  • Extensions
    • i18n
    • Loop Controls
    • Debug Statement
  • Template compiler (builder)
  • ...
Done:

Note: item - not supported

  • Variables
  • Filters
    • forceescape
    • safe
    • unsafe
  • Tests
    • escaped
  • Comments
  • Whitespace Control
  • Escaping (only escape filter)
  • Line Statements
    • Comments
    • Blocks
  • Template Inheritance
    • Base Template
    • Child Template
    • Super Blocks
    • Nesting extends
    • Named Block End-Tags
    • Block Nesting and Scope
    • Required Blocks
    • Template Objects
  • HTML Escaping
  • List of Control Structures
    • For
    • If
    • Macro
    • Call
    • Filters
    • Assignments
    • Block Assignments
    • Extends
    • Blocks
    • Include
    • Import
    • Try / Catch
  • Import Context Behavior
  • Expressions with filters and tests
    • Literals
      • "Hello World"
      • 42 / 123_456
      • 42.23 / 42.1e2 / 123_456.789
      • ['list', 'of', 'objects']
      • ('tuple', 'of', 'values')
      • {'dict': 'of', 'key': 'and', 'value': 'pairs'}
      • true / false
      • null
    • Math
      • +
      • -
      • /
      • //
      • %
      • *
      • **
    • Comparisons
      • ==
      • !=
      • >
      • >=
      • <
      • <=
    • Logic
      • and
      • or
      • ?? (null-coalescing / fallback)
      • not
      • (expr)
    • Other Operators
      • in
      • is
      • |
      • ~
      • ()
      • ./[]
      • [:] (list slice)
    • Conditional Expressions
      • {{ list.last if list }}
      • {{ user.name if user else 'Guest' }}
      • {{ condition ? 'yes' : 'no' }} (ternary operator)
    • Dart Methods and Properties (if reflection is on)
      • {{ string.toUpperCase() }}
      • {{ list.add(item) }}
  • List of Global Functions
    • dict
    • print
    • range
    • list
    • namespace
  • Loaders
    • FileSystemLoader
    • MapLoader (equivalent to Jinja's DictLoader)
  • Extensions
    • Expression Statement (do)
    • With Statement
  • Autoescape Overrides

Contributing

Contributions are welcome! Please open an issue or pull request on GitHub. Look at the ToDo list and comments in the code for ideas on what to work on. There are no strict rules, but please try to follow the existing code style.

As non-native English speaker and learner, I will be grateful for any corrections in the documentation and code comments.

Support

Post issues and feature requests on the GitHub issue tracker.

카테고리

의존성

의존성 목록 5 개

소스 저장소

이 패키지를 사용하는 프로젝트