Class: Inkcite::Email
- Inherits:
-
Object
- Object
- Inkcite::Email
- Defined in:
- lib/inkcite/email.rb
Constant Summary collapse
- BROWSER_VERSION =
:'browser-version'- CACHE_BUST =
:'cache-bust'- IMAGE_HOST =
:'image-host'- IMAGE_PLACEHOLDERS =
:'image-placeholders'- OPTIMIZE_IMAGES =
:'optimize-images'- TRACK_LINKS =
:'track-links'- VIEW_IN_BROWSER_URL =
:'view-in-browser-url'- IMAGES =
Sub-directory where images are located.
'images'- ENVIRONMENTS =
Allowed environments.
[ :development, :preview, :production ].freeze
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
The path to the directory from which the email is being generated.
Instance Method Summary collapse
- #config ⇒ Object
- #formats(env = nil) ⇒ Object
- #image_dir ⇒ Object
- #image_path(file) ⇒ Object
-
#initialize(path) ⇒ Email
constructor
A new instance of Email.
- #meta(key) ⇒ Object
-
#optimize_images ⇒ Object
Optimizes this email’s images if optimize-images is enabled in the email configuration.
-
#optimize_images! ⇒ Object
Optimizes all of the images in this email.
- #optimize_images? ⇒ Boolean
-
#optimized_image_dir ⇒ Object
Returns the directory that optimized, compressed images have been saved to.
- #project_file(file) ⇒ Object
- #set_meta(key, value) ⇒ Object
- #upload ⇒ Object
- #upload! ⇒ Object
- #versions ⇒ Object
- #view(environment, format, version = nil) ⇒ Object
-
#views(environment, &block) ⇒ Object
Returns an array of all possible Views (every combination of version and format )of this email for the designated environment.
Constructor Details
#initialize(path) ⇒ Email
Returns a new instance of Email.
22 23 24 |
# File 'lib/inkcite/email.rb', line 22 def initialize path @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
The path to the directory from which the email is being generated. e.g. /projects/emails/holiday-mailing
20 21 22 |
# File 'lib/inkcite/email.rb', line 20 def path @path end |
Instance Method Details
#config ⇒ Object
26 27 28 |
# File 'lib/inkcite/email.rb', line 26 def config Util.read_yml(File.join(path, 'config.yml'), :fail_if_not_exists => true) end |
#formats(env = nil) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/inkcite/email.rb', line 30 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 ⇒ Object
45 46 47 |
# File 'lib/inkcite/email.rb', line 45 def image_dir File.join(path, IMAGES) end |
#image_path(file) ⇒ Object
49 50 51 |
# File 'lib/inkcite/email.rb', line 49 def image_path file File.join(image_dir, file) end |
#meta(key) ⇒ Object
53 54 55 |
# File 'lib/inkcite/email.rb', line 53 def key [key.to_sym] end |
#optimize_images ⇒ Object
Optimizes this email’s images if optimize-images is enabled in the email configuration.
59 60 61 |
# File 'lib/inkcite/email.rb', line 59 def optimize_images Minifier.images(self, false) if optimize_images? end |
#optimize_images! ⇒ Object
Optimizes all of the images in this email.
64 65 66 |
# File 'lib/inkcite/email.rb', line 64 def optimize_images! Minifier.images(self, true) end |
#optimize_images? ⇒ Boolean
68 69 70 |
# File 'lib/inkcite/email.rb', line 68 def optimize_images? config[OPTIMIZE_IMAGES] == true end |
#optimized_image_dir ⇒ Object
Returns the directory that optimized, compressed images have been saved to.
74 75 76 |
# File 'lib/inkcite/email.rb', line 74 def optimized_image_dir File.join(path, optimize_images?? Minifier::IMAGE_CACHE : IMAGES) end |
#project_file(file) ⇒ Object
78 79 80 |
# File 'lib/inkcite/email.rb', line 78 def project_file file File.join(path, file) end |
#set_meta(key, value) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/inkcite/email.rb', line 82 def key, value md = md[key.to_sym] = value File.open(File.join(path, ), 'w+') { |f| f.write(md.to_yaml) } value end |
#upload ⇒ Object
89 90 91 92 |
# File 'lib/inkcite/email.rb', line 89 def upload require_relative 'uploader' Uploader.upload(self) end |
#upload! ⇒ Object
94 95 96 97 |
# File 'lib/inkcite/email.rb', line 94 def upload! require_relative 'uploader' Uploader.upload!(self) end |
#versions ⇒ Object
99 100 101 |
# File 'lib/inkcite/email.rb', line 99 def versions [* self.config[:versions] || :default ].collect(&:to_sym) end |
#view(environment, format, version = nil) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/inkcite/email.rb', line 103 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, &block) ⇒ Object
Returns an array of all possible Views (every combination of version and format )of this email for the designated environment.
123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/inkcite/email.rb', line 123 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 |