blogpostify 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4a8716c2130ab5e3fbc7636d0e481935f62f6b22
4
- data.tar.gz: bbfd4f0afb1554b3424eb085885361febe6cc76c
3
+ metadata.gz: 4187c3eb2a5ac8073d4186072a590e46e066f139
4
+ data.tar.gz: 0d68d1fca01c54364a8b482d9e4afbe0ad3cb7b9
5
5
  SHA512:
6
- metadata.gz: 7e2f430f148f0df90d72e56ff7c6bfff8f2c98ca2e97479fb54b1c5d8c6b9311da1e7f5ce63d4366879b0ad0fb35a4ad3910f06f493bd5f40e56b405d4dd47db
7
- data.tar.gz: 96e1d7f0a376ceb17b020fb3b15790382e1fd7e93a77b8b3d178859b4e77ba46d64f0ca4d1b4baece36225ceeb1aee1c58f8ba5717b8e16b193ac88df5e9f906
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. If you want to set this to something else, set the third parameter. You can also add a path to an icon that represents this blog if you like.
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
- There are a couple of helpers included to assist you in displaying your post entries in your app. `blog_populated?` allows you to check if any blog posts have been fetched for a blog yet. `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
+ #### 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
- - if blog_populated?('svn')
87
- %h4 Latest News
88
- %ul.blog-posts
89
- = blog_posts_for('svn', :count => 1) do |post|
90
- %li.post
91
- %span.title= post.title
92
- %span.description= truncate post.description, :length => 90
93
- %span.published= post.published_at.strftime("%-d %b %H:%M")
94
- %span.link= link_to "Read More...", post.link
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 :blog
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
@@ -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, short_name, icon)
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(:blog => self.short_name).asc
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
@@ -1,11 +1,9 @@
1
1
  module Blogpostify
2
2
  class Engine < ::Rails::Engine
3
3
 
4
- initializer 'blogpostify.initialize' do |app|
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
@@ -5,7 +5,7 @@ module Blogpostify
5
5
 
6
6
  scope :asc, -> { order(:published_at).reverse_order }
7
7
 
8
- validates :guid, :uniqueness => { :scope => :blog }
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.blog = blog_name
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
@@ -1,3 +1,3 @@
1
1
  module Blogpostify
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -1,25 +1,30 @@
1
1
  module Blogpostify
2
2
  module ViewHelpers
3
3
 
4
- def blog_populated?(blog_name)
4
+ def blog_posts_for(blog_name, options={}, &block)
5
5
  blog = Blogpostify.find_blog!(blog_name)
6
- blog.posts.exists?
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 blog_posts_for(blog_name, options={}, &block)
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 = Blogpostify.find_blog!(blog_name)
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, icon=nil, short_name=nil)
20
- self.blogs << Blog.new(title, url, short_name, icon)
19
+ def add_blog(title, url, options={})
20
+ self.blogs << Blog.new(title, url, options)
21
21
  end
22
22
  end
23
23
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blogpostify
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Wentworth