Sha256: a3c20fc681743516d8fbbbee886bae612ff58f4a9e6d1449e9fd99b8beec5693

Contents?: true

Size: 1.33 KB

Versions: 21

Compression:

Stored size: 1.33 KB

Contents

module RubyApp

  module Mixins

    module TemplateMixin

      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

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

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

      def exclude_parent_template(*formats)
        @_exclude_parent_template_formats = formats
      end

      def get_template(format)
        (@_template_path[format] || @_template_path[:all]).gsub(/\*/,format.to_s)
      end

      def get_cache(format)
        cache = self.get_template(format)
        cache = cache.gsub(/\.haml/, '')
        File.join(File.dirname(cache), '.cache', File.basename(cache))
      end

      def get_templates(format)
        template = self.get_template(format)
        (File.exists?(template) ? [template] : []).concat((!self.exclude_parent_template?(format) && self.superclass.respond_to?(:get_templates) ) ? self.superclass.get_templates(format) : [])
      end

    end

  end

end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
RubyApp-0.0.91 lib/ruby_app/mixins/template_mixin.rb
RubyApp-0.0.90 lib/ruby_app/mixins/template_mixin.rb
RubyApp-0.0.89 lib/ruby_app/mixins/template_mixin.rb
RubyApp-0.0.88 lib/ruby_app/mixins/template_mixin.rb
RubyApp-0.0.87 lib/ruby_app/mixins/template_mixin.rb
RubyApp-0.0.86 lib/ruby_app/mixins/template_mixin.rb
RubyApp-0.0.85 lib/ruby_app/mixins/template_mixin.rb
RubyApp-0.0.84 lib/ruby_app/mixins/template_mixin.rb
RubyApp-0.0.83 lib/ruby_app/mixins/template_mixin.rb
RubyApp-0.0.82 lib/ruby_app/mixins/template_mixin.rb
RubyApp-0.0.81 lib/ruby_app/mixins/template_mixin.rb
RubyApp-0.0.80 lib/ruby_app/mixins/template_mixin.rb
RubyApp-0.0.79 lib/ruby_app/mixins/template_mixin.rb
RubyApp-0.0.78 lib/ruby_app/mixins/template_mixin.rb
RubyApp-0.0.77 lib/ruby_app/mixins/template_mixin.rb
RubyApp-0.0.76 lib/ruby_app/mixins/template_mixin.rb
RubyApp-0.0.75 lib/ruby_app/mixins/template_mixin.rb
RubyApp-0.0.74 lib/ruby_app/mixins/template_mixin.rb
RubyApp-0.0.73 lib/ruby_app/mixins/template_mixin.rb
RubyApp-0.0.72 lib/ruby_app/mixins/template_mixin.rb