spree_awesome_blog 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/README.md +13 -0
  2. data/app/controllers/admin/comments_controller.rb +32 -0
  3. data/app/controllers/admin/post_images_controller.rb +55 -0
  4. data/app/controllers/admin/posts_controller.rb +19 -0
  5. data/app/controllers/comments_controller.rb +23 -0
  6. data/app/controllers/posts_controller.rb +32 -0
  7. data/app/helpers/posts_helper.rb +19 -0
  8. data/app/models/comment.rb +31 -0
  9. data/app/models/comment.rb~ +31 -0
  10. data/app/models/post.rb +47 -0
  11. data/app/stylesheets/blog.less +234 -0
  12. data/app/views/admin/comments/_form.html.erb +28 -0
  13. data/app/views/admin/comments/edit.html.erb +8 -0
  14. data/app/views/admin/comments/index.html.erb +45 -0
  15. data/app/views/admin/post_images/_form.html.erb +8 -0
  16. data/app/views/admin/post_images/edit.html.erb +18 -0
  17. data/app/views/admin/post_images/index.html.erb +44 -0
  18. data/app/views/admin/post_images/new.html.erb +22 -0
  19. data/app/views/admin/posts/_form.html.erb +39 -0
  20. data/app/views/admin/posts/edit.html.erb +8 -0
  21. data/app/views/admin/posts/index.html.erb +53 -0
  22. data/app/views/admin/posts/new.html.erb +6 -0
  23. data/app/views/comments/_form.html.erb +30 -0
  24. data/app/views/comments/new.html.erb +3 -0
  25. data/app/views/posts/_sidebar.html.erb +34 -0
  26. data/app/views/posts/_tag_cloud.html.erb +5 -0
  27. data/app/views/posts/_tags.html.erb +3 -0
  28. data/app/views/posts/index.html.erb +32 -0
  29. data/app/views/posts/index.rss.builder +18 -0
  30. data/app/views/posts/show.html.erb +43 -0
  31. data/app/views/shared/_blog_sub_menu.html.erb +9 -0
  32. data/app/views/shared/_blog_tabs.html.erb +25 -0
  33. data/config/locales/en-US.yml +35 -0
  34. data/config/routes.rb +20 -0
  35. data/lib/generators/spree_awesome_blog/install_generator.rb +14 -0
  36. data/lib/generators/templates/db/migrate/20110110042721_create_posts.rb +21 -0
  37. data/lib/generators/templates/db/migrate/20110110042722_create_comments.rb +20 -0
  38. data/lib/generators/templates/db/migrate/20110110053623_acts_as_taggable_on_migration.rb +28 -0
  39. data/lib/generators/templates/public/images/markitup/bold.png +0 -0
  40. data/lib/generators/templates/public/images/markitup/clean.png +0 -0
  41. data/lib/generators/templates/public/images/markitup/h1.png +0 -0
  42. data/lib/generators/templates/public/images/markitup/h2.png +0 -0
  43. data/lib/generators/templates/public/images/markitup/h3.png +0 -0
  44. data/lib/generators/templates/public/images/markitup/h4.png +0 -0
  45. data/lib/generators/templates/public/images/markitup/h5.png +0 -0
  46. data/lib/generators/templates/public/images/markitup/h6.png +0 -0
  47. data/lib/generators/templates/public/images/markitup/image.png +0 -0
  48. data/lib/generators/templates/public/images/markitup/italic.png +0 -0
  49. data/lib/generators/templates/public/images/markitup/link.png +0 -0
  50. data/lib/generators/templates/public/images/markitup/list-bullet.png +0 -0
  51. data/lib/generators/templates/public/images/markitup/list-numeric.png +0 -0
  52. data/lib/generators/templates/public/images/markitup/paragraph.png +0 -0
  53. data/lib/generators/templates/public/images/markitup/picture.png +0 -0
  54. data/lib/generators/templates/public/images/markitup/preview.png +0 -0
  55. data/lib/generators/templates/public/images/markitup/quotes.png +0 -0
  56. data/lib/generators/templates/public/images/markitup/stroke.png +0 -0
  57. data/lib/generators/templates/public/javascripts/admin/blog.js +15 -0
  58. data/lib/generators/templates/public/javascripts/jquery.markitup.showdown.js +1904 -0
  59. data/lib/generators/templates/public/stylesheets/admin/blog.css +163 -0
  60. data/lib/generators/templates/public/stylesheets/blog.css +34 -0
  61. data/lib/spree_awesome_blog.rb +5 -0
  62. data/lib/spree_awesome_blog/engine.rb +29 -0
  63. data/lib/spree_awesome_blog_hooks.rb +10 -0
  64. metadata +179 -0
