Module: RubyApp::Mixins::TemplateMixin

Included in:
Element
Defined in:
lib/ruby_app/mixins/template_mixin.rb

Instance Method Summary collapse

Instance Method Details

#exclude_parent_template(*formats) ⇒ Object



25
26
27
# File 'lib/ruby_app/mixins/template_mixin.rb', line 25

def exclude_parent_template(*formats)
  @_exclude_parent_template_formats = formats
end

#exclude_parent_template?(format) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/ruby_app/mixins/template_mixin.rb', line 21

def exclude_parent_template?(format)
  ( @_exclude_parent_template_formats ||= [] ).include?(:all) || @_exclude_parent_template_formats.include?(format)
end

#get_templates(format) ⇒ Object



29
30
31
32
# File 'lib/ruby_app/mixins/template_mixin.rb', line 29

def get_templates(format)
  templates = Dir.glob((@_template_path[format] || @_template_path[:all] || "#{File.join(File.dirname(__FILE__), self.template_name)}.*.haml").gsub(/\*/,format.to_s))
  ( templates.length > 0 ? [templates.first] : [] ).concat( ( !self.exclude_parent_template?(format) and self.superclass.respond_to?(:get_templates) ) ? self.superclass.get_templates(format) : [] )
end

#template_nameObject



7
8
9
10
11
12
13
14
15
# File 'lib/ruby_app/mixins/template_mixin.rb', line 7

def template_name

  name = self.to_s.split('::').last
  name.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
  name.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
  name.tr!("-", "_")
  name.downcase

end

#template_path(format, path) ⇒ Object



17
18
19
# File 'lib/ruby_app/mixins/template_mixin.rb', line 17

def template_path(format, path)
  (@_template_path ||= {})[format] = File.directory?(path) ? "#{File.join(path, self.template_name)}.*.haml" : path
end