Sha256: 02ba8a41162ee4960c4233a2e52446e8e2de05a1ca85d09759ab987a4ff1c614

Contents?: true

Size: 1.18 KB

Versions: 8

Compression:

Stored size: 1.18 KB

Contents

module Storytime::PostPartialInheritance
  extend ActiveSupport::Concern

  module ClassMethods

    # Tries to render the appropriate partial, respecting inheritance and per-site overrides
    # Order of preference (lowest is last) looks something like:
    # storytime/views/site-name/blog_posts/blog_post
    # storytime/views/blog_posts/blog_post
    # storytime/views/site-name/posts/post
    # storytime/views/post/post
    def _to_partial_path(site)
      @_to_partial_path ||= begin
        element = ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(self))
        collection = ActiveSupport::Inflector.tableize(self.to_s)
        
        if site && File.exists?(Rails.root.join('app', 'views', "storytime/#{site.custom_view_path}/#{collection.sub("storytime/", "")}/_#{element}.html.erb"))
          "storytime/#{site.custom_view_path}/#{collection.sub("storytime/", "")}/#{element}"
        elsif File.exists?(Rails.root.join('app', 'views', collection, "_#{element}.html.erb")) ||
              self.superclass == ActiveRecord::Base
          "#{collection}/#{element}"
        else
          self.superclass._to_partial_path(site)
        end
      end
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
storytime-2.1.6 app/models/concerns/storytime/post_partial_inheritance.rb
storytime-2.1.5 app/models/concerns/storytime/post_partial_inheritance.rb
storytime-2.1.4 app/models/concerns/storytime/post_partial_inheritance.rb
storytime-2.1.3 app/models/concerns/storytime/post_partial_inheritance.rb
storytime-2.1.2 app/models/concerns/storytime/post_partial_inheritance.rb
storytime-2.1.1 app/models/concerns/storytime/post_partial_inheritance.rb
storytime-2.1.0 app/models/concerns/storytime/post_partial_inheritance.rb
storytime-2.0.0 app/models/concerns/storytime/post_partial_inheritance.rb