### Home Classes Methods

### In Files

- lib/compass/commands/project_stats.rb
- lib/compass/commands/project_structure.rb

### Parent

UpdateProject

### Methods

- ::description
- ::new
- ::option_parser
- ::parse!
- ::parse_arguments!
- ::primary
- ::usage
- #css_columns
- #filename_columns
- #format_kb
- #pad
- #perform
- #print_tree
- #sass_columns
- #sorted_sass_files

### Class/Module Index

Quicksearch

- Compass
- Compass::Actions
- Compass::AppIntegration
- Compass::AppIntegration::Helpers
- Compass::AppIntegration::Rails
- Compass::AppIntegration::StandAlone
- Compass::AppIntegration::StandAlone::ConfigurationDefaults
- Compass::AppIntegration::StandAlone::Installer
- Compass::BrowserSupport
- Compass::Commands
- Compass::Commands::Base
- Compass::Commands::CleanProject
- Compass::Commands::CleanProjectOptionsParser
- Compass::Commands::CompileProjectOptionsParser
- Compass::Commands::ConfigurationOptionsParser
- Compass::Commands::CreateProject
- Compass::Commands::CreateProjectOptionsParser
- Compass::Commands::Default
- Compass::Commands::DefaultOptionsParser
- Compass::Commands::ExtensionCommand
- Compass::Commands::ExtensionOptionsParser
- Compass::Commands::ExtensionsOptionParser
- Compass::Commands::GenerateGridBackground
- Compass::Commands::GridBackgroundOptionsParser
- Compass::Commands::Help
- Compass::Commands::HelpOptionsParser
- Compass::Commands::Imports
- Compass::Commands::InstallerCommand
- Compass::Commands::Interactive
- Compass::Commands::InteractiveOptionsParser
- Compass::Commands::ListFrameworks
- Compass::Commands::MemoryDebugger
- Compass::Commands::PrintVersion
- Compass::Commands::ProjectBase
- Compass::Commands::ProjectStats
- Compass::Commands::Registry
- Compass::Commands::Sprite
- Compass::Commands::SpriteOptionsParser
- Compass::Commands::StampPattern
- Compass::Commands::StampPatternOptionsParser
- Compass::Commands::StatsOptionsParser
- Compass::Commands::StructureOptionsParser
- Compass::Commands::UnpackExtension
- Compass::Commands::UpdateProject
- Compass::Commands::ValidateProject
- Compass::Commands::ValidationOptionsParser
- Compass::Commands::VersionOptionsParser
- Compass::Commands::WatchProject
- Compass::Commands::WatchProjectOptionsParser
- Compass::Commands::WriteConfiguration
- Compass::Compiler
- Compass::Configuration
- Compass::Configuration::Adapters
- Compass::Configuration::Comments
- Compass::Configuration::Data
- Compass::Configuration::Defaults
- Compass::Configuration::FileData
- Compass::Configuration::Helpers
- Compass::Configuration::Inheritance
- Compass::Configuration::Inheritance::ClassMethods
- Compass::Configuration::Inheritance::ClassMethods::ArrayProxy
- Compass::Configuration::Inheritance::InstanceMethods
- Compass::Configuration::Paths
- Compass::Configuration::Serialization
- Compass::Error
- Compass::Exec
- Compass::Exec::CommandOptionParser
- Compass::Exec::GlobalOptionsParser
- Compass::Exec::Helpers
- Compass::Exec::ProjectOptionsParser
- Compass::Exec::SubCommandUI
- Compass::Exec::SwitchUI
- Compass::FilesystemConflict
- Compass::Frameworks
- Compass::Frameworks::Framework
- Compass::GridBuilder
- Compass::Installers
- Compass::Installers::BareInstaller
- Compass::Installers::Base
- Compass::Installers::Manifest
- Compass::Installers::Manifest::Entry
- Compass::Installers::ManifestInstaller
- Compass::Installers::TemplateContext
- Compass::Logger
- Compass::MissingDependency
- Compass::NullLogger
- Compass::PNG
- Compass::SassExtensions
- Compass::SassExtensions::Functions
- Compass::SassExtensions::Functions::Colors
- Compass::SassExtensions::Functions::Constants
- Compass::SassExtensions::Functions::CrossBrowserSupport
- Compass::SassExtensions::Functions::CrossBrowserSupport::CSS2FallbackValue
- Compass::SassExtensions::Functions::Display
- Compass::SassExtensions::Functions::Enumerate
- Compass::SassExtensions::Functions::Env
- Compass::SassExtensions::Functions::FontFiles
- Compass::SassExtensions::Functions::GradientSupport
- Compass::SassExtensions::Functions::GradientSupport::Assertions
- Compass::SassExtensions::Functions::GradientSupport::ColorStop
- Compass::SassExtensions::Functions::GradientSupport::Functions
- Compass::SassExtensions::Functions::GradientSupport::Gradient
- Compass::SassExtensions::Functions::GradientSupport::Gradient::ClassMethods
- Compass::SassExtensions::Functions::GradientSupport::LinearGradient
- Compass::SassExtensions::Functions::GradientSupport::RadialGradient
- Compass::SassExtensions::Functions::ImageSize
- Compass::SassExtensions::Functions::ImageSize::ImageProperties
- Compass::SassExtensions::Functions::ImageSize::JPEG
- Compass::SassExtensions::Functions::InlineImage
- Compass::SassExtensions::Functions::Lists
- Compass::SassExtensions::Functions::Math
- Compass::SassExtensions::Functions::Selectors
- Compass::SassExtensions::Functions::Sprites
- Compass::SassExtensions::Functions::Sprites::VariableReader
- Compass::SassExtensions::Functions::Urls
- Compass::SassExtensions::Functions::Urls::FontUrl
- Compass::SassExtensions::Functions::Urls::GeneratedImageUrl
- Compass::SassExtensions::Functions::Urls::ImageUrl
- Compass::SassExtensions::Functions::Urls::StylesheetUrl
- Compass::SassExtensions::Sprites
- Compass::SassExtensions::Sprites::ChunkyPngEngine
- Compass::SassExtensions::Sprites::Engine
- Compass::SassExtensions::Sprites::Image
- Compass::SassExtensions::Sprites::ImageMethods
- Compass::SassExtensions::Sprites::ImageRow
- Compass::SassExtensions::Sprites::LayoutMethods
- Compass::SassExtensions::Sprites::RowFitter
- Compass::SassExtensions::Sprites::SpriteMap
- Compass::SassExtensions::Sprites::SpriteMethods
- Compass::SpriteException
- Compass::SpriteImporter
- Compass::Sprites
- Compass::Sprites::Binding
- Compass::Stats
- Compass::Stats::CssFile
- Compass::Stats::SassFile
- Compass::Stats::StatsVisitor
- Compass::TestCase
- Compass::Util
- Compass::Version
- Sass
- Sass::Script
- Sass::Script::CrossBrowserFunctionCall
- Sass::Script::Funcall
- Sass::Script::Functions
- Sass::Script::Functions::EvaluationContext
- Sass::Script::HasSimpleCrossBrowserFunctionSupport
- Sass::Script::List
- Sass::Tree
- Sass::Tree::Node
- QuickCache

