inkcite 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e3066d2404f84bcdf743a160b8c85cc838cd19c0
4
- data.tar.gz: 73adb02dd0f48a81a2b9223a5f03d221c18fa908
3
+ metadata.gz: 3e391fed5c45670dba9e4bb01afdec27bb9ce9a8
4
+ data.tar.gz: 07dded169cb4a67d56cad26c7f39ead9c3118dfa
5
5
  SHA512:
6
- metadata.gz: 39ff00165434c67e13ae7b72fa5cb90c4991530ab5005059d0c7f64c118c62a55b7be3cc60d147f44536bbf710934a4c7c455c248f205e75c7ca87730451fe41
7
- data.tar.gz: aa990339b0f3ef6b949231ad2d5efd27eb5218f2e6ccd525a4413a8e421a84d480c3579a11a2bb5e89be862f6483e45130b396f3d66cdb71c1c99f075d695146
6
+ metadata.gz: 541565fcca55aaa6253a29bc437f3350ea4376514da88c13ae1efad1ed2c5d8eff7449949136d406a336d3ee0d36b9c7468e21d63044f6f83bc0af38018153a4
7
+ data.tar.gz: 31fb64ab71c6973d79a92d706ce2328016db9e9f36c9364eba715838088a0f3e631c6ba6a4624c68c04b9d31db6977d03cbfeb778eee8f74da8e8e48f2a7b83c
@@ -49,7 +49,14 @@ module Inkcite
49
49
  meta_data[key.to_sym]
50
50
  end
51
51
 
52
+ # Optimizes this email's images if optimize-images is enabled
53
+ # in the email configuration.
52
54
  def optimize_images
55
+ optimize_images! if optimize_images?
56
+ end
57
+
58
+ # Optimizes all of the images in this email.
59
+ def optimize_images!
53
60
  Minifier.images(self)
54
61
  end
55
62
 
@@ -63,23 +70,6 @@ module Inkcite
63
70
  File.join(path, optimize_images?? Minifier::IMAGE_CACHE : IMAGES)
64
71
  end
65
72
 
66
- def properties
67
-
68
- opts = {
69
- :n => NEW_LINE
70
- }
71
-
72
- # Load the project's properties, which may include references to additional
73
- # properties in other directories.
74
- read_properties opts, 'helpers.tsv'
75
-
76
- # As a convenience pre-populate the month name of the email.
77
- mm = opts[:mm].to_i
78
- opts[:month] = Date::MONTHNAMES[mm] if mm > 0
79
-
80
- opts
81
- end
82
-
83
73
  def project_file file
84
74
  File.join(path, file)
85
75
  end
@@ -115,12 +105,9 @@ module Inkcite
115
105
  raise "Unknown format \"#{format}\" - must be one of #{FORMATS.join(',')}" unless FORMATS.include?(format)
116
106
  raise "Unknown version: \"#{version}\" - must be one of #{versions.join(',')}" unless versions.include?(version)
117
107
 
118
- opt = properties
119
- opt.merge!(self.config)
120
-
121
108
  # Instantiate a new view of this email with the desired view and
122
109
  # format.
123
- View.new(self, environment, format, version, opt)
110
+ View.new(self, environment, format, version)
124
111
 
125
112
  end
126
113
 
@@ -151,16 +138,6 @@ module Inkcite
151
138
  META_FILE_NAME = :'meta-file'
152
139
  META_FILE = '.inkcite'
153
140
 
154
- COMMENT = '//'
155
- NEW_LINE = "\n"
156
- TAB = "\t"
157
- CARRIAGE_RETURN = "\r"
158
-
159
- # Used for
160
- MULTILINE_START = "<<-START"
161
- MULTILINE_END = "END->>"
162
- TAB_TO_SPACE = ' '
163
-
164
141
  def meta_data
165
142
  Util.read_yml(File.join(path, meta_file_name), false)
166
143
  end
@@ -169,51 +146,5 @@ module Inkcite
169
146
  config[META_FILE_NAME] || META_FILE
170
147
  end
171
148
 
