ignoramos 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +34 -3
- data/ignoramos.gemspec +2 -2
- data/lib/commands/base_tweet_command.rb +51 -0
- data/lib/commands/build_command.rb +19 -34
- data/lib/commands/import_tweet_command.rb +11 -0
- data/lib/commands/new_command.rb +4 -9
- data/lib/commands/tweet_command.rb +4 -56
- data/lib/file_helper.rb +25 -0
- data/lib/ignoramos.rb +19 -18
- data/rebuild_gem +2 -2
- data/spec/commands/import_tweet_command_spec.rb +12 -0
- data/spec/commands/tweet_command_spec.rb +6 -53
- data/spec/ignoramos_spec.rb +68 -0
- data/spec/shared_examples/tweet_command_examples.rb +58 -0
- metadata +12 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b775b7dbb49c4b26b018f96eac206bf6db773142
|
4
|
+
data.tar.gz: 565c0ebf1aaf1c829799331d39341f44d1a4fa7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f51c2fc953aa4f3e94aa6382ceb2317110d16feed96de03940c3a4af866607b985e28c981945cba492d27d7f8cbfd08d3eb1c9339cd4c339e445200e7a33638
|
7
|
+
data.tar.gz: 731ed4f2bce2065b04f5c85ec71881105828d7fd53d858acb12649a53fe60f7453dacc3107308f30b377bf42783020fe82322a5c596d0de95a6a3d8b2263d869
|
data/README.md
CHANGED
@@ -7,6 +7,7 @@ Status](https://travis-ci.org/achan/ignoramos.svg?branch=master)](https://travis
|
|
7
7
|
Climate](https://codeclimate.com/github/achan/ignoramos/badges/gpa.svg)](https://codeclimate.com/github/achan/ignoramos)
|
8
8
|
[![Coverage
|
9
9
|
Status](https://img.shields.io/coveralls/achan/ignoramos.svg)](https://coveralls.io/r/achan/ignoramos)
|
10
|
+
[![Gem Version](https://badge.fury.io/rb/ignoramos.svg)](http://badge.fury.io/rb/ignoramos)
|
10
11
|
|
11
12
|
Getting started
|
12
13
|
===============
|
@@ -42,7 +43,7 @@ Directory structure
|
|
42
43
|
```
|
43
44
|
|
44
45
|
```
|
45
|
-
$ ignoramos build
|
46
|
+
~ $ ignoramos build
|
46
47
|
```
|
47
48
|
|
48
49
|
The `build` command is expected to be run at the root directory of the
|
@@ -57,7 +58,37 @@ How posts are built
|
|
57
58
|
- Render layout as content
|
58
59
|
- Render liquid layout (header, footer, content)
|
59
60
|
|
60
|
-
After all posts and pages are generated, all remaining files that are not from
|
61
|
-
folder prefixed with `_` will be copied over to `_site`. Custom files take
|
61
|
+
After all posts and pages are generated, all remaining files that are not from
|
62
|
+
a folder prefixed with `_` will be copied over to `_site`. Custom files take
|
62
63
|
precedence, so if your files conflict with generated ones, yours will overwrite
|
63
64
|
the generated file.
|
65
|
+
|
66
|
+
Microblogging
|
67
|
+
===============
|
68
|
+
|
69
|
+
Currently, the only external microblogging platform that is supported is Twitter:
|
70
|
+
|
71
|
+
```
|
72
|
+
~ $ ignoramos tweet "hello world #testing"
|
73
|
+
```
|
74
|
+
|
75
|
+
This command will post to twitter and create a micro blog in your `_posts`
|
76
|
+
directory with filename: `tweet-<twitter_id>.md` with the following contents:
|
77
|
+
|
78
|
+
```
|
79
|
+
---
|
80
|
+
title: tweet 526064479298396163
|
81
|
+
timestamp: 2014-10-25T13:35:20-04:00
|
82
|
+
layout: tweet
|
83
|
+
tweet: https://twitter.com/amoschan/status/526064479298396163
|
84
|
+
---
|
85
|
+
|
86
|
+
hello world #testing
|
87
|
+
```
|
88
|
+
|
89
|
+
It is them up to your theme to support the `tweet` layout and optionally use the
|
90
|
+
`tweet` variable to link back to Twitter.
|
91
|
+
|
92
|
+
For an example of tweets in action, see the [achan/amoschan][ac] theme.
|
93
|
+
|
94
|
+
[ac]: https://github.com/achan/amoschan/commit/f15c149e531a35f9c3a38f8c49311a0f3ce7c612
|
data/ignoramos.gemspec
CHANGED
@@ -4,12 +4,12 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "ignoramos"
|
7
|
-
spec.version = "1.0
|
7
|
+
spec.version = "1.1.0"
|
8
8
|
spec.authors = ["Amos Chan"]
|
9
9
|
spec.email = ["amosschan@gmail.com"]
|
10
10
|
spec.summary = %q{A static site generator for blogs and microposts.}
|
11
11
|
spec.description = spec.summary
|
12
|
-
spec.homepage = "http://
|
12
|
+
spec.homepage = "http://github.com/achan/ignoramos"
|
13
13
|
spec.license = "MIT"
|
14
14
|
|
15
15
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'liquid'
|
2
|
+
require 'models/post'
|
3
|
+
require 'models/app_config'
|
4
|
+
require 'twitter'
|
5
|
+
require 'twitter/tweet'
|
6
|
+
require 'file_helper'
|
7
|
+
|
8
|
+
class BaseTweetCommand
|
9
|
+
attr_reader :file_helper
|
10
|
+
|
11
|
+
TWEET_LAYOUT = <<-LAYOUT
|
12
|
+
---
|
13
|
+
title: tweet {{tweet.id}}
|
14
|
+
timestamp: {{tweet.timestamp}}
|
15
|
+
layout: tweet
|
16
|
+
tweet: {{tweet.url}}
|
17
|
+
---
|
18
|
+
|
19
|
+
{{tweet.content}}
|
20
|
+
LAYOUT
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
@file_helper = FileHelper.new(Dir.pwd)
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
def app_config
|
28
|
+
@config ||= AppConfig.new(file_helper.read_file("_config.yml"))
|
29
|
+
end
|
30
|
+
|
31
|
+
def twitter
|
32
|
+
@twitter ||= Twitter::REST::Client.new do |config|
|
33
|
+
config.consumer_key = "RerlMuPVgYySMdqvuaBeSw"
|
34
|
+
config.consumer_secret = "Ccq3hS7fMplpjwCfvpVyPQXV6nPGGGonXSAdmi8ZIc"
|
35
|
+
config.access_token = app_config.vars['twitter']['access_token']
|
36
|
+
config.access_token_secret = app_config.vars['twitter']['access_token_secret']
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def persist_tweet(tweet)
|
41
|
+
file_helper.new_file("_posts/tweet-#{tweet.id}.md",
|
42
|
+
Liquid::Template.parse(TWEET_LAYOUT).render({
|
43
|
+
'tweet' => {
|
44
|
+
'content' => tweet.text,
|
45
|
+
'id' => tweet.id,
|
46
|
+
'url' => tweet.uri.to_s,
|
47
|
+
'timestamp' => DateTime.parse(tweet.created_at.to_s)
|
48
|
+
}
|
49
|
+
}))
|
50
|
+
end
|
51
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'liquid'
|
2
|
-
require '
|
2
|
+
require 'file_helper'
|
3
3
|
require 'models/post'
|
4
4
|
require 'models/page'
|
5
5
|
require 'models/app_config'
|
@@ -7,12 +7,13 @@ require 'models/app_config'
|
|
7
7
|
class BuildCommand
|
8
8
|
def initialize(dir = Dir.pwd)
|
9
9
|
@dir = dir
|
10
|
+
@file_helper = FileHelper.new(dir)
|
10
11
|
end
|
11
12
|
|
12
13
|
def execute
|
13
14
|
Liquid::Template.file_system = Liquid::LocalFileSystem.new("#{ @dir }/_includes")
|
14
15
|
FileUtils.rm_rf("#{ @dir }/_site")
|
15
|
-
mkdir_p("_site")
|
16
|
+
@file_helper.mkdir_p("_site")
|
16
17
|
|
17
18
|
generate_pages
|
18
19
|
generate_posts
|
@@ -24,7 +25,7 @@ class BuildCommand
|
|
24
25
|
|
25
26
|
private
|
26
27
|
def config
|
27
|
-
@config ||= AppConfig.new(read_file("_config.yml"))
|
28
|
+
@config ||= AppConfig.new(@file_helper.read_file("_config.yml"))
|
28
29
|
end
|
29
30
|
|
30
31
|
def copy_custom_files
|
@@ -63,7 +64,7 @@ class BuildCommand
|
|
63
64
|
Dir.foreach("#{ @dir }/#{ dir }") do |item|
|
64
65
|
next if item == '.' || item == '..'
|
65
66
|
|
66
|
-
contents = read_file("#{ dir }/#{ item }")
|
67
|
+
contents = @file_helper.read_file("#{ dir }/#{ item }")
|
67
68
|
posts << if block_given?
|
68
69
|
yield contents
|
69
70
|
else
|
@@ -85,11 +86,11 @@ class BuildCommand
|
|
85
86
|
def generate_dir(posts, template, &block)
|
86
87
|
posts.each do |post|
|
87
88
|
params = yield post
|
88
|
-
layout = read_file("_layouts/#{ post.vars['layout'] }/#{ template }.liquid")
|
89
|
+
layout = @file_helper.read_file("_layouts/#{ post.vars['layout'] }/#{ template }.liquid")
|
89
90
|
post_params = { 'site' => site_config }.merge(params.merge(post.vars))
|
90
91
|
post_params['title'] = "#{ post_params['title'] } - #{ config.vars['site']['name'] }"
|
91
|
-
mkdir_p("_site#{ post.path }")
|
92
|
-
new_file("_site#{ post.permalink }",
|
92
|
+
@file_helper.mkdir_p("_site#{ post.path }")
|
93
|
+
@file_helper.new_file("_site#{ post.permalink }",
|
93
94
|
Liquid::Template.parse(layout).render(post_params))
|
94
95
|
end
|
95
96
|
end
|
@@ -117,11 +118,11 @@ class BuildCommand
|
|
117
118
|
end
|
118
119
|
|
119
120
|
def tags_layout
|
120
|
-
@layout ||= read_file("_layouts/default/tags.liquid")
|
121
|
+
@layout ||= @file_helper.read_file("_layouts/default/tags.liquid")
|
121
122
|
end
|
122
123
|
|
123
124
|
def new_tags_index_file(filename, title, tags)
|
124
|
-
new_file(filename,
|
125
|
+
@file_helper.new_file(filename,
|
125
126
|
Liquid::Template.parse(tags_layout).render({
|
126
127
|
'title' => title,
|
127
128
|
'tags' => tags,
|
@@ -130,7 +131,7 @@ class BuildCommand
|
|
130
131
|
end
|
131
132
|
|
132
133
|
def generate_index_per_tag
|
133
|
-
mkdir_p("_site/tags")
|
134
|
+
@file_helper.mkdir_p("_site/tags")
|
134
135
|
|
135
136
|
tags.each do |tag|
|
136
137
|
new_tags_index_file("_site/tags/#{ tag['name'] }.html",
|
@@ -144,14 +145,14 @@ class BuildCommand
|
|
144
145
|
reverse.
|
145
146
|
first(5)
|
146
147
|
|
147
|
-
layout = read_file("_layouts/default/posts.liquid")
|
148
|
+
layout = @file_helper.read_file("_layouts/default/posts.liquid")
|
148
149
|
|
149
|
-
new_file("_site/index.html",
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
150
|
+
@file_helper.new_file("_site/index.html",
|
151
|
+
Liquid::Template.parse(layout).render({
|
152
|
+
'posts' => homepage_posts,
|
153
|
+
'title' => config.vars['site']['name'],
|
154
|
+
'site' => site_config
|
155
|
+
}))
|
155
156
|
end
|
156
157
|
|
157
158
|
def site_config
|
@@ -162,27 +163,11 @@ class BuildCommand
|
|
162
163
|
}
|
163
164
|
end
|
164
165
|
|
165
|
-
def mkdir_p(dir)
|
166
|
-
FileUtils.mkdir_p("#{ @dir }/#{ dir }")
|
167
|
-
end
|
168
|
-
|
169
|
-
def new_file(filename, contents)
|
170
|
-
new_post_file = File.new("#{ @dir }/#{ filename }", 'w')
|
171
|
-
new_post_file.write(contents)
|
172
|
-
new_post_file.close
|
173
|
-
end
|
174
|
-
|
175
|
-
def read_file(filename)
|
176
|
-
File.open("#{ @dir }/#{ filename }", 'r') do |file|
|
177
|
-
file.read()
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
166
|
def cache
|
182
167
|
@cache ||= {}
|
183
168
|
end
|
184
169
|
|
185
170
|
def template(layout)
|
186
|
-
cache[layout.to_sym] ||= read_file("_layouts/#{ layout }/post.liquid")
|
171
|
+
cache[layout.to_sym] ||= @file_helper.read_file("_layouts/#{ layout }/post.liquid")
|
187
172
|
end
|
188
173
|
end
|
data/lib/commands/new_command.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
require 'fileutils'
|
2
|
+
require 'file_helper'
|
2
3
|
|
3
4
|
class NewCommand
|
4
5
|
attr_accessor :dir
|
5
6
|
|
6
7
|
def initialize(dir)
|
7
8
|
@dir = dir.to_s
|
9
|
+
@file_helper = FileHelper.new(dir)
|
8
10
|
end
|
9
11
|
|
10
12
|
def execute
|
@@ -21,14 +23,7 @@ class NewCommand
|
|
21
23
|
tagline = 'A short description of my blog'
|
22
24
|
desc = 'Site description'
|
23
25
|
|
24
|
-
new_file("_config.yml",
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
def new_file(filename, contents)
|
30
|
-
new_post_file = File.new("#{ @dir }/#{ filename }", 'w')
|
31
|
-
new_post_file.write(contents)
|
32
|
-
new_post_file.close
|
26
|
+
@file_helper.new_file("_config.yml",
|
27
|
+
"---\nsite:\n name: #{ blog_name }\n tagline: #{ tagline }\n description: #{ desc }")
|
33
28
|
end
|
34
29
|
end
|
@@ -1,64 +1,12 @@
|
|
1
|
-
require '
|
2
|
-
require 'fileutils'
|
3
|
-
require 'models/post'
|
4
|
-
require 'models/app_config'
|
5
|
-
require 'twitter'
|
6
|
-
require 'twitter/tweet'
|
7
|
-
|
8
|
-
class TweetCommand
|
9
|
-
LAYOUT = <<-LAYOUT
|
10
|
-
---
|
11
|
-
title: tweet {{tweet.id}}
|
12
|
-
timestamp: {{tweet.timestamp}}
|
13
|
-
layout: tweet
|
14
|
-
tweet: {{tweet.url}}
|
15
|
-
---
|
16
|
-
|
17
|
-
{{tweet.content}}
|
18
|
-
LAYOUT
|
1
|
+
require 'commands/base_tweet_command'
|
19
2
|
|
3
|
+
class TweetCommand < BaseTweetCommand
|
20
4
|
def initialize(tweet)
|
5
|
+
super()
|
21
6
|
@tweet = tweet
|
22
|
-
@dir = Dir.pwd
|
23
7
|
end
|
24
8
|
|
25
9
|
def execute
|
26
|
-
|
27
|
-
|
28
|
-
new_file("_posts/tweet-#{tweet.id}.md",
|
29
|
-
Liquid::Template.parse(LAYOUT).render({
|
30
|
-
'tweet' => {
|
31
|
-
'content' => @tweet,
|
32
|
-
'id' => tweet.id,
|
33
|
-
'url' => tweet.uri.to_s,
|
34
|
-
'timestamp' => DateTime.now
|
35
|
-
}
|
36
|
-
}))
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
def app_config
|
41
|
-
@config ||= AppConfig.new(read_file("_config.yml"))
|
42
|
-
end
|
43
|
-
|
44
|
-
def new_file(filename, contents)
|
45
|
-
new_post_file = File.new("#{@dir}/#{filename}", 'w')
|
46
|
-
new_post_file.write(contents)
|
47
|
-
new_post_file.close
|
48
|
-
end
|
49
|
-
|
50
|
-
def read_file(filename)
|
51
|
-
File.open("#{@dir}/#{filename}", 'r') do |file|
|
52
|
-
file.read()
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def twitter
|
57
|
-
@twitter ||= Twitter::REST::Client.new do |config|
|
58
|
-
config.consumer_key = "RerlMuPVgYySMdqvuaBeSw"
|
59
|
-
config.consumer_secret = "Ccq3hS7fMplpjwCfvpVyPQXV6nPGGGonXSAdmi8ZIc"
|
60
|
-
config.access_token = app_config.vars['twitter']['access_token']
|
61
|
-
config.access_token_secret = app_config.vars['twitter']['access_token_secret']
|
62
|
-
end
|
10
|
+
persist_tweet(twitter.update(@tweet))
|
63
11
|
end
|
64
12
|
end
|
data/lib/file_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
class FileHelper
|
4
|
+
attr_reader :dir
|
5
|
+
|
6
|
+
def initialize(dir)
|
7
|
+
@dir = dir
|
8
|
+
end
|
9
|
+
|
10
|
+
def new_file(filename, contents)
|
11
|
+
new_post_file = File.new("#{dir}/#{filename}", 'w')
|
12
|
+
new_post_file.write(contents)
|
13
|
+
new_post_file.close
|
14
|
+
end
|
15
|
+
|
16
|
+
def read_file(filename)
|
17
|
+
File.open("#{dir}/#{filename}", 'r') do |file|
|
18
|
+
file.read()
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def mkdir_p(dir)
|
23
|
+
FileUtils.mkdir_p("#{@dir}/#{dir}")
|
24
|
+
end
|
25
|
+
end
|
data/lib/ignoramos.rb
CHANGED
@@ -1,29 +1,30 @@
|
|
1
|
-
require 'commands/new_command'
|
2
|
-
require 'commands/build_command'
|
3
|
-
require 'commands/tweet_command'
|
4
|
-
|
5
1
|
class Ignoramos
|
6
2
|
def initialize(args = [])
|
7
3
|
command(args).execute
|
8
4
|
end
|
9
5
|
|
10
|
-
def command(args)
|
11
|
-
cmd = args[0] unless args.empty?
|
12
|
-
|
13
|
-
if cmd == 'new'
|
14
|
-
NewCommand.new(args[1])
|
15
|
-
elsif cmd == 'build'
|
16
|
-
BuildCommand.new
|
17
|
-
elsif cmd == 'tweet'
|
18
|
-
TweetCommand.new(args[1])
|
19
|
-
else
|
20
|
-
NilCommand.new
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
6
|
NilCommand = Struct.new(:args) do
|
25
7
|
def execute
|
26
8
|
puts 'command not supported'
|
27
9
|
end
|
28
10
|
end
|
11
|
+
|
12
|
+
private
|
13
|
+
def command(args)
|
14
|
+
cmd = args.slice!(0) unless args.empty?
|
15
|
+
Object.const_get(classify(cmd)).new(*args)
|
16
|
+
rescue NameError
|
17
|
+
NilCommand.new
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
def classify(command)
|
22
|
+
snake_class = "#{command}_command"
|
23
|
+
begin
|
24
|
+
require "commands/#{snake_class}"
|
25
|
+
rescue LoadError => e
|
26
|
+
puts e.to_s
|
27
|
+
end
|
28
|
+
snake_class.split('_').collect(&:capitalize).join
|
29
|
+
end
|
29
30
|
end
|
data/rebuild_gem
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
require './lib/commands/import_tweet_command'
|
2
|
+
require 'shared_examples/tweet_command_examples'
|
3
|
+
|
4
|
+
RSpec.describe ImportTweetCommand do
|
5
|
+
describe '#execute' do
|
6
|
+
let(:command) { ImportTweetCommand.new(tweet_id) }
|
7
|
+
let(:client_method) { :status }
|
8
|
+
let(:client_args) { tweet_id }
|
9
|
+
|
10
|
+
it_behaves_like "a command that writes a tweet to file"
|
11
|
+
end
|
12
|
+
end
|
@@ -1,59 +1,12 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
3
|
-
require 'fakefs/spec_helpers'
|
4
|
-
require 'timecop'
|
1
|
+
require 'commands/tweet_command'
|
2
|
+
require 'shared_examples/tweet_command_examples'
|
5
3
|
|
6
4
|
RSpec.describe TweetCommand do
|
7
5
|
describe '#execute' do
|
8
|
-
|
6
|
+
let(:command) { TweetCommand.new(tweet) }
|
7
|
+
let(:client_method) { :update }
|
8
|
+
let(:client_args) { tweet }
|
9
9
|
|
10
|
-
|
11
|
-
let(:tweet) { 'this is a tweet' }
|
12
|
-
let(:tweet_id) { '525483671584002048' }
|
13
|
-
let(:tweet_url) { "https://twitter.com/amoschan/status/#{tweet_id}" }
|
14
|
-
let(:tweet_post) do
|
15
|
-
<<-TWEET
|
16
|
-
---
|
17
|
-
title: tweet #{tweet_id}
|
18
|
-
timestamp: #{now}
|
19
|
-
layout: tweet
|
20
|
-
tweet: #{tweet_url}
|
21
|
-
---
|
22
|
-
|
23
|
-
this is a tweet
|
24
|
-
TWEET
|
25
|
-
end
|
26
|
-
|
27
|
-
let(:now) { DateTime.now }
|
28
|
-
|
29
|
-
let(:created_tweet) do
|
30
|
-
double()
|
31
|
-
end
|
32
|
-
|
33
|
-
before do
|
34
|
-
created_tweet.stub(:uri).and_return(URI(tweet_url))
|
35
|
-
created_tweet.stub(:id).and_return(tweet_id)
|
36
|
-
allow_any_instance_of(AppConfig).
|
37
|
-
to receive(:vars).and_return({
|
38
|
-
'twitter' => { 'access_token' => 'token',
|
39
|
-
'access_token_secret' => 'secret' }
|
40
|
-
})
|
41
|
-
|
42
|
-
expect_any_instance_of(Twitter::REST::Client).
|
43
|
-
to receive(:update).with(tweet).and_return(created_tweet)
|
44
|
-
|
45
|
-
Timecop.freeze do
|
46
|
-
NewCommand.new('testdir').execute
|
47
|
-
Dir.chdir('testdir')
|
48
|
-
TweetCommand.new('this is a tweet').execute
|
49
|
-
now
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'creates new tweet' do
|
54
|
-
File.open("_posts/tweet-#{tweet_id}.md", 'r') do |file|
|
55
|
-
expect(file.read()).to eq(tweet_post)
|
56
|
-
end
|
57
|
-
end
|
10
|
+
it_behaves_like "a command that writes a tweet to file"
|
58
11
|
end
|
59
12
|
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'commands/build_command'
|
2
|
+
require 'commands/tweet_command'
|
3
|
+
require 'commands/new_command'
|
4
|
+
require 'commands/import_tweet_command'
|
5
|
+
require 'pry'
|
6
|
+
require 'ignoramos'
|
7
|
+
|
8
|
+
RSpec.describe Ignoramos do
|
9
|
+
shared_examples_for "a command executer" do
|
10
|
+
let(:command) { double() }
|
11
|
+
|
12
|
+
it 'instantiates a command and calls execute' do
|
13
|
+
expect(command_class).
|
14
|
+
to receive(:new).with(*args[1..-1]).and_return(command)
|
15
|
+
expect(command).to receive(:execute)
|
16
|
+
|
17
|
+
Ignoramos.new(args)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
shared_examples_for 'a command executer with no args' do
|
22
|
+
let(:command) { double() }
|
23
|
+
|
24
|
+
it 'instantiates a command and calls execute' do
|
25
|
+
expect(command_class).to receive(:new).with(no_args).and_return(command)
|
26
|
+
expect(command).to receive(:execute)
|
27
|
+
|
28
|
+
Ignoramos.new(args)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#initialize' do
|
33
|
+
describe 'when the command passed is "new"' do
|
34
|
+
let(:args) { ['new', 'tempsite'] }
|
35
|
+
let(:command_class) { NewCommand }
|
36
|
+
|
37
|
+
it_behaves_like "a command executer"
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'when the command passed is "tweet"' do
|
41
|
+
let(:args) { ['tweet', 'this is a tweet'] }
|
42
|
+
let(:command_class) { TweetCommand }
|
43
|
+
|
44
|
+
it_behaves_like "a command executer"
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'when the command passed is "build"' do
|
48
|
+
let(:args) { ['build'] }
|
49
|
+
let(:command_class) { BuildCommand }
|
50
|
+
|
51
|
+
it_behaves_like "a command executer with no args"
|
52
|
+
end
|
53
|
+
|
54
|
+
describe 'when the command passed is "import_tweet"' do
|
55
|
+
let(:args) { ['import_tweet', '1234'] }
|
56
|
+
let(:command_class) { ImportTweetCommand }
|
57
|
+
|
58
|
+
it_behaves_like "a command executer"
|
59
|
+
end
|
60
|
+
|
61
|
+
describe 'when the command is unsupported' do
|
62
|
+
let(:args) { ['asdasfsdfsd'] }
|
63
|
+
let(:command_class) { Ignoramos::NilCommand }
|
64
|
+
|
65
|
+
it_behaves_like "a command executer with no args"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require './lib/commands/new_command'
|
2
|
+
require 'fakefs/spec_helpers'
|
3
|
+
require 'timecop'
|
4
|
+
|
5
|
+
shared_examples_for "a command that writes a tweet to file" do
|
6
|
+
include FakeFS::SpecHelpers
|
7
|
+
|
8
|
+
let(:tweet) { 'this is a tweet' }
|
9
|
+
let(:tweet_id) { '525483671584002048' }
|
10
|
+
let(:tweet_url) { "https://twitter.com/amoschan/status/#{tweet_id}" }
|
11
|
+
let(:tweet_post) do
|
12
|
+
<<-TWEET
|
13
|
+
---
|
14
|
+
title: tweet #{tweet_id}
|
15
|
+
timestamp: #{now}
|
16
|
+
layout: tweet
|
17
|
+
tweet: #{tweet_url}
|
18
|
+
---
|
19
|
+
|
20
|
+
#{tweet}
|
21
|
+
TWEET
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:now) { DateTime.now }
|
25
|
+
let(:now_time) { Time.now }
|
26
|
+
|
27
|
+
let(:remote_tweet) do
|
28
|
+
double()
|
29
|
+
end
|
30
|
+
|
31
|
+
before do
|
32
|
+
Timecop.freeze do
|
33
|
+
remote_tweet.stub(:uri).and_return(URI(tweet_url))
|
34
|
+
remote_tweet.stub(:id).and_return(tweet_id)
|
35
|
+
remote_tweet.stub(:created_at).and_return(now_time)
|
36
|
+
remote_tweet.stub(:text).and_return(tweet)
|
37
|
+
allow_any_instance_of(AppConfig).
|
38
|
+
to receive(:vars).and_return({
|
39
|
+
'twitter' => { 'access_token' => 'token',
|
40
|
+
'access_token_secret' => 'secret' }
|
41
|
+
})
|
42
|
+
|
43
|
+
expect_any_instance_of(Twitter::REST::Client).
|
44
|
+
to receive(client_method).with(client_args).and_return(remote_tweet)
|
45
|
+
|
46
|
+
NewCommand.new('testdir').execute
|
47
|
+
Dir.chdir('testdir')
|
48
|
+
command.execute
|
49
|
+
now
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'creates new tweet' do
|
54
|
+
File.open("_posts/tweet-#{tweet_id}.md", 'r') do |file|
|
55
|
+
expect(file.read()).to eq(tweet_post)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ignoramos
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Amos Chan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -56,22 +56,28 @@ files:
|
|
56
56
|
- Rakefile
|
57
57
|
- bin/ignoramos
|
58
58
|
- ignoramos.gemspec
|
59
|
+
- lib/commands/base_tweet_command.rb
|
59
60
|
- lib/commands/build_command.rb
|
61
|
+
- lib/commands/import_tweet_command.rb
|
60
62
|
- lib/commands/new_command.rb
|
61
63
|
- lib/commands/tweet_command.rb
|
64
|
+
- lib/file_helper.rb
|
62
65
|
- lib/ignoramos.rb
|
63
66
|
- lib/models/app_config.rb
|
64
67
|
- lib/models/page.rb
|
65
68
|
- lib/models/post.rb
|
66
69
|
- rebuild_gem
|
67
70
|
- spec/commands/build_command_spec.rb
|
71
|
+
- spec/commands/import_tweet_command_spec.rb
|
68
72
|
- spec/commands/new_command_spec.rb
|
69
73
|
- spec/commands/tweet_command_spec.rb
|
74
|
+
- spec/ignoramos_spec.rb
|
70
75
|
- spec/models/app_config_spec.rb
|
71
76
|
- spec/models/page_spec.rb
|
72
77
|
- spec/models/post_spec.rb
|
78
|
+
- spec/shared_examples/tweet_command_examples.rb
|
73
79
|
- spec/spec_helper.rb
|
74
|
-
homepage: http://
|
80
|
+
homepage: http://github.com/achan/ignoramos
|
75
81
|
licenses:
|
76
82
|
- MIT
|
77
83
|
metadata: {}
|
@@ -97,9 +103,12 @@ specification_version: 4
|
|
97
103
|
summary: A static site generator for blogs and microposts.
|
98
104
|
test_files:
|
99
105
|
- spec/commands/build_command_spec.rb
|
106
|
+
- spec/commands/import_tweet_command_spec.rb
|
100
107
|
- spec/commands/new_command_spec.rb
|
101
108
|
- spec/commands/tweet_command_spec.rb
|
109
|
+
- spec/ignoramos_spec.rb
|
102
110
|
- spec/models/app_config_spec.rb
|
103
111
|
- spec/models/page_spec.rb
|
104
112
|
- spec/models/post_spec.rb
|
113
|
+
- spec/shared_examples/tweet_command_examples.rb
|
105
114
|
- spec/spec_helper.rb
|