別のキーワード
種類
- インスタンスメソッド (10)
- モジュール関数 (5)
- モジュール (2)
- 特異メソッド (2)
- クラス (1)
クラス
- ERB (12)
モジュール
-
ERB
:: DefMethod (1) -
ERB
:: Util (4)
キーワード
- DefMethod (1)
- Util (1)
-
def
_ class (1) -
def
_ erb _ method (1) -
def
_ method (1) -
def
_ module (1) - filename (1)
- filename= (1)
- h (1)
-
html
_ escape (1) - new (1)
- result (1)
-
result
_ with _ hash (1) - run (1)
-
set
_ eoutvar (1) - src (1)
- u (1)
-
url
_ encode (1) - version (1)
検索結果
先頭5件
- ERB
- ERB
. new(str , safe _ level=NOT _ GIVEN , trim _ mode=NOT _ GIVEN , eoutvar=NOT _ GIVEN , trim _ mode: nil , eoutvar: & # 39; _ erbout& # 39;) -> ERB - ERB
# def _ class(superklass=Object , methodname=& # 39;erb& # 39;) -> Class - ERB
# def _ method(mod , methodname , fname=& # 39;(ERB)& # 39;) -> nil - ERB
# def _ module(methodname=& # 39;erb& # 39;) -> Module
-
ERB (114187.0)
-
eRuby スクリプトを処理するクラス。
...。
従来 ERbLight と呼ばれていたもので、
標準出力への印字が文字列の挿入とならない点が eruby と異なります。
* https://magazine.rubyist.net/articles/0017/0017-BundledLibraries.html
=== 使い方
ERB クラスを使うためには require 'erb' する必......要があります。
例:
require 'erb'
ERB.new($<.read).run
=== trim_mode
trim_mode は整形の挙動を変更するオプションです。次の振舞いを指定できます。
* 改行の扱い
* %ではじまる行の扱い (ERB 2.0 から追加されました)
trim_mode に......指定できる値は次の通りです。
* ERb-1.4.x 互換の指定方法
* nil, 0: そのまま変換
* 1: 行末が%>のとき改行を出力しない
* 2: 行頭が<%で行末が%>のとき改行を出力しない
* 2.0 からの指定方法
* nil, "": そのまま変換... -
ERB
. new(str , safe _ level=NOT _ GIVEN , trim _ mode=NOT _ GIVEN , eoutvar=NOT _ GIVEN , trim _ mode: nil , eoutvar: & # 39; _ erbout& # 39;) -> ERB (63730.0) -
eRubyスクリプト から ERB オブジェクトを生成して返します。
...eRubyスクリプト から ERB オブジェクトを生成して返します。
@param str eRubyスクリプトを表す文字列
@param safe_level eRubyスクリプトが実行されるときのセーフレベル
@param trim_mode 整形の挙動を変更するオプション
@param eoutvar eRuby......スクリプトの中で出力をためていく変数の名前を表す文
字列。eRuby スクリプトの中でさらに ERB を使うときに変更
します。通常は指定する必要はありません。
Ruby 2.6.0 から位置引数での safe_level, trim_m......3.2 で削除されました。
trim_mode と eoutvar の指定はキーワード引数に移行してください。
//emlist[例][ruby]{
require "erb"
# build data class
class Listings
PRODUCT = { :name => "Chicken Fried Steak",
:desc => "A well messages pattie, breaded and fried... -
ERB
# def _ class(superklass=Object , methodname=& # 39;erb& # 39;) -> Class (63400.0) -
変換した Ruby スクリプトをメソッドとして定義した無名のクラスを返します。
...mlist[例][ruby]{
require 'erb'
class MyClass_
def initialize(arg1, arg2)
@arg1 = arg1; @arg2 = arg2
end
end
filename = 'example.rhtml' # @arg1 と @arg2 が使われている example.rhtml
erb = ERB.new(File.read(filename))
erb.filename = filename
MyClass = erb.def_class(MyClass_, 'rend... -
ERB
# def _ method(mod , methodname , fname=& # 39;(ERB)& # 39;) -> nil (63400.0) -
変換した Ruby スクリプトをメソッドとして定義します。
...に活躍します。
@param mod メソッドを定義するモジュール(またはクラス)
@param methodname メソッド名
@param fname スクリプトを定義する際のファイル名
例:
require 'erb'
erb = ERB.new(script)
erb.def_method(MyClass, 'foo(bar)', 'foo.erb')... -
ERB
# def _ module(methodname=& # 39;erb& # 39;) -> Module (63400.0) -
変換した Ruby スクリプトをメソッドとして定義した無名のモジュールを返します。
...ルを返します。
@param methodname メソッド名
//emlist[例][ruby]{
require 'erb'
filename = 'example.rhtml'
erb = ERB.new("test1<%= arg1 %>\ntest2<%= arg2 %>\n")
erb.filename = filename
MyModule = erb.def_module('render(arg1, arg2)')
class MyClass
include MyModule
end
print MyClass.new... -
ERB
# set _ eoutvar(compiler , eoutvar = & # 39; _ erbout& # 39;) -> Array (63391.0) -
ERBの中でeRubyスクリプトの出力をためていく変数を設定します。
...
ERBの中でeRubyスクリプトの出力をためていく変数を設定します。
ERBでeRubyスクリプトの出力をためていく変数を設定するために使用します。
この設定は ERB#new でも行えるため、通常はそちらを使用した方がより容易です。... -
ERB
# result(b=TOPLEVEL _ BINDING) -> String (63145.0) -
ERB を b の binding で実行し、結果の文字列を返します。
...
ERB を b の binding で実行し、結果の文字列を返します。
@param b eRubyスクリプトが実行されるときのbinding
//emlist[例][ruby]{
require 'erb'
erb = ERB.new("test <%= test1 %>\ntest <%= test2 %>\n")
test1 = "foo"
test2 = "bar"
puts erb.result
# test foo
# test bar
//......}
@see ERB#result_with_hash... -
ERB
# filename= -> String (63133.0) -
エラーメッセージを表示する際のファイル名を設定します。
...filename を設定していない場合は、エラー発生箇所は「 (ERB) 」という出力となります。
//emlist[例][ruby]{
require 'erb'
filename = 'example.rhtml'
erb = ERB.new(File.read(filename))
erb.filename # => nil
erb.filename = filename
erb.filename # =>"example.rhtml"
//}... -
ERB
# run(b=TOPLEVEL _ BINDING) -> nil (63127.0) -
ERB を b の binding で実行し、結果を標準出力へ印字します。
...
ERB を b の binding で実行し、結果を標準出力へ印字します。
@param b eRubyスクリプトが実行されるときのbinding
//emlist[例][ruby]{
require 'erb'
erb = ERB.new("test <%= test1 %>\ntest <%= test2 %>\n")
test1 = "foo"
test2 = "bar"
erb.run
# test foo
# test bar
//}... -
ERB
# filename -> String (63115.0) -
エラーメッセージを表示する際のファイル名を取得します。
...エラーメッセージを表示する際のファイル名を取得します。
//emlist[例][ruby]{
require 'erb'
filename = 'example.rhtml'
erb = ERB.new(File.read(filename))
erb.filename # => nil
erb.filename = filename
erb.filename # =>"example.rhtml"
//}... -
ERB
# src -> String (63079.0) -
変換した Ruby スクリプトを取得します。
...。
//emlist[例][ruby]{
require 'erb'
erb = ERB.new("test1<%= @arg1%>\ntest2<%= @arg2%>\n\n")
puts erb.src
# #coding:UTF-8
# _erbout = +''; _erbout.<< "test1".freeze; _erbout.<<(( @arg1).to_s); _erbout.<< "\ntest2".freeze
# ; _erbout.<<(( @arg2).to_s); _erbout.<< "\n\n".freeze
#
# ; _erbout
//}... -
ERB
# result _ with _ hash(hash) -> String (63073.0) -
ERB をハッシュオブジェクトで指定されたローカル変数を持つ 新しいトップレベルバインディングで実行し、結果の文字列を返します。
...
ERB をハッシュオブジェクトで指定されたローカル変数を持つ
新しいトップレベルバインディングで実行し、結果の文字列を返します。
@param hash ローカル変数名をキーにしたハッシュ
@see ERB#result... -
ERB
. version -> String (63055.0) -
erb.rbのリビジョン情報を返します。
...
erb.rbのリビジョン情報を返します。... -
ERB
:: DefMethod . # def _ erb _ method(methodname , erb) -> nil (27823.0) -
self に erb のスクリプトをメソッドとして定義します。
... erb のスクリプトをメソッドとして定義します。
メソッド名は methodname で指定します。
erb が文字列の時、そのファイルを読み込み ERB で変換したのち、メソッドとして定義します。
@param methodname メソッド名
@param erb ERBイ......ンスタンスもしくはERBソースファイル名
例:
require 'erb'
class Writer
extend ERB::DefMethod
def_erb_method('to_html', 'writer.erb')
...
end
...
puts writer.to_html... -
ERB
:: DefMethod (9055.0) -
def_erb_methodを提供するモジュールです。
...def_erb_methodを提供するモジュールです。... -
ERB
:: Util . # h(s) -> String (9043.0) -
文字列 s を HTML用にエスケープした文字列を返します。
...照 & " < > にそれぞれ変更した文字列を返します
(CGI.escapeHTMLとほぼ同じです)。
@param s HTMLエスケープを行う文字列
//emlist[例][ruby]{
require "erb"
include ERB::Util
puts html_escape("is a > 0 & a < 10?")
# is a > 0 & a < 10?
//}... -
ERB
:: Util . # html _ escape(s) -> String (9043.0) -
文字列 s を HTML用にエスケープした文字列を返します。
...照 & " < > にそれぞれ変更した文字列を返します
(CGI.escapeHTMLとほぼ同じです)。
@param s HTMLエスケープを行う文字列
//emlist[例][ruby]{
require "erb"
include ERB::Util
puts html_escape("is a > 0 & a < 10?")
# is a > 0 & a < 10?
//}... -
ERB
:: Util . # u(s) -> String (9043.0) -
文字列 s を URLエンコードした文字列を返します。
...た文字列を返します(CGI.escapeとほぼ同じです)。
@param s URLエンコードを行う文字列
//emlist[例][ruby]{
require "erb"
include ERB::Util
puts url_encode("Programming Ruby: The Pragmatic Programmer's Guide")
# Programming%20Ruby%3A%20%20The%20Pragmatic%20Programmer%27s%2... -
ERB
:: Util . # url _ encode(s) -> String (9043.0) -
文字列 s を URLエンコードした文字列を返します。
...た文字列を返します(CGI.escapeとほぼ同じです)。
@param s URLエンコードを行う文字列
//emlist[例][ruby]{
require "erb"
include ERB::Util
puts url_encode("Programming Ruby: The Pragmatic Programmer's Guide")
# Programming%20Ruby%3A%20%20The%20Pragmatic%20Programmer%27s%2... -
ERB
:: Util (9007.0) -
eRubyスクリプトのためのユーティリティを提供するモジュールです。
eRubyスクリプトのためのユーティリティを提供するモジュールです。