Module: Ksk::ApplicationHelper
- Defined in:
- app/helpers/ksk/application_helper.rb
Instance Method Summary collapse
- #md(text) ⇒ Object
- #mdap(text, images, data_files) ⇒ Object
- #place_content(text, files, type, &html) ⇒ Object
- #place_data_files(text, data_files) ⇒ Object
- #place_images(text, images) ⇒ Object
- #recursive_navi(navis, current_level = 0, max_level = 99) ⇒ Object
Instance Method Details
#md(text) ⇒ Object
23 24 25 26 27 |
# File 'app/helpers/ksk/application_helper.rb', line 23 def md(text) return '' if text.blank? markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML.new(), fenced_code_blocks: true, autolink: true) markdown.render(text).html_safe end |
#mdap(text, images, data_files) ⇒ Object
29 30 31 32 33 34 |
# File 'app/helpers/ksk/application_helper.rb', line 29 def mdap(text, images, data_files) return '' if text.blank? t = place_images(text, images) t = place_data_files(t, data_files) md(t) end |
#place_content(text, files, type, &html) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'app/helpers/ksk/application_helper.rb', line 36 def place_content(text, files, type, &html) t = text (text || '').scan(Apdown.parse_regex(type)).each do |match| if asset = files[match[1].to_i-1] t = t.gsub(match[0], html.call(asset, match[2])) end end t.html_safe end |
#place_data_files(text, data_files) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/helpers/ksk/application_helper.rb', line 53 def place_data_files(text, data_files) place_content(text, data_files, 'file') do |asset, option| link_to asset.file.url, class: asset.has_preview? ? :uploaded_file_preview : :uploaded_file do if asset.has_preview? image_tag( asset.preview_file.url(:banner) )+ '<span>Hier klicken um die Datei herunter zu laden</span>'.html_safe else asset.file_file_name end end end end |
#place_images(text, images) ⇒ Object
46 47 48 49 50 51 |
# File 'app/helpers/ksk/application_helper.rb', line 46 def place_images(text, images) place_content(text, images, 'img') do |asset, option| c = option || 'thumb' image_tag asset.file.url(c), class: ['uploaded_image', c] end end |
#recursive_navi(navis, current_level = 0, max_level = 99) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/helpers/ksk/application_helper.rb', line 4 def recursive_navi(navis, current_level = 0, max_level = 99) a = ' <ul>' navis.each do |navi| active = navi.slug == @slugs[current_level] ? ' class="active"' : nil next unless nt = navi. link = if nt.name == 'news' link_to navi.title, posts_path else link_to navi.title, navi.link end a += " <li#{active}>#{link}" if active && current_level <= max_level && navi.children.not_hidden.any? a += recursive_navi(navi.children.not_hidden, current_level+1, max_level) end a += '</li> ' end a += '</ul> ' end |