LoginSignup
15
13

More than 5 years have passed since last update.

EJSの使い方を訳してみた(中途半端でごめんなさい)

Posted at

EJSのドキュメントページの内容を勝手な理解で訳してみました。(英語全然わからないので)
Google翻訳と推測による翻訳なので、間違いなどあったらご指摘頂けると嬉しいです!
http://ejs.co/

Get Started(はじめよう的な)

Install(インストール)

It's easy to install EJS with NPM.(NPMでEJSをインストールするの簡単)

$ npm install ejs

Use(使う)

Pass EJS a template string and some data. BOOM, you've got some HTML.(EJSにテンプレート文字列といくつかのデータを渡します。いくつかのHTMLが出来上がりました。でいいのか?)

※BOOM = スラングで物事が瞬時に終わる様子らしい

var ejs = require('ejs'),
    people = ['geddy', 'neil', 'alex'],
    html = ejs.render('<%= people.join(", "); %>', {people: people});

Browser support(ブラウザサポート)

Download a browser build from the latest release, and use it in a script tag.(最新のリリースからブラウザのビルドをダウンロードし、スクリプトタグで使用します。)

<script src="ejs.js"></script>
<script>
  var people = ['geddy', 'neil', 'alex'],
      html = ejs.render('<%= people.join(", "); %>', {people: people});
</script>

Docs(ドキュメント)

Example(使用例)

<% if (user) { %>
  <h2><%= user.name %></h2>
<% } %>

Usage(使用法)

var template = ejs.compile(str, options);
template(data);
// => Rendered HTML string

ejs.render(str, data, options);
// => Rendered HTML string

Options(オプション)

cache Compiled functions are cached, requires filename(コンパイルされた関数はキャッシュされます、filename が必要です。よくわからん。)
filename Used by cache to key caches, and for includes(キーキャッシュにキャッシュを使用、その為に使われる?ここもよくわからん。)
context Function execution context(関数の実行コンテキスト)
compileDebug When false no debug instrumentation is compiled(考え中)
client Returns standalone compiled function(考え中)
delimiter Character to use with angle brackets for open/close(考え中)
debug Output generated function body(考え中)
_with Whether or not to use with() {} constructs. If false then the locals will be stored in the locals object.(考え中)

Tags(タグ)

<% 'Scriptlet' tag, for control-flow, no output(制御フローのためのスクリプトレットタグ、出力されない)
<%= Outputs the value into the template (HTML escaped)(テンプレートに値を出力する、HTMLエスケープされる)
<%- Outputs the unescaped value into the template(エスケープされない版)
<%# Comment tag, no execution, no output(EJSのコメントタグ)
<%% Outputs a literal '<%'(EJSタグのリテラル)
%> Plain ending tag(通常の閉じタグ)
-%> Trim-mode ('newline slurp') tag, trims following newline(改行したあとの閉じタグってこと?)

Includes(インクルード)

Includes are relative to the template with the include call. (This requires the 'filename' option.) For example if you have "./views/users.ejs" and "./views/user/show.ejs" you would use <%- include('user/show'); %>.(考え中)

You'll likely want to use the raw output tag (<%-) with your include to avoid double-escaping the HTML output.(考え中)

<ul>
  <% users.forEach(function(user){ %>
    <%- include('user/show', {user: user}); %>
  <% }); %>
</ul>

Customer delimiters(考え中)

Custom delimiters can be applied on a per-template basis, or globally:(考え中)

var ejs = require('ejs'),
    users = ['geddy', 'neil', 'alex'];

// Just one template
ejs.render('%lt;?= users.join(" | "); ?>', {users: users},
    {delimiter: '?'});
// => 'geddy | neil | alex'

// Or globally
ejs.delimiter = '$';
ejs.render('<$= users.join(" | "); $>', {users: users});
// => 'geddy | neil | alex'
15
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
13