Skip to content

Commit

Permalink
issue 3 Script to add AGENT_SHEET to applicable styles
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonBarnabe committed Jan 6, 2014
1 parent d5d1517 commit 714a862
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions runnerscripts/check_agentsheet.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require 'csspool'

def doc_has_agent_specific_stuff(doc)
doc.rule_sets.each do |rs|
rs.selectors.each do |s|
s.simple_selectors.each do |ss|
return true if ss.is_a?(CSSPool::Selectors::Type) and ss.name == 'scrollbar'
ss.additional_selectors.each do |as|
return true if as.is_a?(CSSPool::Selectors::Type) and as.name == 'scrollbar'
end
end
end
end
return false
end

Style.active.where('code_error is null').includes(:style_code, {:style_options => :style_option_values}).find_in_batches(batch_size: 100) do |styles_batch|
styles_batch.each do |style|
#puts "Checking #{style.id}"
turn_into_agent = false
style.code_possibilities.each do |o, c|
break unless /\/\*\s*AGENT_SHEET\s*\*\//.match(c).nil?
begin
doc = CSSPool::CSS::Document.parse(c)
rescue
break
end
if doc_has_agent_specific_stuff(doc)
turn_into_agent = true
break
end
end
if turn_into_agent
puts "AGENT: #{style.id} #{style.category} #{style.short_description}"
style.style_code.code = "/* AGENT_SHEET */\n" + style.style_code.code
style.style_code.save
end
end
#puts "Completed up to #{styles_batch.last.id}"
end

0 comments on commit 714a862

Please # to comment.