172
- def read_properties into, file
173
-
174
- fp = File.join(path, file)
175
- abort("Can't find #{file} in #{path} - are you sure this is an Inkcite project?") unless File.exists?(fp)
176
-
177
- # Consolidate line-breaks for simplicity
178
- raw = File.read(fp)
179
- raw.gsub!(/[\r\f\n]{1,}/, NEW_LINE)
180
-
181
- # Initial position of the
182
- multiline_starts_at = 0
183
-
184
- # Determine if there are any multiline declarations - those that are wrapped with
185
- # <<-START and END->> and reduce them to single line declarations.
186
- while (multiline_starts_at = raw.index(MULTILINE_START, multiline_starts_at))
187
-
188
- break unless (multiline_ends_at = raw.index(MULTILINE_END, multiline_starts_at))
189
-
190
- declaration = raw[(multiline_starts_at+MULTILINE_START.length)..multiline_ends_at - 1]
191
- declaration.strip!
192
- declaration.gsub!(/\t/, TAB_TO_SPACE)
193
- declaration.gsub!(/\n/, "\r")
194
-
195
- raw[multiline_starts_at..multiline_ends_at+MULTILINE_END.length - 1] = declaration
196
-
197
- end
198
-
199
- raw.split(NEW_LINE).each do |line|
200
- next if line.starts_with?(COMMENT)
201
-
202
- line.gsub!(/\r/, NEW_LINE)
203
- line.strip!
204
-
205
- key, open, close = line.split(TAB)
206
- next if key.blank?
207
-
208
- into[key.to_sym] = open.to_s.freeze
209
-
210
- # Prepend the key with a "/" and populate the closing tag.
211
- into["/#{key}".to_sym] = close.to_s.freeze
212
-
213
- end
214
-
215
- true
216
- end
217
-
218
149
  end
219
150
  end
@@ -1,3 +1,3 @@
1
1
  module Inkcite
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -38,15 +38,20 @@ module Inkcite
38
38
  attr_accessor :css_compressor
39
39
  attr_accessor :js_compressor
40
40
 
41
- def initialize email, environment, format, version, config
41
+ def initialize email, environment, format, version
42
42
  @email = email
43
43
  @environment = environment
44
44
  @format = format
45
45
  @version = version
46
46
 
47
- # TODO Read this ourselves and run it through Erubis for better
48
- # a/b testing capabilities
49
- @config = config
47
+ # Read the helper(s) for this view of the email. This will load
48
+ # the default helpers.tsv and any version-specific (e.g. returning-customer.tsv)
49
+ # helper allowing for overrides.
50
+ @config = load_helpers
51
+
52
+ # Merge in the email's configuration for convience - providing access
53
+ # to the renderers.
54
+ @config.merge!(email.config)
50
55
 
51
56
  # Expose the version, format as a properties so that it can be resolved when
52
57
  # processing pathnames and such. These need to be strings because they are
@@ -468,6 +473,7 @@ module Inkcite
468
473
  NEW_LINE = "\n"
469
474
  REGEX_SLASH = '/'
470
475
  SOURCE_ENCODING = :'source-encoding'
476
+ TAB = "\t"
471
477
  TXT_EXTENSION = '.txt'
472
478
  UTF_8 = 'utf-8'
473
479
 
@@ -481,6 +487,21 @@ module Inkcite
481
487
  # Used when there is no subject or title for this email.
482
488
  UNTITLED_EMAIL = 'Untitled Email'
483
489
 
490
+ # Used to denote the start and end of a multi-line helper entry. e.g.
491
+ # feature-story <<-START
492
+ # I'm a multiline helper where line breaks and indendentation
493
+ # can be used to make the helper file more readable, debuggable.
494
+ # END->>
495
+ MULTILINE_START = "<<-START"
496
+ MULTILINE_END = "END->>"
497
+
498
+ # Tabs within a multiline helper are converted to spaces.
499
+ TAB_TO_SPACE = ' '
500
+
501
+ # Used to mark a helper.tsv line as a comment.
502
+ COMMENT = '//'
503
+
504
+
484
505
  def assert_in_browser msg
485
506
  raise msg if email? && !development?
486
507
  end
@@ -679,6 +700,78 @@ module Inkcite
679
700
  html.join(NEW_LINE)
