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
|
# File 'lib/anecdote.rb', line 19
def self.init_raconteur
raconteur.settings.setting_quotes = '$'
raconteur.processors.register!('graphic', {
handler: lambda do |settings|
klass = (['anecdote-graphic-dn32ja'] + module_classes(settings)).flatten.join(' ')
contents = []
contents << view_context.content_tag((settings[:href].present? ? :a : :div), (settings[:href].present? ? { href: settings[:href], title: settings[:href_title] } : {}).merge({ class: 'anecdote-intrinsic-embed-n42ha1' })) do
if settings[:assets_path]
content = view_context.image_tag(settings[:assets_path], alt: '')
paperclip_geo = Paperclip::Geometry.from_file(Rails.root.join('app', 'assets', 'images', settings[:assets_path]))
geo = { width: paperclip_geo.width, height: paperclip_geo.height }
elsif settings[:image_url]
content = view_context.image_tag(settings[:image_url], alt: '')
dimensions = (settings[:dimensions] || settings[:image_dimensions]).split('x').map(&:to_f)
geo = { width: dimensions.first, height: dimensions.last }
elsif settings[:embed_code]
content = settings[:embed_code].html_safe
dimensions = settings[:dimensions].split('x').map(&:to_f)
geo = { width: dimensions.first, height: dimensions.last }
end
if settings[:_scope_].present? && settings[:_scope_][:processor].tag == 'gallery'
settings[:_scope_][:settings][:_graphics_] ||= []
settings[:_scope_][:settings][:_graphics_] << geo
end
view_context.content_tag(:div, content, class: 'inner', style: "padding-bottom: #{geo[:height] / geo[:width] * 100}%;")
end
if settings[:caption].present?
contents << view_context.content_tag(:div, view_context.content_tag(:div, markdown_and_parse(settings[:caption]), class: 'inner anecdote-wysicontent-ndj4ab'), class: 'anecdote-caption-ajkd3b')
end
view_context.content_tag(:div, view_context.content_tag(:div, contents.join("\n").html_safe, class: 'inner'), class: klass)
end
})
raconteur.processors.register!('gallery', {
handler: lambda do |settings|
klasses = ['anecdote-gallery-dn2bak']
klasses += module_classes(settings)
graphics = settings[:_yield_].html_safe
flexes = []
if settings[:flexes]
flexes = parse_custom_flexes(settings)
else
if settings[:scale_by] == 'relative-width-bottom-alignment'
total_width = settings[:_graphics_].sum { |hsh| hsh[:width]}
settings[:_graphics_].each do |graphic|
flex = {
width: graphic[:width] / total_width,
graphic: graphic,
ratio: graphic[:width] / graphic[:height],
gfx_height_pad: graphic[:height] / graphic[:width]
}
flex[:width_ratio_balance] = flex[:width] / flex[:ratio]
flexes << flex
end
tallest = flexes.sort_by { |k| k[:width_ratio_balance] }.last
flexes.map do |flex|
flex[:faux] = flex[:width_ratio_balance] / tallest[:width_ratio_balance]
flex[:gfx_height_pad_faux] = flex[:gfx_height_pad] / flex[:faux]
flex[:top_offset] = flex[:gfx_height_pad_faux] - flex[:gfx_height_pad]
end
index = 0
graphics.gsub!('<div class="anecdote-intrinsic-embed-n42ha1">') do |match|
flex = flexes[index]
index += 1
(view_context.content_tag(:div, '', class: 'anecdote-flex-offset-a4j2aj', style: "padding-top: #{flex[:top_offset] * 100}%;").html_safe + match.html_safe).html_safe
end
elsif settings[:scale_by] == 'relative-width'
total_width = settings[:_graphics_].sum { |hsh| hsh[:width]}
settings[:_graphics_].each do |graphic|
flexes << { width: graphic[:width] / total_width, graphic: graphic }
end
else
total_ratio = settings[:_graphics_].sum { |geo| geo[:width] / geo[:height] }
settings[:_graphics_].each do |graphic|
flexes << { width: (graphic[:width] / graphic[:height]) / total_ratio, graphic: graphic }
end
end
end
graphics = insert_flex_basis_styles(graphics, flexes)
contents = []
settings[:gutter_spacing] = 'small' if settings[:gutter_spacing].blank?
contents << view_context.content_tag(:div, graphics.html_safe, class: (['content'] + flex_classes(settings)).flatten.join(' '))
if settings[:caption].present?
contents << view_context.content_tag(:div, view_context.content_tag(:div, markdown_and_parse(settings[:caption]), class: 'inner anecdote-wysicontent-ndj4ab'), class: 'anecdote-caption-ajkd3b')
end
view_context.content_tag(:div, view_context.content_tag(:div, contents.join("\n").html_safe, class: 'inner'), class: klasses.flatten.join(' '))
end
})
raconteur.processors.register!('columns', {
handler: lambda do |settings|
klasses = ['anecdote-columns-nab3a2']
klasses += module_classes(settings)
columns = insert_flex_basis_styles(settings[:_yield_].html_safe, parse_custom_flexes(settings))
view_context.content_tag(:div, view_context.content_tag(:div, columns.html_safe, class: (['inner'] + flex_classes(settings)).flatten.join(' ')), class: klasses.flatten.join(' '))
end
})
raconteur.processors.register!('anecdote', {
handler: lambda do |settings|
klass = (['anecdote-inception-ab2a8j'] + module_classes(settings)).flatten.join(' ')
view_context.content_tag(:div, view_context.content_tag(:div, markdown_and_parse(settings[:_yield_]), class: 'anecdote-wysicontent-ndj4ab inner'), class: klass)
end
})
raconteur.processors.register!('pull-quote', {
handler: lambda do |settings|
klass = (['anecdote-pull-quote-sba2ha'] + module_classes(settings)).flatten.join(' ')
view_context.content_tag(:div, view_context.content_tag(:div, markdown_and_parse(settings[:text]), class: 'inner'), class: klass)
end
})
end
|