Module: Premailer::Rails::CSSLoaders::FileSystemLoader

Extended by:
FileSystemLoader
Included in:
FileSystemLoader
Defined in:
lib/premailer/rails/css_loaders/file_system_loader.rb

Instance Method Summary collapse

Instance Method Details

#asset_filename(filename) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/premailer/rails/css_loaders/file_system_loader.rb', line 20

def asset_filename(filename)
  if defined?(::Rails) && ::Rails.respond_to?(:root)
    File.join(::Rails.root, 'public', filename)
  else
    File.join('public', filename)
  end
end

#file_name(url) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/premailer/rails/css_loaders/file_system_loader.rb', line 12

def file_name(url)
  path = URI(url).path
  if relative_url_root
    path = path.sub(/\A#{relative_url_root.chomp('/')}/, '')
  end
  asset_filename(path)
end

#load(url) ⇒ Object



7
8
9
10
# File 'lib/premailer/rails/css_loaders/file_system_loader.rb', line 7

def load(url)
  file = file_name(url)
  File.read(file) if File.file?(file)
end

#relative_url_rootObject



28
29
30
31
32
33
# File 'lib/premailer/rails/css_loaders/file_system_loader.rb', line 28

def relative_url_root
  defined?(::Rails) &&
    ::Rails.respond_to?(:configuration) &&
    ::Rails.configuration.respond_to?(:relative_url_root) &&
    ::Rails.configuration.relative_url_root
end