680
701
  end
681
702
 
703
+ def load_helper_file filename, into, abort_on_fail=true
704
+
705
+ path = @email.path
706
+ file = File.join(path, filename)
707
+ unless File.exists?(file)
708
+ abort("Can't find #{filename} in #{path} - are you sure this is an Inkcite project?") if abort_on_fail
709
+ return
710
+ end
711
+
712
+ # Consolidate line-breaks for simplicity
713
+ raw = File.read(file)
714
+ raw.gsub!(/[\r\f\n]{1,}/, NEW_LINE)
715
+
716
+ # Initial position of the
717
+ multiline_starts_at = 0
718
+
719
+ # Determine if there are any multiline declarations - those that are wrapped with
720
+ # <<-START and END->> and reduce them to single line declarations.
721
+ while (multiline_starts_at = raw.index(MULTILINE_START, multiline_starts_at))
722
+
723
+ break unless (multiline_ends_at = raw.index(MULTILINE_END, multiline_starts_at))
724
+
725
+ declaration = raw[(multiline_starts_at+MULTILINE_START.length)..multiline_ends_at - 1]
726
+ declaration.strip!
727
+ declaration.gsub!(/\t/, TAB_TO_SPACE)
728
+ declaration.gsub!(/\n/, "\r")
729
+
730
+ raw[multiline_starts_at..multiline_ends_at+MULTILINE_END.length - 1] = declaration
731
+
732
+ end
733
+
734
+ raw.split(NEW_LINE).each do |line|
735
+ next if line.starts_with?(COMMENT)
736
+
737
+ line.gsub!(/\r/, NEW_LINE)
738
+ line.strip!
739
+
740
+ key, open, close = line.split(TAB)
741
+ next if key.blank?
742
+
743
+ into[key.to_sym] = open.to_s.freeze
744
+
745
+ # Prepend the key with a "/" and populate the closing tag.
746
+ into["/#{key}".to_sym] = close.to_s.freeze
747
+
748
+ end
749
+
750
+ true
751
+ end
752
+
753
+ # Reads the helpers.tsv and any version-specific override (e.g. helpers-owners.tsv)
754
+ def load_helpers
755
+
756
+ _helpers = {
757
+ :n => NEW_LINE
758
+ }
759
+
760
+ # Load the project's properties, which may include references to additional
761
+ # properties in other directories.
762
+ load_helper_file 'helpers.tsv', _helpers
763
+
764
+ # Look for a version-specific override allowing restyling of an email based
765
+ # on its version - e.g. difference colors in the "no orders for 30 days" email.
766
+ load_helper_file "helpers-#{@version}.tsv", _helpers, false
767
+
768
+ # As a convenience pre-populate the month name of the email.
769
+ mm = _helpers[:mm].to_i
770
+ _helpers[:month] = Date::MONTHNAMES[mm] if mm > 0
771
+
772
+ _helpers
773
+ end
774
+
682
775
  # Retrieves the version-specific meta data for this view.
683
776
  def meta_data
684
777
  @email.meta version
@@ -8,9 +8,4 @@ describe Inkcite::Email do
8
8
  @email = Inkcite::Email.new('test/project/')
9
9
  end
10
10
 
11
- it 'supports multi-line property declarations' do
12
- @email.properties[:multiline].must_equal("This\n is a\n multiline tag.")
13
- @email.properties[:"/multiline"].must_equal("This\n ends the\n multiline tag.")
14
- end
15
-
16
11
  end
@@ -12,4 +12,9 @@ describe Inkcite::View do
12
12
  Inkcite::Renderer.fix_illegal_characters('“That’s what she said!”', @view).must_equal('&#8220;That&#8217;s what she said!&#8221;')
13
13
  end
14
14
 
15
+ it 'supports multi-line property declarations' do
16
+ @view[:multiline].must_equal("This\n is a\n multiline tag.")
17
+ @view[:'/multiline'].must_equal("This\n ends the\n multiline tag.")
18
+ end
19
+
15
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inkcite
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeffrey D. Hoffman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-23 00:00:00.000000000 Z
11
+ date: 2015-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport