Module: Warped::Emails::Slottable::ClassMethods

Defined in:
lib/warped/emails/slottable.rb

Instance Method Summary collapse

Instance Method Details

#slots_many(name) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/warped/emails/slottable.rb', line 30

def slots_many(name)
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
    # def with_column(&block)
    #   slots[:many][:columns] ||= []
    #   slots[:many][:columns] << block
    # end
    #
    # def columns
    #   return [] if slots[:many][:columns].empty?
    #
    #   slots[:many][:columns].map { |block| capture(&block) }
    # end
    def with_#{name.to_s.singularize}(&block)
      slots[:many][:#{name}] ||= []
      slots[:many][:#{name}] << block
    end

    def #{name}
      return [] if slots[:many][:#{name}].empty?

      slots[:many][:#{name}].map { |block| capture(&block) }
    end
  RUBY
end

#slots_one(name) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/warped/emails/slottable.rb', line 11

def slots_one(name)
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
    # def with_header(&block)
    #   slots[:one][:header] = block
    # end
    #
    # def header
    #   capture(&slots[:one][:header]) if slots[:one][:header]
    # end
    def with_#{name}(&block)
      slots[:one][:#{name}] = block
    end

    def #{name}
      capture(&slots[:one][:#{name}]) if slots[:one][:#{name}]
    end
  RUBY
end