Class: Blog
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Blog
- Defined in:
- app/models/blog.rb,
app/models/blog.posts_finder.rb
Class Method Summary collapse
Instance Method Summary collapse
- #editable_by?(user) ⇒ Boolean
- #inline_options ⇒ Object
-
#name_for_path ⇒ Object
————————————————————————————————-.
- #potential_authors ⇒ Object
- #render ⇒ Object
Class Method Details
.default_order ⇒ Object
79 80 81 |
# File 'app/models/blog.rb', line 79 def self.default_order "name" end |
.default_template ⇒ Object
19 20 21 22 23 24 25 |
# File 'app/models/blog.rb', line 19 def self.default_template template_file = ActionController::Base.view_paths.map do |vp| path = vp.to_s.first == "/" ? vp.to_s : File.join(Rails.root, vp.to_s) File.join(path, "cms/blogs/render.html.erb") end.detect{|f| File.exists? f } template_file ? open(template_file){|f| f.read } : "" end |
.posts_finder(options) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/models/blog.rb', line 27 def self.posts_finder(finder, ) if [:tags] finder = finder.tagged_with([:tags]) end if [:exclude_tags] finder = finder.not_tagged_with([:exclude_tags]) end if [:category] || [:category_id] category_type = CategoryType.named("Blog Post").first category = category_type.categories.named([:category]).first if [:category] category = category_type.categories. find([:category_id]) if [:category_id] finder = finder.in_category(category) end finder end |
Instance Method Details
#editable_by?(user) ⇒ Boolean
83 84 85 |
# File 'app/models/blog.rb', line 83 def editable_by?(user) user.able_to?(:administrate) || !(group_ids & user.group_ids).empty? end |
#inline_options ⇒ Object
75 76 77 |
# File 'app/models/blog.rb', line 75 def {:inline => self.template} end |
#name_for_path ⇒ Object
94 95 96 |
# File 'app/models/blog.rb', line 94 def name_for_path name.to_slug.gsub('-', '_') end |
#potential_authors ⇒ Object
87 88 89 |
# File 'app/models/blog.rb', line 87 def groups.map(&:users).flatten.uniq end |
#render ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/models/blog.rb', line 43 def render @blog = self finder = @blog.posts.published finder = Blog.posts_finder(finder, params) if params[:year] && params[:month] && params[:day] @date = Date.new(params[:year].to_i, params[:month].to_i, params[:day].to_i) finder = posts.published_between(@date, @date + 1.day) elsif params[:year] && params[:month] @date = Date.new(params[:year].to_i, params[:month].to_i) finder = posts.published_between(@date, @date + 1.month) elsif params[:year] @date = Date.new(params[:year].to_i) finder = posts.published_between(@date, @date + 1.year) end @blog_posts = finder.all(:limit => 25, :order => "published_at desc") raise ActiveRecord::RecordNotFound.new("No posts found") if @blog_posts.empty? if params[:category] @page_title = "#{params[:category]}" elsif params[:tag] @page_title = "Posts tagged with #{params[:tag]}" elsif params[:year] && params[:month] && params[:day] @page_title = "Posts from #{@date.to_s(:long)}" elsif params[:year] && params[:month] @page_title = "Posts from #{Date::MONTHNAMES[@date.month]} #{@date.year}" elsif params[:year] @page_title = "Posts from #{@date.year}" end end |