Permalink
Browse files

Merge pull request #672 from CristinaRO/issue-3110-wordcount

Issue 3110 wordcount
  • Loading branch information...
elzj committed Jun 6, 2012
2 parents 4df91f8 + 5f37a7c commit ff0164e18be48f2c1a9cb876261d44d20427bf67
Showing with 18 additions and 16 deletions.
  1. +12 −10 app/models/chapter.rb
  2. +6 −6 app/models/work.rb
View
@@ -13,22 +13,22 @@ class Chapter < ActiveRecord::Base
has_many :kudos, :as => :commentable
validates_length_of :title, :allow_blank => true, :maximum => ArchiveConfig.TITLE_MAX,
- :too_long => t('title_too_long', :default => "must be less than %{max} characters long.", :max => ArchiveConfig.TITLE_MAX)
+ :too_long => ts("must be less than %{max} characters long.", :max => ArchiveConfig.TITLE_MAX)
validates_length_of :summary, :allow_blank => true, :maximum => ArchiveConfig.SUMMARY_MAX,
- :too_long => t('summary_too_long', :default => "must be less than %{max} characters long.", :max => ArchiveConfig.SUMMARY_MAX)
+ :too_long => ts("must be less than %{max} characters long.", :max => ArchiveConfig.SUMMARY_MAX)
validates_length_of :notes, :allow_blank => true, :maximum => ArchiveConfig.NOTES_MAX,
- :too_long => t('notes_too_long', :default => "must be less than %{max} characters long.", :max => ArchiveConfig.NOTES_MAX)
+ :too_long => ts("must be less than %{max} characters long.", :max => ArchiveConfig.NOTES_MAX)
validates_length_of :endnotes, :allow_blank => true, :maximum => ArchiveConfig.NOTES_MAX,
- :too_long => t('notes_too_long', :default => "must be less than %{max} characters long.", :max => ArchiveConfig.NOTES_MAX)
+ :too_long => ts("must be less than %{max} characters long.", :max => ArchiveConfig.NOTES_MAX)
validates_presence_of :content
validates_length_of :content, :minimum => ArchiveConfig.CONTENT_MIN,
- :too_short => t('content_too_short', :default => "must be at least %{min} characters long.", :min => ArchiveConfig.CONTENT_MIN)
+ :too_short => ts("must be at least %{min} characters long.", :min => ArchiveConfig.CONTENT_MIN)
validates_length_of :content, :maximum => ArchiveConfig.CONTENT_MAX,
- :too_long => t('content_too_long', :default => "cannot be more than %{max} characters long.", :max => ArchiveConfig.CONTENT_MAX)
+ :too_long => ts("cannot be more than %{max} characters long.", :max => ArchiveConfig.CONTENT_MAX)
# Virtual attribute to use as a placeholder for pseuds before the chapter has been saved
# Can't write to chapter.pseuds until the chapter has an id
@@ -170,11 +170,11 @@ def validate_published_at
if !self.published_at
self.published_at = Date.today
elsif self.published_at > Date.today
- errors.add(:base, t('no_future_dating', :default => "Publication date can't be in the future."))
+ errors.add(:base, ts("Publication date can't be in the future."))
return false
end
- end
-
+ end
+
# Set the value of word_count to reflect the length of the text in the chapter content
def set_word_count
if self.new_record? || self.content_changed?
@@ -190,9 +190,11 @@ def set_word_count
end
end
self.word_count = count
+ else
+ self.word_count
end
end
-
+
# Return the name to link comments to for this object
def commentable_name
self.work.title
View
@@ -134,13 +134,13 @@ def create_hit_counter
def validate_authors
if self.authors.blank?
if self.pseuds.blank?
- errors.add(:base, t('must_have_author', :default => "Work must have at least one author."))
+ errors.add(:base, ts("Work must have at least one author."))
return false
else
self.authors_to_sort_on = self.sorted_pseuds
end
elsif !self.invalid_pseuds.blank?
- errors.add(:base, t('invalid_pseuds', :default => "These pseuds are invalid: %{pseuds}", :pseuds => self.invalid_pseuds.inspect))
+ errors.add(:base, ts("These pseuds are invalid: %{pseuds}", :pseuds => self.invalid_pseuds.inspect))
else
self.authors_to_sort_on = self.sorted_authors
end
@@ -164,7 +164,7 @@ def validate_published_at
if !self.first_chapter.published_at
self.first_chapter.published_at = Date.today
elsif self.first_chapter.published_at > Date.today
- errors.add(:base, t('no_future_dating', :default => "Publication date can't be in the future."))
+ errors.add(:base, ts("Publication date can't be in the future."))
return false
end
end
@@ -173,7 +173,7 @@ def validate_published_at
after_validation :check_for_invalid_chapters
def check_for_invalid_chapters
if self.errors[:chapters].any?
- self.errors.add(:base, t('chapter_invalid', :default => "Please enter your story in the text field below."))
+ self.errors.add(:base, ts("Please enter your story in the text field below."))
self.errors.delete(:chapters)
end
end
@@ -187,11 +187,10 @@ def check_for_invalid_chapters
########################################################################
before_save :validate_authors, :clean_and_validate_title, :validate_published_at, :ensure_revised_at
- before_save :set_word_count, :post_first_chapter
+ before_save :post_first_chapter, :set_word_count
after_save :save_chapters, :save_parents
- # before_save :validate_tags # Enigel's feeble attempt
before_save :check_for_invalid_tags
before_update :validate_tags
after_update :adjust_series_restriction
@@ -467,6 +466,7 @@ def save_chapters
def post_first_chapter
if self.posted_changed?
self.chapters.first.posted = self.posted
+ self.chapters.first.save
end
end

0 comments on commit ff0164e

Please sign in to comment.