class Adalog::Web
Constants
- Config
Attributes
config[R]
Public Class Methods
new(app = nil, web_options = {})
click to toggle source
Calls superclass method
# File lib/adalog/web.rb, line 9 def initialize(app = nil, web_options = {}) super(app) options = default_options.merge(web_options) @config = Adalog::Web::Config.new determine_config_settings(config, options) sinatra_class_option_overrides(options) end
Public Instance Methods
/()
click to toggle source
The primary page that matters in this simple little log.
# File lib/adalog/web.rb, line 72 get '/' do @entries = config.repo.all erb :'index.html' end
/clear()
click to toggle source
CONSIDER: Since this is all-destructive, should this be a confirmation
page first and a followup action via post?
# File lib/adalog/web.rb, line 95 post '/clear' do config.repo.clear! redirect to('/') end
default_options()
click to toggle source
# File lib/adalog/web.rb, line 35 def default_options Adalog.configuration.web_defaults end
determine_config_settings(config, options)
click to toggle source
# File lib/adalog/web.rb, line 18 def determine_config_settings(config, options) config.repo = options.fetch(:repo) config.heading = options.fetch(:heading) config.time_format = options.fetch(:time_format) end
heading()
click to toggle source
# File lib/adalog/web.rb, line 59 def heading config.heading end
humanize_time(val)
click to toggle source
# File lib/adalog/web.rb, line 47 def humanize_time(val) case val when DateTime, Time val.strftime(config.time_format) when String val else val.to_s end end
path_from_web_root(path)
click to toggle source
# File lib/adalog/web.rb, line 64 def path_from_web_root(path) File.join(("#{env['SCRIPT_NAME']}/" || "/"), path) end
sinatra_class_option_overrides(options)
click to toggle source
# File lib/adalog/web.rb, line 25 def sinatra_class_option_overrides(options) if options.key?(:erb_layout) class_exec { set :erb, layout: options[:erb_layout] } end if options.key?(:views_folder) class_exec { set :views, options[:views_folder] } end end