Method: Innate::Node#to_template

Defined in:
lib/innate/node.rb

#to_template(path, wish) ⇒ nil, String

Try to find a template at the given path for wish.

Since Innate supports multiple paths to templates the path has to be an Array that may be nested one level.

Examples:

Usage to find available templates


# This assumes following files:
# view/foo.erb
# view/bar.erb
# view/bar.rss.erb
# view/bar.yaml.erb

class FooBar
  Innate.node('/')
end

FooBar.to_template(['.', 'view', '/', 'foo'], 'html')
# => "./view/foo.erb"
FooBar.to_template(['.', 'view', '/', 'foo'], 'yaml')
# => "./view/foo.erb"
FooBar.to_template(['.', 'view', '/', 'foo'], 'rss')
# => "./view/foo.erb"

FooBar.to_template(['.', 'view', '/', 'bar'], 'html')
# => "./view/bar.erb"
FooBar.to_template(['.', 'view', '/', 'bar'], 'yaml')
# => "./view/bar.yaml.erb"
FooBar.to_template(['.', 'view', '/', 'bar'], 'rss')
# => "./view/bar.rss.erb"

Parameters:

  • path (Array<Array<String>>, Array<String>)

    array containing strings and nested (1 level) arrays containing strings

  • wish (String)

Returns:

  • (nil, String)

    relative path to the first template found

See Also:

Author:

  • manveru



777
778
779
# File 'lib/innate/node.rb', line 777

def to_template(path, wish)
  to_view(path, wish) || to_layout(path, wish)
end