class Inkcite::Email
Constants
- BROWSER_VERSION
- CACHE_BUST
- ENVIRONMENTS
Allowed environments.
- IMAGES
Sub-directory where images are located.
- IMAGE_HOST
- IMAGE_PLACEHOLDERS
- META_FILE
- META_FILE_NAME
Name of the property controlling the meta data file name and the default file name.
- OPTIMIZE_IMAGES
- TRACK_LINKS
- VIEW_IN_BROWSER_URL
Attributes
path[R]
The path to the directory from which the email is being generated. e.g. /projects/emails/holiday-mailing
Public Class Methods
new(path)
click to toggle source
# File lib/inkcite/email.rb, line 22 def initialize path @path = path end
Public Instance Methods
config()
click to toggle source
# File lib/inkcite/email.rb, line 26 def config Util.read_yml(config_file, :fail_if_not_exists => true) end
config_file()
click to toggle source
# File lib/inkcite/email.rb, line 30 def config_file File.join(path, 'config.yml') end
formats(env=nil)
click to toggle source
# File lib/inkcite/email.rb, line 34 def formats env=nil # Inkcite is always capable of producing an email version of # the project. f = [ :email ] f << :browser if config[BROWSER_VERSION] == true # Need to make sure a source.txt exists before we can include # it in the list of known formats. f << :text if File.exist?(project_file('source.txt')) f end
image_dir()
click to toggle source
# File lib/inkcite/email.rb, line 49 def image_dir File.join(path, IMAGES) end
image_path(file)
click to toggle source
# File lib/inkcite/email.rb, line 53 def image_path file File.join(image_dir, file) end
meta(key)
click to toggle source
# File lib/inkcite/email.rb, line 57 def meta key meta_data[key.to_sym] end
optimize_images()
click to toggle source
Optimizes this email's images if optimize-images is enabled in the email configuration.
# File lib/inkcite/email.rb, line 63 def optimize_images ImageMinifier.minify_all(self, false) if optimize_images? end
optimize_images!()
click to toggle source
Optimizes all of the images in this email.
# File lib/inkcite/email.rb, line 68 def optimize_images! ImageMinifier.minify_all(self, true) end
optimize_images?()
click to toggle source
# File lib/inkcite/email.rb, line 72 def optimize_images? config[OPTIMIZE_IMAGES] == true end
optimized_image_dir()
click to toggle source
Returns the directory that optimized, compressed images have been saved to.
# File lib/inkcite/email.rb, line 78 def optimized_image_dir File.join(path, optimize_images?? ImageMinifier::IMAGE_CACHE : IMAGES) end
project_file(file)
click to toggle source
# File lib/inkcite/email.rb, line 82 def project_file file File.join(path, file) end
set_meta(key, value)
click to toggle source
# File lib/inkcite/email.rb, line 86 def set_meta key, value md = meta_data md[key.to_sym] = value File.open(File.join(path, meta_file_name), 'w+') { |f| f.write(md.to_yaml) } value end
upload(opts={})
click to toggle source
# File lib/inkcite/email.rb, line 93 def upload opts={} require_relative 'uploader' Uploader.upload(self, opts) end
versions()
click to toggle source
# File lib/inkcite/email.rb, line 98 def versions [* self.config[:versions] || :default ].collect(&:to_sym) end
view(environment, format, version=nil)
click to toggle source
# File lib/inkcite/email.rb, line 102 def view environment, format, version=nil environment = environment.to_sym format = format.to_sym version = (version || versions.first).to_sym raise "Unknown environment \"#{environment}\" - must be one of #{ENVIRONMENTS.join(',')}" unless ENVIRONMENTS.include?(environment) _formats = formats(environment) raise "Unknown format \"#{format}\" - must be one of #{_formats.join(',')}" unless _formats.include?(format) raise "Unknown version: \"#{version}\" - must be one of #{versions.join(',')}" unless versions.include?(version) # Instantiate a new view of this email with the desired view and # format. View.new(self, environment, format, version) end
views(environment) { |ev| ... }
click to toggle source
Returns an array of all possible Views (every combination of version and format )of this email for the designated environment.
# File lib/inkcite/email.rb, line 122 def views environment, &block vs = [] formats(environment).each do |format| versions.each do |version| ev = view(environment, format, version) yield(ev) if block_given? vs << ev end end vs end
Private Instance Methods
meta_data()
click to toggle source
# File lib/inkcite/email.rb, line 144 def meta_data Util.read_yml(File.join(path, meta_file_name)) end
meta_file_name()
click to toggle source
# File lib/inkcite/email.rb, line 148 def meta_file_name config[META_FILE_NAME] || META_FILE end