diff --git a/Gemfile b/Gemfile index 416f7ba..0899118 100644 --- a/Gemfile +++ b/Gemfile @@ -4,6 +4,7 @@ gem 'rails', '3.0.3' gem 'sqlite3-ruby', '1.3.2', :require => 'sqlite3', :group => :development gem 'gravatar_image_tag', '1.0.0.pre2' gem 'will_paginate', '3.0.pre2' +gem 'maruku' group :development do gem 'rspec-rails', '2.3.0' diff --git a/Gemfile.lock b/Gemfile.lock index 7ad827c..111745f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -46,6 +46,8 @@ GEM i18n (>= 0.4.0) mime-types (~> 1.16) treetop (~> 1.4.8) + maruku (0.6.0) + syntax (>= 1.0.0) mime-types (1.16) nokogiri (1.4.4.1-x86-mingw32) polyglot (0.3.1) @@ -82,6 +84,7 @@ GEM railties (~> 3.0) rspec (~> 2.3.0) sqlite3-ruby (1.3.2-x86-mingw32) + syntax (1.0.0) thor (0.14.6) treetop (1.4.9) polyglot (>= 0.3.1) @@ -100,6 +103,7 @@ DEPENDENCIES factory_girl_rails (= 1.0) faker (= 0.3.1) gravatar_image_tag (= 1.0.0.pre2) + maruku rails (= 3.0.3) rspec (= 2.3.0) rspec-rails (= 2.3.0) diff --git a/app/controllers/blogs_controller.rb b/app/controllers/blogs_controller.rb index 253e039..d598da1 100644 --- a/app/controllers/blogs_controller.rb +++ b/app/controllers/blogs_controller.rb @@ -1,2 +1,9 @@ class BlogsController < ApplicationController + + def destroy + redirect_to root_path unless signed_in? + @blog = Blog.find(params[:id]) + @blog.destroy + redirect_to blogs_path, :flash => { :success => "Blog deleted!" } + end end diff --git a/app/controllers/microposts_controller.rb b/app/controllers/microposts_controller.rb index 2b16ac9..f875040 100644 --- a/app/controllers/microposts_controller.rb +++ b/app/controllers/microposts_controller.rb @@ -5,7 +5,8 @@ class MicropostsController < ApplicationController def create success_message = "Micropost created!" @micropost = current_user.microposts.build(params[:micropost]) - + puts params[:micropost] + if Blog.is_blog_post? params[:micropost][:content] current_user.blogs.create_with_post params[:micropost][:content] success_message = "Blog created!" diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 7914d1a..66e493d 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -37,7 +37,8 @@ def create @user = User.new(params[:user]) if @user.save sign_in @user - redirect_to @user, :flash => { :success => "Welcome to the Sample App!" } + @user.follow_all + redirect_to @user, :flash => { :success => "Welcome to the Sample App!" } else @title = "Sign up" render 'new' diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 5e4c3f8..c1f83aa 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2,7 +2,7 @@ module ApplicationHelper # Return a title on a per-page basis. def title - base_title = "Ruby on Rails Tutorial Sample App" + base_title = "Geronimo!" if @title.nil? base_title else diff --git a/app/models/blog.rb b/app/models/blog.rb index 3c7ae4d..400afd4 100644 --- a/app/models/blog.rb +++ b/app/models/blog.rb @@ -11,10 +11,17 @@ # updated_at :datetime # +require 'maruku' + class Blog < ActiveRecord::Base belongs_to :user + def to_html + doc = Maruku.new(blogtext) + doc.to_html + end + class << self def latest_for_frontpage self.where(:frontpage => true).last @@ -32,14 +39,8 @@ def new_from_post(post) end end - def get_blog_text(post) - post_array = post.split() - if(is_front_page? post) - post_array.shift(2) - else - post_array.shift(1) - end - post_array.join(' ') + def get_blog_text(post) + post.gsub(/blog\sfrontpage\s|blog\s/, '') end def is_blog_post?(post) diff --git a/app/models/show.rb b/app/models/show.rb index 91e17de..886bf78 100644 --- a/app/models/show.rb +++ b/app/models/show.rb @@ -12,6 +12,12 @@ class Show < ActiveRecord::Base + + def to_html + doc = Maruku.new(showtext) + doc.to_html + end + class << self def next_show() @@ -74,9 +80,7 @@ def get_date(post) end def get_show_text(post) - post_array = post.split() - post_array.shift(1) - post_array.join(' ') + post.gsub(/^show\s/,'') end end -end +end \ No newline at end of file diff --git a/app/models/user.rb b/app/models/user.rb index 335f415..b45929c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -65,6 +65,15 @@ def follow!(followed) def unfollow!(followed) relationships.find_by_followed_id(followed).destroy end + + def follow_all + User.all.each { |u| + if u != self + u.follow! (self) + self.follow! (u) + end + } + end class << self def authenticate(email, submitted_password) diff --git a/app/views/blogs/_blog.html.erb b/app/views/blogs/_blog.html.erb index 8303015..7ea5ca6 100644 --- a/app/views/blogs/_blog.html.erb +++ b/app/views/blogs/_blog.html.erb @@ -1,6 +1,6 @@