Class: Liquid2::Environment
- Inherits:
-
Object
- Object
- Liquid2::Environment
- Defined in:
- lib/liquid2/environment.rb
Overview
Template parsing and rendering configuration.
A Liquid2::Environment is where you might register custom tags and filters, or store global context data that should be available to all templates.
‘Liquid2.parse(source)` is equivalent to `Liquid2::Environment.new.parse(source)`.
Instance Attribute Summary collapse
-
#arithmetic_operators ⇒ Object
readonly
Returns the value of attribute arithmetic_operators.
-
#context_depth_limit ⇒ Object
readonly
Returns the value of attribute context_depth_limit.
-
#falsy_undefined ⇒ Object
readonly
Returns the value of attribute falsy_undefined.
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#local_namespace_limit ⇒ Object
readonly
Returns the value of attribute local_namespace_limit.
-
#loop_iteration_limit ⇒ Object
readonly
Returns the value of attribute loop_iteration_limit.
-
#markup_comment_prefix ⇒ Object
readonly
Returns the value of attribute markup_comment_prefix.
-
#markup_comment_suffix ⇒ Object
readonly
Returns the value of attribute markup_comment_suffix.
-
#markup_out_end ⇒ Object
readonly
Returns the value of attribute markup_out_end.
-
#markup_out_start ⇒ Object
readonly
Returns the value of attribute markup_out_start.
-
#markup_tag_end ⇒ Object
readonly
Returns the value of attribute markup_tag_end.
-
#markup_tag_start ⇒ Object
readonly
Returns the value of attribute markup_tag_start.
-
#output_stream_limit ⇒ Object
readonly
Returns the value of attribute output_stream_limit.
-
#persistent_namespaces ⇒ Object
readonly
Returns the value of attribute persistent_namespaces.
-
#re_block_comment_chunk ⇒ Object
readonly
Returns the value of attribute re_block_comment_chunk.
-
#re_double_quote_string_special ⇒ Object
readonly
Returns the value of attribute re_double_quote_string_special.
-
#re_float ⇒ Object
readonly
Returns the value of attribute re_float.
-
#re_int ⇒ Object
readonly
Returns the value of attribute re_int.
-
#re_line_statement_comment ⇒ Object
readonly
Returns the value of attribute re_line_statement_comment.
-
#re_markup_end ⇒ Object
readonly
Returns the value of attribute re_markup_end.
-
#re_markup_end_chars ⇒ Object
readonly
Returns the value of attribute re_markup_end_chars.
-
#re_markup_start ⇒ Object
readonly
Returns the value of attribute re_markup_start.
-
#re_punctuation ⇒ Object
readonly
Returns the value of attribute re_punctuation.
-
#re_single_quote_string_special ⇒ Object
readonly
Returns the value of attribute re_single_quote_string_special.
-
#re_tag_name ⇒ Object
readonly
Returns the value of attribute re_tag_name.
-
#re_up_to_doc_end ⇒ Object
readonly
Returns the value of attribute re_up_to_doc_end.
-
#re_up_to_inline_comment_end ⇒ Object
readonly
Returns the value of attribute re_up_to_inline_comment_end.
-
#re_up_to_markup_start ⇒ Object
readonly
Returns the value of attribute re_up_to_markup_start.
-
#re_up_to_raw_end ⇒ Object
readonly
Returns the value of attribute re_up_to_raw_end.
-
#re_word ⇒ Object
readonly
Returns the value of attribute re_word.
-
#shorthand_indexes ⇒ Object
readonly
Returns the value of attribute shorthand_indexes.
-
#suppress_blank_control_flow_blocks ⇒ Object
readonly
Returns the value of attribute suppress_blank_control_flow_blocks.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#universal_markup_end ⇒ Object
readonly
Returns the value of attribute universal_markup_end.
Instance Method Summary collapse
-
#delete_filter(name) ⇒ callable | nil
Remove a filter from the filter register.
-
#delete_tag(name) ⇒ _Tag | nil
Remove a tag from the tag register.
-
#get_template(name, globals: nil, context: nil, **kwargs) ⇒ Template
Load and parse a template using the configured template loader.
-
#initialize(arithmetic_operators: false, context_depth_limit: 30, auto_trim: nil, falsy_undefined: true, globals: nil, loader: nil, local_namespace_limit: nil, loop_iteration_limit: nil, markup_comment_prefix: "{#", markup_comment_suffix: "}", markup_out_end: "}}", markup_out_start: "{{", markup_tag_end: "%}", markup_tag_start: "{%", output_stream_limit: nil, parser: Parser, scanner: Scanner, shorthand_indexes: false, suppress_blank_control_flow_blocks: true, undefined: Undefined) ⇒ Environment
constructor
A new instance of Environment.
-
#make_globals(namespace) ⇒ Object
Merge environment globals with another namespace.
-
#parse(source, name: "", path: nil, up_to_date: nil, globals: nil, overlay: nil) ⇒ Template
Parse source text as a template.
-
#register_filter(name, callable) ⇒ Object
Add or replace a filter.
-
#register_tag(name, tag) ⇒ Object
Add or replace a tag.
-
#render(source, data = nil) ⇒ String
Parse and render template source text with data as template variables.
-
#setup_scanner ⇒ Object
Compile regular expressions for use by the tokenizer attached to this environment.
- #setup_tags_and_filters ⇒ Object
-
#trim(text, left_trim, right_trim) ⇒ Object
Trim text.
- #undefined(name, node: nil) ⇒ Object
Constructor Details
#initialize(arithmetic_operators: false, context_depth_limit: 30, auto_trim: nil, falsy_undefined: true, globals: nil, loader: nil, local_namespace_limit: nil, loop_iteration_limit: nil, markup_comment_prefix: "{#", markup_comment_suffix: "}", markup_out_end: "}}", markup_out_start: "{{", markup_tag_end: "%}", markup_tag_start: "{%", output_stream_limit: nil, parser: Parser, scanner: Scanner, shorthand_indexes: false, suppress_blank_control_flow_blocks: true, undefined: Undefined) ⇒ Environment
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/liquid2/environment.rb', line 97 def initialize( arithmetic_operators: false, context_depth_limit: 30, auto_trim: nil, falsy_undefined: true, globals: nil, loader: nil, local_namespace_limit: nil, loop_iteration_limit: nil, markup_comment_prefix: "{#", markup_comment_suffix: "}", markup_out_end: "}}", markup_out_start: "{{", markup_tag_end: "%}", markup_tag_start: "{%", output_stream_limit: nil, parser: Parser, scanner: Scanner, shorthand_indexes: false, suppress_blank_control_flow_blocks: true, undefined: Undefined ) # A mapping of tag names to objects responding to `parse(token, parser)`. = {} # A mapping of filter names to objects responding to `#call(left, ...)`, # along with a flag to indicate if the callable accepts a `context` # keyword argument. @filters = {} # An array of symbols indicating which namespaces from RenderContext.tag_namespaces # should be preserved when using RenderContext#copy. @persistent_namespaces = [:extends] # When `true`, arithmetic operators `+`, `-`, `*`, `/`, `%` and `**` are enabled. # Defaults to `false`. @arithmetic_operators = arithmetic_operators # The maximum number of times a render context can be extended or copied before # a Liquid2::LiquidResourceLimitError is raised. @context_depth_limit = context_depth_limit # The default whitespace trimming applied to the left of text content when neither # `-` or `~` is specified. Defaults to `nil`, which means no automatic whitespace # trimming. @auto_trim = auto_trim # Variables that are available to all templates rendered from this environment. @globals = globals # An instance of `Liquid2::Loader`. A template loader is responsible for finding and # reading templates for `{% include %}` and `{% render %}` tags, or when calling # `Liquid2::Environment.get_template(name)`. @loader = loader || HashLoader.new({}) # The maximum allowed "size" of the template local namespace (variables from `assign` # and `capture` tags) before a Liquid2::LiquidResourceLimitError is raised. @local_namespace_limit = local_namespace_limit # The maximum number of loop iterations allowed before a `LiquidResourceLimitError` # is raised. @loop_iteration_limit = loop_iteration_limit # The maximum number of bytes that can be written to a template's output buffer # before a `LiquidResourceLimitError` is raised. @output_stream_limit = output_stream_limit # Liquid2::Scanner or a subclass of it. This is used to tokenize Liquid source # text before parsing it. @scanner = scanner # Liquid2::Parser or a subclass of it. The parser takes tokens from the scanner # and produces an abstract syntax tree. @parser = parser # We reuse the same string scanner when parsing templates for improved performance. # TODO: Is this going to cause issues in multi threaded environments? @string_scanner = StringScanner.new("") # When `true`, allow shorthand dotted array indexes as well as bracketed indexes # in variable paths. Defaults to `false`. @shorthand_indexes = shorthand_indexes # When `true`, suppress blank control flow block output, so as not to include # unnecessary whitespace. Defaults to `true`. @suppress_blank_control_flow_blocks = suppress_blank_control_flow_blocks # A singleton returning an instance of `Liquid2::Undefined`, which is used to # represent template variables that don't exist. @undefined = undefined # When `true` (the default), undefined variables are considered falsy and do not # raise an error when tested for truthiness. @falsy_undefined = falsy_undefined # The string of characters that indicate the start of a Liquid output statement. @markup_out_start = markup_out_start # The string of characters that indicate the end of a Liquid output statement. @markup_out_end = markup_out_end # The string of characters that indicate the start of a Liquid tag. @markup_tag_start = markup_tag_start # The string of characters that indicate the end of a Liquid tag. @markup_tag_end = markup_tag_end # Indicates if tag and output end delimiters are identical. This is used by the # parser when parsing output statements. @universal_markup_end = markup_tag_end == markup_out_end # The string of characters that indicate the start of a Liquid comment. This should # include a single trailing `#`. Additional, variable length hashes will be handled # by the tokenizer. It is not possible to change comment syntax to not use `#`. @markup_comment_prefix = markup_comment_prefix # The string of characters that indicate the end of a Liquid comment, excluding any # hashes. @markup_comment_suffix = markup_comment_suffix # You might need to override `setup_scanner` if you've specified custom markup # delimiters and they conflict with standard punctuation. setup_scanner # Override `setup_tags_and_filters` in environment subclasses to configure custom # tags and/or filters. end |
Instance Attribute Details
#arithmetic_operators ⇒ Object (readonly)
Returns the value of attribute arithmetic_operators.
46 47 48 |
# File 'lib/liquid2/environment.rb', line 46 def arithmetic_operators @arithmetic_operators end |
#context_depth_limit ⇒ Object (readonly)
Returns the value of attribute context_depth_limit.
46 47 48 |
# File 'lib/liquid2/environment.rb', line 46 def context_depth_limit @context_depth_limit end |
#falsy_undefined ⇒ Object (readonly)
Returns the value of attribute falsy_undefined.
46 47 48 |
# File 'lib/liquid2/environment.rb', line 46 def falsy_undefined @falsy_undefined end |
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
46 47 48 |
# File 'lib/liquid2/environment.rb', line 46 def filters @filters end |
#local_namespace_limit ⇒ Object (readonly)
Returns the value of attribute local_namespace_limit.
46 47 48 |
# File 'lib/liquid2/environment.rb', line 46 def local_namespace_limit @local_namespace_limit end |
#loop_iteration_limit ⇒ Object (readonly)
Returns the value of attribute loop_iteration_limit.
46 47 48 |
# File 'lib/liquid2/environment.rb', line 46 def loop_iteration_limit @loop_iteration_limit end |
#markup_comment_prefix ⇒ Object (readonly)
Returns the value of attribute markup_comment_prefix.
46 47 48 |
# File 'lib/liquid2/environment.rb', line 46 def markup_comment_prefix @markup_comment_prefix end |
#markup_comment_suffix ⇒ Object (readonly)
Returns the value of attribute markup_comment_suffix.
46 47 48 |
# File 'lib/liquid2/environment.rb', line 46 def markup_comment_suffix @markup_comment_suffix end |
#markup_out_end ⇒ Object (readonly)
Returns the value of attribute markup_out_end.
46 47 48 |
# File 'lib/liquid2/environment.rb', line 46 def markup_out_end @markup_out_end end |
#markup_out_start ⇒ Object (readonly)
Returns the value of attribute markup_out_start.
46 47 48 |
# File 'lib/liquid2/environment.rb', line 46 def markup_out_start @markup_out_start end |
#markup_tag_end ⇒ Object (readonly)
Returns the value of attribute markup_tag_end.
46 47 48 |
# File 'lib/liquid2/environment.rb', line 46 def markup_tag_end @markup_tag_end end |
#markup_tag_start ⇒ Object (readonly)
Returns the value of attribute markup_tag_start.
46 47 48 |
# File 'lib/liquid2/environment.rb', line 46 def markup_tag_start @markup_tag_start end |
#output_stream_limit ⇒ Object (readonly)
Returns the value of attribute output_stream_limit.
46 47 48 |
# File 'lib/liquid2/environment.rb', line 46 def output_stream_limit @output_stream_limit end |
#persistent_namespaces ⇒ Object (readonly)
Returns the value of attribute persistent_namespaces.
46 47 48 |
# File 'lib/liquid2/environment.rb', line 46 def persistent_namespaces @persistent_namespaces end |
#re_block_comment_chunk ⇒ Object (readonly)
Returns the value of attribute re_block_comment_chunk.
46 47 48 |
# File 'lib/liquid2/environment.rb', line 46 def re_block_comment_chunk @re_block_comment_chunk end |
#re_double_quote_string_special ⇒ Object (readonly)
Returns the value of attribute re_double_quote_string_special.
46 47 48 |
# File 'lib/liquid2/environment.rb', line 46 def re_double_quote_string_special @re_double_quote_string_special end |
#re_float ⇒ Object (readonly)
Returns the value of attribute re_float.
46 47 48 |
# File 'lib/liquid2/environment.rb', line 46 def re_float @re_float end |
#re_int ⇒ Object (readonly)
Returns the value of attribute re_int.
46 47 48 |
# File 'lib/liquid2/environment.rb', line 46 def re_int @re_int end |
#re_line_statement_comment ⇒ Object (readonly)
Returns the value of attribute re_line_statement_comment.
46 47 48 |
# File 'lib/liquid2/environment.rb', line 46 def re_line_statement_comment @re_line_statement_comment end |
#re_markup_end ⇒ Object (readonly)
Returns the value of attribute re_markup_end.
46 47 48 |
# File 'lib/liquid2/environment.rb', line 46 def re_markup_end @re_markup_end end |
#re_markup_end_chars ⇒ Object (readonly)
Returns the value of attribute re_markup_end_chars.
46 47 48 |
# File 'lib/liquid2/environment.rb', line 46 def re_markup_end_chars @re_markup_end_chars end |
#re_markup_start ⇒ Object (readonly)
Returns the value of attribute re_markup_start.
46 47 48 |
# File 'lib/liquid2/environment.rb', line 46 def re_markup_start @re_markup_start end |
#re_punctuation ⇒ Object (readonly)
Returns the value of attribute re_punctuation.
46 47 48 |
# File 'lib/liquid2/environment.rb', line 46 def re_punctuation @re_punctuation end |
#re_single_quote_string_special ⇒ Object (readonly)
Returns the value of attribute re_single_quote_string_special.
46 47 48 |
# File 'lib/liquid2/environment.rb', line 46 def re_single_quote_string_special @re_single_quote_string_special end |
#re_tag_name ⇒ Object (readonly)
Returns the value of attribute re_tag_name.
46 47 48 |
# File 'lib/liquid2/environment.rb', line 46 def re_tag_name @re_tag_name end |
#re_up_to_doc_end ⇒ Object (readonly)
Returns the value of attribute re_up_to_doc_end.
46 47 48 |
# File 'lib/liquid2/environment.rb', line 46 def re_up_to_doc_end @re_up_to_doc_end end |
#re_up_to_inline_comment_end ⇒ Object (readonly)
Returns the value of attribute re_up_to_inline_comment_end.
46 47 48 |
# File 'lib/liquid2/environment.rb', line 46 def re_up_to_inline_comment_end @re_up_to_inline_comment_end end |
#re_up_to_markup_start ⇒ Object (readonly)
Returns the value of attribute re_up_to_markup_start.
46 47 48 |
# File 'lib/liquid2/environment.rb', line 46 def re_up_to_markup_start @re_up_to_markup_start end |
#re_up_to_raw_end ⇒ Object (readonly)
Returns the value of attribute re_up_to_raw_end.
46 47 48 |
# File 'lib/liquid2/environment.rb', line 46 def re_up_to_raw_end @re_up_to_raw_end end |
#re_word ⇒ Object (readonly)
Returns the value of attribute re_word.
46 47 48 |
# File 'lib/liquid2/environment.rb', line 46 def re_word @re_word end |
#shorthand_indexes ⇒ Object (readonly)
Returns the value of attribute shorthand_indexes.
46 47 48 |
# File 'lib/liquid2/environment.rb', line 46 def shorthand_indexes @shorthand_indexes end |
#suppress_blank_control_flow_blocks ⇒ Object (readonly)
Returns the value of attribute suppress_blank_control_flow_blocks.
46 47 48 |
# File 'lib/liquid2/environment.rb', line 46 def suppress_blank_control_flow_blocks @suppress_blank_control_flow_blocks end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
46 47 48 |
# File 'lib/liquid2/environment.rb', line 46 def end |
#universal_markup_end ⇒ Object (readonly)
Returns the value of attribute universal_markup_end.
46 47 48 |
# File 'lib/liquid2/environment.rb', line 46 def universal_markup_end @universal_markup_end end |
Instance Method Details
#delete_filter(name) ⇒ callable | nil
Remove a filter from the filter register.
271 272 273 |
# File 'lib/liquid2/environment.rb', line 271 def delete_filter(name) @filters.delete(name) end |
#delete_tag(name) ⇒ _Tag | nil
Remove a tag from the tag register.
285 286 287 |
# File 'lib/liquid2/environment.rb', line 285 def delete_tag(name) .delete(name) end |
#get_template(name, globals: nil, context: nil, **kwargs) ⇒ Template
Load and parse a template using the configured template loader.
462 463 464 465 466 467 |
# File 'lib/liquid2/environment.rb', line 462 def get_template(name, globals: nil, context: nil, **kwargs) @loader.load(self, name, globals: globals, context: context, **kwargs) rescue LiquidError => e e.template_name = name unless e.template_name || e.is_a?(LiquidTemplateNotFoundError) raise e end |
#make_globals(namespace) ⇒ Object
Merge environment globals with another namespace.
470 471 472 473 474 475 |
# File 'lib/liquid2/environment.rb', line 470 def make_globals(namespace) return @globals if namespace.nil? return namespace if @globals.nil? (@globals || raise).merge(namespace) end |
#parse(source, name: "", path: nil, up_to_date: nil, globals: nil, overlay: nil) ⇒ Template
Parse source text as a template.
229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/liquid2/environment.rb', line 229 def parse(source, name: "", path: nil, up_to_date: nil, globals: nil, overlay: nil) Template.new( self, source, @parser.new(self, @scanner.tokenize(self, source, @string_scanner), source.length).parse, name: name, path: path, up_to_date: up_to_date, globals: make_globals(globals), overlay: ) rescue LiquidError => e e.source = source unless e.source e.template_name = name unless e.template_name || name.empty? raise end |
#register_filter(name, callable) ⇒ Object
Add or replace a filter. The same callable can be registered multiple times with different names.
If callable accepts a keyword parameter called ‘context`, the active render context will be passed to `#call`.
260 261 262 263 264 265 |
# File 'lib/liquid2/environment.rb', line 260 def register_filter(name, callable) with_context = callable.parameters.index do |(kind, param)| kind == :keyreq && param == :context end @filters[name] = [callable, with_context] end |
#register_tag(name, tag) ⇒ Object
Add or replace a tag.
278 279 280 |
# File 'lib/liquid2/environment.rb', line 278 def register_tag(name, tag) [name] = tag end |
#render(source, data = nil) ⇒ String
Parse and render template source text with data as template variables.
247 248 249 |
# File 'lib/liquid2/environment.rb', line 247 def render(source, data = nil) parse(source).render(data) end |
#setup_scanner ⇒ Object
Compile regular expressions for use by the tokenizer attached to this environment.
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 |
# File 'lib/liquid2/environment.rb', line 381 def setup_scanner # A regex pattern matching Liquid tag names. Should include `#` for inline comments. @re_tag_name = /(?:[a-z][a-z_0-9]*|#)/ # A regex pattern matching keywords and/or variable/path names. Replace this if # you want to disable Unicode characters in identifiers, for example. @re_word = /[\u0080-\uFFFFa-zA-Z_][\u0080-\uFFFFa-zA-Z0-9_-]*/ # Patterns matching literal integers and floats, possibly in scientific notation. # You could simplify these to disable scientific notation. @re_int = /-?\d+(?:[eE]\+?\d+)?/ @re_float = /((?:-?\d+\.\d+(?:[eE][+-]?\d+)?)|(-?\d+[eE]-\d+))/ # Patterns matching escape sequences, interpolation and end of string in string literals. # You could remove `\$` from these to disable string interpolation. @re_double_quote_string_special = /[\\"\$]/ @re_single_quote_string_special = /[\\'\$]/ # rubocop: disable Layout/LineLength # A regex pattern matching the start of some Liquid markup. Could be the start of an # output statement, tag or comment. Traditionally `{{`, `{%` and `{#`, respectively. @re_markup_start = /#{Regexp.escape(@markup_out_start)}|#{Regexp.escape(@markup_tag_start)}|#{Regexp.escape(@markup_comment_prefix)}/ # A regex pattern matching the end of some Liquid markup. Could be the end of # an output statement or tag. Traditionally `}}`, `%}`, respectively. @re_markup_end = /#{Regexp.escape(@markup_out_end)}|#{Regexp.escape(@markup_tag_end)}/ # A regex pattern matching any one of the possible characters ending some Liquid # markup. This is used to detect incomplete and malformed markup and provide # helpful error messages. @re_markup_end_chars = /[#{Regexp.escape((@markup_out_end + @markup_tag_end).each_char.uniq.join)}]/ @re_up_to_markup_start = /(?=#{Regexp.escape(@markup_out_start)}|#{Regexp.escape(@markup_tag_start)}|#{Regexp.escape(@markup_comment_prefix)})/ # Braces `{` and `}` are handled separately by the scanner, similar to how we handle # `"` and `'`, so we don't confuse ending a nested object/hash literal with ending an # output statement. # # In this example we need two `:token_rbrace` before `:token_output_end`. # `{{ {"thing": {"foo": 1, "bar": 2}} }}` @re_punctuation = %r{(?!#{@re_markup_end})(\?|\[|\]|\|{1,2}|\.{1,3}|,|:|\(|\)|[<>=!]+|[+\-%*/]+(?!#{@re_markup_end_chars}))} @re_up_to_inline_comment_end = /(?=([+\-~])?#{Regexp.escape(@markup_tag_end)})/ @re_up_to_raw_end = /(?=(#{Regexp.escape(@markup_tag_start)}[+\-~]?\s*endraw\s*[+\-~]?#{Regexp.escape(@markup_tag_end)}))/ @re_block_comment_chunk = /(#{Regexp.escape(@markup_tag_start)}[+\-~]?\s*(comment|raw|endcomment|endraw)\s*[+\-~]?#{Regexp.escape(@markup_tag_end)})/ @re_up_to_doc_end = /(?=(#{Regexp.escape(@markup_tag_start)}[+\-~]?\s*enddoc\s*[+\-~]?#{Regexp.escape(@markup_tag_end)}))/ @re_line_statement_comment = /(?=([\r\n]+|-?#{Regexp.escape(@markup_tag_end)}))/ # rubocop: enable Layout/LineLength end |
#setup_tags_and_filters ⇒ Object
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
# File 'lib/liquid2/environment.rb', line 289 def ["#"] = InlineComment ["assign"] = AssignTag ["break"] = BreakTag ["capture"] = CaptureTag ["case"] = CaseTag ["comment"] = BlockComment ["continue"] = ContinueTag ["cycle"] = CycleTag ["decrement"] = DecrementTag ["doc"] = DocTag ["echo"] = EchoTag ["extends"] = ExtendsTag ["block"] = BlockTag ["for"] = ForTag ["if"] = IfTag ["include"] = IncludeTag ["increment"] = IncrementTag ["liquid"] = LiquidTag ["macro"] = MacroTag ["call"] = CallTag ["raw"] = RawTag ["render"] = RenderTag ["tablerow"] = TableRowTag ["unless"] = UnlessTag ["with"] = WithTag register_filter("abs", Liquid2::Filters.method(:abs)) register_filter("append", Liquid2::Filters.method(:append)) register_filter("at_least", Liquid2::Filters.method(:at_least)) register_filter("at_most", Liquid2::Filters.method(:at_most)) register_filter("base64_decode", Liquid2::Filters.method(:base64_decode)) register_filter("base64_encode", Liquid2::Filters.method(:base64_encode)) register_filter("base64_url_safe_decode", Liquid2::Filters.method(:base64_url_safe_decode)) register_filter("base64_url_safe_encode", Liquid2::Filters.method(:base64_url_safe_encode)) register_filter("capitalize", Liquid2::Filters.method(:capitalize)) register_filter("ceil", Liquid2::Filters.method(:ceil)) register_filter("compact", Liquid2::Filters.method(:compact)) register_filter("concat", Liquid2::Filters.method(:concat)) register_filter("date", Liquid2::Filters.method(:date)) register_filter("default", Liquid2::Filters.method(:default)) register_filter("divided_by", Liquid2::Filters.method(:divided_by)) register_filter("downcase", Liquid2::Filters.method(:downcase)) register_filter("escape_once", Liquid2::Filters.method(:escape_once)) register_filter("escape", Liquid2::Filters.method(:escape)) register_filter("find_index", Liquid2::Filters.method(:find_index)) register_filter("find", Liquid2::Filters.method(:find)) register_filter("first", Liquid2::Filters.method(:first)) register_filter("floor", Liquid2::Filters.method(:floor)) register_filter("has", Liquid2::Filters.method(:has)) register_filter("join", Liquid2::Filters.method(:join)) register_filter("json", Liquid2::Filters.method(:json)) register_filter("last", Liquid2::Filters.method(:last)) register_filter("lstrip", Liquid2::Filters.method(:lstrip)) register_filter("map", Liquid2::Filters.method(:map)) register_filter("minus", Liquid2::Filters.method(:minus)) register_filter("modulo", Liquid2::Filters.method(:modulo)) register_filter("newline_to_br", Liquid2::Filters.method(:newline_to_br)) register_filter("plus", Liquid2::Filters.method(:plus)) register_filter("prepend", Liquid2::Filters.method(:prepend)) register_filter("range", Liquid2::Filters.method(:better_slice)) register_filter("reject", Liquid2::Filters.method(:reject)) register_filter("remove_first", Liquid2::Filters.method(:remove_first)) register_filter("remove_last", Liquid2::Filters.method(:remove_last)) register_filter("remove", Liquid2::Filters.method(:remove)) register_filter("replace_first", Liquid2::Filters.method(:replace_first)) register_filter("replace_last", Liquid2::Filters.method(:replace_last)) register_filter("replace", Liquid2::Filters.method(:replace)) register_filter("reverse", Liquid2::Filters.method(:reverse)) register_filter("round", Liquid2::Filters.method(:round)) register_filter("rstrip", Liquid2::Filters.method(:rstrip)) register_filter("size", Liquid2::Filters.method(:size)) register_filter("slice", Liquid2::Filters.method(:slice)) register_filter("sort_natural", Liquid2::Filters.method(:sort_natural)) register_filter("sort_numeric", Liquid2::Filters.method(:sort_numeric)) register_filter("sort", Liquid2::Filters.method(:sort)) register_filter("split", Liquid2::Filters.method(:split)) register_filter("strip_html", Liquid2::Filters.method(:strip_html)) register_filter("strip_newlines", Liquid2::Filters.method(:strip_newlines)) register_filter("strip", Liquid2::Filters.method(:strip)) register_filter("sum", Liquid2::Filters.method(:sum)) register_filter("times", Liquid2::Filters.method(:times)) register_filter("truncate", Liquid2::Filters.method(:truncate)) register_filter("truncatewords", Liquid2::Filters.method(:truncatewords)) register_filter("uniq", Liquid2::Filters.method(:uniq)) register_filter("url_encode", Liquid2::Filters.method(:url_encode)) register_filter("url_decode", Liquid2::Filters.method(:url_decode)) register_filter("upcase", Liquid2::Filters.method(:upcase)) register_filter("where", Liquid2::Filters.method(:where)) end |
#trim(text, left_trim, right_trim) ⇒ Object
Trim text.
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 |
# File 'lib/liquid2/environment.rb', line 438 def trim(text, left_trim, right_trim) case left_trim || @auto_trim when "-" text.lstrip! when "~" text.sub!(/\A[\r\n]+/, "") end case right_trim when "-" text.rstrip! when "~" text.sub!(/[\r\n]+\Z/, "") end end |
#undefined(name, node: nil) ⇒ Object
433 434 435 |
# File 'lib/liquid2/environment.rb', line 433 def undefined(name, node: nil) @undefined.new(name, node: node) end |