guard-blogger 0.0.1

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: 244db9c2eb5d72523a744fffff9c5e5f929845ff
4
+ data.tar.gz: c518bdfe76c5479ecb77a3a57451c4265dbe5ca0
5
+ SHA512:
6
+ metadata.gz: 7b4676d79a3bde7bee3b3c2ae8980979a27fd834c3560c771bfd5499d2848b46d2f66027212ac41c9e7b7255bebcf797795152b3b815630289b9df35a6b00197
7
+ data.tar.gz: bc69bb9a751cd3f9a32d6ae15b0bbf1ea76fae201c93b130b4e19c873b96f28d107dc2903af72908e94d996b7b5f046a0183a82772a2a4128c5ebe382102694b
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in guard-blogger.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Scott Arthur
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # Guard::Blogger
2
+
3
+ Guard plugin to update a Blogger template.
4
+
5
+ ## Requirements
6
+
7
+ You will need Firefox installed as this plugin currently uses selenium-webdriver
8
+
9
+ ## Installation
10
+
11
+ Add to your Gemfile:
12
+
13
+ gem 'guard-blogger'
14
+
15
+ Init the Guardfile definition:
16
+
17
+ guard init blogger
18
+
19
+ Set your Blogger login credentials and the name of your blog in the Guardfile:
20
+
21
+ guard :blogger, email: 'blogger@mydomain.com', password: 'sshhhhhhitsasecret', blog: 'My Blog' do
22
+ watch 'template.xml'
23
+ end
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'guard/blogger/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "guard-blogger"
8
+ spec.version = Guard::BloggerVersion::VERSION
9
+ spec.authors = ["Scott Arthur"]
10
+ spec.email = ["scott@scottatron.com"]
11
+ spec.summary = "Guard plugin for updating Blogger templates"
12
+ spec.description = "Guard plugin for updating Blogger templates using Capybara/Selenium Webdriver."
13
+ spec.homepage = "https://github.com/scottatron/guard-blogger"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ # spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ # spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "guard"
22
+ spec.add_dependency "capybara"
23
+ spec.add_dependency "selenium-webdriver"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.5"
26
+ spec.add_development_dependency "rake"
27
+ end
@@ -0,0 +1,34 @@
1
+ module Blogger
2
+ module Helpers
3
+
4
+ ESCAPE_MAP = { '\\' => '\\\\', '</' => '<\/', "\r\n" => '\n', "\n" => '\n', "\r" => '\n', '"' => '\\"', "'" => "\\'" }
5
+
6
+ def escape_template(template)
7
+ if template
8
+ template.gsub(/(\|<\/|\r\n|\342\200\250|\342\200\251|[\n\r"'])/u) {|match| ESCAPE_MAP[match] }
9
+ else
10
+ ''
11
+ end
12
+ end
13
+
14
+ DEFAULT_TEMPLATE = <<-eos
15
+ <?xml version="1.0" encoding="UTF-8" ?>
16
+ <!DOCTYPE html>
17
+ <html>
18
+ <head>
19
+ <b:skin></b:skin>
20
+ </head>
21
+ <body>
22
+ <b:section id='main'>
23
+ <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
24
+ </b:section>
25
+ </body>
26
+ </html>
27
+ eos
28
+
29
+ def default_template
30
+ escape_template(DEFAULT_TEMPLATE)
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,67 @@
1
+ require 'guard'
2
+ require 'guard/plugin'
3
+ require 'capybara'
4
+ require 'blogger/helpers'
5
+
6
+ module Guard
7
+ class Blogger < Plugin
8
+ include Capybara::DSL
9
+ include ::Blogger::Helpers
10
+
11
+ attr_reader :email, :password, :blog
12
+
13
+ def initialize(options = {})
14
+ super
15
+
16
+ Capybara.default_driver = :selenium
17
+ Capybara.app_host = "https://www.blogger.com"
18
+
19
+ @email = options[:email]
20
+ @password = options[:password]
21
+ @blog = options[:blog]
22
+ end
23
+
24
+ def start
25
+ sign_in
26
+ end
27
+
28
+ def run_on_changes(paths)
29
+ update_template(paths.first)
30
+ end
31
+
32
+ private
33
+
34
+ def sign_in
35
+ visit '/'
36
+ resize
37
+ fill_in 'Email', with: email
38
+ fill_in 'Password', with: password
39
+ click_on 'Sign in'
40
+ click_on blog
41
+ click_on 'Template'
42
+ click_on 'Edit HTML'
43
+ end
44
+
45
+ def update_template(path)
46
+ UI.info "Updating Blogger template..."
47
+ page.execute_script "document.getElementsByClassName('CodeMirror')[0].CodeMirror.doc.setValue('#{template(path)}')"
48
+ click_on 'Save template'
49
+ if page.has_selector? '.GFPUSQ2NMB'
50
+ throw :task_has_failed
51
+ UI.error 'Could not update Blogger template'
52
+ end
53
+ end
54
+
55
+ def template(path)
56
+ t = File.read(path)
57
+ escape_template(t.nil? || t.empty? ? default_template : t)
58
+ end
59
+
60
+ def resize
61
+ width = page.execute_script('return window.screen.width')
62
+ height = page.execute_script('return window.screen.height')
63
+ page.driver.browser.manage.window.resize_to width, height
64
+ end
65
+
66
+ end
67
+ end
@@ -0,0 +1,3 @@
1
+ guard :blogger, email: '', password: '', blog: '' do
2
+ watch 'template.xml'
3
+ end
@@ -0,0 +1,5 @@
1
+ module Guard
2
+ module BloggerVersion
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-blogger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Scott Arthur
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: guard
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: capybara
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: selenium-webdriver
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Guard plugin for updating Blogger templates using Capybara/Selenium Webdriver.
84
+ email:
85
+ - scott@scottatron.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - guard-blogger.gemspec
96
+ - lib/blogger/helpers.rb
97
+ - lib/guard/blogger.rb
98
+ - lib/guard/blogger/templates/Guardfile
99
+ - lib/guard/blogger/version.rb
100
+ homepage: https://github.com/scottatron/guard-blogger
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.1.11
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Guard plugin for updating Blogger templates
124
+ test_files: []