module Racket::Helpers::Sass
Helper module that allows CSS files to be loaded dynamically using SASS.
Public Class Methods
included(klass)
click to toggle source
Whenever this helper is included in a controller it will setup a link between a SASS directory and a CSS directory.
@param [Class] klass @return [nil]
# File lib/racket/helpers/sass.rb, line 56 def self.included(klass) route = klass.get_route.slice(1..-1) # Remove leading slash sass_dir = add_template_location(klass, route) add_warmup_urls(klass, sass_dir, route) nil end
Private Class Methods
add_template_location(klass, route)
click to toggle source
# File lib/racket/helpers/sass.rb, line 34 def self.add_template_location(klass, route) utils = klass.context.utils sass_dir = utils.build_path('sass', route).to_s css_dir = utils.build_path('public', 'css', route).to_s ::Sass::Plugin.add_template_location(sass_dir, css_dir) sass_dir end
add_warmup_urls(klass, sass_dir, route)
click to toggle source
# File lib/racket/helpers/sass.rb, line 42 def self.add_warmup_urls(klass, sass_dir, route) Dir.chdir(sass_dir) do basedir = route.empty? ? '/css' : "/css/#{route}" Dir.glob('*.s[ac]ss').each do |file| klass.settings.fetch(:warmup_urls) << "#{basedir}/#{::File.basename(file, '.*')}.css" end end end
Public Instance Methods
css(sym)
click to toggle source
Get route to CSS, which will use SASS in the background to deliver the CSS.
@param [Symbol] sym @return [String]
# File lib/racket/helpers/sass.rb, line 28 def css(sym) route = self.class.get_route route = '' if route == '/' # Special case for root controller "/css#{route}/#{sym}.css" end