Class: Maximus::Stylestats

Inherits:
Statistic show all
Defined in:
lib/maximus/statistics/stylestats.rb

Overview

Since:

  • 0.1.0

Instance Attribute Summary

Attributes inherited from Statistic

#output

Instance Method Summary collapse

Methods inherited from Statistic

#initialize

Methods included from Helper

#check_default_config_path, #edit_yaml, #file_count, #file_list, #is_rails?, #lines_added_to_range, #node_module_exists, #path_exists, #prompt, #reporter_path, #root_dir, #truthy

Constructor Details

This class inherits a constructor from Maximus::Statistic

Instance Method Details

#resultObject

See Also:

Since:

  • 0.1.0


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/maximus/statistics/stylestats.rb', line 9

def result

  return if @settings[:stylestats].blank?

  node_module_exists('stylestats')
  @path = is_rails? ? "#{@settings[:root_dir]}/public/assets/**/*.css" : "#{@settings[:root_dir]}/**/*.css" if @path.blank?

  css_files = @path.is_a?(Array) ? @path : find_css_files

  css_files.each do |file|

    # For Rails, we only want the name of the compiled asset, because we know it'll live in public/assets.
    #   If this isn't Rails, sure, give me the full path because the directory structure is likely unique
    pretty_name = is_rails? ? file.split('/').pop.gsub(/(-{1}[a-z0-9]{32}*\.{1}){1}/, '.') : file

    puts "#{'stylestats'.color(:green)}: #{pretty_name}\n\n"

    # include JSON formatter unless we're in dev
    stylestats = `stylestats #{file} --config=#{@settings[:stylestats]} #{'--type=json' unless @@config.is_dev?}`
    puts stylestats
    refine(stylestats, pretty_name)

    File.delete(file)
  end

  if is_rails?    # @todo I'd rather Rake::Task but it's not working in different directories

    Dir.chdir(@settings[:root_dir]) do
      if @@config.is_dev?        # @todo review that this may not be best practice, but it's really noisy in the console

        quietly { `rake assets:clobber` }
      else
        `rake assets:clobber`
      end
    end
  end
  @@config.destroy_temp('stylestats')
  @output

end