diff options
Diffstat (limited to 'app/helpers')
| -rw-r--r-- | app/helpers/admin/comments_helper.rb | 2 | ||||
| -rw-r--r-- | app/helpers/admin/games_helper.rb | 2 | ||||
| -rw-r--r-- | app/helpers/admin/quotes_helper.rb | 2 | ||||
| -rw-r--r-- | app/helpers/application_helper.rb | 57 | ||||
| -rw-r--r-- | app/helpers/comments_helper.rb | 5 | ||||
| -rw-r--r-- | app/helpers/games_helper.rb | 2 | ||||
| -rw-r--r-- | app/helpers/quotes_helper.rb | 12 | ||||
| -rw-r--r-- | app/helpers/tags_helper.rb | 11 | ||||
| -rw-r--r-- | app/helpers/votes_helper.rb | 32 | ||||
| -rw-r--r-- | app/helpers/webmentions_helper.rb | 2 |
10 files changed, 127 insertions, 0 deletions
| diff --git a/app/helpers/admin/comments_helper.rb b/app/helpers/admin/comments_helper.rb new file mode 100644 index 0000000..ce9444d --- /dev/null +++ b/app/helpers/admin/comments_helper.rb | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | module Admin::CommentsHelper | ||
| 2 | end | ||
| diff --git a/app/helpers/admin/games_helper.rb b/app/helpers/admin/games_helper.rb new file mode 100644 index 0000000..ab083dc --- /dev/null +++ b/app/helpers/admin/games_helper.rb | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | module Admin::GamesHelper | ||
| 2 | end | ||
| diff --git a/app/helpers/admin/quotes_helper.rb b/app/helpers/admin/quotes_helper.rb new file mode 100644 index 0000000..3dde719 --- /dev/null +++ b/app/helpers/admin/quotes_helper.rb | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | module Admin::QuotesHelper | ||
| 2 | end | ||
| 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 |
| diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb new file mode 100644 index 0000000..5939adc --- /dev/null +++ b/app/helpers/comments_helper.rb | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | module CommentsHelper | ||
| 2 | def show_comments(blog) | ||
| 3 | render "comments/layout", blog: blog | ||
| 4 | end | ||
| 5 | end | ||
| diff --git a/app/helpers/games_helper.rb b/app/helpers/games_helper.rb new file mode 100644 index 0000000..2ef8c1f --- /dev/null +++ b/app/helpers/games_helper.rb | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | module GamesHelper | ||
| 2 | end | ||
| diff --git a/app/helpers/quotes_helper.rb b/app/helpers/quotes_helper.rb new file mode 100644 index 0000000..c0753e0 --- /dev/null +++ b/app/helpers/quotes_helper.rb | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | module QuotesHelper | ||
| 2 | def quote_format(text) | ||
| 3 | text = text ? text.to_str : '' | ||
| 4 | text = text.dup if text.frozen? | ||
| 5 | text.gsub!(/^([\(\[][^\]\)]*[\]\)] )?([^:\n]*): /, "\\1<span class=\"quote-speaker\">\\2</span>: ") | ||
| 6 | text.gsub!(/\r\n?/, "\n") # \r\n and \r -> \n | ||
| 7 | text.gsub!(/\n/, '<br />') # 1 newline -> br | ||
| 8 | text = sanitize(text) | ||
| 9 | text = auto_link(text, :link => :urls) | ||
| 10 | text | ||
| 11 | end | ||
| 12 | end | ||
| diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb new file mode 100644 index 0000000..9643834 --- /dev/null +++ b/app/helpers/tags_helper.rb | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | module TagsHelper | ||
| 2 | |||
| 3 | def tag_cloud(tags, classes) | ||
| 4 | max = tags.sort_by(&:taggings_count).last | ||
| 5 | tags.each do |tag| | ||
| 6 | index = tag.taggings_count.to_f / max.taggings_count * (classes.size - 1) | ||
| 7 | yield(tag, classes[index.round]) | ||
| 8 | end | ||
| 9 | end | ||
| 10 | |||
| 11 | end | ||
| diff --git a/app/helpers/votes_helper.rb b/app/helpers/votes_helper.rb new file mode 100644 index 0000000..169d7bf --- /dev/null +++ b/app/helpers/votes_helper.rb | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | module VotesHelper | ||
| 2 | |||
| 3 | def voters_list(votes, html = false) | ||
| 4 | voters = votes.select {|v| !v.liker_url.nil?}.map do |v| | ||
| 5 | if html | ||
| 6 | tag.strong(link_to v.liker_name, v.liker_url) | ||
| 7 | else | ||
| 8 | "#{v.liker_name} (#{v.liker_url})" | ||
| 9 | end | ||
| 10 | end | ||
| 11 | |||
| 12 | anons = votes.select {|v| v.liker_url.nil?}.size | ||
| 13 | if anons > 0 | ||
| 14 | if voters.empty? && anons == 1 | ||
| 15 | if html | ||
| 16 | voters << tag.strong("A guest") | ||
| 17 | else | ||
| 18 | voters << "A guest" | ||
| 19 | end | ||
| 20 | else | ||
| 21 | if html | ||
| 22 | voters << tag.strong(pluralize(anons, "guest")) | ||
| 23 | else | ||
| 24 | voters << pluralize(anons, "guest") | ||
| 25 | end | ||
| 26 | end | ||
| 27 | end | ||
| 28 | |||
| 29 | to_sentence(voters) | ||
| 30 | end | ||
| 31 | |||
| 32 | end | ||
| diff --git a/app/helpers/webmentions_helper.rb b/app/helpers/webmentions_helper.rb new file mode 100644 index 0000000..4b22e43 --- /dev/null +++ b/app/helpers/webmentions_helper.rb | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | module WebmentionsHelper | ||
| 2 | end | ||
