wp_wrapper 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 84593928500719e7492d7872902ed82016bd59dd
4
+ data.tar.gz: ec08aebed77d677a320cb64b9005a47723883968
5
+ SHA512:
6
+ metadata.gz: bfc21471d832c2c500894e759ed99d8418199e586c58ce7c3b386a106b369a4c81f662fedf26417ba4d014565ce96e251411efc02bd7906ff94ba7453581883d
7
+ data.tar.gz: fa650d62900e6d038d3aa015f5a0454698da384e97326dd6762da62242b09687842c40972227f1ac3ae2ef47bb309548e4e458a19877ef17199daca1d64820f0
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'nokogiri', ">= 1.5.9"
4
+ gem 'http_utilities', ">= 1.0.1"
5
+
6
+ group :development, :test do
7
+ gem 'rspec'
8
+ gem "mocha"
9
+ end
10
+
11
+ gemspec
12
+
data/LICENSE.txt ADDED
@@ -0,0 +1,50 @@
1
+
2
+ Version 0.9.3
3
+
4
+ Copyright (c) 2011, Majestic-12 Ltd
5
+
6
+ All rights reserved.
7
+
8
+
9
+
10
+ Redistribution and use in source and binary forms, with or without
11
+
12
+ modification, are permitted provided that the following conditions are met:
13
+
14
+ * Redistributions of source code must retain the above copyright
15
+
16
+ notice, this list of conditions and the following disclaimer.
17
+
18
+ * Redistributions in binary form must reproduce the above copyright
19
+
20
+ notice, this list of conditions and the following disclaimer in the
21
+
22
+ documentation and/or other materials provided with the distribution.
23
+
24
+ * Neither the name of the Majestic-12 Ltd nor the
25
+
26
+ names of its contributors may be used to endorse or promote products
27
+
28
+ derived from this software without specific prior written permission.
29
+
30
+
31
+
32
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
33
+
34
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
35
+
36
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
37
+
38
+ DISCLAIMED. IN NO EVENT SHALL Majestic-12 Ltd BE LIABLE FOR ANY
39
+
40
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
41
+
42
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43
+
44
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45
+
46
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
47
+
48
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
49
+
50
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.markdown ADDED
@@ -0,0 +1,3 @@
1
+ # WP Wrapper #
2
+
3
+ **Wrapper layer to interact with WordPress (using Mechanize) when the XML RPC API doesn't suffice.**
data/Rakefile ADDED
@@ -0,0 +1,87 @@
1
+ ## helper functions
2
+
3
+ def name
4
+ @name ||= Dir['*.gemspec'].first.split('.').first
5
+ end
6
+
7
+ def version
8
+ line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
9
+ line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
10
+ end
11
+
12
+ def gemspec_file
13
+ "#{name}.gemspec"
14
+ end
15
+
16
+ def gem_file
17
+ "#{name}-#{version}.gem"
18
+ end
19
+
20
+ def replace_header(head, header_name)
21
+ head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
22
+ end
23
+
24
+ begin
25
+ # Rspec 2.0
26
+ require 'rspec/core/rake_task'
27
+
28
+ desc 'Default: run specs'
29
+ task :default => :spec
30
+ RSpec::Core::RakeTask.new do |t|
31
+ t.pattern = "spec/**/*_spec.rb"
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new('rcov') do |t|
35
+ t.pattern = "spec/**/*_spec.rb"
36
+ t.rcov = true
37
+ t.rcov_opts = ['--exclude', 'spec']
38
+ end
39
+
40
+ rescue LoadError
41
+ puts "Rspec not available. Install it with: gem install rspec"
42
+ end
43
+
44
+ ## release management tasks
45
+
46
+ desc "Commit, create tag v#{version} and build and push #{gem_file} to Rubygems"
47
+ task :release => :build do
48
+ sh "git commit --allow-empty -a -m 'Release #{version}'"
49
+ sh "git tag v#{version}"
50
+ sh "git push"
51
+ sh "git push origin v#{version}"
52
+ sh "gem push pkg/#{gem_file}"
53
+ end
54
+
55
+ desc "Build #{gem_file} into the pkg directory"
56
+ task :build => :gemspec do
57
+ sh "mkdir -p pkg"
58
+ sh "gem build #{gemspec_file}"
59
+ sh "mv #{gem_file} pkg"
60
+ end
61
+
62
+ desc "Generate #{gemspec_file}"
63
+ task :gemspec do
64
+ # read spec file and split out manifest section
65
+ spec = File.read(gemspec_file)
66
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
67
+
68
+ # replace name version and date
69
+ replace_header(head, :name)
70
+ replace_header(head, :version)
71
+
72
+ # determine file list from git ls-files
73
+ files = `git ls-files`.
74
+ split("\n").
75
+ sort.
76
+ reject { |file| file =~ /^\./ }.
77
+ reject { |file| file =~ /^(rdoc|pkg)/ }.
78
+ map { |file| " #{file}" }.
79
+ join("\n")
80
+
81
+ # piece file back together and write
82
+ manifest = " s.files = %w[\n#{files}\n ]\n"
83
+ spec = [head, manifest, tail].join(" # = MANIFEST =\n")
84
+ File.open(gemspec_file, 'w') { |io| io.write(spec) }
85
+ puts "Updated #{gemspec_file}"
86
+ end
87
+
@@ -0,0 +1,63 @@
1
+ module WpWrapper
2
+ class Client
3
+ attr_accessor :url, :username, :password
4
+ attr_accessor :environment, :logged_in
5
+ attr_accessor :http_client, :mechanize_client
6
+
7
+ def initialize(options = {})
8
+ options.symbolize_keys! if options.respond_to?(:symbolize_keys!)
9
+
10
+ self.url = options.fetch(:url, nil)
11
+ self.url = "#{self.url}/" unless self.url.nil? || self.url =~ /\/$/i
12
+
13
+ self.username = options.fetch(:username, nil)
14
+ self.password = options.fetch(:password, nil)
15
+ self.logged_in = false
16
+
17
+ self.http_client = HttpUtilities::Http::Client.new
18
+ self.mechanize_client = HttpUtilities::Http::Mechanize::Client.new
19
+ end
20
+
21
+ include WpWrapper::Modules::Authorization
22
+ include WpWrapper::Modules::Setup
23
+ include WpWrapper::Modules::Upgrade
24
+ include WpWrapper::Modules::Themes
25
+ include WpWrapper::Modules::Plugins
26
+ include WpWrapper::Modules::Options
27
+ include WpWrapper::Modules::Profiles
28
+ include WpWrapper::Modules::Api
29
+
30
+ protected
31
+ def logged_in?
32
+ return self.logged_in
33
+ end
34
+
35
+ def get_url(type = :home, options = {})
36
+ absolute = options.fetch(:absolute, true)
37
+ admin_prefix = options.fetch(:admin_prefix, "wp-admin/")
38
+ uri = absolute ? self.url : ""
39
+
40
+ return case type
41
+ when :home then "#{uri}"
42
+ when :admin then "#{uri}#{admin_prefix}"
43
+ when :upgrade then "#{uri}#{admin_prefix}update-core.php"
44
+ when :general_options then "#{uri}#{admin_prefix}options-general.php"
45
+ when :write_options then "#{uri}#{admin_prefix}options-writing.php"
46
+ when :read_options then "#{uri}#{admin_prefix}options-reading.php"
47
+ when :discussion_options then "#{uri}#{admin_prefix}options-discussion.php"
48
+ when :plugins then "#{uri}#{admin_prefix}plugins.php"
49
+ when :themes then "#{uri}#{admin_prefix}themes.php"
50
+ when :profile then "#{uri}#{admin_prefix}profile.php"
51
+ when :new_user then "#{uri}#{admin_prefix}user-new.php"
52
+ end
53
+ end
54
+
55
+ def set_options_and_submit(url, form_identifier = {}, fields = {}, submit_identifier = :first, options = {})
56
+ login unless logged_in?
57
+
58
+ form_page_url = "#{get_url(:admin)}/#{url}"
59
+ response = self.mechanize_client.set_form_and_submit(form_page_url, form_identifier, submit_identifier, fields, options)
60
+ end
61
+
62
+ end
63
+ end
@@ -0,0 +1,20 @@
1
+ module WpWrapper
2
+ module Modules
3
+ module Api
4
+
5
+ def enable_xml_rpc_api
6
+ if (login)
7
+ write_options_page = self.mechanize_client.open_url(get_url(:write_options))
8
+
9
+ if (write_options_page)
10
+ form = write_options_page.form_with(:action => /options\.php/i)
11
+ form.checkbox_with(:name => 'enable_xmlrpc').checked = true
12
+
13
+ updated_page = form.submit(form.buttons.first)
14
+ end
15
+ end
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,46 @@
1
+ module WpWrapper
2
+ module Modules
3
+
4
+ module Authorization
5
+
6
+ def login(retries = 3)
7
+ success = logged_in?
8
+
9
+ if (!success && retries > 0)
10
+ login_page = self.mechanize_client.open_url(get_url(:admin))
11
+ agent = self.mechanize_client.agent
12
+
13
+ if (login_page)
14
+ login_form = login_page.form_with(:name => 'loginform')
15
+
16
+ if (login_form)
17
+ login_form.field_with(:name => 'log').value = self.username
18
+ login_form.field_with(:name => 'pwd').value = self.password
19
+
20
+ begin
21
+ logged_in_page = login_form.submit
22
+ log_out_link = logged_in_page.link_with(:href => /wp-login\.php\?action=logout/i)
23
+ self.logged_in = !log_out_link.nil?
24
+ success = self.logged_in
25
+
26
+ puts "#{Time.now}: Url: #{self.url}. Successfully logged in? #{self.logged_in}"
27
+
28
+ rescue Exception => e
29
+ puts "#{Time.now}: Url: #{self.url}. Failed to login. Error Class: #{e.class.name}. Error Message: #{e.message}"
30
+ login(retries - 1) if (retries > 0)
31
+ end
32
+
33
+ else
34
+ puts "\n\n#{Time.now}: Url: #{self.url}. Something's broken! Can't find wp-admin login form! Retrying...\n\n"
35
+ login(retries - 1) if (retries > 0)
36
+ end
37
+ end
38
+ end
39
+
40
+ return success
41
+ end
42
+
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,28 @@
1
+ module WpWrapper
2
+ module Modules
3
+ module Options
4
+
5
+ def set_blog_description(description)
6
+ return set_options(:general, {:blogdescription => {:value => description, :type => :input}})
7
+ end
8
+
9
+ def disable_comments_and_trackbacks
10
+ options = {
11
+ :default_pingback_flag => {:checked => false, :type => :checkbox},
12
+ :default_ping_status => {:checked => false, :type => :checkbox},
13
+ :default_comment_status => {:checked => false, :type => :checkbox},
14
+ :comments_notify => {:checked => false, :type => :checkbox},
15
+ :moderation_notify => {:checked => false, :type => :checkbox}
16
+ }
17
+
18
+ return set_options(:discussion, options)
19
+ end
20
+
21
+ def set_options(type, options = {})
22
+ url = get_url("#{type}_options".to_sym, absolute: false, admin_prefix: '')
23
+ return set_options_and_submit(url, {action: /options\.php/i}, options)
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,17 @@
1
+ module WpWrapper
2
+ module Modules
3
+ module Plugins
4
+ module Akismet
5
+
6
+ def configure_akismet(api_key)
7
+ options = {
8
+ :key => {:value => api_key, :type => :input}
9
+ }
10
+
11
+ response = set_options_and_submit("options-general.php?page=akismet-key-config", {:id => 'akismet-enter-api-key'}, options)
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ module WpWrapper
2
+ module Modules
3
+ module Plugins
4
+ module Gocodes
5
+
6
+ def configure_gocodes(url_trigger = 'go')
7
+ options = {
8
+ :urltrigger => {:value => url_trigger, :type => :input},
9
+ :nofollow => {:checked => true, :type => :checkbox},
10
+ }
11
+
12
+ return set_options_and_submit("options-general.php?page=gocodes/gocodes.php", {:action => /page=gocodes\/gocodes\.php/i}, options)
13
+ end
14
+
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ module WpWrapper
2
+ module Modules
3
+ module Plugins
4
+ module TrackingCode
5
+
6
+ def configure_tracking_code(tracking_code)
7
+ options = {
8
+ 'data[tracking_head][code]' => {:value => tracking_code, :type => :input},
9
+ 'data[tracking_head][disable]' => {:checked => false, :type => :checkbox},
10
+ 'data[tracking_footer][code]' => {:value => '', :type => :input},
11
+ 'data[tracking_footer][disable]' => {:checked => true, :type => :checkbox},
12
+ }
13
+
14
+ return set_options_and_submit("options-general.php?page=tracking-code", {:method => /post/i}, options)
15
+ end
16
+
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,129 @@
1
+ module WpWrapper
2
+ module Modules
3
+ module Plugins
4
+ module W3TotalCache
5
+
6
+ def configure_w3_total_cache(caching_mechanism = :memcached, options = {})
7
+ configure_general_settings(caching_mechanism, options)
8
+ configure_page_cache
9
+ configure_minification
10
+ configure_browser_cache
11
+ activate_configuration
12
+ end
13
+
14
+ def configure_general_settings(caching_mechanism, options = {})
15
+ caching_options = {}
16
+ cache_sections = [:pg, :db, :object]
17
+
18
+ url = "admin.php?page=w3tc_general"
19
+ form_identifier = {:id => 'w3tc_form'}
20
+ button_identifier = {:name => 'w3tc_save_options'}
21
+
22
+ varnish_server = options.fetch(:varnish_server, "localhost")
23
+
24
+ cache_sections.each do |cache_section|
25
+ section_options = {
26
+ "#{cache_section}cache.enabled" => {:checked => true, :type => :checkbox},
27
+ "#{cache_section}cache.engine" => {:value => caching_mechanism, :type => :select}
28
+ }
29
+
30
+ caching_options.merge!(section_options)
31
+ end
32
+
33
+ minify_options = {
34
+ "minify.enabled" => {:checked => true, :type => :checkbox},
35
+ "minify.engine" => {:value => caching_mechanism, :type => :select},
36
+ #"minify.auto" => {:checked => true, :type => :radiobutton}
37
+ }
38
+
39
+ caching_options.merge!(minify_options)
40
+
41
+ browser_cache_options = {
42
+ "browsercache.enabled" => {:checked => true, :type => :checkbox},
43
+ }
44
+
45
+ caching_options.merge!(browser_cache_options)
46
+
47
+ varnish_options = {
48
+ "varnish.enabled" => {:checked => true, :type => :checkbox},
49
+ "varnish.servers" => {:value => varnish_server, :type => :input}
50
+ }
51
+
52
+ caching_options.merge!(varnish_options)
53
+
54
+ return set_options_and_submit(url, form_identifier, caching_options, button_identifier)
55
+ end
56
+
57
+ def configure_page_cache
58
+ url = "admin.php?page=w3tc_pgcache"
59
+ form_identifier = {:action => /admin\.php\?page=w3tc_pgcache/i, :index => 1}
60
+ button_identifier = {:name => 'w3tc_save_options'}
61
+
62
+ options = {
63
+ "pgcache.cache.feed" => {:checked => true, :type => :checkbox},
64
+ }
65
+
66
+ return set_options_and_submit(url, form_identifier, options, button_identifier)
67
+ end
68
+
69
+ def configure_minification
70
+ url = "admin.php?page=w3tc_minify"
71
+ form_identifier = {:action => /admin\.php\?page=w3tc_minify/i, :index => 1}
72
+ button_identifier = {:name => 'w3tc_save_options'}
73
+
74
+ options = {
75
+ "minify.html.enable" => {:checked => true, :type => :checkbox},
76
+ "minify.html.inline.css" => {:checked => true, :type => :checkbox},
77
+ "minify.html.inline.js" => {:checked => true, :type => :checkbox},
78
+ "minify.auto.disable_filename_length_test" => {:checked => true, :type => :checkbox},
79
+ }
80
+
81
+ return set_options_and_submit(url, form_identifier, options, button_identifier)
82
+ end
83
+
84
+ def configure_browser_cache
85
+ options = {}
86
+
87
+ url = "admin.php?page=w3tc_browsercache"
88
+ form_identifier = {:action => /admin\.php\?page=w3tc_browsercache/i, :index => 1}
89
+ button_identifier = {:name => 'w3tc_save_options'}
90
+
91
+ sections = [
92
+ :cssjs, :html, :other
93
+ ]
94
+
95
+ sections.each do |section|
96
+ section_options = {
97
+ "browsercache.#{section}.expires" => {:checked => true, :type => :checkbox},
98
+ "browsercache.#{section}.cache.control" => {:checked => true, :type => :checkbox},
99
+ "browsercache.#{section}.etag" => {:checked => true, :type => :checkbox},
100
+ }
101
+
102
+ options.merge!(section_options)
103
+ end
104
+
105
+ return set_options_and_submit(url, form_identifier, options)
106
+ end
107
+
108
+ def activate_configuration
109
+ url = "#{get_url(:admin)}admin.php?page=w3tc_general"
110
+ page = self.mechanize_client.get_page(url)
111
+
112
+ parser = page ? self.mechanize_client.get_parser(page) : nil
113
+ input = parser ? parser.at_css('input[value = "deploy"]') : nil
114
+
115
+ if (input)
116
+ on_click = input["onclick"]
117
+ url = on_click.gsub("admin.php?page=w3tc_general", url)
118
+ url = url.gsub(/^document\.location\.href='/i, "").gsub(/';$/, "")
119
+
120
+ puts "Will activate new W3 Total Cache-configuration. Activation url: #{url}"
121
+
122
+ self.http_client.retrieve_raw_content(url)
123
+ end
124
+ end
125
+
126
+ end
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,150 @@
1
+ # encoding: UTF-8
2
+
3
+ module WpWrapper
4
+ module Modules
5
+ module Plugins
6
+ module WordpressSeo
7
+
8
+ def configure_wordpress_seo(language = :sv)
9
+ login unless logged_in?
10
+
11
+ options = get_author_options
12
+
13
+ options.merge!(get_taxonomy_options)
14
+ options.merge!(get_title_options(language))
15
+
16
+ url = "#{get_url(:admin)}/admin.php?page=wpseo_titles"
17
+
18
+ page = self.mechanize_client.get_page(url)
19
+ form = self.mechanize_client.get_form(page, {:action => /wp-admin\/options\.php/i})
20
+
21
+ if (form)
22
+ options.each do |key, values|
23
+ case values[:type]
24
+ when :input
25
+ form[key] = values[:value]
26
+ when :checkbox
27
+ form[key] = "on" if values[:checked]
28
+ end
29
+ end
30
+
31
+ form.submit
32
+ end
33
+
34
+ end
35
+
36
+ def get_author_options
37
+ options = {
38
+ "wpseo_titles[noindex-author-wpseo]" => {:type => :checkbox, :checked => true},
39
+ "wpseo_titles[disable-author]" => {:type => :checkbox, :checked => true},
40
+ }
41
+ end
42
+
43
+ def get_taxonomy_options
44
+ options = {
45
+ "wpseo_titles[noindex-tax-category]" => {:type => :checkbox, :checked => true},
46
+ "wpseo_titles[noindex-tax-post_tag]" => {:type => :checkbox, :checked => true},
47
+ "wpseo_titles[noindex-tax-post_format]" => {:type => :checkbox, :checked => true},
48
+ }
49
+
50
+ return options
51
+ end
52
+
53
+ def get_title_options(language = :sv)
54
+ options = {
55
+ "wpseo_titles[forcerewritetitle]" => {:type => :checkbox, :checked => true},
56
+ "wpseo_titles[title-home]" => {:type => :input, :value => '%%sitename%% %%page%%'},
57
+ "wpseo_titles[title-search]" => {:type => :input, :value => translate_pattern(:search, language)},
58
+ "wpseo_titles[title-404]" => {:type => :input, :value => translate_pattern(:not_found, language)}
59
+ }
60
+
61
+ standard_pattern = '%%title%% %%page%% %%sep%% %%sitename%%'
62
+ standard_term_pattern = translate_pattern(:term, language)
63
+
64
+ types = {
65
+ :post => {:pattern => standard_pattern, :noindex => false},
66
+ :page => {:pattern => standard_pattern, :noindex => false},
67
+ :attachment => {:pattern => standard_pattern, :noindex => true},
68
+ :wooframework => {:pattern => standard_pattern, :noindex => false},
69
+ :category => {:pattern => standard_term_pattern, :noindex => false},
70
+ :post_tag => {:pattern => standard_term_pattern, :noindex => true},
71
+ :post_format => {:pattern => standard_term_pattern, :noindex => true},
72
+ :author => {:pattern => translate_pattern(:author, language), :noindex => true},
73
+ :archive => {:pattern => '%%date%% %%page%% %%sep%% %%sitename%%', :noindex => true},
74
+ }
75
+
76
+ types.each do |key, values|
77
+ type_options = {
78
+ "wpseo_titles[title-#{key}]" => {:type => :input, :value => values[:pattern]},
79
+ "wpseo_titles[noindex-#{key}]" => {:type => :checkbox, :checked => values[:noindex]}
80
+ }
81
+
82
+ options.merge!(type_options)
83
+ end
84
+
85
+ return options
86
+ end
87
+
88
+ def configure_wordpress_seo_sitemaps(not_included_post_types: [], not_included_taxonomies: [], disable_author_sitemap: true)
89
+ login unless logged_in?
90
+
91
+ url = "#{get_url(:admin)}/admin.php?page=wpseo_xml"
92
+ page = self.mechanize_client.get_page(url)
93
+ form = self.mechanize_client.get_form(page, {:action => /wp-admin\/options\.php/i})
94
+
95
+ options = {
96
+ "wpseo_xml[enablexmlsitemap]" => {:type => :checkbox, :checked => true}
97
+ }
98
+
99
+ if (disable_author_sitemap)
100
+ options["wpseo_xml[disable_author_sitemap]"] = {:type => :checkbox, :checked => true}
101
+ end
102
+
103
+ not_included_post_types.each do |post_type|
104
+ post_type_options = {
105
+ "wpseo_xml[post_types-#{post_type}-not_in_sitemap]" => {:type => :checkbox, :checked => true}
106
+ }
107
+
108
+ options.merge!(post_type_options)
109
+ end
110
+
111
+ not_included_taxonomies.each do |taxonomy|
112
+ taxonomy_options = {
113
+ "wpseo_xml[taxonomies-#{taxonomy}-not_in_sitemap]" => {:type => :checkbox, :checked => true}
114
+ }
115
+
116
+ options.merge!(taxonomy_options)
117
+ end
118
+
119
+ if (form)
120
+ options.each do |key, values|
121
+ case values[:type]
122
+ when :input
123
+ form[key] = values[:value] if (form.has_field?(key))
124
+ when :checkbox
125
+ form.checkbox_with(name: key).check rescue nil if values[:checked]
126
+ end
127
+ end
128
+
129
+ form.submit
130
+ end
131
+ end
132
+
133
+ #Retarded method for now, look into I18n later
134
+ def translate_pattern(key, language = :en)
135
+ case key
136
+ when :search
137
+ language.eql?(:sv) ? 'Du sökte efter %%searchphrase%% %%page%% %%sep%% %%sitename%%' : 'You searched for %%searchphrase%% %%page%% %%sep%% %%sitename%%'
138
+ when :not_found
139
+ language.eql?(:sv) ? 'Sidan kunde inte hittas %%sep%% %%sitename%%' : 'Page Not Found %%sep%% %%sitename%%'
140
+ when :author
141
+ language.eql?(:sv) ? '%%name%%, Författare %%sitename%% %%page%%' : '%%name%%, Author at %%sitename%% %%page%%'
142
+ when :term
143
+ language.eql?(:sv) ? '%%term_title%% Arkiv %%page%% %%sep%% %%sitename%%' : '%%term_title%% Archives %%page%% %%sep%% %%sitename%%'
144
+ end
145
+ end
146
+
147
+ end
148
+ end
149
+ end
150
+ end