jekyll-twitter-plugin 1.0.0
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 +7 -0
- data/.gitignore +34 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +92 -0
- data/Rakefile +1 -0
- data/jekyll-twitter-plugin.gemspec +22 -0
- data/lib/jekyll-twitter-plugin.rb +171 -0
- metadata +93 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 80e8d5cf8433bd544dd046d6305444676e9d07b5
|
4
|
+
data.tar.gz: 93421fcb83701f3960321ff34434116a5e381912
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bf621b7035e5ad7da48b95130a9a0a61652c72dc216720b5251ae5df9ca605a8552125d162270728e5968ac790b2f3fca804be30b8b0324801967bb1b729be31
|
7
|
+
data.tar.gz: 46427dceea766f3bc1ccf28c5bae0e3e4507fac56c0b687c860986dbf3602d12f262dc55d792d4289b2b7c9daa6c687c07206f3d607eba0c93d3be7508fada69
|
data/.gitignore
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
29
|
+
Gemfile.lock
|
30
|
+
.ruby-version
|
31
|
+
.ruby-gemset
|
32
|
+
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
|
+
.rvmrc
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Robert Murray
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
## jekyll-twitter-plugin
|
2
|
+
|
3
|
+
A Liquid tag plugin for Jekyll that renders Tweets from Twitter API.
|
4
|
+
|
5
|
+
[](http://badge.fury.io/rb/jekyll-twitter-plugin)
|
6
|
+
|
7
|
+
### Description
|
8
|
+
|
9
|
+
A Liquid tag plugin for [Jekyll](http://jekyllrb.com/) that renders Tweets from Twitter API.
|
10
|
+
|
11
|
+
It is based on the original Jekyll Tweet Tag from [scottwb](https://github.com/scottwb/jekyll-tweet-tag) which has not been updated since Twitter updated their API to require Oauth.
|
12
|
+
|
13
|
+
This plugin replaces the broken plugin mentioned above and uses a different tag and API just in case the original gets fixed and to be more flexible.
|
14
|
+
|
15
|
+
|
16
|
+
### Features
|
17
|
+
|
18
|
+
The plugin supports the following features from the Twitter API:
|
19
|
+
|
20
|
+
* Oembed - Embed a Tweet in familiar Twitter styling.
|
21
|
+
* Caching - API requests can be cached to avoid hitting request limits.
|
22
|
+
|
23
|
+
|
24
|
+
### Requirements
|
25
|
+
|
26
|
+
* You have set up a Twitter application and have auth credentials.
|
27
|
+
|
28
|
+
|
29
|
+
### Usage
|
30
|
+
|
31
|
+
As mentioned by [Jekyll's documentation](http://jekyllrb.com/docs/plugins/#installing-a-plugin) you have two options; manually import the source file or require the plugin as a `gem`.
|
32
|
+
|
33
|
+
#### Require gem
|
34
|
+
|
35
|
+
Add the `jekyll-twitter-plugin` to your site `_config.yml` file for Jekyll to import the plugin as a gem.
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
gems: [jekyll-twitter-plugin]
|
39
|
+
```
|
40
|
+
|
41
|
+
#### Manual import
|
42
|
+
|
43
|
+
Just download the source file into your `_plugins` directory, e.g.
|
44
|
+
|
45
|
+
TODO
|
46
|
+
|
47
|
+
#### Plugin tag usage
|
48
|
+
|
49
|
+
To use the plugin, in your source content use the tag `twitter` and then pass additional parameters to the plugin.
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
{% twitter type params %}
|
53
|
+
```
|
54
|
+
|
55
|
+
##### type
|
56
|
+
|
57
|
+
This is the type of Twitter API
|
58
|
+
|
59
|
+
#### Oembed
|
60
|
+
|
61
|
+
{% twitter oembed url %}
|
62
|
+
|
63
|
+
##### Output
|
64
|
+
|
65
|
+
As with the original plugin, all content will be rendered inside a div with the classes 'embed' and 'twitter'
|
66
|
+
|
67
|
+
```
|
68
|
+
<div class='embed twitter'>
|
69
|
+
content
|
70
|
+
</div>
|
71
|
+
```
|
72
|
+
|
73
|
+
#### Output
|
74
|
+
|
75
|
+
If the request cannot be processed then a basic error message will be displayed;
|
76
|
+
|
77
|
+
> Tweet could not be processed
|
78
|
+
|
79
|
+
|
80
|
+
### Caching
|
81
|
+
|
82
|
+
TODO
|
83
|
+
|
84
|
+
|
85
|
+
### Contributions
|
86
|
+
|
87
|
+
Please use the GitHub pull-request mechanism to submit contributions.
|
88
|
+
|
89
|
+
### License
|
90
|
+
|
91
|
+
This project is available for use under the MIT software license.
|
92
|
+
See LICENSE
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'jekyll-twitter-plugin'
|
7
|
+
spec.version = '1.0.0'
|
8
|
+
spec.authors = ['Rob Murray']
|
9
|
+
spec.email = ['robmurray17@gmail.com']
|
10
|
+
spec.summary = 'A Liquid tag plugin for Jekyll that renders Tweets from Twitter API'
|
11
|
+
spec.homepage = 'https://github.com/rob-murray/jekyll-twitter-plugin'
|
12
|
+
spec.license = 'MIT'
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\x0")
|
15
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
16
|
+
spec.require_paths = ['lib']
|
17
|
+
|
18
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
19
|
+
spec.add_development_dependency 'rake'
|
20
|
+
|
21
|
+
spec.add_dependency 'twitter', '~> 5.11'
|
22
|
+
end
|
@@ -0,0 +1,171 @@
|
|
1
|
+
require 'twitter'
|
2
|
+
|
3
|
+
##
|
4
|
+
# A Liquid tag plugin for Jekyll that renders Tweets from Twitter API.
|
5
|
+
# https://github.com/rob-murray/jekyll-twitter-plugin
|
6
|
+
#
|
7
|
+
module TwitterJekyll
|
8
|
+
class FileCache
|
9
|
+
def initialize(path)
|
10
|
+
@cache_folder = File.expand_path path
|
11
|
+
FileUtils.mkdir_p @cache_folder
|
12
|
+
end
|
13
|
+
|
14
|
+
def read(key)
|
15
|
+
file_to_read = cache_file(cache_filename(key))
|
16
|
+
JSON.parse(File.read(file_to_read)) if File.exist?(file_to_read)
|
17
|
+
end
|
18
|
+
|
19
|
+
def write(key, data)
|
20
|
+
file_to_write = cache_file(cache_filename(key))
|
21
|
+
data_to_write = JSON.generate data.to_h
|
22
|
+
|
23
|
+
File.open(file_to_write, 'w') do |f|
|
24
|
+
f.write(data_to_write)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def cache_file(filename)
|
31
|
+
File.join(@cache_folder, filename)
|
32
|
+
end
|
33
|
+
|
34
|
+
def cache_filename(cache_key)
|
35
|
+
"#{cache_key}.cache"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class NullCache
|
40
|
+
def initialize; end
|
41
|
+
|
42
|
+
def read(_key); end
|
43
|
+
|
44
|
+
def write(_key, _data); end
|
45
|
+
end
|
46
|
+
|
47
|
+
module Cacheable
|
48
|
+
def cache_key
|
49
|
+
Digest::MD5.hexdigest("#{self.class.name}-#{key}")
|
50
|
+
end
|
51
|
+
|
52
|
+
def key; end
|
53
|
+
end
|
54
|
+
|
55
|
+
module TwitterApiMixin
|
56
|
+
def id_from_status_url(url)
|
57
|
+
if url.to_s =~ /([^\/]+$)/
|
58
|
+
Regexp.last_match[1]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def find_tweet(id)
|
63
|
+
return unless id
|
64
|
+
|
65
|
+
@client.status(id.to_i)
|
66
|
+
rescue Twitter::Error::NotFound
|
67
|
+
nil
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
class Oembed
|
72
|
+
include TwitterJekyll::TwitterApiMixin
|
73
|
+
include TwitterJekyll::Cacheable
|
74
|
+
|
75
|
+
def initialize(client, params)
|
76
|
+
@client = client
|
77
|
+
@status_url = params
|
78
|
+
end
|
79
|
+
|
80
|
+
def fetch
|
81
|
+
tweet_id = id_from_status_url(@status_url)
|
82
|
+
|
83
|
+
if tweet = find_tweet(tweet_id)
|
84
|
+
@client.oembed tweet
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def key
|
89
|
+
@status_url
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
class UnknownTypeClient
|
94
|
+
def fetch; end
|
95
|
+
|
96
|
+
def cache_key; end
|
97
|
+
end
|
98
|
+
|
99
|
+
class TwitterTag < Liquid::Tag
|
100
|
+
ERROR_BODY_TEXT = 'Tweet could not be processed'
|
101
|
+
|
102
|
+
def initialize(_name, params, _tokens)
|
103
|
+
super
|
104
|
+
@params = params.split(/\s+/).map(&:strip)
|
105
|
+
@cache = FileCache.new('./.tweet-cache')
|
106
|
+
|
107
|
+
create_twitter_rest_client
|
108
|
+
end
|
109
|
+
|
110
|
+
def render(_context)
|
111
|
+
api_type = @params.first
|
112
|
+
tweet_params = @params.last
|
113
|
+
|
114
|
+
api_client = create_api_client(api_type, tweet_params)
|
115
|
+
html_output_for(api_client)
|
116
|
+
end
|
117
|
+
|
118
|
+
private
|
119
|
+
|
120
|
+
def html_output_for(api_client)
|
121
|
+
body = ERROR_BODY_TEXT
|
122
|
+
|
123
|
+
if response = cached_response(api_client) || live_response(api_client)
|
124
|
+
body = response.html || body
|
125
|
+
end
|
126
|
+
|
127
|
+
"<div class='embed twitter'>#{body}</div>"
|
128
|
+
end
|
129
|
+
|
130
|
+
def live_response(api_client)
|
131
|
+
if response = api_client.fetch
|
132
|
+
@cache.write(api_client.cache_key, response)
|
133
|
+
response
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def cached_response(api_client)
|
138
|
+
response = @cache.read(api_client.cache_key)
|
139
|
+
OpenStruct.new(response) unless response.nil?
|
140
|
+
end
|
141
|
+
|
142
|
+
def create_api_client(api_type, params)
|
143
|
+
klass_name = api_type.capitalize
|
144
|
+
if TwitterJekyll.const_defined?(klass_name)
|
145
|
+
api_client_klass = TwitterJekyll.const_get(klass_name)
|
146
|
+
api_client_klass.new(@twitter_client, params)
|
147
|
+
else
|
148
|
+
UnknownTypeClient.new
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def create_twitter_rest_client
|
153
|
+
@twitter_client = Twitter::REST::Client.new do |config|
|
154
|
+
config.consumer_key = ENV.fetch('twitter_consumer_key')
|
155
|
+
config.consumer_secret = ENV.fetch('twitter_consumer_secret')
|
156
|
+
config.access_token = ENV.fetch('twitter_access_token')
|
157
|
+
config.access_token_secret = ENV.fetch('twitter_access_token_secret')
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
class TwitterTagNoCache < TwitterTag
|
163
|
+
def initialize(_tag_name, _text, _token)
|
164
|
+
super
|
165
|
+
@cache = NullCache.new
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
Liquid::Template.register_tag('twitter', TwitterJekyll::TwitterTag)
|
171
|
+
Liquid::Template.register_tag('twitternocache', TwitterJekyll::TwitterTagNoCache)
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-twitter-plugin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rob Murray
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: twitter
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.11'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.11'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- robmurray17@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- jekyll-twitter-plugin.gemspec
|
68
|
+
- lib/jekyll-twitter-plugin.rb
|
69
|
+
homepage: https://github.com/rob-murray/jekyll-twitter-plugin
|
70
|
+
licenses:
|
71
|
+
- MIT
|
72
|
+
metadata: {}
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 2.2.2
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: A Liquid tag plugin for Jekyll that renders Tweets from Twitter API
|
93
|
+
test_files: []
|