module Madness::ServerHelper

All the methods that we may need inside of any server route. The module can also be included manually anywhere else.

Public Instance Methods

config() click to toggle source
# File lib/madness/server_helper.rb, line 5
def config
  @config ||= Settings.instance
end
disallowed_static?(path) click to toggle source
# 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() click to toggle source
# File lib/madness/server_helper.rb, line 9
def docroot
  @docroot ||= File.expand_path(config.path, Dir.pwd)
end
find_static_file(path) click to toggle source

Search for static file, first in the users docroot, then in the template directory.

# 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) click to toggle source
# 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
theme() click to toggle source
# File lib/madness/server_helper.rb, line 13
def theme
  @theme ||= Theme.new config.theme
end