Module: RubyApp::Mixins::TemplateMixin
- Included in:
- Element
- Defined in:
- lib/ruby_app/mixins/template_mixin.rb
Instance Method Summary collapse
- #exclude_parent_template(*formats) ⇒ Object
- #exclude_parent_template?(format) ⇒ Boolean
- #get_cache(format) ⇒ Object
- #get_default_template ⇒ Object
- #get_template(format) ⇒ Object
- #get_template_name ⇒ Object
- #get_templates(format) ⇒ Object
- #template_path(format, path) ⇒ Object
Instance Method Details
#exclude_parent_template(*formats) ⇒ Object
23 24 25 |
# File 'lib/ruby_app/mixins/template_mixin.rb', line 23 def exclude_parent_template(*formats) @_exclude_parent_template_formats = formats end |
#exclude_parent_template?(format) ⇒ Boolean
19 20 21 |
# File 'lib/ruby_app/mixins/template_mixin.rb', line 19 def exclude_parent_template?(format) return ( @_exclude_parent_template_formats ||= [] ).include?(:all) || @_exclude_parent_template_formats.include?(format) end |
#get_cache(format) ⇒ Object
40 41 42 43 |
# File 'lib/ruby_app/mixins/template_mixin.rb', line 40 def get_cache(format) template = self.get_template(format) return File.join(File.dirname(template), '.cache', File.basename(template)).gsub(/\.haml/, '') end |
#get_default_template ⇒ Object
31 32 33 |
# File 'lib/ruby_app/mixins/template_mixin.rb', line 31 def get_default_template return File.join(File.dirname(__FILE__), %w[template_mixin.haml]) end |
#get_template(format) ⇒ Object
27 28 29 |
# File 'lib/ruby_app/mixins/template_mixin.rb', line 27 def get_template(format) return (@_template_path[format] || @_template_path[:all]).gsub(/\*/,format.to_s) end |
#get_template_name ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/ruby_app/mixins/template_mixin.rb', line 7 def get_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!("-", "_") return name.downcase end |
#get_templates(format) ⇒ Object
35 36 37 38 |
# File 'lib/ruby_app/mixins/template_mixin.rb', line 35 def get_templates(format) template = self.get_template(format) return (File.exists?(template) ? [template] : []).concat((!self.exclude_parent_template?(format) && self.superclass.respond_to?(:get_templates) ) ? self.superclass.get_templates(format) : []) end |
#template_path(format, path) ⇒ Object
15 16 17 |
# File 'lib/ruby_app/mixins/template_mixin.rb', line 15 def template_path(format, path) (@_template_path ||= {})[format] = File.directory?(path) ? "#{File.join(path, self.get_template_name)}.*.haml" : path end |