Class: Blabs::BlogPost
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Blabs::BlogPost
- Defined in:
- app/models/blabs/blog_post.rb
Class Method Summary collapse
Instance Method Summary collapse
- #author_twitter_username ⇒ Object
- #post_image_url ⇒ Object
- #publish! ⇒ Object
- #tag_list ⇒ Object
- #tag_list=(names) ⇒ Object
- #to_param ⇒ Object
- #toggle_publish!(value) ⇒ Object
- #unpublish! ⇒ Object
Class Method Details
.tagged_with(name) ⇒ Object
18 19 20 |
# File 'app/models/blabs/blog_post.rb', line 18 def self.tagged_with(name) Tag.find_by_name!(name).blog_posts end |
Instance Method Details
#author_twitter_username ⇒ Object
45 46 47 48 |
# File 'app/models/blabs/blog_post.rb', line 45 def username = self[:author_twitter_username] username.blank? ? "" : "@#{username}".squeeze("@") end |
#post_image_url ⇒ Object
38 39 40 41 42 43 |
# File 'app/models/blabs/blog_post.rb', line 38 def post_image_url (Blabs.post_image_url_attribute && extra_attributes[Blabs.post_image_url_attribute]) || begin find_link_regex = /\[([^\[]+)\]\(([^\)]+)\)/ body.match(find_link_regex) && $2 end end |
#publish! ⇒ Object
26 27 28 |
# File 'app/models/blabs/blog_post.rb', line 26 def publish! update_attributes(published: true, published_at: Time.now) unless published? end |
#tag_list ⇒ Object
56 57 58 |
# File 'app/models/blabs/blog_post.rb', line 56 def tag_list self..collect {|t| t.name }.join(", ") end |
#tag_list=(names) ⇒ Object
50 51 52 53 54 |
# File 'app/models/blabs/blog_post.rb', line 50 def tag_list=(names) self. = names.split(",").map do |n| Blabs::Tag.where(name: n.strip).first_or_create! end end |
#to_param ⇒ Object
22 23 24 |
# File 'app/models/blabs/blog_post.rb', line 22 def to_param path end |
#toggle_publish!(value) ⇒ Object
34 35 36 |
# File 'app/models/blabs/blog_post.rb', line 34 def toggle_publish!(value) value ? publish! : unpublish! end |
#unpublish! ⇒ Object
30 31 32 |
# File 'app/models/blabs/blog_post.rb', line 30 def unpublish! update_attributes(published: false, published_at: nil) if published? end |