Module: WpWrapper::Modules::Themes
- Included in:
- Client
- Defined in:
- lib/wp_wrapper/modules/themes.rb
Instance Method Summary collapse
- #activate_random_theme ⇒ Object
- #activate_theme(theme_identifier = 'twentytwelve') ⇒ Object
- #get_theme_links ⇒ Object
- #perform_activation(url) ⇒ Object
Instance Method Details
#activate_random_theme ⇒ Object
5 6 7 8 9 10 |
# File 'lib/wp_wrapper/modules/themes.rb', line 5 def activate_random_theme theme_links = get_theme_links random_link = (theme_links && theme_links.any?) ? theme_links.to_a.sample : nil perform_activation(random_link["href"]) if (random_link) end |
#activate_theme(theme_identifier = 'twentytwelve') ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/wp_wrapper/modules/themes.rb', line 12 def activate_theme(theme_identifier = 'twentytwelve') success = false theme_links = get_theme_links if (theme_links && theme_links.any?) activation_link = nil regex = Regexp.new("stylesheet=#{theme_identifier}", Regexp::IGNORECASE) theme_links.each do |link| href = link["href"] if (regex.match(href)) activation_link = href break end end success = perform_activation(activation_link) if success puts "[WpWrapper::Modules::Themes] - #{Time.now}: Url: #{self.url}. Theme '#{theme_identifier}' has been activated!" else puts "[WpWrapper::Modules::Themes] - #{Time.now}: Url: #{self.url}. Couldn't find the theme #{theme_identifier}'s activation-link." end end return success end |
#get_theme_links ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/wp_wrapper/modules/themes.rb', line 53 def get_theme_links theme_links = [] if (login) themes_page = self.mechanize_client.open_url(get_url(:themes)) if (themes_page) theme_links = themes_page.parser.css("div.themes div.theme div.theme-actions a.activate") end end puts "[WpWrapper::Modules::Themes] - #{Time.now}: Found a total of #{theme_links.try(:size)} installed themes." return theme_links end |
#perform_activation(url) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/wp_wrapper/modules/themes.rb', line 41 def perform_activation(url) success = false if (url && url.present?) puts "[WpWrapper::Modules::Themes] - #{Time.now}: Will activate theme with url #{url}." self.mechanize_client.open_url(url) success = true end return success end |