Module: Madness::ServerHelper
- Included in:
- Directory, Document, InlineTableOfContents, Item, MarkdownDocument, Navigation, Rendering::Pandoc, Rendering::Redcarpet, Search, ServerBase, TableOfContents
- Defined in:
- lib/madness/server_helper.rb
Overview
All the methods that we may need inside of any server route. The module can also be included manually anywhere else.
Instance Method Summary collapse
- #config ⇒ Object
- #disallowed_static?(path) ⇒ Boolean
- #docroot ⇒ Object
-
#find_static_file(path) ⇒ Object
Search for static file, first in the users docroot, then in the template directory.
- #log(obj) ⇒ Object
- #theme ⇒ Object
Instance Method Details
#config ⇒ Object
5 6 7 |
# File 'lib/madness/server_helper.rb', line 5 def config @config ||= Settings.instance end |
#disallowed_static?(path) ⇒ Boolean
42 43 44 |
# File 'lib/madness/server_helper.rb', line 42 def disallowed_static?(path) path.end_with?('.md') || path.empty? || File.basename(path).start_with?('.') end |
#docroot ⇒ Object
9 10 11 |
# File 'lib/madness/server_helper.rb', line 9 def docroot @docroot ||= File.(config.path, Dir.pwd) end |
#find_static_file(path) ⇒ Object
Search for static file, first in the users docroot, then in the template directory.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/madness/server_helper.rb', line 27 def find_static_file(path) return nil if disallowed_static?(path) candidates = [ "#{config.path}/#{path}", "#{theme.public_path}/#{path}", ] candidates.each do |candidate| return candidate if File.file? candidate end nil end |
#log(obj) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/madness/server_helper.rb', line 17 def log(obj) # :nocov: open('madness.log', 'a') do |f| f.puts obj.inspect end # :nocov: end |