Class: Cucumber::UnusedCss::Checker
- Inherits:
-
Object
- Object
- Cucumber::UnusedCss::Checker
- Includes:
- Singleton
- Defined in:
- lib/cucumber/unused_css/checker.rb
Class Attribute Summary collapse
-
.ignored_selectors ⇒ Object
readonly
Returns the value of attribute ignored_selectors.
-
.unused_selectors ⇒ Object
readonly
Returns the value of attribute unused_selectors.
-
.used_selectors ⇒ Object
readonly
Returns the value of attribute used_selectors.
Class Method Summary collapse
- .check_selectors(page) ⇒ Object
- .ignore(list = []) ⇒ Object
- .load_css_in_page(html_string, current_url) ⇒ Object
- .prepare(output_directory:) ⇒ Object
- .save_and_summarize ⇒ Object
Class Attribute Details
.ignored_selectors ⇒ Object (readonly)
Returns the value of attribute ignored_selectors.
70 71 72 |
# File 'lib/cucumber/unused_css/checker.rb', line 70 def ignored_selectors @ignored_selectors end |
.unused_selectors ⇒ Object (readonly)
Returns the value of attribute unused_selectors.
70 71 72 |
# File 'lib/cucumber/unused_css/checker.rb', line 70 def unused_selectors @unused_selectors end |
.used_selectors ⇒ Object (readonly)
Returns the value of attribute used_selectors.
70 71 72 |
# File 'lib/cucumber/unused_css/checker.rb', line 70 def used_selectors @used_selectors end |
Class Method Details
.check_selectors(page) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/cucumber/unused_css/checker.rb', line 47 def self.check_selectors(page) new_used_selectors = [] @unused_selectors.each do |selector| new_used_selectors.push selector if page.has_css?(selector, wait: 0) end # Add newly used selectors @used_selectors += new_used_selectors # Remove from unused list @unused_selectors -= new_used_selectors end |
.ignore(list = []) ⇒ Object
26 27 28 |
# File 'lib/cucumber/unused_css/checker.rb', line 26 def self.ignore(list = []) @ignores += list end |
.load_css_in_page(html_string, current_url) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/cucumber/unused_css/checker.rb', line 30 def self.load_css_in_page(html_string, current_url) html_page = Nokogiri::HTML(html_string) html_page.css('link[rel="stylesheet"]').each do |file_tag| if file_tag['href'].match?(/^https?:/) css_file_url = file_tag['href'] else uri = URI.parse(current_url) css_file_url = "#{uri.scheme}://#{uri.host}:#{uri.port}#{file_tag['href']}" end next if @css_files.include? css_file_url load_selectors css_file_url end end |
.prepare(output_directory:) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/cucumber/unused_css/checker.rb', line 11 def self.prepare(output_directory:) @output_directory = output_directory @used_selectors = [] @unused_selectors = [] @css_files = [] @ignored_selectors = [] @ignores = [ /^@(font-face|(-moz-|-webkit-)?keyframes)/, /^\*$/, /:active/, /:hover/, /::(before|after)/, ] end |
.save_and_summarize ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/cucumber/unused_css/checker.rb', line 60 def self.save_and_summarize @unused_selectors.sort! @used_selectors.sort! @ignored_selectors.sort! write_files summarize end |