class LB::Project::Site
Site
context for templates
Constants
- DEFAULT_MESSAGE_TYPES
Public Class Methods
new(context = {})
click to toggle source
# File lib/lb/project/site.rb, line 14 def initialize(context = {}) @context = context end
Public Instance Methods
[](*args)
click to toggle source
# File lib/lb/project/site.rb, line 22 def [](*args) options.fetch(*args) end
csrf_metatag()
click to toggle source
# File lib/lb/project/site.rb, line 94 def csrf_metatag self[:csrf_metatag].call end
csrf_tag()
click to toggle source
# File lib/lb/project/site.rb, line 98 def csrf_tag self[:csrf_tag].call end
csrf_token()
click to toggle source
# File lib/lb/project/site.rb, line 90 def csrf_token self[:csrf_token].call end
css_for(bundle)
click to toggle source
# File lib/lb/project/site.rb, line 43 def css_for(bundle) path_for(bundle, 'css') end
escape_all(data)
click to toggle source
# File lib/lb/project/site.rb, line 55 def escape_all(data) case data when Array escape_array(data) when Hash escape_hash(data) when String Rack::Utils.escape_html(data) else data end end
escape_array(data)
click to toggle source
# File lib/lb/project/site.rb, line 68 def escape_array(data) data.map(&method(:escape_all)) end
escape_hash(data)
click to toggle source
# File lib/lb/project/site.rb, line 72 def escape_hash(data) data.map do |key, value| [key, escape_all(value)] end.to_h end
escaped_json(data)
click to toggle source
# File lib/lb/project/site.rb, line 51 def escaped_json(data) "JSON#{Rack::Utils.escape_html(JSON.generate(escape_all(data)))}" end
flash()
click to toggle source
# File lib/lb/project/site.rb, line 86 def flash self[:flash, {}] end
flash?()
click to toggle source
# File lib/lb/project/site.rb, line 78 def flash? %i[notice alert].any? { |type| flash[type] } end
image_path(path)
click to toggle source
# File lib/lb/project/site.rb, line 47 def image_path(path) "#{LB::Project.config.image_base_path}/#{path}" end
js_for(bundle)
click to toggle source
# File lib/lb/project/site.rb, line 39 def js_for(bundle) path_for(bundle, 'js') end
logged_in?()
click to toggle source
# File lib/lb/project/site.rb, line 106 def logged_in? session.key?(:user_id) end
message_types()
click to toggle source
# File lib/lb/project/site.rb, line 110 def message_types DEFAULT_MESSAGE_TYPES end
messages()
click to toggle source
# File lib/lb/project/site.rb, line 114 def messages flash.map do |type, message| { message: message }.merge(message_types[type.to_sym]) end end
options()
click to toggle source
# File lib/lb/project/site.rb, line 18 def options @options ||= {} end
path_for(bundle, type)
click to toggle source
# File lib/lb/project/site.rb, line 32 def path_for(bundle, type) path = 'webpack-assets.json' file = File.read(path) json = JSON.parse(file) LB::Project.config.base_path + json[bundle][type] end
session()
click to toggle source
# File lib/lb/project/site.rb, line 102 def session self[:session].call end
with(opts)
click to toggle source
# File lib/lb/project/site.rb, line 26 def with(opts) options.merge!(opts) self end
with_flash(flash)
click to toggle source
# File lib/lb/project/site.rb, line 82 def with_flash(flash) with(flash: flash) end