jekyll-hasty 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/jekyll/hasty.rb +2 -0
- data/lib/jekyll/hasty/version.rb +5 -0
- data/lib/jekyll/post.rb +15 -0
- data/lib/jekyll/tags/hasty_comments.rb +57 -0
- metadata +49 -0
data/lib/jekyll/hasty.rb
ADDED
data/lib/jekyll/post.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
module Jekyll
|
2
|
+
class HastyCommentsTag < Liquid::Tag
|
3
|
+
|
4
|
+
API_REPOS_URL = 'https://api.github.com/repos/'
|
5
|
+
|
6
|
+
def initialize(tag_name, text, tokens)
|
7
|
+
super
|
8
|
+
@text = text
|
9
|
+
end
|
10
|
+
|
11
|
+
def render(context)
|
12
|
+
file = file_name(context)
|
13
|
+
|
14
|
+
attributes = {
|
15
|
+
'id' => 'comments',
|
16
|
+
'data-commits-url' => github_commits_url,
|
17
|
+
'data-commit-ids' => commit_ids(file)
|
18
|
+
}
|
19
|
+
generate_tag(attributes)
|
20
|
+
end
|
21
|
+
|
22
|
+
#
|
23
|
+
|
24
|
+
def file_name(context)
|
25
|
+
context.environments.first["page"]["file_name"]
|
26
|
+
end
|
27
|
+
|
28
|
+
def commit_ids(file)
|
29
|
+
cmd = "git log --pretty=format:'%H' --follow #{file}"
|
30
|
+
`#{cmd}`.split(/\W+/)
|
31
|
+
end
|
32
|
+
|
33
|
+
def repo
|
34
|
+
url = `git config --get remote.origin.url`.chomp
|
35
|
+
url.gsub!(%r{git://github.com/(.*\.git)}, 'git@github.com:\1')
|
36
|
+
|
37
|
+
if url =~ /^git@github/
|
38
|
+
url.scan(%r{git@github.com:(.*).git}).flatten.first
|
39
|
+
else
|
40
|
+
# TODO: proper exception
|
41
|
+
raise "only supports github URLs"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def github_commits_url
|
46
|
+
File.join(API_REPOS_URL, repo, 'commits')
|
47
|
+
end
|
48
|
+
|
49
|
+
def generate_tag(attributes)
|
50
|
+
attr = attributes.map{|k, v| "#{k}='#{v}'"}.join(' ')
|
51
|
+
"<div #{attr}>#{@text}</div>"
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
Liquid::Template.register_tag('hasty_comments', Jekyll::HastyCommentsTag)
|
metadata
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-hasty
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Polarblau
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-15 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: A wrapper for a small plugin in ease integration with jquery.hasty comments.
|
15
|
+
email:
|
16
|
+
- polarblau@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/jekyll/hasty.rb
|
22
|
+
- lib/jekyll/hasty/version.rb
|
23
|
+
- lib/jekyll/post.rb
|
24
|
+
- lib/jekyll/tags/hasty_comments.rb
|
25
|
+
homepage: https://github.com/polarblau/jekyll-hasty
|
26
|
+
licenses: []
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
none: false
|
33
|
+
requirements:
|
34
|
+
- - ! '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
requirements: []
|
44
|
+
rubyforge_project: ! '[none]'
|
45
|
+
rubygems_version: 1.8.10
|
46
|
+
signing_key:
|
47
|
+
specification_version: 3
|
48
|
+
summary: jquery.hasty comments
|
49
|
+
test_files: []
|