Sha256: dbfc0812daea10904adb65b98868733eaf222c311935ea4abcbca2e08312cc51

Contents?: true

Size: 1.14 KB

Versions: 17

Compression:

Stored size: 1.14 KB

Contents

module EffectiveEmailTemplates
  class LiquidResolver < ::ActionView::Resolver

    attr_reader :name, :prefix
    alias_method :slug, :name

    def find_all(name, prefix=nil, partial=false, details={}, key=nil, locals=[])
      # key is used for caching which we won't do since
      # these templates can be updated at any time by
      # an admin. TODO: expire the resolver's cache when
      # a template is updated rather than skip caching
      @name = name
      @prefix = prefix

      return [] unless liquid_mailer?

      templates = collect_view_templates
      decorate(templates, [name, prefix, partial], details, locals)
      templates
    end

  private

    # Ensures all the resolver information is set in the template.
    def decorate(templates, path_info, details, locals)
      templates.each do |t|
        t.locals = locals
      end
    end

    def collect_view_templates
      effective_email_templates.map do |eet|
        EmailViewTemplate.new(eet)
      end
    end

    def effective_email_templates
      Array.wrap(Effective::EmailTemplate.find_by_slug(slug))
    end

    def liquid_mailer?
      prefix =~ /liquid/
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
effective_email_templates-0.6.1 lib/effective_email_templates/liquid_resolver.rb
effective_email_templates-0.6.0 lib/effective_email_templates/liquid_resolver.rb
effective_email_templates-0.5.1 lib/effective_email_templates/liquid_resolver.rb
effective_email_templates-0.5.0 lib/effective_email_templates/liquid_resolver.rb
effective_email_templates-0.4.6 lib/effective_email_templates/liquid_resolver.rb
effective_email_templates-0.4.5 lib/effective_email_templates/liquid_resolver.rb
effective_email_templates-0.4.4 lib/effective_email_templates/liquid_resolver.rb
effective_email_templates-0.4.3 lib/effective_email_templates/liquid_resolver.rb
effective_email_templates-0.4.2 lib/effective_email_templates/liquid_resolver.rb
effective_email_templates-0.4.1 lib/effective_email_templates/liquid_resolver.rb
effective_email_templates-0.4.0 lib/effective_email_templates/liquid_resolver.rb
effective_email_templates-0.3.5 lib/effective_email_templates/liquid_resolver.rb
effective_email_templates-0.3.4 lib/effective_email_templates/liquid_resolver.rb
effective_email_templates-0.3.3 lib/effective_email_templates/liquid_resolver.rb
effective_email_templates-0.3.1 lib/effective_email_templates/liquid_resolver.rb
effective_email_templates-0.3.0 lib/effective_email_templates/liquid_resolver.rb
effective_email_templates-0.2.8 lib/effective_email_templates/liquid_resolver.rb