data/README.md ADDED
@@ -0,0 +1,13 @@
1
+ Awesome Blog
2
+ ===
3
+
4
+ Introduction goes here.
5
+
6
+
7
+ Example
8
+ =======
9
+
10
+ Example goes here.
11
+
12
+
13
+ Copyright (c) 2010 [name of extension creator], released under the New BSD License
@@ -0,0 +1,32 @@
1
+ class Admin::CommentsController < Admin::BaseController
2
+ resource_controller
3
+
4
+ helper 'spree/base'
5
+
6
+ update.response do |format|
7
+ format.html { redirect_to admin_comments_path }
8
+ end
9
+ create.response do |format|
10
+ format.html { redirect_to edit_admin_comments_path(@comments) }
11
+ end
12
+ private
13
+ def collection
14
+ return @collection if @collection
15
+
16
+ @collection = Comment
17
+ if params[:post_id]
18
+ @post = Post.find_by_permalink(params[:post_id])
19
+ @collection = @post.comments
20
+ end
21
+
22
+ @collection = @collection.paginate(:page => params[:page], :per_page => 10)
23
+ end
24
+
25
+ def object
26
+ return @object if @object
27
+
28
+ @object = Comment.find_by_id(params[:id])
29
+ @object.approved = params[:comment][:approved] if params[:comment] && params[:comment].key?(:approved)
30
+ @object
31
+ end
32
+ end
@@ -0,0 +1,55 @@
1
+ class Admin::PostImagesController < Admin::BaseController
2
+ resource_controller
3
+ belongs_to :post
4
+
5
+ new_action.response do |wants|
6
+ wants.html {render :action => :new, :layout => false}
7
+ end
8
+
9
+ create.response do |wants|
10
+ wants.html {redirect_to admin_post_images_url(@post)}
11
+ end
12
+
13
+ update.response do |wants|
14
+ wants.html {redirect_to admin_post_images_url(@post)}
15
+ end
16
+
17
+ create.before :set_viewable
18
+ update.before :set_viewable
19
+ destroy.before :destroy_before
20
+
21
+ destroy.response do |wants|
22
+ wants.html do
23
+ render :text => ""
24
+ end
25
+ end
26
+
27
+
28
+ private
29
+ def parent_object
30
+ @parent_object ||= Post.find_by_permalink(params[:post_id])
31
+ end
32
+
33
+ def object
34
+ @object ||= end_of_association_chain.find(params[:id])
35
+ @image = @object
36
+ end
37
+
38
+ def model_name
39
+ 'image'
40
+ end
41
+
42
+ def object_name
43
+ 'image'
44
+ end
45
+
46
+ def set_viewable
47
+ object.viewable = @post
48
+ end
49
+
50
+ def destroy_before
51
+ @viewable = object.viewable
52
+ end
53
+
54
+
55
+ end
@@ -0,0 +1,19 @@
1
+ class Admin::PostsController < Admin::BaseController
2
+ resource_controller
3
+
4
+ helper 'spree/base'
5
+
6
+ new_action.response do |format|
7
+ format.html {render :action => :new, :layout => false}
8
+ end
9
+ update.response do |format|
10
+ format.html { redirect_to admin_posts_path }
11
+ end
12
+ create.response do |format|
13
+ format.html { redirect_to edit_admin_posts_path(@posts) }
14
+ end
15
+ private
16
+ def collection
17
+ @collection ||= Post.paginate(:page => params[:page], :per_page => 10)
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ class CommentsController < Spree::BaseController
2
+ before_filter :load_post, :only => [:new, :create]
3
+
4
+ def new
5
+ @comment = Comment.new
6
+ end
7
+
8
+ def create
9
+ @comment = @post.comments.build(params[:comment])
10
+ @comment.user = current_user
11
+ if @comment.save
12
+ flash[:notice] = I18n.t(:created_successfully_pending_approval)
13
+ redirect_to post_path(@post)
14
+ else
15
+ render 'new'
16
+ end
17
+ end
18
+
19
+ private
20
+ def load_post
21
+ @post = Post.find_by_permalink(params[:post_id])
22
+ end
23
+ end
@@ -0,0 +1,32 @@
1
+ class PostsController < Spree::BaseController
2
+ before_filter :load_tag_cloud, :load_dates
3
+
4
+ def index
5
+ @tag = params[:tag]
6
+ @year = params[:year]
7
+ @month = params[:month]
8
+ @day = params[:day]
9
+
10
+ @posts = @year ? Post.by_date(@year.to_i, @month.try(:to_i), @day.try(:to_i)) : Post
11
+ @posts = @posts.published
12
+ @posts = @posts.tagged_with(@tag) if @tag
13
+
14
+ respond_to do |format|
15
+ format.html { @posts = @posts.paginate(:page => params[:page], :per_page => 10) }
16
+ format.rss
17
+ end
18
+ end
19
+
20
+ def show
21
+ @post = Post.published.find_by_permalink(params[:id])
22
+ end
23
+
24
+ protected
25
+ def load_tag_cloud
26
+ @tags = Post.tag_counts_on(:tags)
27
+ end
28
+
29
+ def load_dates
30
+ @dates = Post.group_dates
31
+ end
32
+ end
@@ -0,0 +1,19 @@
1
+ module PostsHelper
2
+ include ActsAsTaggableOn::TagsHelper
3
+
4
+ def make_title(tag=nil, year=nil, month=nil, day=nil)
5
+ if tag
6
+ t("posts_tagged") % tag.humanize.capitalize
7
+ elsif year
8
+ if day
9
+ t("posts_day") % Date.new(year.to_i,month.to_i,day.to_i).strftime("%A, %d %B, %Y")
10
+ elsif month
11
+ t("posts_month") % Date.new(year.to_i,month.to_i,1).strftime("%B %Y")
12
+ else
13
+ t("posts_year") % year.to_s
14
+ end
15
+ else
16
+ Spree::Config[:blog_title] || t("blog")
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,31 @@
1
+ class Comment < ActiveRecord::Base
2
+ belongs_to :post
3
+ belongs_to :user
4
+ before_save :check_approved
5
+ before_save :check_user, :if => :user
6
+
7
+ attr_accessible :name, :email, :message, :url
8
+
9
+ validates_presence_of :message, :post_id, :name
10
+ validates_length_of :message, :maximum => 1000
11
+ validates_presence_of :email, :unless => :user
12
+ validates_format_of :email, :with => /\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i
13
+ validates_format_of :url, :with => /http\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/, :allow_blank => true
14
+
15
+ default_scope order('approved, approved_on DESC')
16
+ scope :approved, where(:approved => true)
17
+
18
+ def status
19
+ approved ? "approved" : "not approved"
20
+ end
21
+
22
+ private
23
+ def check_user
24
+ self.email = user.email
25
+ end
26
+
27
+ def check_approved
28
+ return unless approved_changed?
29
+ self.approved_on = approved ? Date.today : nil
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ class Comment < ActiveRecord::Base
2
+ belongs_to :post
3
+ belongs_to :user
4
+ before_save :check_approved
5
+ before_save :check_user, :if => :user
6
+
7
+ attr_accessible :name, :email, :message, :approved
8
+
9
+ validates_presence_of :message, :post_id, :name
10
+ validates_length_of :message, :maximum => 1000
11
+ validates_presence_of :email, :unless => :user
12
+ validates_format_of :email, :with => /\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i
13
+ validates_format_of :url, :with => /^http\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?$/
14
+
15
+ default_scope order('approved, approved_on DESC')
16
+ scope :approved, where(:approved => true)
17
+
18
+ def status
19
+ approved ? "approved" : "not approved"
20
+ end
21
+
22
+ private
23
+ def check_user
24
+ self.email = user.email
25
+ end
26
+
27
+ def check_approved
28
+ return unless approved_changed?
29
+ self.approved_on = approved ? Date.today : nil
30
+ end
31
+ end
@@ -0,0 +1,47 @@
1
+ class Post < ActiveRecord::Base
2
+ make_permalink
3
+ acts_as_taggable
4
+ validates_presence_of :title
5
+ has_many :images, :as => :viewable, :order => :position, :dependent => :destroy
6
+ has_many :comments, :dependent => :destroy
7
+ before_save :check_published
8
+
9
+ default_scope includes(:tags).order('publish, published_on DESC')
10
+ scope :published, where(:publish => true)
11
+
12
+ def self.by_date(year, month=nil, day=nil)
13
+ start_date = Date.new(year, month || 1, day || 1)
14
+ end_date = nil
15
+
16
+ if day
17
+ end_date = start_date.advance(:days => 1)
18
+ elsif month
19
+ end_date = start_date.advance(:months => 1)
20
+ else
21
+ end_date = start_date.advance(:years => 1)
22
+ end
23
+
24
+ where('published_on BETWEEN ? AND ?', start_date, end_date)
25
+ end
26
+
27
+ def self.group_dates
28
+ select('published_on, title, permalink').
29
+ group_by {|post| post.published_on.to_date.advance(:days => -(post.published_on.day-1)) }.
30
+ group_by {|date| date.first.year }
31
+ end
32
+
33
+ def status
34
+ publish ? "published" : "unpublished"
35
+ end
36
+
37
+ def to_param
38
+ return permalink unless permalink.blank?
39
+ title.to_url
40
+ end
41
+
42
+ private
43
+ def check_published
44
+ return unless publish_changed?
45
+ self.published_on = publish ? Date.today : nil
46
+ end
47
+ end
@@ -0,0 +1,234 @@
1
+ #posts {
2
+ h2 {
3
+ font-size: 2em;
4
+
5
+ a {
6
+ text-decoration: none;
7
+ }
8
+ }
9
+
10
+ .post {
11
+ margin: 5px 0px;
12
+
13
+ hr {
14
+ margin: 10px 0 20px;
15
+ }
16
+
17
+ .body {
18
+ margin: 0 40px 0 0;
19
+ }
20
+ }
21
+
22
+ }
23
+
24
+ #blog-archive {
25
+ span {
26
+ cursor: pointer;
27
+ }
28
+
29
+ a { text-decoration: none; }
30
+
31
+ ul.months, ul.posts {
32
+ display: none;
33
+ }
34
+
35
+ ul.posts {
36
+ list-style-type: none;
37
+ margin: 0px;
38
+ }
39
+ }
40
+
41
+ .tag-cloud {
42
+ a {
43
+ text-decoration: none;
44
+ }
45
+ .tag1 { font-size: 1.0em; font-weight: lighter; }
46
+ .tag2 { font-size: 1.2em; font-weight: normal; }
47
+ .tag3 { font-size: 1.4em; font-weight: bold; }
48
+ .tag4 { font-size: 1.6em; font-weight: bolder; }
49
+ }
50
+
51
+ #post {
52
+ h2 {
53
+ margin: 0px;
54
+ }
55
+ #body {
56
+ margin: 0px 20px 0 0;
57
+ }
58
+ }
59
+
60
+ .tags, #tags {
61
+ a {
62
+ text-decoration: none;
63
+ }
64
+ }
65
+
66
+
67
+ /* -------------------------------------------------------------------
68
+ // markItUp! Universal MarkUp Engine, JQuery plugin
69
+ // By Jay Salvat - http://markitup.jaysalvat.com/
70
+ // ------------------------------------------------------------------*/
71
+ .markItUp a:link,
72
+ .markItUp a:visited {
73
+ color:#000;
74
+ text-decoration:none;
75
+ }
76
+ .markItUp {
77
+ width:700px;
78
+ margin:5px 0 5px 0;
79
+ }
80
+ .markItUpContainer {
81
+ font:11px Verdana, Arial, Helvetica, sans-serif;
82
+ }
83
+ .markItUpEditor {
84
+ font:12px 'Courier New', Courier, monospace;
85
+ padding:5px;
86
+ width:690px;
87
+ height:320px;
88
+ clear:both;
89
+ line-height:18px;
90
+ overflow:auto;
91
+ }
92
+ .markItUpPreviewFrame {
93
+ overflow:auto;
94
+ background-color:#FFF;
95
+ width:99.9%;
96
+ height:300px;
97
+ margin:5px 0;
98
+ }
99
+ .markItUpFooter {
100
+ width:100%;
101
+ }
102
+ .markItUpResizeHandle {
103
+ overflow:hidden;
104
+ width:22px; height:5px;
105
+ margin-left:auto;
106
+ margin-right:auto;
107
+ background-image:url(../../images/markitup/handle.png);
108
+ cursor:n-resize;
109
+ }
110
+ /***************************************************************************************/
111
+ /* first row of buttons */
112
+ .markItUpHeader ul li {
113
+ list-style:none;
114
+ float:left;
115
+ position:relative;
116
+ }
117
+ .markItUpHeader ul li:hover > ul{
118
+ display:block;
119
+ }
120
+ .markItUpHeader ul .markItUpDropMenu {
121
+ background:transparent url(../../images/markitup/menu.png) no-repeat 115% 50%;
122
+ margin-right:5px;
123
+ }
124
+ .markItUpHeader ul .markItUpDropMenu li {
125
+ margin-right:0px;
126
+ }
127
+ /* next rows of buttons */
128
+ .markItUpHeader ul ul {
129
+ display:none;
130
+ position:absolute;
131
+ top:18px; left:0px;
132
+ background:#FFF;
133
+ border:1px solid #000;
134
+ }
135
+ .markItUpHeader ul ul li {
136
+ float:none;
137
+ border-bottom:1px solid #000;
138
+ }
139
+ .markItUpHeader ul ul .markItUpDropMenu {
140
+ background:#FFF url(../../images/markitup/submenu.png) no-repeat 100% 50%;
141
+ }
142
+ .markItUpHeader ul .markItUpSeparator {
143
+ margin:0 10px;
144
+ width:1px;
145
+ height:16px;
146
+ overflow:hidden;
147
+ background-color:#CCC;
148
+ }
149
+ .markItUpHeader ul ul .markItUpSeparator {
150
+ width:auto; height:1px;
151
+ margin:0px;
152
+ }
153
+ /* next rows of buttons */
154
+ .markItUpHeader ul ul ul {
155
+ position:absolute;
156
+ top:-1px; left:150px;
157
+ }
158
+ .markItUpHeader ul ul ul li {
159
+ float:none;
160
+ }
161
+ .markItUpHeader ul a {
162
+ display:block;
163
+ width:16px; height:16px;
164
+ text-indent:-10000px;
165
+ background-repeat:no-repeat;
166
+ padding:3px;
167
+ margin:0px;
168
+ }
169
+ .markItUpHeader ul ul a {
170
+ display:block;
171
+ padding-left:0px;
172
+ text-indent:0;
173
+ width:120px;
174
+ padding:5px 5px 5px 25px;
175
+ background-position:2px 50%;
176
+ }
177
+ .markItUpHeader ul ul a:hover {
178
+ color:#FFF;
179
+ background-color:#000;
180
+ }
181
+ /* -------------------------------------------------------------------
182
+ // markItUp!
183
+ // By Jay Salvat - http://markitup.jaysalvat.com/
184
+ // ------------------------------------------------------------------*/
185
+ .markItUp .heading1 a {
186
+ background-image:url(../../images/markitup/h1.png);
187
+ }
188
+ .markItUp .heading2 a {
189
+ background-image:url(../../images/markitup/h2.png);
190
+ }
191
+ .markItUp .heading3 a {
192
+ background-image:url(../../images/markitup/h3.png);
193
+ }
194
+ .markItUp .heading4 a {
195
+ background-image:url(../../images/markitup/h4.png);
196
+ }
197
+ .markItUp .heading5 a {
198
+ background-image:url(../../images/markitup/h5.png);
199
+ }
200
+ .markItUp .heading6 a {
201
+ background-image:url(../../images/markitup/h6.png);
202
+ }
203
+ .markItUp .paragraph a {
204
+ background-image:url(../../images/markitup/paragraph.png);
205
+ }
206
+ .markItUp .bullet-list a {
207
+ background-image:url(../../images/markitup/list-bullet.png);
208
+ }
209
+ .markItUp .number-list a {
210
+ background-image:url(../../images/markitup/list-numeric.png);
211
+ }
212
+ .markItUp .quotes a {
213
+ background-image:url(../../images/markitup/quotes.png);
214
+ }
215
+ .markItUp .bold a {
216
+ background-image:url(../../images/markitup/bold.png);
217
+ }
218
+ .markItUp .italic a {
219
+ background-image:url(../../images/markitup/italic.png);
220
+ }
221
+
222
+ .markItUp .picture > a {
223
+ background-image:url(../../images/markitup/picture.png);
224
+ }
225
+ .markItUp .link a {
226
+ background-image:url(../../images/markitup/link.png);
227
+ }
228
+
229
+ .markItUp .clean a {
230
+ background-image:url(../../images/markitup/clean.png);
231
+ }
232
+ .markItUp .preview a {
233
+ background-image:url(../../images/markitup/preview.png);
234
+ }