No matching classes.

# Compass::Commands::ProjectStats

### Public Class Methods

description(command) click to toggle source

    # File lib/compass/commands/project_stats.rb, line 151
    def description(command)
      "Report statistics about your stylesheets"
    end

new(working_path, options) click to toggle source

    # File lib/compass/commands/project_stats.rb, line 26
    def initialize(working_path, options)
      super
      assert_project_directory_exists!
    end

option_parser(arguments) click to toggle source

    # File lib/compass/commands/project_stats.rb, line 140
    def option_parser(arguments)
      parser = Compass::Exec::CommandOptionParser.new(arguments)
      parser.extend(Compass::Exec::GlobalOptionsParser)
      parser.extend(Compass::Exec::ProjectOptionsParser)
      parser.extend(StatsOptionsParser)
    end

parse!(arguments) click to toggle source

    # File lib/compass/commands/project_stats.rb, line 157
    def parse!(arguments)
      parser = option_parser(arguments)
      parser.parse!
      parse_arguments!(parser, arguments)
      parser.options
    end

parse_arguments!(parser, arguments) click to toggle source

    # File lib/compass/commands/project_stats.rb, line 164
    def parse_arguments!(parser, arguments)
      if arguments.size == 1
        parser.options[:project_name] = arguments.shift
      elsif arguments.size == 0
        # default to the current directory.
      else
        raise Compass::Error, "Too many arguments were specified."
      end
    end

primary() click to toggle source

    # File lib/compass/commands/project_stats.rb, line 155
    def primary; false; end

usage() click to toggle source

    # File lib/compass/commands/project_stats.rb, line 147
    def usage
      option_parser([]).to_s
    end

### Public Instance Methods

css_columns(css_file) click to toggle source

    # File lib/compass/commands/project_stats.rb, line 123
    def css_columns(css_file)
      if File.exists?(css_file)
        cf = Compass::Stats::CssFile.new(css_file)
        cf.analyze!
        %(selector_count prop_count file_size).map do |t|
          cf.send(t).to_s
        end
      else
        return [ '--', '--' , '--']
      end
    rescue LoadError
      @missing_css_parser = true
      return [ 'DISABLED', 'DISABLED' ]
    end

filename_columns(sass_file) click to toggle source

    # File lib/compass/commands/project_stats.rb, line 110
    def filename_columns(sass_file)
      filename = Compass.deprojectize(sass_file, working_path)
      [filename]
    end

