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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: adf477739d735773b11bc6b294f9f75dddddd2ae
4
- data.tar.gz: 56428869e4e6bd1b2ed0b45a46f90c496a6f6dc9
3
+ metadata.gz: 86dfc6b62c1d8c4a9e1b5216b380c8c57c6729e4
4
+ data.tar.gz: dd489fea590eb9aeec89df0df0187da0b538acbd
5
5
  SHA512:
6
- metadata.gz: a2bff165bd493364e1d714a03bdced612889c4d3cbe304fe461fe9ece75b94cf83446d474bd023855c5907f1344c519ed0759710acfbfced155f98a05e80bd3b
7
- data.tar.gz: 44bab40228ce47ec82883b6dcad070f73d3cf2e6a16d04baa83189ac01d7ff21d729055b80d0b0e07ffab914f38b0c88a679ae40b76ac1f826b7cdc3dc33d2de
6
+ metadata.gz: 38c50a13e1ac6925c9cfe8623fbd06edade18c3bbbd6cdb6f36da99fc89414cf0a1b139c99879cdaf61c025907b2a026c2e65ec074b6c91da1b5209808740d1f
7
+ data.tar.gz: eb0a169caf8fedc49796c1bb48523f96ef5e04bfd28dafb7045e8eabc2e4817684ca29c805305cacd941d1a00ecdf2fa6267808b88e9e80233a92260ecd9b137
data/.gitignore CHANGED
@@ -11,4 +11,5 @@
11
11
  *.so
12
12
  *.o
13
13
  *.a
14
+ *.gem
14
15
  mkmf.log
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Gem Version](https://badge.fury.io/rb/simb.svg)](http://badge.fury.io/rb/simb)
2
+
1
3
  # simb
2
4
 
3
5
  A simple blogging util. Posts are generated by Jekyll and GitHub pages are used for hosting.
data/bin/simb CHANGED
@@ -1,70 +1,34 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'thor'
3
- require 'github_api'
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
- puts ":: creating at #{ROOTDIR}#{name}"
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
- file = "#{ROOTDIR}#{blog}/_posts/#{post_filename post_name}"
35
- if File.exists? file
36
- editor file
37
- return
38
- end
39
- puts ":: creating new post '#{post_name}' in blog '#{blog}'"
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 Dir.exists?("#{ROOTDIR}#{blog}/.git/")
48
- `cd #{ROOTDIR}#{blog} && git add --all && git commit -m "new posts (#{Time.now})" && git push origin gh-pages`
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
- github = Github.new basic_auth: "#{user}:#{pass}"
56
- github.repos.create name: "#{blog}",
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
@@ -1,3 +1,3 @@
1
1
  module Simb
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.4"
3
3
  end
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
- # Your code goes here...
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 bloggin utility that uses Jekyll and GitHub pages.}
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.1
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-08-18 00:00:00.000000000 Z
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 bloggin utility that uses Jekyll and GitHub pages.
41
+ description: A simple blogging utility that uses Jekyll and GitHub pages.
42
42
  email:
43
43
  - chuckiels2011@gmail.com
44
44
  executables: