Treat all newly entered blocks of text as Markdown

This commit is contained in:
Tom Hughes 2012-02-15 00:48:52 +00:00
parent 2ee961be9f
commit aa4205482a
21 changed files with 154 additions and 23 deletions

View file

@ -7,6 +7,12 @@ class DiaryComment < ActiveRecord::Base
attr_accessible :body
after_initialize :set_defaults
def body
RichText.new(read_attribute(:body_format), read_attribute(:body))
end
def digest
md5 = Digest::MD5.new
md5 << diary_entry_id.to_s
@ -15,4 +21,10 @@ class DiaryComment < ActiveRecord::Base
md5 << body
md5.hexdigest
end
private
def set_defaults
self.body_format = "markdown" unless self.attribute_present?(:body_format)
end
end

View file

@ -25,4 +25,16 @@ class DiaryEntry < ActiveRecord::Base
validates_associated :language
attr_accessible :title, :body, :language_code, :latitude, :longitude
after_initialize :set_defaults
def body
RichText.new(read_attribute(:body_format), read_attribute(:body))
end
private
def set_defaults
self.body_format = "markdown" unless self.attribute_present?(:body_format)
end
end

View file

@ -11,6 +11,12 @@ class Message < ActiveRecord::Base
attr_accessible :title, :body
after_initialize :set_defaults
def body
RichText.new(read_attribute(:body_format), read_attribute(:body))
end
def digest
md5 = Digest::MD5.new
md5 << from_user_id.to_s
@ -20,4 +26,10 @@ class Message < ActiveRecord::Base
md5 << body
md5.hexdigest
end
private
def set_defaults
self.body_format = "markdown" unless self.attribute_present?(:body_format)
end
end

View file

@ -44,7 +44,7 @@ class User < ActiveRecord::Base
attr_accessible :display_name, :email, :email_confirmation, :openid_url,
:pass_crypt, :pass_crypt_confirmation, :consider_pd
after_initialize :set_creation_time
after_initialize :set_defaults
before_save :encrypt_password
has_attached_file :image,
@ -101,6 +101,10 @@ class User < ActiveRecord::Base
return el1
end
def description
RichText.new(read_attribute(:description_format), read_attribute(:description))
end
def languages
attribute_present?(:languages) ? read_attribute(:languages).split(/ *, */) : []
end
@ -220,8 +224,9 @@ class User < ActiveRecord::Base
private
def set_creation_time
def set_defaults
self.creation_time = Time.now.getutc unless self.attribute_present?(:creation_time)
self.description_format = "markdown" unless self.attribute_present?(:description_format)
end
def encrypt_password

View file

@ -5,8 +5,16 @@ class UserBlock < ActiveRecord::Base
belongs_to :creator, :class_name => "User", :foreign_key => :creator_id
belongs_to :revoker, :class_name => "User", :foreign_key => :revoker_id
after_initialize :set_defaults
PERIODS = USER_BLOCK_PERIODS
##
# return a renderable version of the reason text.
def reason
RichText.new(read_attribute(:reason_format), read_attribute(:reason))
end
##
# returns true if the block is currently active (i.e: the user can't
# use the API).
@ -25,7 +33,14 @@ class UserBlock < ActiveRecord::Base
}, :without_protection => true)
end
private
private
##
# set default values for new records.
def set_defaults
self.reason_format = "markdown" unless self.attribute_present?(:reason_format)
end
##
# validate that only moderators are allowed to change the
# block. this should be caught and dealt with in the controller,