Class: LiquidMarkdown::Resolver

Inherits:
ActionView::Resolver
  • Object
show all
Includes:
Singleton
Defined in:
lib/liquid_markdown/resolver.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.using(model, options = {}) ⇒ Object

Instantiate Resolver by passing a model (decoupled from ORMs)



38
39
40
41
42
# File 'lib/liquid_markdown/resolver.rb', line 38

def self.using(model, options={})
  @@model = model
  @@resolver_options = options
  self.instance
end

Instance Method Details

#find_templates(name, prefix, partial, details, key = nil, locals = []) ⇒ Object

this method is mandatory to implement a Resolver



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/liquid_markdown/resolver.rb', line 7

def find_templates(name, prefix, partial, details, key=nil, locals=[])
  return [] if @@resolver_options[:only] && !@@resolver_options[:only].include?(prefix)

  conditions = {
      :path => build_path(name, prefix),
      :locale => [normalize_array(details[:locale]).first, nil],
      :format => normalize_array(details[:formats]),
      :handler => normalize_array(details[:handlers]),
      :partial => partial || false
  }

  @records = []
  @@model.find_model_templates(conditions).map do |record|
    @records << record
    if record.format == 'html'
      rec = OpenStruct.new(record.attributes)
      rec.format = 'text'
      @records << rec
    else
      rec = OpenStruct.new(record.attributes)
      rec.format = 'html'
      @records << rec
    end
  end

  @records.map do |record|
    initialize_template(record, record.format)
  end
end