Class: Railsthemes::EmailInstaller
- Inherits:
-
Object
- Object
- Railsthemes::EmailInstaller
show all
- Includes:
- Logging
- Defined in:
- lib/railsthemes/email_installer.rb
Instance Method Summary
collapse
Methods included from Logging
debug, logger, #logger, logger=, verbose
Instance Method Details
#add_to_asset_precompilation_list ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/railsthemes/email_installer.rb', line 28
def add_to_asset_precompilation_list
filenames = email_stylesheet_filenames.map do |filename|
"railsthemes/#{File.basename(filename.gsub(/\.erb$/, ''))}"
end
updated_or_new_line = " config.assets.precompile += %w( #{filenames.join(' ')} )"
config_lines = Utils.lines('config/environments/production.rb')
email_regex = /^\s*config.assets.precompile\s*\+=\s*%w\(\s*railsthemes\/\w*email\.css.*\)$/
count = config_lines.grep(email_regex).count
if count == 0 added = false Utils.safe_write('config/environments/production.rb') do |f|
config_lines.each do |line|
f.puts line
if !added && (line =~ /Precompile additional assets/ || line =~ /config\.assets\.precompile/)
f.puts updated_or_new_line
added = true
end
end
end
else
Utils.safe_write('config/environments/production.rb') do |f|
config_lines.each do |line|
if line =~ email_regex
f.puts updated_or_new_line
else
f.puts line
end
end
end
end
end
|
#email_stylesheet_filenames ⇒ Object
5
6
7
|
# File 'lib/railsthemes/email_installer.rb', line 5
def email_stylesheet_filenames
Dir["app/assets/stylesheets/railsthemes/*_email.css.*"]
end
|
#install_from_file_system(source_filepath) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/railsthemes/email_installer.rb', line 9
def install_from_file_system source_filepath
if email_stylesheet_filenames.count > 0
logger.warn 'Installing email...'
logger.info "Source filepath: #{source_filepath}"
unless File.directory?(source_filepath)
Safe.log_and_abort 'Expected a directory to install email theme from, but found none.'
end
add_to_asset_precompilation_list
install_mail_gems_if_necessary
logger.warn 'Done installing email.'
true
else
false
end
end
|
#install_mail_gems_if_necessary ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/railsthemes/email_installer.rb', line 61
def install_mail_gems_if_necessary
gem_names = Utils.gemspecs.map(&:name)
logger.debug "gem_names: #{gem_names}"
unless gem_names.include?('premailer-rails')
if (gem_names & ['hpricot', 'nokogiri']).empty?
Utils.add_gem_to_gemfile 'hpricot'
end
logger.warn 'Installing assistant mail gems...'
Utils.add_gem_to_gemfile 'premailer-rails'
logger.warn 'Done installing assistant mail gems.'
end
end
|