This repository has been archived by the owner on Jul 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom_helpers.rb
86 lines (75 loc) · 2.38 KB
/
custom_helpers.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
module CustomHelpers
def screens_for_project(project)
project_date = project.date.strftime('%Y-%m-%d')
folder_name = "#{project_date}-#{project.slug}"
[].tap do |results|
Dir.glob("./source/projects/#{folder_name}/*.*") do |screen|
the_path = ['/projects', folder_name, screen.split('/').last]
path_to_image = File.join(the_path)
photo = image_tag(path_to_image)
thumb = link_to photo, path_to_image, class: 'thumbnail', data: { toggle: 'lightbox' }
results << content_tag(:div, thumb, class: 'col-xs-3')
end
end.join.html_safe
end
def page_data
current_page.data
end
def gravatar_image_tag(email, options = {})
if email
hash = Digest::MD5.hexdigest(email.chomp.downcase)
image_tag "http://www.gravatar.com/avatar/#{hash}.jpg", options
else
image_tag 'http://www.gravatar.com/avatar/?d=mm', options
end
end
def tag_links_for(tags)
content = []
tags_for(tags).each do |tag|
content << link_to_tag(tag)
end
content.join(', ')
end
def tags_for(tags)
if tags.is_a? String
tags.split(', ')
else
tags
end
end
def link_to_tag(tag)
content_tag(:a, tag, href: tag_path(tag))
end
def bs_dropdown(name, options = {}, &block)
defaults = { class: 'dropdown' }
caret = content_tag(:b, nil, class: 'caret')
toggle = "#{name} #{caret}"
link_options = {
class: 'dropdown-toggle',
data: { toggle: 'dropdown' }
}
link = link_to(toggle, '#', link_options)
menu = content_tag(:ul, capture(&block), class: 'dropdown-menu')
content_tag(:li, link + menu, defaults.update(options))
end
def contact_link(text = nil, options = {}, &block)
content = block_given? ? yield : text
defaults = {
encode: 'hex',
subject: 'My project',
body: "Hai guiz! I've got a hankering for some sweet coding love!"
}
end
def active_nav?(name, active_class = 'active')
filename = File.basename(current_page.path, '.html')
directory = File.dirname(current_page.path)
directories = File.dirname(current_page.path).split('/')
if name == 'index'
active_class if filename == 'index' && directory == '.'
else
is_active = [filename, directories].flatten.include?(name)
is_active ? active_class : ''
end
end
end