Method: Merb::Template.template_name

Defined in:
lib/merb-core/controller/template.rb

.template_name(path) ⇒ Object

Get the template’s method name from a full path. This replaces non-alphanumeric characters with __ and “.” with “_”

Collisions are potentially possible with something like: ~foo.bar and __foo.bar or !foo.bar.

Parameters

path<String>

A full path to convert to a valid Ruby method name

Returns

String

The template name.

We might want to replace this with something that varies the character replaced based on the non-alphanumeric character to avoid edge-case collisions.

:api: private



30
31
32
33
# File 'lib/merb-core/controller/template.rb', line 30

def template_name(path)
  path = File.expand_path(path)      
  path.gsub(/[^\.a-zA-Z0-9]/, "__").gsub(/\./, "_")
end