glynn 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ _site/*
2
+ pkg/*
3
+ *.kpf
4
+ *.tmproj
5
+ .DS_Store
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Damien MATHIEU
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ Glynn
2
+ =====
3
+
4
+ Glynn offers you a bin to easily send a jekyll powered blog to your host through FTP.
5
+
6
+ Installation
7
+ ------------
8
+
9
+ Glynn comes as a gem. It has no dependencies other than the ruby default libraries.
10
+ Install it with gem install.
11
+
12
+ gem install glynn --source http://gemcutter.org
13
+
14
+ That's it ! You now have the Glynn executable on your machine.
15
+ Go to your jekyll project, configure the host and distant directory where the files will be sent.
16
+ For example, this is my _config.yml file :
17
+
18
+ markdown: rdiscount
19
+ pygments: true
20
+ auto: true
21
+ ftp_host: dmathieu.com
22
+ ftp_dir: /web/portfolio
23
+
24
+ Glynn will connect itself to the host "dmathieu.com" and send every file to the FTP directory /web/portfolio.
25
+ To do yo, you just need to be at the top of your jekyll project. And in a console, enter the following :
26
+
27
+ glynn
28
+
29
+ Quite simple again. It'll connect to the remote host, ask you for login and password and send the files :)
30
+
31
+ Contributing
32
+ ------------
33
+
34
+ If you think Glynn is great but can be improved, feel free to contribute.
35
+ To do so, you can :
36
+
37
+ * [Fork](http://help.github.com/forking/) the project
38
+ * Do your changes and commit them to your repository
39
+ * Test your changes. We won't accept any untested contributions (except if they're not testable).
40
+ * Create an [issue](http://github.com/dmathieu/glynn/issues) with a link to your commits.
41
+
42
+ And that's it! I'll soon take a look at your issue and review your changes.
43
+
44
+ Author
45
+ ------------------
46
+
47
+ Damien MATHIEU :: 42 (AT|CHEZ) dmathieu.com
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ require 'rubygems'
2
+ require 'spec/rake/spectask'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gemspec|
7
+ gemspec.name = "glynn"
8
+ gemspec.summary = "Deploy a jekyll weblog through ftp"
9
+ gemspec.description = "Deploy a jekyll weblog through ftp"
10
+ gemspec.email = "42@dmathieu.com"
11
+ gemspec.homepage = "http://github.com/dmathieu/glynn"
12
+ gemspec.authors = ["Damien MATHIEU"]
13
+ gemspec.version = '0.0.1'
14
+
15
+ gemspec.add_dependency('jekyll', '>= 0.5.4')
16
+ end
17
+ rescue LoadError
18
+ puts "Jeweler not available. Install it with:"
19
+ puts "gem install jeweler"
20
+ end
21
+
22
+ #
23
+ # The rspec tasks
24
+ #
25
+ task :default => :spec
26
+
27
+ desc "Run all specs"
28
+ Spec::Rake::SpecTask.new('spec') do |t|
29
+ t.spec_files = FileList['spec/**/*.rb']
30
+ t.spec_opts = ['-cfs']
31
+ end
32
+
33
+ #
34
+ # The sdoc generator
35
+ #
36
+ begin
37
+ require 'sdoc_helpers'
38
+ rescue LoadError
39
+ puts "sdoc support not enabled. Please gem install sdoc-helpers."
40
+ end
data/bin/glynn ADDED
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'jekyll'
4
+ require 'glynn'
5
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
6
+
7
+
8
+ options = {}
9
+ case ARGV.size
10
+ when 0
11
+ when 1
12
+ options['destination'] = ARGV[0]
13
+ when 2
14
+ options['source'] = ARGV[0]
15
+ options['destination'] = ARGV[1]
16
+ end
17
+ options = Jekyll.configuration(options)
18
+
19
+
20
+ puts "Building site: #{options['source']} -> #{options['destination']}"
21
+ jekyll = Glynn::Jekyll.new
22
+ jekyll.build
23
+ puts "Successfully generated site"
24
+
25
+ puts "Sending site over FTP (host: #{options['ftp_host']})"
26
+ begin
27
+ print "FTP Username: "
28
+ username = $stdin.gets.chomp
29
+
30
+ print "FTP Password: "
31
+ # We hide the entered characters before to ask for the password
32
+ system "stty -echo"
33
+ password = $stdin.gets.chomp
34
+ system "stty echo"
35
+ rescue NoMethodError, Interrupt
36
+ # When the process is exited, we display the characters again
37
+ # And we exit
38
+ system "stty echo"
39
+ exit
40
+ end
41
+
42
+ ftp = Glynn::Ftp.new(options['ftp_host'], 21, {:username => username, :password => password})
43
+ puts "\r\nConnected to server. Sending site"
44
+ ftp.sync(options['destination'], options['ftp_dir'])
45
+ puts "Successfully sent site"
data/glynn.gemspec ADDED
@@ -0,0 +1,60 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{glynn}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Damien MATHIEU"]
12
+ s.date = %q{2009-12-16}
13
+ s.default_executable = %q{glynn}
14
+ s.description = %q{Deploy a jekyll weblog through ftp}
15
+ s.email = %q{42@dmathieu.com}
16
+ s.executables = ["glynn"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.md"
20
+ ]
21
+ s.files = [
22
+ ".gitignore",
23
+ "LICENSE",
24
+ "README.md",
25
+ "Rakefile",
26
+ "bin/glynn",
27
+ "glynn.gemspec",
28
+ "lib/glynn.rb",
29
+ "lib/glynn/ftp.rb",
30
+ "lib/glynn/jekyll.rb",
31
+ "spec/lib/ftp.rb",
32
+ "spec/lib/jekyll.rb",
33
+ "spec/spec.opts",
34
+ "spec/spec_helper.rb"
35
+ ]
36
+ s.homepage = %q{http://github.com/dmathieu/glynn}
37
+ s.rdoc_options = ["--charset=UTF-8"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = %q{1.3.5}
40
+ s.summary = %q{Deploy a jekyll weblog through ftp}
41
+ s.test_files = [
42
+ "spec/spec_helper.rb",
43
+ "spec/lib/jekyll.rb",
44
+ "spec/lib/ftp.rb"
45
+ ]
46
+
47
+ if s.respond_to? :specification_version then
48
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
49
+ s.specification_version = 3
50
+
51
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
52
+ s.add_runtime_dependency(%q<jekyll>, [">= 0.5.4"])
53
+ else
54
+ s.add_dependency(%q<jekyll>, [">= 0.5.4"])
55
+ end
56
+ else
57
+ s.add_dependency(%q<jekyll>, [">= 0.5.4"])
58
+ end
59
+ end
60
+
data/lib/glynn/ftp.rb ADDED
@@ -0,0 +1,54 @@
1
+ require 'net/ftp'
2
+
3
+ module Glynn
4
+ class Ftp
5
+ attr_reader :host, :port, :username, :password
6
+
7
+ def initialize(host, port = 21, options = Hash.new)
8
+ options = {:username => nil, :password => nil}.merge(options)
9
+ @host, @port = host, port
10
+ @username, @password = options[:username], options[:password]
11
+ end
12
+
13
+ def sync(local, distant)
14
+ connect do |ftp|
15
+ send_dir(ftp, local, distant)
16
+ end
17
+ end
18
+
19
+ private
20
+ def connect
21
+ ftp = Net::FTP.new(host, username, password)
22
+ yield ftp
23
+ ftp.close
24
+ end
25
+
26
+ def send_dir(ftp, local, distant)
27
+ begin
28
+ ftp.mkdir(distant)
29
+ rescue Net::FTPPermError
30
+ # We don't do anything. The directory already exists.
31
+ # TODO : this is also risen if we don't have write access. Then, we need to raise.
32
+ end
33
+ Dir.foreach(local) do |file_name|
34
+ # If the file/directory is hidden (first character is a dot), we ignore it
35
+ next if file_name =~ /^\./
36
+
37
+ if File.stat(local + "/" + file_name).directory?
38
+ # It is a directory, we recursively send it
39
+ begin
40
+ ftp.mkdir(distant + "/" + file_name)
41
+ rescue Net::FTPPermError
42
+ # We don't do anything. The directory already exists.
43
+ # TODO : this is also risen if we don't have write access. Then, we need to raise.
44
+ end
45
+ send_dir(ftp, local + "/" + file_name, distant + "/" + file_name)
46
+ else
47
+ # It's a file, we just send it
48
+ ftp.puttextfile(local + "/" + file_name, distant + "/" + file_name)
49
+ end
50
+ end
51
+
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,18 @@
1
+ require 'jekyll'
2
+
3
+ module Glynn
4
+ class Jekyll
5
+ attr_reader :site
6
+
7
+ def initialize(options = {})
8
+ @site = ::Jekyll::Site.new(::Jekyll.configuration(options))
9
+ end
10
+
11
+ #
12
+ # Builds the website in the ./_site directory.
13
+ #
14
+ def build
15
+ site.process
16
+ end
17
+ end
18
+ end
data/lib/glynn.rb ADDED
@@ -0,0 +1,5 @@
1
+ $:.unshift File.dirname(__FILE__) # For use/testing when no gem is installed
2
+ require 'rubygems'
3
+
4
+ require 'glynn/jekyll'
5
+ require 'glynn/ftp'
data/spec/lib/ftp.rb ADDED
@@ -0,0 +1,53 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "FTP Interface" do
4
+ before(:each) do
5
+ # We mock the FTP server
6
+ @mock = mock('Ftp server', :null_object => true)
7
+
8
+ # And the puttextfile method
9
+ class Net::FTP
10
+ def puttextfile; true; end
11
+ end
12
+ end
13
+
14
+ it 'should login to ftp server' do
15
+ Net::FTP.should_receive(:new).with('localhost', nil, nil).and_return(@mock)
16
+ Glynn::Ftp.new('localhost').send(:connect) do |ftp|
17
+ ftp.should eql(@mock)
18
+ end
19
+ end
20
+
21
+ it 'should accept a username and password' do
22
+ Net::FTP.should_receive(:new).with('localhost', 'username', 'password').and_return(@mock)
23
+ Glynn::Ftp.new('localhost', 21, {:username => 'username', :password => 'password'}).send(:connect) do |ftp|
24
+ ftp.should eql(@mock)
25
+ end
26
+ end
27
+
28
+ it 'should recursively send a directory' do
29
+ # We expect NET/FTP to create every file
30
+ @mock.should_receive(:puttextfile).with('/test/README', '/blah/README').and_return(true)
31
+ @mock.should_receive(:puttextfile).with('/test/subdir/README', '/blah/subdir/README').and_return(true)
32
+ FakeFS do
33
+ # We create the fake files and directories
34
+ Dir.mkdir('/test')
35
+ Dir.mkdir('/test/subdir')
36
+ File.open('/test/README', 'w') { |f| f.write 'N/A' }
37
+ File.open('/test/subdir/README', 'w') { |f| f.write 'N/A' }
38
+
39
+ # And send them
40
+ Glynn::Ftp.new('localhost').send(:send_dir, @mock, '/test', '/blah')
41
+ end
42
+ end
43
+
44
+ it 'should connect itself to the server and send the local file to distant directory' do
45
+ FakeFS do
46
+ interface = Glynn::Ftp.new('localhost')
47
+ Net::FTP.should_receive(:new).with('localhost', nil, nil).and_return(@mock)
48
+ interface.should_receive(:send_dir).with(@mock, '/test', '/blah')
49
+
50
+ interface.sync '/test', '/blah'
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,28 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "Relation between glynn and jekyll" do
4
+ before(:all) do
5
+ FakeFS.activate!
6
+ File.open('/_config.yml', 'w') { |f| f.write 'auto: true' }
7
+ end
8
+ after(:all) do
9
+ FakeFS.deactivate!
10
+ end
11
+
12
+ it 'should create a new website' do
13
+ jekyll = Glynn::Jekyll.new({ 'source' => '/' })
14
+ jekyll.build
15
+ end
16
+
17
+ it 'should accept the ftp host option' do
18
+ File.open('/_config.yml', 'w') { |f| f.write 'ftp_host: example.com' }
19
+ options = Jekyll.configuration({'source' => '/'})
20
+ options['ftp_host'].should eql('example.com')
21
+ end
22
+
23
+ it 'should accept the fto dir option' do
24
+ File.open('/_config.yml', 'w') { |f| f.write 'ftp_dir: /home/glynn' }
25
+ options = Jekyll.configuration({'source' => '/'})
26
+ options['ftp_dir'].should eql('/home/glynn')
27
+ end
28
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format progress
3
+ --loadby mtime
4
+ --reverse
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require 'mocha'
4
+ require 'spec/autorun'
5
+ require 'spec/interop/test'
6
+ require 'fakefs/safe'
7
+
8
+
9
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
10
+ require 'glynn'
11
+
12
+ Spec::Runner.configure do |config|
13
+
14
+
15
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: glynn
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Damien MATHIEU
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-16 00:00:00 +01:00
13
+ default_executable: glynn
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: jekyll
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.5.4
24
+ version:
25
+ description: Deploy a jekyll weblog through ftp
26
+ email: 42@dmathieu.com
27
+ executables:
28
+ - glynn
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.md
34
+ files:
35
+ - .gitignore
36
+ - LICENSE
37
+ - README.md
38
+ - Rakefile
39
+ - bin/glynn
40
+ - glynn.gemspec
41
+ - lib/glynn.rb
42
+ - lib/glynn/ftp.rb
43
+ - lib/glynn/jekyll.rb
44
+ - spec/lib/ftp.rb
45
+ - spec/lib/jekyll.rb
46
+ - spec/spec.opts
47
+ - spec/spec_helper.rb
48
+ has_rdoc: true
49
+ homepage: http://github.com/dmathieu/glynn
50
+ licenses: []
51
+
52
+ post_install_message:
53
+ rdoc_options:
54
+ - --charset=UTF-8
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ version:
69
+ requirements: []
70
+
71
+ rubyforge_project:
72
+ rubygems_version: 1.3.5
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: Deploy a jekyll weblog through ftp
76
+ test_files:
77
+ - spec/spec_helper.rb
78
+ - spec/lib/jekyll.rb
79
+ - spec/lib/ftp.rb