<commit_before>class Shoebox::StylesController < ActionController::Base

  include Shoebox::Common

  def index
    buffer = Rails.cache.fetch(cache_key) { build } if Shoebox.config.cache
    render_buffer(buffer || build)
  end

private ######################################################################

  def controller
    params[:name]
  end

  def media
    params[:media]
  end

  def cache_key
    "#{controller}.#{media}"
  end

  def build
    buffer = collapse_files(files)
    buffer = minify(buffer) if Shoebox.config.minify
    buffer
  end

  def collapse_files(files)
    files.inject('') do |buffer, file|
      data = File.read(file)
      buffer << case File.extname(file)
        when '.sass' then require 'sass'; Sass::Engine.new(data).render
        when '.less' then require 'less'; Less::Engine.new(data).to_css(:desc)
        else data
      end << "\n"
    end
  end

  def files
    support_files(:styles).select do |filename|
      dir  = File.dirname(filename).split('/').last
      name = File.basename(filename)

      next(false) unless [ 'application', controller ].include?(dir)

      case (parts = name.split('.')).length
        when 1 then raise "Unable to parse filename: #{filename}"
        when 2 then next(true)
        else        next(true) if parts[-2] == media.to_s
      end<commit_msg>less no longer requires a parameter for to_css<commit_after>class Shoebox::StylesController < ActionController::Base

  include Shoebox::Common

  def index
    buffer = Rails.cache.fetch(cache_key) { build } if Shoebox.config.cache
    render_buffer(buffer || build)
  end

private ######################################################################

  def controller
    params[:name]
  end

  def media
    params[:media]
  end

  def cache_key
    "#{controller}.#{media}"
  end

  def build
    buffer = collapse_files(files)
    buffer = minify(buffer) if Shoebox.config.minify
    buffer
  end

  def collapse_files(files)
    files.inject('') do |buffer, file|
      data = File.read(file)
      buffer << case File.extname(file)
        when '.sass' then require 'sass'; Sass::Engine.new(data).render
        when '.less' then require 'less'; Less::Engine.new(data).to_css
        else data
      end << "\n"
    end
  end

  def files
    support_files(:styles).select do |filename|
      dir  = File.dirname(filename).split('/').last
      name = File.basename(filename)

      next(false) unless [ 'application', controller ].include?(dir)

      case (parts = name.split('.')).length
        when 1 then raise "Unable to parse filename: #{filename}"
        when 2 then next(true)
        else        next(true) if parts[-2] == media.to_s
      end
{'fraction_non_alphanumeric': 0.16543301258327164, 'fraction_numerical': 0.0022205773501110288, 'mean_word_length': 2.9985207100591715, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1551113', 'n_tokens_mistral': 819, 'n_tokens_neox': 790, 'n_words': 212}