Class: Wordstress::Models::Themes

Inherits:
Object
  • Object
show all
Defined in:
lib/wordstress/models/themes.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {:dbname=>"themes.db"}) ⇒ Themes

Returns a new instance of Themes.



28
29
30
31
32
# File 'lib/wordstress/models/themes.rb', line 28

def initialize(options={:dbname=>"themes.db"})
  DataMapper.setup(:default, "sqlite3://#{File.join(Dir.pwd, options[:dbname])}")
  DataMapper.finalize
  DataMapper.auto_migrate!
end

Instance Method Details

#import_from_file(filename) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/wordstress/models/themes.rb', line 34

def import_from_file(filename)
  doc = Nokogiri::HTML(File.read(filename))
  title = doc.at_css('title').children.text

  return nil unless title.include?"Revision"
  revision = title.split("Revision ")[1].split(':')[0].to_i
  links = doc.xpath('//li//a')


  puts "Theme SVN revision is: #{revision}"
  puts "#{links.count} themes found"

  i = Info.new
  i.revision = revision
  i.save

  links.each do |link|
    # puts "-> #{link.attr('href')} - #{link.text.chop}"
    t = Theme.new
    t.name = link.text.chop
    t.link = 'https://themes.svn.wordpress.org/'+link.attr('href')
    t.save

  end
end