format_kb(v) click to toggle source

    # File lib/compass/commands/project_stats.rb, line 87
    def format_kb(v)
      return v unless v =~ /^\d+$/
      v = Integer(v)
      if v < 1024
        "#{v} B"
      else
        v = v / 1024.0
        "#{v.ceil} KB"
      end
    end

pad(c, max, options = {}) click to toggle source

    # File lib/compass/commands/project_stats.rb, line 73
    def pad(c, max, options = {})
      options[:align] ||= :left
      if c == :-
        filler = '-'
        c = ''
      else
        filler = ' '
      end
      c = send(:"format_#{options[:formatter]}", c) if options[:formatter]
      spaces = max - c.size
      filled = filler * [spaces,0].max
      "#{options[:left]}#{filled if options[:align] == :right}#{c}#{filled if options[:align] == :left}#{options[:right]}"
    end

perform() click to toggle source

    # File lib/compass/commands/project_stats.rb, line 31
    def perform
      super
      require 'compass/stats'
      compiler = new_compiler_instance
      sass_files = sorted_sass_files(compiler)
      total_label = "Total (#{sass_files.size} files):"
      rows       = [[           :-,           :-,           :-,            :-,            :-,          :-,              :-,               :-,             :- ],
                    [   'Filename',      'Rules', 'Properties', 'Mixins Defs', 'Mixins Used',  'Filesize', 'CSS Selectors', 'CSS Properties', 'CSS Filesize' ],
                    [           :-,           :-,           :-,            :-,            :-,          :-,              :-,               :-,             :- ]]
      maximums   =  [ total_label.length,      5,           10,            14,            11,          13,              13,               14,             14 ]
      alignments =  [        :left,       :right,       :right,        :right,        :right,      :right,          :right,           :right,         :right ]
      delimiters =  [ ['| ', ' |'],  [' ', ' |'],  [' ', ' |'],   [' ', ' |'],   [' ', ' |'], [' ', ' |'],     [' ', ' |'],      [' ', ' |'],    [' ', ' |'] ]
      formatters =  [          nil,          nil,          nil,           nil,           nil,         :kb,             nil,             nil,             :kb ]
      totals     =  [ total_label,             0,            0,             0,             0,           0,               0,                0,              0 ]

      columns = rows.first.size

      sass_files.each do |sass_file|
        css_file = compiler.corresponding_css_file(sass_file) unless sass_file[0..0] == '_'
        row = filename_columns(sass_file)
        row += sass_columns(sass_file)
        row += css_columns(css_file)
        row.each_with_index do |c, i|
          maximums[i] = [maximums[i].to_i, c.size].max
          totals[i] = totals[i] + c.to_i if i > 0
        end
        rows << row
      end
      rows << [:-] * columns
      rows << totals.map{|t| t.to_s}
      rows << [:-] * columns
      rows.each do |row|
        row.each_with_index do |col, i|
          print pad(col, maximums[i], :align => alignments[i], :left => delimiters[i].first, :right => delimiters[i].last, :formatter => formatters[i])
        end
        print "\n"
      end
      if @missing_css_parser
        puts "\nInstall css_parser to enable stats on your css files:\n\n\tgem install css_parser"
      end
    end

print_tree(file, depth = 0, importer = @compiler.importer) click to toggle source

    # File lib/compass/commands/project_structure.rb, line 36
    def print_tree(file, depth = 0, importer = @compiler.importer)
      puts ((depth > 0 ? "|  " : "   ") * depth) + "+- " + Compass.deprojectize(file)
      @compiler.staleness_checker.send(:compute_dependencies, file, importer).each do |(dep, dep_importer)|
        print_tree(dep, depth + 1, dep_importer)# unless Compass.deprojectize(dep)[0...1] == "/"
      end
    end

sass_columns(sass_file) click to toggle source

    # File lib/compass/commands/project_stats.rb, line 115
    def sass_columns(sass_file)
      sf = Compass::Stats::SassFile.new(sass_file)
      sf.analyze!
      %(rule_count prop_count mixin_def_count mixin_count file_size).map do |t|
        sf.send(t).to_s
      end
    end

sorted_sass_files(compiler) click to toggle source

    # File lib/compass/commands/project_stats.rb, line 98
    def sorted_sass_files(compiler)
      sass_files = compiler.sass_files(:exclude_partials => false)
      sass_files.map! do |s|
        filename = Compass.deprojectize(s, File.join(Compass.configuration.project_path, Compass.configuration.sass_dir))
        [s, File.dirname(filename), File.basename(filename)]
      end
      sass_files = sass_files.sort_by do |s,d,f|
        File.join(d, f[0] == __ ? f[1..-1] : f)
      end
      sass_files.map!{|s,d,f| s}
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.