diff --git a/Gemfile b/Gemfile index 70cc30fb0..86300e1e9 100644 --- a/Gemfile +++ b/Gemfile @@ -8,7 +8,7 @@ group :test do gem "faker" end -gem "rails", "3.0.0.beta" +gem "rails", "3.0.0.beta3" gem "pg" gem "memcache-client", :require => "memcache" gem "imagesize", :require => "image_size" diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 0eca12f53..4171b4be3 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -1,7 +1,27 @@ class CommentsController < ApplicationController + respond_to :html, :xml, :json + def index end def update + @comment = Comment.find(params[:id]) + @comment.update_attributes(params[:comment]) + respond_with(@comment) + end + + def create + @comment = Comment.new(params[:comment]) + @comment.post_id = params[:comment][:post_id] + @comment.creator_id = @current_user.id + @comment.ip_addr = request.remote_ip + @comment.score = 0 + @comment.save + respond_with(@comment) do |format| + format.html do + flash[:notice] = "Comment posted" + redirect_to posts_path(@comment.post) + end + end end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 2acd1302e..c0157128f 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -9,6 +9,10 @@ module ApplicationHelper content_tag("li", link_to(text, url, options), :class => klass) end + def format_text(text, options = {}) + DText.parse(text) + end + protected def nav_link_match(controller, url) url =~ case controller diff --git a/app/helpers/post_helper.rb b/app/helpers/post_helper.rb deleted file mode 100644 index 01357d239..000000000 --- a/app/helpers/post_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module PostHelper -end diff --git a/app/helpers/posts_helper.rb b/app/helpers/posts_helper.rb new file mode 100644 index 000000000..db1e2f370 --- /dev/null +++ b/app/helpers/posts_helper.rb @@ -0,0 +1,27 @@ +module PostsHelper + def image_dimensions(post, current_user) + if post.is_image? + "(#{post.image_width_for(current_user)}x#{post.image_height_for(current_user)})" + else + "" + end + end + + def image_dimension_menu(post, current_user) + html = "" + file_size = number_to_human_size(post.file_size) + original_dimensions = post.is_image? ? "(#{post.image_width}x#{post.image_height})" : nil + large_dimensions = post.has_large? ? "(#{post.large_image_width}x#{post.large_image_height})" : nil + medium_dimensions = post.has_medium? ? "(#{post.medium_image_width}x#{post.medium_image_height})" : nil + current_dimensions = "(#{post.image_width_for(current_user)}x#{post.image_height_for(current_user)})" + html << %{} + html << %{
  • #{file_size} #{current_dimensions}
  • } + html << %{} + html << %{
    } + html.html_safe + end +end diff --git a/app/logical/anonymous_user.rb b/app/logical/anonymous_user.rb index 46cecbccf..dfb3722f2 100644 --- a/app/logical/anonymous_user.rb +++ b/app/logical/anonymous_user.rb @@ -104,6 +104,10 @@ class AnonymousUser "Eastern Time (US & Canada)" end + def default_image_size + "medium" + end + %w(member banned privileged contributor janitor moderator admin).each do |name| define_method("is_#{name}?") do false diff --git a/app/logical/d_text.rb b/app/logical/d_text.rb new file mode 100644 index 000000000..3ec2b8b9c --- /dev/null +++ b/app/logical/d_text.rb @@ -0,0 +1,138 @@ +require 'cgi' + +class DText + def self.parse_inline(str, options = {}) + str = str.gsub(/&/, "&") + str.gsub!(//, ">") + str.gsub!(/\[\[.+?\]\]/m) do |tag| + tag = tag[2..-3] + if tag =~ /^(.+?)\|(.+)$/ + tag = $1 + name = $2 + '' + name + '' + else + '' + tag + '' + end + end + str.gsub!(/\{\{.+?\}\}/m) do |tag| + tag = tag[2..-3] + '' + tag + '' + end + str.gsub!(/[Pp]ost #(\d+)/, 'post #\1') + str.gsub!(/[Ff]orum #(\d+)/, 'forum #\1') + str.gsub!(/[Cc]omment #(\d+)/, 'comment #\1') + str.gsub!(/[Pp]ool #(\d+)/, 'pool #\1') + str.gsub!(/\n/m, "
    ") + str.gsub!(/\[b\](.+?)\[\/b\]/, '\1') + str.gsub!(/\[i\](.+?)\[\/i\]/, '\1') + str.gsub!(/\[spoilers?\](.+?)\[\/spoilers?\]/m, '\1') + str.gsub!(/("[^"]+":(http:\/\/|\/)\S+|http:\/\/\S+)/m) do |link| + if link =~ /^"([^"]+)":(.+)$/ + text = $1 + link = $2 + else + text = link + end + + if link =~ /([;,.!?\)\]<>])$/ + link.chop! + ch = $1 + else + ch = "" + end + + link.gsub!(/"/, '"') + '' + text + '' + ch + end + str + end + + def self.parse_list(str, options = {}) + html = "" + layout = [] + nest = 0 + + str.split(/\n/).each do |line| + if line =~ /^\s*(\*+) (.+)/ + nest = $1.size + content = parse_inline($2) + else + content = parse_inline(line) + end + + if nest > layout.size + html += "