blogpostify 1.0.1 → 1.1.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 +4 -4
- data/README.md +29 -13
- data/db/migrate/20150209104023_create_posts.rb +4 -2
- data/lib/blogpostify/blog.rb +10 -5
- data/lib/blogpostify/engine.rb +2 -4
- data/lib/blogpostify/post.rb +7 -3
- data/lib/blogpostify/version.rb +1 -1
- data/lib/blogpostify/view_helpers.rb +17 -12
- data/lib/blogpostify.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4187c3eb2a5ac8073d4186072a590e46e066f139
|
4
|
+
data.tar.gz: 0d68d1fca01c54364a8b482d9e4afbe0ad3cb7b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5380f149444491657b6ca7a64cfaedcc265d63bfe9a24ddf655e56724b23e77a51c6eb7f2fcd8a63ad4c9b02bda63ae3b7a54f617a21f92f904b8c1888c5f7e
|
7
|
+
data.tar.gz: ffc3be2fd52e6c6684810f97c8e04dfc936fa711bd74c27a5f548ced9a7a5fa7f1f51340d2649cf45307057f899a1b84e9c4a94d22c07b5da4c70bdd19b2280c
|
data/README.md
CHANGED
@@ -19,6 +19,7 @@ And then execute:
|
|
19
19
|
Once bundled with your application, run the migration included with the gem:
|
20
20
|
|
21
21
|
```sh
|
22
|
+
bundle exec rake blogpostify:install:migrations
|
22
23
|
bundle exec rake db:migrate
|
23
24
|
```
|
24
25
|
|
@@ -33,12 +34,12 @@ Blogpostify.configure do |config|
|
|
33
34
|
end
|
34
35
|
```
|
35
36
|
|
36
|
-
The title of your blog will be parameterized to form an blog identifier for your cached posts.
|
37
|
+
The title of your blog will be parameterized to form an blog identifier for your cached posts. You can optionally set `:short_name` to override this. If you wish to add an icon to your blog you can set `:icon`. Finally, if you'd like to set the homepage the feed is related to set `:homepage`.
|
37
38
|
|
38
39
|
```ruby
|
39
40
|
Blogpostify.configure do |config|
|
40
|
-
config.add_blog("Riding Rails", "http://weblog.rubyonrails.org/feed/atom.xml")
|
41
|
-
config.add_blog("Signal v. Noise", "https://signalvnoise.com/posts.rss", "svn", "https://basecamp.com/assets/general/basecamp.png")
|
41
|
+
config.add_blog("Riding Rails", "http://weblog.rubyonrails.org/feed/atom.xml", homepage: "http://weblog.rubyonrails.org/")
|
42
|
+
config.add_blog("Signal v. Noise", "https://signalvnoise.com/posts.rss", :short_name: "svn", icon: "https://basecamp.com/assets/general/basecamp.png")
|
42
43
|
end
|
43
44
|
```
|
44
45
|
|
@@ -80,18 +81,33 @@ If we can't find the blog specified in the configuration you'll recieve a Blogpo
|
|
80
81
|
|
81
82
|
### Displaying Entries
|
82
83
|
|
83
|
-
|
84
|
+
#### Single Blog
|
85
|
+
|
86
|
+
There are a couple of helpers included to assist you in displaying your post entries in your app. `blog_posts_for` fetches the most recent posts for a particular blog, sorted by published date. Lets have a look at these in practice in `app/views/dashboard/index.html.haml`:
|
84
87
|
|
85
88
|
```haml
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
%
|
92
|
-
|
93
|
-
|
94
|
-
|
89
|
+
= blog_posts_for('svn', :count => 1) do |blog, posts|
|
90
|
+
- if blog.populated?
|
91
|
+
%h4 Latest News
|
92
|
+
%ul.blog-posts
|
93
|
+
- posts.each do |post|
|
94
|
+
%li.post
|
95
|
+
%span.title= post.title
|
96
|
+
%span.description= truncate post.description, :length => 90
|
97
|
+
%span.published= post.published_at.strftime("%-d %b %H:%M")
|
98
|
+
%span.link= link_to "Read More...", post.link
|
95
99
|
```
|
96
100
|
|
97
101
|
Note that you can optionally pass `count` to `blog_posts_for` to only get the n-latest posts. By default this is 3.
|
102
|
+
|
103
|
+
#### Mutliple Blogs
|
104
|
+
|
105
|
+
If you'd like to render all of the blogs configured in Blogpostify you can call `all_blogs` in your view. Your block will get passed the Blog object and an array of posts.
|
106
|
+
|
107
|
+
```haml
|
108
|
+
- all_blogs(:count => 3) do |blog, posts|
|
109
|
+
%h4= link_to blog.name, blog.homepage
|
110
|
+
%ul.blog_posts
|
111
|
+
- posts.each do |post|
|
112
|
+
%li= link_to post.title, post.link
|
113
|
+
```
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class CreatePosts < ActiveRecord::Migration
|
2
2
|
def change
|
3
|
-
create_table :blogpostify_posts do |t|
|
4
|
-
t.string :
|
3
|
+
create_table :blogpostify_posts, force: true do |t|
|
4
|
+
t.string :blog_id
|
5
5
|
t.string :title
|
6
6
|
t.text :description
|
7
7
|
t.string :guid
|
@@ -10,5 +10,7 @@ class CreatePosts < ActiveRecord::Migration
|
|
10
10
|
|
11
11
|
t.timestamps
|
12
12
|
end
|
13
|
+
|
14
|
+
add_index :blogpostify_posts, :blog_id
|
13
15
|
end
|
14
16
|
end
|
data/lib/blogpostify/blog.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
module Blogpostify
|
2
2
|
class Blog
|
3
3
|
|
4
|
-
attr_accessor :title, :url, :short_name, :icon
|
4
|
+
attr_accessor :title, :url, :short_name, :icon, :homepage
|
5
5
|
|
6
|
-
def initialize(title, url,
|
6
|
+
def initialize(title, url, options={})
|
7
7
|
self.title = title
|
8
8
|
self.url = url
|
9
|
-
self.short_name = short_name
|
10
|
-
self.icon = icon
|
9
|
+
self.short_name = options[:short_name]
|
10
|
+
self.icon = options[:icon]
|
11
|
+
self.homepage = options[:homepage]
|
11
12
|
end
|
12
13
|
|
13
14
|
def update_posts
|
@@ -27,7 +28,11 @@ module Blogpostify
|
|
27
28
|
end
|
28
29
|
|
29
30
|
def posts
|
30
|
-
Post.where(:
|
31
|
+
Post.where(:blog_id => self.short_name).asc
|
32
|
+
end
|
33
|
+
|
34
|
+
def populated?
|
35
|
+
posts.exists?
|
31
36
|
end
|
32
37
|
|
33
38
|
def short_name
|
data/lib/blogpostify/engine.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
module Blogpostify
|
2
2
|
class Engine < ::Rails::Engine
|
3
3
|
|
4
|
-
|
5
|
-
config.paths["db/migrate"].expanded.each do |expanded_path|
|
6
|
-
app.config.paths["db/migrate"] << expanded_path
|
7
|
-
end
|
4
|
+
engine_name 'blogpostify'
|
8
5
|
|
6
|
+
initializer 'blogpostify.initialize' do |app|
|
9
7
|
ActiveSupport.on_load :action_controller do
|
10
8
|
helper Blogpostify::ViewHelpers
|
11
9
|
end
|
data/lib/blogpostify/post.rb
CHANGED
@@ -5,7 +5,7 @@ module Blogpostify
|
|
5
5
|
|
6
6
|
scope :asc, -> { order(:published_at).reverse_order }
|
7
7
|
|
8
|
-
validates :guid, :uniqueness => { :scope => :
|
8
|
+
validates :guid, :uniqueness => { :scope => :blog_id }
|
9
9
|
|
10
10
|
class << self
|
11
11
|
|
@@ -13,10 +13,10 @@ module Blogpostify
|
|
13
13
|
|
14
14
|
def create_from_item(blog_name, post_item)
|
15
15
|
post = self.new
|
16
|
-
post.
|
16
|
+
post.blog_id = blog_name
|
17
17
|
post.title = post_item.title
|
18
18
|
post.description = sanitize_description(post_item.description)
|
19
|
-
post.guid = post_item.guid.content
|
19
|
+
post.guid = post_item.guid.content.to_s
|
20
20
|
post.published_at = post_item.pubDate
|
21
21
|
post.link = post_item.link
|
22
22
|
post.save
|
@@ -31,5 +31,9 @@ module Blogpostify
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
def blog
|
35
|
+
@blog ||= Blogpostify.find_blog!(self.blog_id)
|
36
|
+
end
|
37
|
+
|
34
38
|
end
|
35
39
|
end
|
data/lib/blogpostify/version.rb
CHANGED
@@ -1,25 +1,30 @@
|
|
1
1
|
module Blogpostify
|
2
2
|
module ViewHelpers
|
3
3
|
|
4
|
-
def
|
4
|
+
def blog_posts_for(blog_name, options={}, &block)
|
5
5
|
blog = Blogpostify.find_blog!(blog_name)
|
6
|
-
|
6
|
+
|
7
|
+
if block_given?
|
8
|
+
yield blog, get_posts(blog, options)
|
9
|
+
return nil # Block should do all of the rendering
|
10
|
+
end
|
7
11
|
end
|
8
12
|
|
9
|
-
def
|
13
|
+
def all_blogs(options={}, &block)
|
14
|
+
Blogpostify.blogs.each do |blog|
|
15
|
+
yield blog, get_posts(blog, options) if block_given?
|
16
|
+
end
|
17
|
+
return nil
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def get_posts(blog, options={})
|
10
23
|
options.reverse_merge!({
|
11
24
|
:count => 3
|
12
25
|
})
|
13
26
|
|
14
|
-
blog
|
15
|
-
posts_scope = blog.posts.asc.limit(options[:count])
|
16
|
-
|
17
|
-
if block_given?
|
18
|
-
posts_scope.each {|post| yield post }
|
19
|
-
return nil # Block should do all of the rendering
|
20
|
-
else
|
21
|
-
posts_scope.to_a
|
22
|
-
end
|
27
|
+
blog.posts.asc.limit(options[:count]).to_a
|
23
28
|
end
|
24
29
|
|
25
30
|
end
|
data/lib/blogpostify.rb
CHANGED
@@ -16,8 +16,8 @@ module Blogpostify
|
|
16
16
|
@blogs ||= []
|
17
17
|
end
|
18
18
|
|
19
|
-
def add_blog(title, url,
|
20
|
-
self.blogs << Blog.new(title, url,
|
19
|
+
def add_blog(title, url, options={})
|
20
|
+
self.blogs << Blog.new(title, url, options)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|