Class: ApplicationController
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- ApplicationController
- Defined in:
- lib/eucalypt/controller.rb,
lib/eucalypt/core/helpers/assets.rb,
lib/eucalypt/core/helpers/static.rb,
lib/eucalypt/core/helpers/logging.rb,
lib/eucalypt/core/helpers/partial.rb,
lib/eucalypt/core/helpers/manifest.rb,
lib/eucalypt/core/helpers/maintenance.rb,
lib/eucalypt/core/templates/eucalypt/app.rb,
lib/eucalypt/core/templates/eucalypt/config/assets.rb,
lib/eucalypt/core/templates/eucalypt/config/logging.rb
Direct Known Subclasses
Constant Summary collapse
- LOGGER =
if (settings.logging == !!settings.logging) Lumberjack::Logger.new $stdout else Lumberjack::Logger.new $stdout, level: settings.logging end
Class Method Summary collapse
Class Method Details
.maintenance(enabled:, &block) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/eucalypt/core/helpers/maintenance.rb', line 2 def self.maintenance(enabled:, &block) if enabled MainController.get '/maintenance', &block Eucalypt.glob('app', 'controllers', '*.rb') do |file| controller = File.basename(file,'.*').camelize.constantize controller.before '*' do splat = params[:splat].reject {|param| /\/assets\/.*/.match? param} redirect '/maintenance' unless splat.include?('/maintenance') || splat.empty? end end end end |
.static(file = nil, aliases: []) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/eucalypt/core/helpers/static.rb', line 25 def self.static(file = nil, aliases: []) if settings.static_router.is_a? Eucalypt::Static::Router if block_given? yield settings.static_router settings.static_router.routes.each do |route| route.values.flatten.each do |path| get(path) { send_file File.join(settings.public_folder, route[:file].sub('/','')) } end end else if file && aliases raise ArgumentError.new("Invalid argument #{file} for 'file' - Expected string (file path with preceding /)") unless file.is_a?(String) && file.start_with?('/') location = File.join settings.public_folder, file.sub('/', '') raise ArgumentError.new("Invalid argument #{file} for 'file' - File \"#{location}\" doesn't exist") unless File.file? location raise ArgumentError.new("Invalid keyword argument #{aliases} for 'aliases' - Expected Array of String") unless aliases.is_a?(Array) && aliases.all?{|a| a.is_a? String} raise ArgumentError.new("Invalid keyword argument #{aliases} for 'aliases' - Expected Array of route names (preceded by /)") unless aliases.all?{|a| a.start_with? '/'} routes = [file] + aliases routes.each {|path| get(path){send_file location} } end end end end |