# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true module Contrast module Framework # This module is to help perform sometimes necessary tasks specific to Sinatra module SinatraApplicationHelper SINATRA_VIEWS = [ Contrast::Framework::ViewTechnologiesDescriptor.new('public/stylesheets', 'scss', %w[SASS]), Contrast::Framework::ViewTechnologiesDescriptor.new('views', 'html', %w[HTML5]), Contrast::Framework::ViewTechnologiesDescriptor.new('views', 'html.erb', %w[HTML5 ERB]), Contrast::Framework::ViewTechnologiesDescriptor.new('views', 'html.haml', %w[HTML5 HAML]), Contrast::Framework::ViewTechnologiesDescriptor.new('public', 'html', %w[HTML5]) ].cs__freeze def app_class @_app_class ||= begin return nil unless defined?(Sinatra) && defined?(Sinatra::Base) sinatra_layers = ObjectSpace.each_object(Sinatra::Base).to_a result_layer = sinatra_layers.find { |layer| layer.app.nil? } result_layer end end def scannable_view_dirs @_scannable_view_dirs ||= begin views = SINATRA_VIEWS.dup views << Contrast::Framework::ViewTechnologiesDescriptor.new(view_directory, 'erb', %w[HTML5 ERB]) if view_directory views << Contrast::Framework::ViewTechnologiesDescriptor.new(view_directory, 'haml', %w[HTML5 HAML]) if view_directory views << Contrast::Framework::ViewTechnologiesDescriptor.new(public_directory, 'html', %w[HTML5]) if public_directory views end end def view_directory @_view_directory ||= begin app_class&.settings&.views end end def public_directory @_public_directory ||= begin app_class&.settings&.public_dir end end end end end