jekyll-ftp 0.1.0

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: 0016314453e927b4cb42a3542ad62e29fa39f54e
4
+ data.tar.gz: 1c55c25f8fe13f539d6899349b02fc2f53615471
5
+ SHA512:
6
+ metadata.gz: 535502ea3b71c933cd992c977b691380c06a94294791850e536890e08a87d55c172b14f6c57ab01acf787b2af586dcb606fbb3fd0ccafe5f288e7ef68863cb79
7
+ data.tar.gz: 0b46d02e68da8662e59b2768b97c03af99d6ea4b5a7377fefbebc63e6b9dc51e69f4e15730c62699ca8b1a192c262555f2b89122c7f720c221ddbaf5dd26daec
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ test/
2
+ *.gem
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Jesse Herrick
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # Jekyll-FTP
2
+
3
+ ## Commands
4
+ * `jekyll-ftp deploy` - Deploy your site via FTP with the preconfigured settings.
5
+ * `jekyll-ftp clean` - Remove all the files from the preconfigured `remote_dir`.
6
+
7
+ ## Configuring your `_config.yml` File
8
+ Since [Jekyll](https://github.com/mojombo/jekyll) uses `_config.yml`, Jekyll-FTP uses this too. To configure Jekyll-FTP needs 3 configuration settings.
9
+ * `username` - Your FTP server username.
10
+ * `server_url` - The URL for your FTP server (can also be an FTP).
11
+ * `remote_dir` - The remote directory where your site is to be deployed.
12
+
13
+ ```yaml
14
+ username: UserName
15
+ server_url: ftp.myserver.com
16
+ remote_dir: /public_html
17
+ ```
18
+
19
+ If you still don't get it, [here's an example](https://gist.github.com/JesseHerrick/6965950).
data/bin/jekyll-ftp ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.expand_path(File.dirname(__FILE__) + "/../lib")
4
+
5
+ require 'rubygems'
6
+ require 'commander/import'
7
+ require 'jekyll-ftp.rb'
8
+
9
+ program :version, Jekyll_FTP::VERSION
10
+ program :description, 'Jekyll deployment made easy.'
11
+
12
+ command :deploy do |c|
13
+ c.syntax = 'jekyll-ftp deploy'
14
+ c.summary = 'Deploy your site via FTP with the preconfigured server settings.'
15
+ c.description = 'Deploy your site via FTP.'
16
+ c.action do |args, options|
17
+ Jekyll_FTP::Command.deploy
18
+ end
19
+ end
20
+
21
+ command :clean do |c|
22
+ c.syntax = 'jekyll-ftp clean'
23
+ c.summary = 'Just remove all files in the given remote directory.'
24
+ c.description = c.summary
25
+ c.example 'Remove the files in the preconfigured directory.', 'jekyll-ftp clean'
26
+ c.action do |args, options|
27
+ Jekyll_FTP::Command.deploy(false)
28
+ end
29
+ end
30
+
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jekyll-ftp/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jekyll-ftp"
8
+ spec.version = Jekyll_FTP::VERSION
9
+ spec.authors = ["Jesse Herrick"]
10
+ spec.email = ["jessegrantherrick@gmail.com"]
11
+ spec.description = %q{Jekyll deployment made easy.}
12
+ spec.summary = %q{Deploy your Jekyll site to FTP with one simple command!}
13
+ spec.homepage = "https://github.com/JesseHerrick/jekyll-ftp"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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('colorize')
22
+ spec.add_dependency('commander')
23
+ end
@@ -0,0 +1,26 @@
1
+ module Jekyll_FTP
2
+ class SubCommand
3
+ def self.clean(ftp)
4
+ ftp.nlst.each do |file|
5
+ next if ['.', '..'].include?(file)
6
+ if directory?(ftp, file)
7
+ ftp.chdir file
8
+ clean(ftp)
9
+ ftp.chdir '..'
10
+ puts "Deleting directory: ".red + ftp.pwd + "/" + file + "/"
11
+ ftp.rmdir(file)
12
+ else
13
+ puts "Deleting: ".red + ftp.pwd + "/" + file
14
+ ftp.delete(file)
15
+ end
16
+ end
17
+ end
18
+ def self.directory?(ftp, filename)
19
+ ftp.chdir(filename)
20
+ ftp.chdir('..')
21
+ return true
22
+ rescue
23
+ return false
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,69 @@
1
+ require 'yaml'
2
+ require 'net/ftp'
3
+
4
+ module Jekyll_FTP
5
+ class Command
6
+ def self.deploy(deploy_now = true)
7
+ if File.exists?("_config.yml")
8
+ # The file is there and will now be parsed.
9
+ $config = YAML.load_file("_config.yml")
10
+
11
+ # Create variables from the config hash.
12
+ server = $config["server_url"]
13
+ username = $config["username"]
14
+ remote_dir = $config["remote_dir"]
15
+
16
+ # If the server or username is missing...
17
+ if server.nil? || username.nil? || remote_dir.nil?
18
+ # Make a new array for the missing configuration.
19
+ missing = Array.new
20
+ # If server doesn't exist add it to the array of missing stuff.
21
+ if server.nil?
22
+ missing.push("server_url")
23
+ end
24
+ # If username doesn't exist add it to the array of missing stuff.
25
+ if username.nil?
26
+ missing.push("username")
27
+ end
28
+ # If remote_dir doesn't exist add it to the array of missing stuff.
29
+ if remote_dir.nil?
30
+ missing.push("remote_dir")
31
+ end
32
+
33
+ # Pass the missing array to 'config_error'.
34
+ Jekyll_FTP::Error.config_error(missing)
35
+ end
36
+
37
+ # Give some info about the FTP server.
38
+ say " FTP Server: ".blue + server
39
+ say " Username: ".blue + username
40
+ say "Remote Directory: ".blue + remote_dir
41
+
42
+ # Error handling over...
43
+ # Now deploy!
44
+ ftp = Net::FTP.new(server)
45
+ ftp.login(username, password)
46
+ ftp.chdir(remote_dir)
47
+ say "\nDeploying...".yellow unless deploy_now == false
48
+
49
+ # Delete old files.
50
+ if File.directory?("_site")
51
+ Jekyll_FTP::SubCommand.clean(ftp)
52
+ else
53
+ say "ERROR: _site directory does not exist."
54
+ abort "Have you tried `jekyll build`?".yellow
55
+ end
56
+
57
+ # Deploy the site... unless not supposed to deploy.
58
+ unless deploy_now == false
59
+ Dir.chdir("_site")
60
+ path = Dir.getwd
61
+ Jekyll_FTP::SubCommand.send(ftp, path)
62
+ end
63
+ else
64
+ # The file is missing!
65
+ Jekyll_FTP::Error.file_missing("_config.yml")
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,17 @@
1
+ module Jekyll_FTP
2
+ class Error
3
+ def self.file_missing(filename)
4
+ abort("ERROR:".red + " #{filename} does not exist.\n" + "Make sure you're in your site's root directory.".yellow)
5
+ end
6
+
7
+ def self.config_error(missing)
8
+ unless missing.empty?
9
+ say "ERROR:".red + " Config file not set up properly."
10
+ missing.each do |missed|
11
+ say " Missing:".yellow + " #{missed}"
12
+ end
13
+ abort
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,23 @@
1
+ module Jekyll_FTP
2
+ class SubCommand
3
+ def self.send(ftp, path, init_path = nil)
4
+ init_path ||= path
5
+ Dir.entries(path).each do |file|
6
+ next if ['.', '..'].include? file
7
+
8
+ file_path = path + '/' + file
9
+ short_file_path = file_path[init_path.length, file_path.length]
10
+ if File.directory?(file_path)
11
+ ftp.mkdir(file) unless ftp.nlst.index(file)
12
+ ftp.chdir(file)
13
+ send(ftp, file_path, init_path)
14
+ ftp.chdir('..')
15
+ else
16
+ puts "Deploying: ".green + short_file_path
17
+ puts " To: ".yellow + ftp.pwd + '/' + file
18
+ ftp.putbinaryfile(path + '/' + file, file)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module Jekyll_FTP
2
+ VERSION = "0.1.0"
3
+ end
data/lib/jekyll-ftp.rb ADDED
@@ -0,0 +1,9 @@
1
+ # 3rd Party
2
+ require 'colorize'
3
+
4
+ # Local
5
+ require 'jekyll-ftp/clean'
6
+ require 'jekyll-ftp/deploy'
7
+ require 'jekyll-ftp/error'
8
+ require 'jekyll-ftp/send'
9
+ require 'jekyll-ftp/version'
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-ftp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jesse Herrick
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
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: commander
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
+ description: Jekyll deployment made easy.
42
+ email:
43
+ - jessegrantherrick@gmail.com
44
+ executables:
45
+ - jekyll-ftp
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - LICENSE
51
+ - README.md
52
+ - bin/jekyll-ftp
53
+ - jekyll-ftp.gemspec
54
+ - lib/jekyll-ftp.rb
55
+ - lib/jekyll-ftp/clean.rb
56
+ - lib/jekyll-ftp/deploy.rb
57
+ - lib/jekyll-ftp/error.rb
58
+ - lib/jekyll-ftp/send.rb
59
+ - lib/jekyll-ftp/version.rb
60
+ homepage: https://github.com/JesseHerrick/jekyll-ftp
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.1.8
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Deploy your Jekyll site to FTP with one simple command!
84
+ test_files: []