47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/css_primer.rb', line 47
def prime!
if self.parsed_options?
begin
self.log("Time to pwn...\n")
parser = Proc.new { |full_path|
self.log("\nOpening up #{full_path}\n") if @options.verbose
self.read_in_file(full_path) do |line|
line.scan(/class="((\s|\w|\-)*)"/) do |class_attribute|
class_attribute[0].split(" ").each do |class_name|
@attributes << [class_name, "."]
self.log("Found class => #{class_name}") if @options.verbose
end
end
line.scan(/id="((\w|\-)*)"/) do |id_attribute|
@attributes << [id_attribute[0], "#"]
self.log("Found id => #{id_attribute[0]}") if @options.verbose
end
end
}
if File.directory?(@markup_file)
self.recurse_directories(@markup_file) do |full_path|
parser.call(full_path) if full_path =~ /\.(html|xml)$/
end
else
parser.call(@markup_file)
end
buffer_array = @attributes.uniq
buffer_array.sort! if @options.sort
self.save(buffer_array.inject("") { |buffer, item| buffer << "#{item[1]}#{item[0]} {\n\n}\n\n" }, @css_file)
puts "\nSaved to #{@css_file}\n\nLet's Roll!"
rescue Exception => e
self.handle_exception(e)
end
end
end
|