-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.rb
335 lines (274 loc) · 7.46 KB
/
config.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
###
# Compass
###
# Change Compass configuration
# compass_config do |config|
# config.output_style = :compact
# end
###
# Page options, layouts, aliases and proxies
###
# Per-page layout changes:
#
# With no layout
# page "/path/to/file.html", :layout => false
#
# With alternative layout
# page "/path/to/file.html", :layout => :otherlayout
#
# A path which all have the same layout
# with_layout :admin do
# page "/admin/*"
# end
# Proxy pages (http://middlemanapp.com/basics/dynamic-pages/)
# proxy "/this-page-has-no-template.html", "/template-file.html", :locals => {
# :which_fake_page => "Rendering a fake page with a local variable" }
###
# Helpers
###
require 'date'
require 'time'
require 'slim'
require 'uri'
require 'premailer'
require 'open-uri'
require 'htmlentities'
require 'nokogiri'
Slim::Engine.disable_option_validator!
helpers do
def decode(this)
coder = HTMLEntities.new
string = this
coder.decode(string)
end
def feed_xml
feed = Nokogiri::XML(open('https://drexel.edu/biomed/news-and-events/rss'))
end
def tree
tree = Hash.new { |hash, key| hash[key] = {} }
end
def fix_relative_img(link)
link.gsub(/~\/media/,"http://drexel.edu/~/media")
end
def parse_date(date)
Date.parse(date, "%a, %b %e, %Y %H:%M:%S %z").strftime("%B %e, %Y")
end
def feed
items = []
# Search for only rss "items"
# Iterate through the children elements i.e.
# Title, Description, GUID, pubDate
# Skip over randomly injected "text" or whitespace elements
# Structure into a hash format
feed_xml.css('rss item').each_with_index do |item, index|
details = []
item.children.each do |element|
if element.name != "text"
content = decode(element.inner_html)
end
details << content
end
# puts details
items << {:title => details[1],
:description => fix_relative_img(details[3]),
:link => details[5],
:pubDate => parse_date(details[7]),
:guid => details[9]}
end
return items
end
def bme_path
"http://www.biomed.drexel.edu/media/newsletter/"
end
def newsletter_base_href
"http://biomed.drexel.edu/media/newsletter/"
end
def format_date(string)
Date.strptime(string, '%m-%d-%y').strftime("%B %d, %Y")
end
def data_file
current_page.data.data_file
end
def quarter_term
eval("data."+"#{data_file}.term")
end
def read_in_browser
newsletter_base_href + "#{quarter_term.downcase.gsub(" ", "-")}.html"
end
def spotlight
eval("data."+"#{data_file}.spotlight")
end
def students
eval("data."+"#{data_file}.students")
end
def research
eval("data."+"#{data_file}.research")
end
def faculty
eval("data."+"#{data_file}.faculty")
end
def faculty_even
faculty.select.each_with_index{ |_, i| i.even? }
end
def faculty_odd
faculty.select.each_with_index{ |_, i| i.odd? }
end
def alumni
eval("data."+"#{data_file}.alumni")
end
def utm_source
current_page.data.utm_source ||= current_page.data.source
end
def utm_medium
"HTML_Email"
end
def home_link
html = '<a target="_blank" href="http://drexel.edu/biomed'
if environment == :development
html += "#development"
html += '">'
html += "<!-- Analytics Tags: "
html += gua
html += " -->"
else
html += gua
html += '">'
end
end
def coulter_link
html = '<a target="_blank" href="http://drexel.edu/coulter'
if environment == :development
html += "#development"
html += '">'
html += "<!-- Analytics Tags: "
html += gua
html += " -->"
else
html += gua
html += '">'
end
end
def end_link
"</a>"
end
def a_href(section, index=888)
if index == 888
html = '<a target="_blank" href="'
html += eval("#{section}.url")
html += gua
html += '">'
else
html = '<a target="_blank" href="'
html += eval("#{section}"+"["+"#{index}"+"].url")
html += gua
html += '">'
end
end
def link_me (title, link)
html = '<a target="_blank" href="'
html += link
html += '">'
html += title
html += '</a>'
end
# def utm_term
# depends on where in the newsletter it is
# i.e. alumni, spotlight, students, faculty
# end
def utm_campaign
# grab info directly from YAML file
current_page.data.utm_campaign ||= current_page.data.campaign
end
def utm_term
if environment == :development
# "This is in development"
else
# grab info directly from YAML file
current_page.data.term ||= current_page.data.term
end
end
def utm_dp
current_page.data.utm_dp ||= ""
end
def utm_dt
current_page.data.utm_dt ||= ""
end
def utm_dl
current_page.data.utm_dl ||= ""
end
def ga
if environment == :development
# "This is in development"
else
"?utm_source=#{utm_source}&utm_medium=#{utm_medium}&utm_campaign=#{utm_campaign}"
end
end
def gua
if environment == :development
'#'
else
"?utm_source=#{utm_source}&utm_medium=#{utm_medium}&utm_campaign=#{utm_campaign}"
end
end
def tracking_id
"UA-87264639-1"
end
def track_opens_url
if environment == :development
tracking_link = "https://placehold.it/5x5"
else
tracking_link = "https://google-analytics.com/collect?v=1&tid=#{tracking_id}&cid=333&t=event&ec=email&ea=open&cn=#{utm_campaign}&cs=#{utm_source}"
end
"<img src=\"#{tracking_link}\" />"
end
end
# Automatic image dimensions on image_tag helper
# activate :automatic_image_sizes
# Reload the browser automatically whenever files change
activate :livereload
# page '/biomed-newsletter-inline.html', :layout => false
# Methods defined in the helpers block are available in templates
# helpers do
# def some_helper
# "Helping"
# end
# end
require 'slim'
set :css_dir, 'stylesheets'
set :js_dir, 'javascripts'
set :images_dir, 'images'
activate :deploy do |deploy|
deploy.build_before = true # default: false
deploy.method = :ftp
deploy.host = data.ftp.host
deploy.path = data.ftp.path
deploy.user = data.ftp.user
deploy.password = data.ftp.password
# Optional Settings
# deploy.remote = "custom-remote" # remote name or git url, default: origin
# deploy.branch = "custom-branch" # default: gh-pages
# deploy.strategy = :submodule # commit strategy: can be :force_push or :submodule, default: :force_push
# deploy.commit_message = "custom-message" # commit message (can be empty), default: Automated commit at `timestamp` by middleman-deploy `version`
end
# Build-specific configuration
configure :build do
# For example, change the Compass output style for deployment
# activate :minify_css
# Minify Javascript on build
activate :minify_javascript
# Enable cache buster
# activate :asset_hash
# Use relative URLs
# activate :relative_assets
# Or use a different image path
set :http_prefix, "/media/newsletter"
# activate :gzip
# activate :minify_html
# activate :imageoptim
ignore "*.jpg"
ignore "*.jpeg"
ignore "*.gif"
ignore "*.psd"
ignore "images/*"
ignore ".git/"
end