Class: StyleVacuum
Overview
Detects styles that are not used in a Flex application.
This needs to be provided with a source directory to search for used styles, and a directory containing css files which will be loaded and parsed for style definitions.
NOTE: This tool needs further work before it can be considerd to cover all
use cases.
Constant Summary
Constants inherited from Tool
Instance Attribute Summary collapse
-
#declared ⇒ Object
readonly
Returns the value of attribute declared.
-
#report ⇒ Object
readonly
Returns the value of attribute report.
-
#undeclared ⇒ Object
readonly
Returns the value of attribute undeclared.
-
#unused ⇒ Object
readonly
Returns the value of attribute unused.
-
#used ⇒ Object
readonly
Returns the value of attribute used.
Instance Method Summary collapse
-
#detect ⇒ Object
Scans the project and detects styles referenced in the source and css files.
-
#initialize(opt, out = STDOUT) ⇒ StyleVacuum
constructor
A new instance of StyleVacuum.
-
#valid_opts ⇒ Object
Valid if we can find .css files in the specifed css_dir.
Methods inherited from Tool
#add_sigint_handler, #generated_at, #log, #puts, #to_disk
Constructor Details
#initialize(opt, out = STDOUT) ⇒ StyleVacuum
Returns a new instance of StyleVacuum.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/shed/style_vacuum.rb', line 20 def initialize(opt,out=STDOUT) super(opt,out) @css_dir = opt[:css_dir] do_exit unless valid_opts @style_regex = /styleName\s*=\s*["']\s*\{?\s*([\w.]+)\s*\}?\s*["']/ @declared_regex = /^\.(\w+)/ @declared, @used, @unused, @undeclared = [], [], [], [] detect @report = describe to_disk(@report) end |
Instance Attribute Details
#declared ⇒ Object (readonly)
Returns the value of attribute declared.
14 15 16 |
# File 'lib/shed/style_vacuum.rb', line 14 def declared @declared end |
#report ⇒ Object (readonly)
Returns the value of attribute report.
14 15 16 |
# File 'lib/shed/style_vacuum.rb', line 14 def report @report end |
#undeclared ⇒ Object (readonly)
Returns the value of attribute undeclared.
14 15 16 |
# File 'lib/shed/style_vacuum.rb', line 14 def undeclared @undeclared end |
#unused ⇒ Object (readonly)
Returns the value of attribute unused.
14 15 16 |
# File 'lib/shed/style_vacuum.rb', line 14 def unused @unused end |
#used ⇒ Object (readonly)
Returns the value of attribute used.
14 15 16 |
# File 'lib/shed/style_vacuum.rb', line 14 def used @used end |
Instance Method Details
#detect ⇒ Object
Scans the project and detects styles referenced in the source and css files.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/shed/style_vacuum.rb', line 53 def detect puts "Scanning project for styles..." @declared = scan_dirs(/\.(css)/, @css_dir, @declared_regex) @used = scan_dirs(/\.(as|mxml)/, @src, @style_regex) #Find any style names used in the source which haven't been declared. @undeclared = @used-@declared #Find any style names declared in the css but not used in the src. @unused = @declared-@used summarise end |
#valid_opts ⇒ Object
Valid if we can find .css files in the specifed css_dir.
42 43 44 45 46 47 48 |
# File 'lib/shed/style_vacuum.rb', line 42 def valid_opts return false unless File.exist?(@css_dir) found = Dir.chdir("#{@css_dir}") { Dir.glob('*.css') } found.length > 0 end |