Sha256: 9fcba79822641985aca8d2dc37d36ee8071f5f399103e1e8f5e5deeb5979d8c0

Contents?: true

Size: 1.28 KB

Versions: 39

Compression:

Stored size: 1.28 KB

Contents

module Blue
  module Template

    def self.included(klass)
      klass.class_eval do
        def local_template_dir
          @local_template_dir ||= Pathname.new(Blue.rails_current + '/app/manifests/templates')
        end

        def local_template(pathname)
         (local_template_dir + pathname.basename).expand_path
        end

        # Render the ERB template located at <tt>pathname</tt>. If a template exists
        # with the same basename at <tt>RAILS_ROOT/app/manifests/templates</tt>, it
        # is used instead. This is useful to override templates provided by plugins
        # to customize application configuration files.
        def template(pathname, b = binding)
          pathname = Pathname.new(pathname) unless pathname.kind_of?(Pathname)

          pathname = if local_template(pathname).exist?
                       local_template(pathname)
                     elsif pathname.exist?
                       pathname
                     else
                       raise LoadError, "Can't find template #{pathname}"
                     end
          erb = ERB.new(pathname.read)
          erb.filename = pathname.to_s
          erb.result(b)
        end
      end
    end

    def template(pathname, b = binding)
      self.class.template(pathname, b)
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
blue-0.0.20 lib/blue/template.rb
blue-0.0.19 lib/blue/template.rb
blue-0.0.18 lib/blue/template.rb
blue-0.0.17 lib/blue/template.rb
blue-0.0.16 lib/blue/template.rb
blue-0.0.15 lib/blue/template.rb
blue-0.0.14 lib/blue/template.rb
blue-0.0.13 lib/blue/template.rb
blue-0.0.12 lib/blue/template.rb
blue-0.0.11 lib/blue/template.rb
blue-0.0.10 lib/blue/template.rb
blue-0.0.9 lib/blue/template.rb
blue-0.0.8 lib/blue/template.rb
blue-0.0.7 lib/blue/template.rb
blue-0.0.6 lib/blue/template.rb
blue-0.0.5 lib/blue/template.rb
blue-0.0.4 lib/blue/template.rb
blue-0.0.3 lib/blue/template.rb
blue-0.0.2 lib/blue/template.rb