siyelo-blogify 0.1.2

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.
@@ -0,0 +1,12 @@
1
+ == 0.1.1
2
+
3
+ * initial commit
4
+
5
+ * enhancements
6
+ * n/a
7
+
8
+ * bug fix
9
+ * n/a
10
+
11
+ * deprecation
12
+ * none
@@ -0,0 +1,20 @@
1
+ Copyright 2010 Siyelo. http://www.siyelo.com
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,94 @@
1
+ == Blogify
2
+
3
+ A Rails engine for embedding Posterous blog extracts
4
+
5
+ == Dependencies
6
+
7
+ Blogify needs;
8
+
9
+ glennr-posterous (may also work with the original posterous gem)
10
+ httparty (a requirement of the posterous gem)
11
+ rufus-scheduler (for caching the blog posts in the background)
12
+
13
+ == Installation
14
+
15
+ All gems are on gemcutter, so you need to add gemcutter to your sources if you havent yet:
16
+
17
+ sudo gem sources -a http://gemcutter.org/
18
+
19
+ Install required gem if you dont already have them
20
+
21
+ sudo gem install httparty
22
+ sudo gem install glennr-posterous
23
+ sudo gem install rufus-scheduler
24
+
25
+ Install the blogify gem:
26
+
27
+ sudo gem install siyelo-blogify
28
+
29
+ Configure gems inside your app:
30
+
31
+ config.gem 'httparty'
32
+ config.gem 'glennr-posterous', :lib => "posterous"
33
+ config.gem 'rufus-scheduler'
34
+ config.gem 'siyelo-blogify', :lib => "blogify"
35
+
36
+ Run the generator:
37
+
38
+ ruby script/generate blogify_install
39
+
40
+ And you're ready to go. The generator will install an initializer which describes ALL Blogify's configuration options, so be sure to take a look at it.
41
+
42
+ == Basic Usage
43
+
44
+ Once the rufus scheduler task is running, it will go off and cache your last N (BlogPost.post_limit) blog posts locally
45
+
46
+ Inside your relevant controller, all you need to do is read the cached posts from your database.
47
+
48
+ @blog_posts = BlogPost.find(:all, :limit => BLOG_POST_LIMIT)
49
+
50
+ And render them in your view as you wish
51
+
52
+ For convenience, some partials are included
53
+
54
+ = render :partial => '/blog_posts/list', :locals => { :blog_posts => @news_posts }
55
+
56
+ == Advanced Usage
57
+
58
+ Blogify can also work with multiple Posterous blogs. The BlogPost model is compatible with STI, so all you need to do is subclass it. E.g. in app/models/news_post.rb
59
+
60
+ def NewsPost < BlogPost
61
+ ...
62
+ end
63
+
64
+ You'll need to set up your rufus cron task to cache the relevant blog posts
65
+
66
+ scheduler.every '1h' do
67
+ ...
68
+ NewsPost.cache_posts( 'some_other_posterous_user', 5)
69
+ end
70
+
71
+ And the controller/views work pretty much the same
72
+
73
+ @news_posts = NewsPost.find(:all, :limit => BLOG_POST_LIMIT)
74
+
75
+ == TODO
76
+
77
+ Please refer to TODO file.
78
+
79
+ == Maintainers
80
+
81
+ * Glenn Roberts
82
+
83
+ == Contributors
84
+
85
+ Check them in the CHANGELOG or do `git shortlog -s -n` in the cloned repository.
86
+
87
+ == Bugs and Feedback
88
+
89
+ If you discover any bugs or want to drop a line, feel free to create an issue on
90
+ GitHub.
91
+
92
+ http://github.com/siyelo/blogify/issues
93
+
94
+ MIT License. Copyright 2010. Siyelo Software CC. http://www.siyelo.com
@@ -0,0 +1,44 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+
6
+ begin
7
+ require 'jeweler'
8
+ Jeweler::Tasks.new do |gem|
9
+ gem.name = "siyelo-blogify"
10
+ gem.summary = %Q{A Rails engine for embedding Posterous blog extracts}
11
+ gem.description = %Q{A Rails engine for embedding Posterous blog extracts}
12
+ gem.email = "glenn.roberts@siyelo.com"
13
+ gem.homepage = "http://github.com/siyelo/siyelo-blogify"
14
+ gem.authors = ["Glenn Roberts"]
15
+ gem.add_development_dependency "glennr-posterous", ">= 0.1.7"
16
+ gem.add_development_dependency "httparty", '>=0.5.0'
17
+ gem.add_development_dependency 'rufus-scheduler', '>=2.0.3'
18
+ gem.files = FileList["[A-Z]*", "{app,config,generators,lib}/**/*", "init.rb"]
19
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
20
+ end
21
+ Jeweler::GemcutterTasks.new
22
+ rescue LoadError
23
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
24
+ end
25
+
26
+ desc 'Run Blogify unit tests.'
27
+ Rake::TestTask.new(:test) do |t|
28
+ t.libs << 'lib'
29
+ t.libs << 'test'
30
+ t.pattern = 'test/**/*_test.rb'
31
+ t.verbose = true
32
+ end
33
+
34
+ desc 'Generate documentation for Blogify.'
35
+ Rake::RDocTask.new(:rdoc) do |rdoc|
36
+ rdoc.rdoc_dir = 'rdoc'
37
+ rdoc.title = 'Blogify'
38
+ rdoc.options << '--line-numbers' << '--inline-source'
39
+ rdoc.rdoc_files.include('README.rdoc')
40
+ rdoc.rdoc_files.include('lib/**/*.rb')
41
+ end
42
+
43
+ desc 'Default: run unit tests.'
44
+ task :default => :test
data/TODO ADDED
@@ -0,0 +1,3 @@
1
+
2
+ write tests
3
+ test the app with the posterous gem (not glennr-posterous)
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.2
@@ -0,0 +1,9 @@
1
+ module BlogPostsHelper
2
+
3
+ def pluralize_if(count, string)
4
+ result = "#{count.to_s} #{string.pluralize}"
5
+ result = "#{count.to_s} #{string}" if count == 1
6
+ result
7
+ end
8
+
9
+ end
@@ -0,0 +1,62 @@
1
+ class BlogPost < ActiveRecord::Base
2
+
3
+ cattr_accessor :default_posterous_user
4
+ @@default_posterous_user = nil
5
+
6
+ cattr_accessor :read_timeout
7
+ @@read_timeout = 5.seconds
8
+
9
+ cattr_accessor :post_limit
10
+ @@post_limit = 3
11
+
12
+ cattr_accessor :debug
13
+ @@debug = false
14
+
15
+ attr_accessible :title, :body, :url, :comment_count, :posted
16
+
17
+
18
+ def self.cache_posts( posterous_user = default_posterous_user, count = post_limit )
19
+ posts = self.read_posts( posterous_user, count)
20
+ self.update_posts(posts)
21
+ end
22
+
23
+ protected
24
+
25
+ def self.read_posts( posterous_user, count )
26
+ posts = []
27
+ begin
28
+ timeout(read_timeout) do
29
+ reader = Posterous::Reader.new(posterous_user, nil, count)
30
+ posts = reader.response
31
+ if !reader.response[0] # then we only got one result
32
+ posts = [reader.response] # force it into an hash of hashes
33
+ end
34
+ end
35
+ rescue TimeoutError
36
+ logger.warn("Timeout accessing Posterous Blog: #{$!}, #{$@}")
37
+ rescue
38
+ logger.warn("Error accessing Posterous blog: #{$!}")
39
+ end
40
+
41
+ posts
42
+ end
43
+
44
+ def self.update_posts(posts)
45
+ unless posts.empty?
46
+ old_posts = self.find(:all, :order => 'created_at')
47
+
48
+ posts.each do |p|
49
+ b = self.new( :title => p['title'],
50
+ :body => p['body'],
51
+ :url => p['link'],
52
+ :comment_count => p['commentsCount'].to_i,
53
+ :posted => p['date'].to_date)
54
+
55
+ b.save
56
+ # expire oldest
57
+ old_posts.pop.destroy unless old_posts.empty?
58
+ end
59
+ end
60
+ end
61
+
62
+ end
@@ -0,0 +1,13 @@
1
+ - posts = []
2
+ - posts = blog_posts if !blog_posts.nil?
3
+
4
+ .blog_posts
5
+ - posts.each do |p|
6
+ - comment_count = p.comment_count.to_i
7
+ .post
8
+ .top
9
+ %p
10
+ %span.gray= time_ago_in_words(p.posted) + " ago"
11
+ = link_to pluralize_if(comment_count,"comment"), p.url
12
+ .bottom
13
+ %p= link_to h(p.title), p.url
@@ -0,0 +1,15 @@
1
+ - posts = []
2
+ - posts = blog_posts if !blog_posts.nil?
3
+
4
+ .blog_posts
5
+ - posts.each do |p|
6
+ - comment_count = p.comment_count.to_i
7
+ .post
8
+ .top
9
+ %p= link_to h(p.title), p.url
10
+ .body
11
+ %p= h(Sanitize.clean(p.body.first(300))) + "... " + link_to("Read More", p.url)
12
+ .bottom
13
+ = link_to pluralize_if(comment_count,"comment"), p.url
14
+ %span= " | "
15
+ %span.gray= time_ago_in_words(p.posted) + " ago"
@@ -0,0 +1,4 @@
1
+ To copy a Blogify initializer & migration & partials to your Rails App, with some configuration values, just do:
2
+
3
+ script/generate blogify_install
4
+
@@ -0,0 +1,15 @@
1
+
2
+ class BlogifyInstallGenerator < Rails::Generator::Base
3
+
4
+ def manifest
5
+ record do |m|
6
+
7
+ m.migration_template 'migration.rb', 'db/migrate', :migration_file_name => "blogify_create_blog_posts"
8
+
9
+ m.directory "config/initializers"
10
+ m.template "blogify.rb", "config/initializers/blogify.rb"
11
+
12
+ end
13
+ end
14
+
15
+ end
@@ -0,0 +1,13 @@
1
+
2
+ ===============================================================================
3
+
4
+ Some setup you must do manually if you haven't yet:
5
+
6
+ 1. Ensure you have defined your Posterous user name in config/blogify.rb
7
+
8
+ 2. Run rake db:migrate to create the BlogPosts table.
9
+
10
+ Note: the initializer creates its own Rufus scheduler task - so if you have
11
+ other Rufus tasks, you may want to consolidate them.
12
+
13
+ ===============================================================================
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'rufus/scheduler'
3
+
4
+ # BlogPost.default_posterous_user = 'CHANGEME'
5
+
6
+ scheduler = Rufus::Scheduler.start_new(:frequency => 900.0)
7
+
8
+ scheduler.every '1h' do
9
+ BlogPost.cache_posts
10
+ #BlogPostSubclass.cache_posts( 'some_other_posterous_user', 5)
11
+ end
@@ -0,0 +1,18 @@
1
+ class BlogifyCreateBlogPosts < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :blog_posts do |t|
4
+ t.string :type
5
+ t.string :title
6
+ t.text :body
7
+ t.integer :comment_count
8
+ t.string :url
9
+ t.date :posted
10
+
11
+ t.timestamps
12
+ end
13
+ end
14
+
15
+ def self.down
16
+ drop_table :blog_posts
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ To copy the view partials from blogify to your app just run the following command:
2
+
3
+ script/generate blogify_views
@@ -0,0 +1,21 @@
1
+ class BlogifyViewsGenerator < Rails::Generator::Base
2
+
3
+ def initialize(*args)
4
+ super
5
+ @source_root = options[:source] || File.join(spec.path, '..', '..')
6
+ end
7
+
8
+ def manifest
9
+ record do |m|
10
+ m.directory "app/views"
11
+
12
+ Dir[File.join(@source_root, "app", "views", "**/*.haml")].each do |file|
13
+ file = file.gsub(@source_root, "")[1..-1]
14
+
15
+ m.directory File.dirname(file)
16
+ m.file file, file
17
+ end
18
+ end
19
+ end
20
+
21
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'blogify'
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'posterous'
3
+ rescue
4
+ gem 'glennr-posterous'
5
+ require 'posterous'
6
+ end
7
+
8
+ begin
9
+ require 'rufus/scheduler'
10
+ rescue
11
+ gem 'rufus-scheduler'
12
+ require 'rufus/scheduler'
13
+ end
14
+
15
+ begin
16
+ require 'httparty'
17
+ rescue
18
+ gem 'httparty'
19
+ require 'httparty'
20
+ end
21
+
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+ require 'performance_test_help'
3
+
4
+ # Profiling results for each test method are written to tmp/performance.
5
+ class BrowsingTest < ActionController::PerformanceTest
6
+ def test_homepage
7
+ get '/'
8
+ end
9
+ end
@@ -0,0 +1,38 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+ require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
3
+ require 'test_help'
4
+
5
+ class ActiveSupport::TestCase
6
+ # Transactional fixtures accelerate your tests by wrapping each test method
7
+ # in a transaction that's rolled back on completion. This ensures that the
8
+ # test database remains unchanged so your fixtures don't have to be reloaded
9
+ # between every test method. Fewer database queries means faster tests.
10
+ #
11
+ # Read Mike Clark's excellent walkthrough at
12
+ # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
13
+ #
14
+ # Every Active Record database supports transactions except MyISAM tables
15
+ # in MySQL. Turn off transactional fixtures in this case; however, if you
16
+ # don't care one way or the other, switching from MyISAM to InnoDB tables
17
+ # is recommended.
18
+ #
19
+ # The only drawback to using transactional fixtures is when you actually
20
+ # need to test transactions. Since your test is bracketed by a transaction,
21
+ # any transactions started in your code will be automatically rolled back.
22
+ self.use_transactional_fixtures = true
23
+
24
+ # Instantiated fixtures are slow, but give you @david where otherwise you
25
+ # would need people(:david). If you don't want to migrate your existing
26
+ # test cases which use the @david style and don't mind the speed hit (each
27
+ # instantiated fixtures translates to a database query per test method),
28
+ # then set this back to true.
29
+ self.use_instantiated_fixtures = false
30
+
31
+ # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
32
+ #
33
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
34
+ # -- they do not yet inherit this setting
35
+ fixtures :all
36
+
37
+ # Add more helper methods to be used by all tests here...
38
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class BlogPostTest < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: siyelo-blogify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Glenn Roberts
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-03-08 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: glennr-posterous
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.1.7
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: httparty
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.5.0
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: rufus-scheduler
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 2.0.3
44
+ version:
45
+ description: A Rails engine for embedding Posterous blog extracts
46
+ email: glenn.roberts@siyelo.com
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - README.rdoc
53
+ - TODO
54
+ files:
55
+ - CHANGELOG
56
+ - MIT-LICENSE
57
+ - README.rdoc
58
+ - Rakefile
59
+ - TODO
60
+ - VERSION
61
+ - app/helpers/blog_posts_helper.rb
62
+ - app/models/blog_post.rb
63
+ - app/views/blog_posts/_list.html.haml
64
+ - app/views/blog_posts/_long_list.html.haml
65
+ - generators/blogify_install/USAGE
66
+ - generators/blogify_install/blogify_install_generator.rb
67
+ - generators/blogify_install/templates/README
68
+ - generators/blogify_install/templates/blogify.rb
69
+ - generators/blogify_install/templates/migration.rb
70
+ - generators/blogify_views/USAGE
71
+ - generators/blogify_views/blogify_views_generator.rb
72
+ - init.rb
73
+ - lib/blogify.rb
74
+ has_rdoc: true
75
+ homepage: http://github.com/siyelo/siyelo-blogify
76
+ licenses: []
77
+
78
+ post_install_message:
79
+ rdoc_options:
80
+ - --charset=UTF-8
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: "0"
88
+ version:
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: "0"
94
+ version:
95
+ requirements: []
96
+
97
+ rubyforge_project:
98
+ rubygems_version: 1.3.5
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: A Rails engine for embedding Posterous blog extracts
102
+ test_files:
103
+ - test/performance/browsing_test.rb
104
+ - test/test_helper.rb
105
+ - test/unit/blog_post_test.rb