Module: Precious::Helpers
- Included in:
- App
- Defined in:
- lib/gollum/helpers.rb
Constant Summary collapse
- EMOJI_PATHNAME =
Pathname.new(Gemojione.images_path).freeze
Instance Method Summary collapse
-
#clean_url(url) ⇒ Object
Remove all slashes from the start of string.
- #emoji(name) ⇒ Object
- #forbid(msg = "Forbidden. This wiki is set to no-edit mode.") ⇒ Object
- #not_found(msg = nil) ⇒ Object
- #not_found_proc ⇒ Object
- #sanitize_empty_params(param) ⇒ Object
- #strip_page_name(name) ⇒ Object
Instance Method Details
#clean_url(url) ⇒ Object
Remove all slashes from the start of string. Remove all double slashes
20 21 22 23 |
# File 'lib/gollum/helpers.rb', line 20 def clean_url(url) return url if url.nil? url.gsub('%2F', '/').gsub(%r{/{2,}}, '/').gsub(%r{^/}, '') end |
#emoji(name) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/gollum/helpers.rb', line 42 def emoji(name) if emoji = Gemojione.index.find_by_name(name) IO.read(EMOJI_PATHNAME.join("#{emoji['unicode'].downcase}.png")) else fail ArgumentError, "emoji `#{name}' not found" end end |
#forbid(msg = "Forbidden. This wiki is set to no-edit mode.") ⇒ Object
25 26 27 28 29 |
# File 'lib/gollum/helpers.rb', line 25 def forbid(msg = "Forbidden. This wiki is set to no-edit mode.") @message = msg status 403 halt mustache :error end |
#not_found(msg = nil) ⇒ Object
31 32 33 34 35 |
# File 'lib/gollum/helpers.rb', line 31 def not_found(msg = nil) @message = msg || "The requested page does not exist." status 404 return mustache :error end |
#not_found_proc ⇒ Object
37 38 39 40 |
# File 'lib/gollum/helpers.rb', line 37 def not_found_proc not_found_msg = 'Not found.' Proc.new {[404, {'Content-Type' => 'text/html', 'Content-Length' => not_found_msg.length.to_s}, [not_found_msg]]} end |
#sanitize_empty_params(param) ⇒ Object
9 10 11 |
# File 'lib/gollum/helpers.rb', line 9 def sanitize_empty_params(param) [nil, ''].include?(param) ? nil : CGI.unescape(param) end |