Class: VertxWeb::TemplateEngine

Inherits:
Object
  • Object
show all
Defined in:
/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web/template_engine.rb

Overview

A template engine uses a specific template and the data in a routing context to render a resource into a buffer.

Concrete implementations exist for several well-known template engines.

Direct Known Subclasses

FreeMarkerTemplateEngine, HandlebarsTemplateEngine, JadeTemplateEngine, MVELTemplateEngine, PebbleTemplateEngine, ThymeleafTemplateEngine

Constant Summary

@@j_api_type =
Object.new

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Boolean) accept?(obj)

Returns:

  • (Boolean)


21
22
23
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web/template_engine.rb', line 21

def @@j_api_type.accept?(obj)
  obj.class == TemplateEngine
end

+ (Object) j_api_type



30
31
32
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web/template_engine.rb', line 30

def self.j_api_type
  @@j_api_type
end

+ (Object) j_class



33
34
35
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web/template_engine.rb', line 33

def self.j_class
  Java::IoVertxExtWebTempl::TemplateEngine.java_class
end

+ (Object) unwrap(obj)



27
28
29
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web/template_engine.rb', line 27

def @@j_api_type.unwrap(obj)
  obj.j_del
end

+ (Object) wrap(obj)



24
25
26
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web/template_engine.rb', line 24

def @@j_api_type.wrap(obj)
  TemplateEngine.new(obj)
end

Instance Method Details

- (true, false) caching_enabled?

Returns true if the template engine caches template files. If false, then template files are freshly loaded each time they are used.

Returns:

  • (true, false)
    True if template files are cached; otherwise, false.

Raises:

  • (ArgumentError)


56
57
58
59
60
61
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web/template_engine.rb', line 56

def caching_enabled?
  if !block_given?
    return @j_del.java_method(:isCachingEnabled, []).call()
  end
  raise ArgumentError, "Invalid arguments when calling caching_enabled?()"
end

- (void) render(context = nil, templateDirectory = nil, templateFileName = nil) { ... }

This method returns an undefined value.

Render the template

NOTE if you call method directly (i.e. not using VertxWeb::TemplateHandler) make sure that templateFileName is sanitized via Nil#normalize_path

Parameters:

  • context (::VertxWeb::RoutingContext) (defaults to: nil)
    the routing context
  • templateDirectory (String) (defaults to: nil)
    the template directory to use
  • templateFileName (String) (defaults to: nil)
    the relative template file name to use

Yields:

  • the handler that will be called with a result containing the buffer or a failure.

Raises:

  • (ArgumentError)


45
46
47
48
49
50
51
52
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web/template_engine.rb', line 45

def render(context=nil,templateDirectory=nil,templateFileName=nil)
  if context.class.method_defined?(:j_del) && templateDirectory.class == String && block_given? && templateFileName == nil
    return @j_del.java_method(:render, [Java::IoVertxExtWeb::RoutingContext.java_class,Java::java.lang.String.java_class,Java::IoVertxCore::Handler.java_class]).call(context.j_del,templateDirectory,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::Vertx::Buffer) : nil) }))
  elsif context.class.method_defined?(:j_del) && templateDirectory.class == String && templateFileName.class == String && block_given?
    return @j_del.java_method(:render, [Java::IoVertxExtWeb::RoutingContext.java_class,Java::java.lang.String.java_class,Java::java.lang.String.java_class,Java::IoVertxCore::Handler.java_class]).call(context.j_del,templateDirectory,templateFileName,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::Vertx::Buffer) : nil) }))
  end
  raise ArgumentError, "Invalid arguments when calling render(#{context},#{templateDirectory},#{templateFileName})"
end