tooky-utter 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.
@@ -0,0 +1,4 @@
1
+ ---
2
+ :minor: 0
3
+ :patch: 1
4
+ :major: 0
@@ -0,0 +1,14 @@
1
+ require 'jekyll'
2
+ require 'git'
3
+ require 'sequel'
4
+ require 'digest/sha1'
5
+
6
+ DB = Sequel.connect(ENV['DATABASE_URL'] || 'sqlite://utter.db')
7
+
8
+ require 'utter/site'
9
+ require 'utter/application'
10
+
11
+ module Utter
12
+ Site.make_table
13
+ Salt = 'd42ab5ae256429c2d1928763606554ebc46f6565'
14
+ end
@@ -0,0 +1,22 @@
1
+ module Utter
2
+ class Application
3
+ def call(env)
4
+ req = Rack::Request.new(env)
5
+ return [405, {"Allow" => 'POST', "Content-Type" => 'text/plain'}, "Not Acceptable"] unless req.post?
6
+
7
+ if req.path_info =~ /^\/([a-z\d]+)$/
8
+ site = Site[$1]
9
+ if site
10
+ site.regenerate
11
+ return [200, {"Content-Type" => 'text/plain'}, "OK"]
12
+ end
13
+ end
14
+
15
+ not_found
16
+ end
17
+
18
+ def not_found
19
+ return [404, {"Content-Type" => 'text/plain'}, "Not Found!\n"]
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,51 @@
1
+ module Utter
2
+ class Site < Sequel::Model
3
+ set_primary_key :key
4
+
5
+ before_create do
6
+ self[:key] = generate_key
7
+ end
8
+
9
+ def regenerate
10
+ self.update
11
+ Jekyll.process(self[:source], self[:destination]) if source_exists?
12
+ end
13
+
14
+ def source_exists?
15
+ File.exist? self.source
16
+ end
17
+
18
+ def clone
19
+ unless source_exists?
20
+ Git.clone self[:repo], self[:source]
21
+ end
22
+ end
23
+
24
+ def update
25
+ if source_exists?
26
+ g = Git.open self[:source]
27
+ g.pull
28
+ end
29
+ end
30
+
31
+ def self.make_table
32
+ begin
33
+ DB.create_table :sites do
34
+ primary_key :key, :string, :auto_increment => false
35
+ String :name
36
+ String :source
37
+ String :destination
38
+ String :repo
39
+ Time :created_at
40
+ end
41
+ rescue
42
+ # table exists!
43
+ end
44
+ end
45
+
46
+ private
47
+ def generate_key
48
+ Digest::SHA1.hexdigest self[:name] + Salt
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,21 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class SiteTest < Test::Unit::TestCase
4
+ context "A new site" do
5
+ setup do
6
+ @site = Utter::Site.new :name => 'tooky.github.com',
7
+ :source => File.join(tmp_dir, 'tooky.github,com'),
8
+ :destination => File.join(tmp_dir, 'tooky.github,com', 'public'),
9
+ :repo => 'git@github.com:tooky/tooky.github.com.git'
10
+ end
11
+
12
+ should "not have a key" do
13
+ assert ! @site[:key]
14
+ end
15
+
16
+ should "generate a key after create" do
17
+ @site.save
18
+ assert @site[:key]
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'mocha'
5
+ require 'time'
6
+
7
+ ENV['DATABASE_URL'] = "sqlite:///"
8
+
9
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
10
+ require 'utter'
11
+
12
+ class Test::Unit::TestCase
13
+ def tmp_dir
14
+ File.join(File.dirname(__FILE__), 'tmp')
15
+ end
16
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class UtterTest < Test::Unit::TestCase
4
+ should "not fail" do
5
+ assert true
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tooky-utter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Steve Tooke
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-26 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Simple instant deployment for jekyll websites
17
+ email: steve.tooke@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - VERSION.yml
26
+ - lib/utter
27
+ - lib/utter/application.rb
28
+ - lib/utter/site.rb
29
+ - lib/utter.rb
30
+ - test/site_test.rb
31
+ - test/test_helper.rb
32
+ - test/utter_test.rb
33
+ has_rdoc: true
34
+ homepage: http://github.com/tooky/utter
35
+ post_install_message:
36
+ rdoc_options:
37
+ - --inline-source
38
+ - --charset=UTF-8
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ version:
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ requirements: []
54
+
55
+ rubyforge_project:
56
+ rubygems_version: 1.2.0
57
+ signing_key:
58
+ specification_version: 2
59
+ summary: An instant deployment solution for using Github webhooks to generate jekyll sites
60
+ test_files: []
61
+