diff options
Diffstat (limited to 'app/helpers/application_helper.rb')
| -rw-r--r-- | app/helpers/application_helper.rb | 57 |
1 files changed, 57 insertions, 0 deletions
| diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..a51f1a1 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb | |||
| @@ -1,2 +1,59 @@ | |||
| 1 | require 'redcarpet' | ||
| 2 | require 'rouge' | ||
| 3 | require 'rouge/plugins/redcarpet' | ||
| 4 | require 'redcarpet/render_strip' | ||
| 5 | |||
| 1 | module ApplicationHelper | 6 | module ApplicationHelper |
| 7 | |||
| 8 | class HTML < Redcarpet::Render::HTML | ||
| 9 | include Rouge::Plugins::Redcarpet # yep, that's it. | ||
| 10 | end | ||
| 11 | |||
| 12 | def title(text) | ||
| 13 | content_for :title, text | ||
| 14 | end | ||
| 15 | |||
| 16 | def sortable(col, title = nil) | ||
| 17 | title ||= col.titleize | ||
| 18 | css_class = (col == sort_column) ? "current #{sort_direction}" : nil | ||
| 19 | direction = (col == sort_column and sort_direction == "asc") ? "desc" : "asc" | ||
| 20 | link_to title, {:sort => col, :dir => direction}, {:class => css_class} | ||
| 21 | end | ||
| 22 | |||
| 23 | def markdown(text, params = {}) | ||
| 24 | options = { fenced_code_blocks: true, highlight: true, footnotes: true } | ||
| 25 | |||
| 26 | html_options = { with_toc_data: true } | ||
| 27 | if params[:restricted] | ||
| 28 | html_options[:filter_html] = true | ||
| 29 | end | ||
| 30 | |||
| 31 | Redcarpet::Markdown.new(HTML.new(html_options), options).render(text).html_safe | ||
| 32 | end | ||
| 33 | |||
| 34 | def links_sidebar | ||
| 35 | [ | ||
| 36 | { title: "Code repositories", url: "https://code.fourisland.com/" }, | ||
| 37 | { title: "Quotes database", url: "https://www.fourisland.com/quotes" }, | ||
| 38 | { title: "Pokémon", url: "https://www.fourisland.com/poke3" }, | ||
| 39 | { title: "Wittle", url: "https://www.fourisland.com/wittle/" }, | ||
| 40 | ] | ||
| 41 | end | ||
| 42 | |||
| 43 | def friends_sidebar | ||
| 44 | [ | ||
| 45 | { title: "Entropically", url: "https://entropically.neocities.org/" }, | ||
| 46 | ] | ||
| 47 | end | ||
| 48 | |||
| 49 | class StrippedSummary < Redcarpet::Render::StripDown | ||
| 50 | def block_html(raw_html) | ||
| 51 | nil | ||
| 52 | end | ||
| 53 | end | ||
| 54 | |||
| 55 | def stripped_markdown(text) | ||
| 56 | Redcarpet::Markdown.new(StrippedSummary).render(text) | ||
| 57 | end | ||
| 58 | |||
| 2 | end | 59 | end |
