Module: Warped::Emails::Styleable::ClassMethods

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#base_stylesObject



30
31
32
# File 'lib/warped/emails/styleable.rb', line 30

def base_styles
  @base_styles ||= {}
end

#default_variantsObject



26
27
28
# File 'lib/warped/emails/styleable.rb', line 26

def default_variants
  @default_variants ||= {}
end

#variantsObject



34
35
36
# File 'lib/warped/emails/styleable.rb', line 34

def variants
  @variants ||= {}
end

Instance Method Details

#default_variant(variant_name = :_base_variant, **kwargs) ⇒ Object

Raises:

  • (ArgumentError)


45
46
47
48
49
50
51
# File 'lib/warped/emails/styleable.rb', line 45

def default_variant(variant_name = :_base_variant, **kwargs)
  raise ArgumentError, "You must provide a hash" unless kwargs.is_a?(Hash)

  self.default_variants ||= {}
  self.default_variants[variant_name] ||= {}
  self.default_variants[variant_name].merge!(kwargs)
end

#inherited(subclass) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/warped/emails/styleable.rb', line 18

def inherited(subclass)
  super

  subclass.default_variants = default_variants.deep_dup.deep_merge!(subclass.default_variants)
  subclass.base_styles = base_styles.deep_dup.deep_merge!(subclass.base_styles)
  subclass.variants = variants.deep_dup.deep_merge!(subclass.variants)
end

#variant(name = :_base_variant) ⇒ Object

Raises:

  • (ArgumentError)


38
39
40
41
42
43
# File 'lib/warped/emails/styleable.rb', line 38

def variant(name = :_base_variant, &)
  raise ArgumentError, "You must provide a block" unless block_given?

  variant_builder = VariantBuilder.new(self, variant_name: name)
  variant_builder.compile_variants(&)
end