Permalink
Browse files

More rails 3 support

  • Loading branch information...
1 parent 80b0b1c commit 06fa627bc1c773f96b39fbf6e1166f3d44bc05ff @ryanstout committed May 29, 2010
View
@@ -96,6 +96,12 @@ Optional:
gem install bluecloth
+Rails 3
+=======
+
+Rails 3 is supported, however, if you are using legacy routing, you may need to copy in routes from config/routes.rb to
+your main routes.rb file
+
Customization
=============
View
@@ -11,8 +11,13 @@ class BlogPost < ActiveRecord::Base
validates_presence_of :title
validates_presence_of :body
- named_scope :published, { :conditions => {:published => true }}
- named_scope :drafts, { :conditions => {:published => false }}
+ if defined?(Rails) && Rails::VERSION::MAJOR >= 3
+ scope :published, { :conditions => {:published => true }}
+ scope :drafts, { :conditions => {:published => false }}
+ else
+ named_scope :published, { :conditions => {:published => true }}
+ named_scope :drafts, { :conditions => {:published => false }}
+ end
before_save :check_published
@@ -30,7 +35,9 @@ def show_user?
def user_name(skip_link=false)
if !skip_link && BlogKit.instance.settings['link_to_user']
- return "<a href=\"/users/#{self.user.id}\">#{self.user.name}</a>"
+ link = "<a href=\"/users/#{self.user.id}\">#{self.user.name}</a>"
+ return link.html_safe if link.respond_to?(:html_safe)
+ return link
else
return self.user.name
end
View
@@ -2,7 +2,7 @@
# Rails 3
Rails.application.routes.draw do |map|
resources :blog_posts do
- resource :blog_comments
+ resources :blog_comments
collection do
get :drafts
View
@@ -1,4 +1,4 @@
require File.dirname(__FILE__) + "/lib/blog_kit"
# Setup blog kit
-# BlogKit.instance
+BlogKit.instance
@@ -1,8 +1,9 @@
+require 'rubygems'
begin
require 'bluecloth'
rescue Exception => e
require 'erb'
- puts "Could not load bluecloth"
+ puts "Could not load bluecloth #{e.inspect}"
end
begin
require 'uv'
@@ -13,11 +14,12 @@
module BlogKitModelHelper
def code_highlight_and_markdown(text, markdown_options = {})
+ puts "TEXT: #{text.inspect}"
text_pieces = text.split(/(<code>|<code lang="[A-Za-z0-9_-]+">|
<code lang='[A-Za-z0-9_-]+'>|<\/code>)/)
in_pre = false
language = nil
- text_pieces.collect do |piece|
+ post = text_pieces.collect do |piece|
if piece =~ /^<code( lang=(["'])?(.*)\2)?>$/
language = $3
in_pre = true
@@ -37,16 +39,20 @@ def code_highlight_and_markdown(text, markdown_options = {})
if defined?(BlueCloth)
BlueCloth.new(piece, markdown_options).to_html
else
+ puts "HTML ESCAPE"
ERB::Util.html_escape(piece)
end
end
- end
+ end.join('')
+
+ return post.html_safe if post.respond_to?(:html_safe)
+ return post
end
def user_image_tag
if self.user && self.user.respond_to?(:blog_image_url) && self.user.blog_image_url
# Load image from model
- return "<img src=\"#{self.user.blog_image_url}\" />"
+ ret = "<img src=\"#{self.user.blog_image_url}\" />"
elsif BlogKit.instance.settings['gravatar']
# Gravatar
require 'digest/md5'
@@ -59,10 +65,13 @@ def user_image_tag
end
hash = Digest::MD5.hexdigest(email.downcase)
- return "<img src=\"http://www.gravatar.com/avatar/#{hash}.jpg\" />"
+ ret = "<img src=\"http://www.gravatar.com/avatar/#{hash}.jpg\" />"
else
# No Image
return ''
end
+
+ return ret.html_safe if ret.respond_to?(:html_safe)
+ return ret
end
end
@@ -1,35 +1,94 @@
-class BlogAssetsGenerator < Rails::Generator::Base
- def manifest
- record do |m|
- m.migration_template 'blog_comments_migration.rb', "db/migrate", {:migration_file_name => "create_blog_comments"}
- m.migration_template 'blog_posts_migration.rb', "db/migrate", {:migration_file_name => "create_blog_posts"}
- m.file "config/blog_kit.yml", "config/blog_kit.yml"
- m.file "blog_kit.css", "public/stylesheets/blog_kit.css"
+if defined?(Rails) && Rails::VERSION::MAJOR >= 3
+ require 'rails/generators/migration'
+ class BlogAssetsGenerator < Rails::Generators::Base
+ include Rails::Generators::Migration
+
+ def self.next_migration_number(dirname)
+ if ActiveRecord::Base.timestamped_migrations
+ @current_time ||= Time.now
+ @current_time += 1
+ @current_time.utc.strftime("%Y%m%d%H%M%S")
+ else
+ "%.3d" % (current_migration_number(dirname) + 1)
+ end
+ end
+
+
+ def self.source_root
+ @source_root ||= File.join(File.dirname(__FILE__), 'templates')
+ end
+
+ def create_assets
+ migration_template 'blog_comments_migration.rb', "db/migrate/create_blog_comments.rb"
+ migration_template 'blog_posts_migration.rb', "db/migrate/create_blog_posts.rb"
+ copy_file "config/blog_kit.yml", "config/blog_kit.yml"
+ copy_file "blog_kit.css", "public/stylesheets/blog_kit.css"
+
# Copy highlighting bundles
- m.directory "public/stylesheets/syntax"
- m.file "syntax/active4d.css", "public/stylesheets/syntax/active4d.css"
- m.file "syntax/all_hallows_eve.css", "public/stylesheets/syntax/all_hallows_eve.css"
- m.file "syntax/amy.css", "public/stylesheets/syntax/amy.css"
- m.file "syntax/blackboard.css", "public/stylesheets/syntax/blackboard.css"
- m.file "syntax/brilliance_black.css", "public/stylesheets/syntax/brilliance_black.css"
- m.file "syntax/brilliance_dull.css", "public/stylesheets/syntax/brilliance_dull.css"
- m.file "syntax/cobalt.css", "public/stylesheets/syntax/cobalt.css"
- m.file "syntax/dawn.css", "public/stylesheets/syntax/dawn.css"
- m.file "syntax/eiffel.css", "public/stylesheets/syntax/eiffel.css"
- m.file "syntax/espresso_libre.css", "public/stylesheets/syntax/espresso_libre.css"
- m.file "syntax/idle.css", "public/stylesheets/syntax/idle.css"
- m.file "syntax/iplastic.css", "public/stylesheets/syntax/iplastic.css"
- m.file "syntax/lazy.css", "public/stylesheets/syntax/lazy.css"
- m.file "syntax/mac_classic.css", "public/stylesheets/syntax/mac_classic.css"
- m.file "syntax/magicwb_amiga.css", "public/stylesheets/syntax/magicwb_amiga.css"
- m.file "syntax/pastels_on_dark.css", "public/stylesheets/syntax/pastels_on_dark.css"
- m.file "syntax/slush_poppies.css", "public/stylesheets/syntax/slush_poppies.css"
- m.file "syntax/spacecadet.css", "public/stylesheets/syntax/spacecadet.css"
- m.file "syntax/sunburst.css", "public/stylesheets/syntax/sunburst.css"
- m.file "syntax/twilight.css", "public/stylesheets/syntax/twilight.css"
- m.file "syntax/zenburnesque.css", "public/stylesheets/syntax/zenburnesque.css"
+ empty_directory "public/stylesheets/syntax"
+ copy_file "syntax/active4d.css", "public/stylesheets/syntax/active4d.css"
+ copy_file "syntax/all_hallows_eve.css", "public/stylesheets/syntax/all_hallows_eve.css"
+ copy_file "syntax/amy.css", "public/stylesheets/syntax/amy.css"
+ copy_file "syntax/blackboard.css", "public/stylesheets/syntax/blackboard.css"
+ copy_file "syntax/brilliance_black.css", "public/stylesheets/syntax/brilliance_black.css"
+ copy_file "syntax/brilliance_dull.css", "public/stylesheets/syntax/brilliance_dull.css"
+ copy_file "syntax/cobalt.css", "public/stylesheets/syntax/cobalt.css"
+ copy_file "syntax/dawn.css", "public/stylesheets/syntax/dawn.css"
+ copy_file "syntax/eiffel.css", "public/stylesheets/syntax/eiffel.css"
+ copy_file "syntax/espresso_libre.css", "public/stylesheets/syntax/espresso_libre.css"
+ copy_file "syntax/idle.css", "public/stylesheets/syntax/idle.css"
+ copy_file "syntax/iplastic.css", "public/stylesheets/syntax/iplastic.css"
+ copy_file "syntax/lazy.css", "public/stylesheets/syntax/lazy.css"
+ copy_file "syntax/mac_classic.css", "public/stylesheets/syntax/mac_classic.css"
+ copy_file "syntax/magicwb_amiga.css", "public/stylesheets/syntax/magicwb_amiga.css"
+ copy_file "syntax/pastels_on_dark.css", "public/stylesheets/syntax/pastels_on_dark.css"
+ copy_file "syntax/slush_poppies.css", "public/stylesheets/syntax/slush_poppies.css"
+ copy_file "syntax/spacecadet.css", "public/stylesheets/syntax/spacecadet.css"
+ copy_file "syntax/sunburst.css", "public/stylesheets/syntax/sunburst.css"
+ copy_file "syntax/twilight.css", "public/stylesheets/syntax/twilight.css"
+ copy_file "syntax/zenburnesque.css", "public/stylesheets/syntax/zenburnesque.css"
+ end
+ end
+else
+ # Rails 2.x
+ class BlogAssetsGenerator < Rails::Generator::Base
+ def self.source_root
+ @source_root ||= File.join(File.dirname(__FILE__), 'templates')
+ end
+
+ def manifest
+ record do |m|
+ m.migration_template 'blog_comments_migration.rb', "db/migrate", {:migration_file_name => "create_blog_comments"}
+ m.migration_template 'blog_posts_migration.rb', "db/migrate", {:migration_file_name => "create_blog_posts"}
+ m.file "config/blog_kit.yml", "config/blog_kit.yml"
+ m.file "blog_kit.css", "public/stylesheets/blog_kit.css"
- end
- end
+ # Copy highlighting bundles
+ m.directory "public/stylesheets/syntax"
+ m.file "syntax/active4d.css", "public/stylesheets/syntax/active4d.css"
+ m.file "syntax/all_hallows_eve.css", "public/stylesheets/syntax/all_hallows_eve.css"
+ m.file "syntax/amy.css", "public/stylesheets/syntax/amy.css"
+ m.file "syntax/blackboard.css", "public/stylesheets/syntax/blackboard.css"
+ m.file "syntax/brilliance_black.css", "public/stylesheets/syntax/brilliance_black.css"
+ m.file "syntax/brilliance_dull.css", "public/stylesheets/syntax/brilliance_dull.css"
+ m.file "syntax/cobalt.css", "public/stylesheets/syntax/cobalt.css"
+ m.file "syntax/dawn.css", "public/stylesheets/syntax/dawn.css"
+ m.file "syntax/eiffel.css", "public/stylesheets/syntax/eiffel.css"
+ m.file "syntax/espresso_libre.css", "public/stylesheets/syntax/espresso_libre.css"
+ m.file "syntax/idle.css", "public/stylesheets/syntax/idle.css"
+ m.file "syntax/iplastic.css", "public/stylesheets/syntax/iplastic.css"
+ m.file "syntax/lazy.css", "public/stylesheets/syntax/lazy.css"
+ m.file "syntax/mac_classic.css", "public/stylesheets/syntax/mac_classic.css"
+ m.file "syntax/magicwb_amiga.css", "public/stylesheets/syntax/magicwb_amiga.css"
+ m.file "syntax/pastels_on_dark.css", "public/stylesheets/syntax/pastels_on_dark.css"
+ m.file "syntax/slush_poppies.css", "public/stylesheets/syntax/slush_poppies.css"
+ m.file "syntax/spacecadet.css", "public/stylesheets/syntax/spacecadet.css"
+ m.file "syntax/sunburst.css", "public/stylesheets/syntax/sunburst.css"
+ m.file "syntax/twilight.css", "public/stylesheets/syntax/twilight.css"
+ m.file "syntax/zenburnesque.css", "public/stylesheets/syntax/zenburnesque.css"
+
+ end
+ end
+ end
end
File renamed without changes.

0 comments on commit 06fa627

Please sign in to comment.