6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/wordpress_theme_finder.rb', line 6
def self.check(url)
doc = Nokogiri::HTML(open(url))
style_css = doc.xpath("//link[@rel='stylesheet' and contains(@href, 'style.css')]/@href").first
return nil if style_css.nil?
values = Hash.new
source = open(style_css){|f|f.read}
source.each_line do |line|
['Theme Name', 'Theme URI', 'Author', 'Author URI', 'Description', 'Version', 'License', 'License URI', 'Tags', 'Text Domain'].each do |key|
values[key] = line.gsub("#{key}:", '').strip if line.match("#{key}:") && values[key].nil?
end
end
if values.has_key?('Tags')
values['Tags'] = values['Tags'].split(',').map!(&:strip)
end
values
end
|