simb 0.0.1 → 0.0.4
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +2 -0
- data/bin/simb +12 -48
- data/lib/simb/version.rb +1 -1
- data/lib/simb.rb +85 -1
- data/simb.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86dfc6b62c1d8c4a9e1b5216b380c8c57c6729e4
|
4
|
+
data.tar.gz: dd489fea590eb9aeec89df0df0187da0b538acbd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38c50a13e1ac6925c9cfe8623fbd06edade18c3bbbd6cdb6f36da99fc89414cf0a1b139c99879cdaf61c025907b2a026c2e65ec074b6c91da1b5209808740d1f
|
7
|
+
data.tar.gz: eb0a169caf8fedc49796c1bb48523f96ef5e04bfd28dafb7045e8eabc2e4817684ca29c805305cacd941d1a00ecdf2fa6267808b88e9e80233a92260ecd9b137
|
data/README.md
CHANGED
data/bin/simb
CHANGED
@@ -1,70 +1,34 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'thor'
|
3
|
-
require '
|
4
|
-
|
5
|
-
def editor file
|
6
|
-
system("#{ENV['EDITOR']} #{file}")
|
7
|
-
end
|
8
|
-
|
9
|
-
def add_header file, post_name
|
10
|
-
File.open(file, 'a') do |f|
|
11
|
-
f.puts "---"
|
12
|
-
f.puts "layout: post"
|
13
|
-
f.puts "title: #{post_name}"
|
14
|
-
f.puts "date: #{Time.now}"
|
15
|
-
f.puts "categories:"
|
16
|
-
f.puts "---"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def post_filename(post_name)
|
21
|
-
return "#{Time.now.strftime("%F")}-#{post_name.gsub(" ", "-")}.markdown"
|
22
|
-
end
|
3
|
+
require 'simb'
|
23
4
|
|
24
5
|
class SimbCLI < Thor
|
25
|
-
ROOTDIR="#{ENV['HOME']}/.simb/"
|
26
6
|
desc "blog NAME", "create a new blog"
|
27
7
|
def blog(name)
|
28
|
-
|
29
|
-
`jekyll new #{ROOTDIR}#{name}`
|
8
|
+
Simb.init_blog(name)
|
30
9
|
end
|
31
10
|
|
32
11
|
desc "new-post POSTNAME BLOG", "create a new post for BLOG and open it in $EDITOR"
|
33
12
|
def new_post(post_name, blog)
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
`touch #{file}`
|
41
|
-
add_header file, post_name
|
42
|
-
editor file
|
13
|
+
Simb.new_post(post_name, blog)
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "config BLOG", "edit _config.yml for BLOG"
|
17
|
+
def config(blog)
|
18
|
+
Simb.edit_config(blog)
|
43
19
|
end
|
44
20
|
|
45
21
|
desc "publish BLOG", "publish BLOG to github pages"
|
46
22
|
def publish(blog)
|
47
|
-
if
|
48
|
-
|
23
|
+
if Simb.blog_initted? (blog)
|
24
|
+
Simb.commit(blog)
|
49
25
|
else
|
50
|
-
puts ":: creating new repository on GitHub"
|
51
26
|
user = ask "GitHub username:"
|
52
27
|
pass = ask "GitHub password:", echo: false
|
53
28
|
puts
|
54
29
|
begin
|
55
|
-
|
56
|
-
|
57
|
-
description: "Blog for #{blog}",
|
58
|
-
private: false,
|
59
|
-
has_issues: false,
|
60
|
-
has_wiki: false,
|
61
|
-
has_downloads: false
|
62
|
-
Dir.chdir("#{ROOTDIR}#{blog}") do
|
63
|
-
`git init .`
|
64
|
-
`git remote add origin https://github.com/#{user}/#{blog}.git`
|
65
|
-
`git checkout -b gh-pages`
|
66
|
-
publish(blog) # go back and publish now
|
67
|
-
end
|
30
|
+
Simb.create_repo(blog, user, pass)
|
31
|
+
Simb.config_remote(blog, user)
|
68
32
|
rescue Github::Error::Unauthorized
|
69
33
|
abort "Invalid credentials!"
|
70
34
|
end
|
data/lib/simb/version.rb
CHANGED
data/lib/simb.rb
CHANGED
@@ -1,5 +1,89 @@
|
|
1
1
|
require "simb/version"
|
2
|
+
require "github_api"
|
2
3
|
|
3
4
|
module Simb
|
4
|
-
#
|
5
|
+
ROOTDIR="#{ENV['HOME']}/.simb/"
|
6
|
+
|
7
|
+
def self.editor file
|
8
|
+
system("#{ENV['EDITOR']} #{file}")
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.add_header file, post_name
|
12
|
+
File.open(file, 'a') do |f|
|
13
|
+
f.puts "---"
|
14
|
+
f.puts "layout: post"
|
15
|
+
f.puts "title: #{post_name}"
|
16
|
+
f.puts "date: #{Time.now}"
|
17
|
+
f.puts "categories:"
|
18
|
+
f.puts "---"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.repo_exists? (user, repo)
|
23
|
+
repos = Github::Client::Repos.new
|
24
|
+
not repos.list(user: user).select{|e| e.name == repo}.first.nil?
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.post_filename(post_name)
|
28
|
+
return "#{Time.now.strftime("%F")}-#{post_name.gsub(" ", "-")}.markdown"
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.init_blog(name)
|
32
|
+
`jekyll new #{ROOTDIR}#{name}`
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.new_post(post_name, blog)
|
36
|
+
file = "#{ROOTDIR}#{blog}/_posts/#{post_filename post_name}"
|
37
|
+
if File.exists? file
|
38
|
+
editor file
|
39
|
+
return
|
40
|
+
end
|
41
|
+
`touch #{file}`
|
42
|
+
add_header file, post_name
|
43
|
+
editor file
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.edit_config(blog)
|
47
|
+
Dir.chdir("#{ROOTDIR}#{blog}") do
|
48
|
+
editor "_config.yml"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.blog_initted?(blog) # is that even a word? pffffttt...
|
53
|
+
Dir.exists?("#{ROOTDIR}#{blog}/.git/")
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.commit(blog)
|
57
|
+
Dir.chdir("#{ROOTDIR}#{blog}") do
|
58
|
+
`git pull origin gh-pages` # do any merges
|
59
|
+
`git add --all && git commit -m "new posts (#{Time.now})"`
|
60
|
+
`git push --force origin gh-pages`
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.create_repo(blog, user, pass)
|
65
|
+
github = Github.new basic_auth: "#{user}:#{pass}"
|
66
|
+
if repo_exists? user, blog
|
67
|
+
if (ask "A repo named '#{blog}' already exists! Commit? (y/n)") !~ /^[yY].*/
|
68
|
+
abort "Aborting!"
|
69
|
+
end
|
70
|
+
else
|
71
|
+
github.repos.create name: "#{blog}",
|
72
|
+
description: "Blog for #{blog}",
|
73
|
+
private: false,
|
74
|
+
has_issues: false,
|
75
|
+
has_wiki: false,
|
76
|
+
has_downloads: false
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.config_remote(blog, user)
|
81
|
+
Dir.chdir("#{ROOTDIR}#{blog}") do
|
82
|
+
`git init .`
|
83
|
+
`git remote add origin git@github.com:#{user}/#{blog}.git`
|
84
|
+
`git checkout -b gh-pages`
|
85
|
+
`git pull` # get code if repo already exists
|
86
|
+
commit(blog) # go back and publish now
|
87
|
+
end
|
88
|
+
end
|
5
89
|
end
|
data/simb.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["charles-l"]
|
10
10
|
spec.email = ["chuckiels2011@gmail.com"]
|
11
11
|
spec.summary = %q{Simple blogging util.}
|
12
|
-
spec.description = %q{A simple
|
12
|
+
spec.description = %q{A simple blogging utility that uses Jekyll and GitHub pages.}
|
13
13
|
spec.homepage = ""
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- charles-l
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,7 +38,7 @@ dependencies:
|
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
-
description: A simple
|
41
|
+
description: A simple blogging utility that uses Jekyll and GitHub pages.
|
42
42
|
email:
|
43
43
|
- chuckiels2011@gmail.com
|
44
44
|
executables:
|