Module: InlineStylesMailer::ClassMethods

Defined in:
lib/inline_styles_mailer.rb

Instance Method Summary collapse

Instance Method Details

#css_contentObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/inline_styles_mailer.rb', line 25

def css_content
  @stylesheet_path ||= File.join("app", "assets", "stylesheets")
  @css_content ||= stylesheets.map {|stylesheet|
    Dir[Rails.root.join(@stylesheet_path, "#{stylesheet}")].map {|file|
      case file
      when /\.scss$/
        Sass::Engine.new(File.read(file), syntax: :scss).render
      when /\.sass$/
        Sass::Engine.new(File.read(file), syntax: :sass).render
      else
        # Plain old CSS? Let's assume it is.
        File.read(file)
      end
    }.join("\n")
  }.compact.join("\n")
  @css_content
end

#locate_template(name) ⇒ Object



21
22
23
# File 'lib/inline_styles_mailer.rb', line 21

def locate_template(name)
  "#{self.name.underscore}/#{name}.html"
end

#pageObject



47
48
49
# File 'lib/inline_styles_mailer.rb', line 47

def page
  @page ||= InlineStyles::Page.new.with_css(css_content)
end

#resetObject

For testing



52
53
54
55
# File 'lib/inline_styles_mailer.rb', line 52

def reset
  @css_content = nil
  @page = nil
end

#stylesheet_path(path) ⇒ Object



17
18
19
# File 'lib/inline_styles_mailer.rb', line 17

def stylesheet_path(path)
  @stylesheet_path = path
end

#stylesheetsObject



43
44
45
# File 'lib/inline_styles_mailer.rb', line 43

def stylesheets
  @stylesheets ||= [self.name.underscore.sub(/^(.*\/)*(.*)$/, '\1_\2*')]
end

#use_stylesheet(*stylesheets) ⇒ Object



13
14
15
# File 'lib/inline_styles_mailer.rb', line 13

def use_stylesheet(*stylesheets)
  @stylesheets = Array(stylesheets)
end