blog_basic 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. data/Gemfile +24 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Manifest +0 -0
  4. data/README.md +186 -0
  5. data/Rakefile +47 -0
  6. data/app/admin/blog_basic_blog_posts.rb +9 -0
  7. data/app/admin/dashboards.rb +38 -0
  8. data/app/assets/images/rails.png +0 -0
  9. data/app/assets/javascripts/active_admin.js +1 -0
  10. data/app/assets/javascripts/application.js +9 -0
  11. data/app/assets/stylesheets/active_admin.css.scss +6 -0
  12. data/app/assets/stylesheets/application.css +7 -0
  13. data/app/controllers/application_controller.rb +3 -0
  14. data/app/controllers/blog_basic/app_controller.rb +27 -0
  15. data/app/controllers/blog_basic/application_controller.rb +4 -0
  16. data/app/controllers/blog_basic/blog_comments_controller.rb +69 -0
  17. data/app/controllers/blog_basic/blog_posts_controller.rb +149 -0
  18. data/app/controllers/blog_basic/sessions_controller.rb +32 -0
  19. data/app/controllers/blog_basic/tags_controller.rb +11 -0
  20. data/app/helpers/application_helper.rb +2 -0
  21. data/app/helpers/blog_basic/application_helper.rb +21 -0
  22. data/app/helpers/blog_basic/blog_posts_helper.rb +17 -0
  23. data/app/helpers/blog_basic/shared_helper.rb +36 -0
  24. data/app/helpers/blog_basic/tags_helper.rb +5 -0
  25. data/app/models/admin_user.rb +9 -0
  26. data/app/models/blog_basic/blog_comment.rb +78 -0
  27. data/app/models/blog_basic/blog_content.rb +4 -0
  28. data/app/models/blog_basic/blog_image.rb +23 -0
  29. data/app/models/blog_basic/blog_post.rb +104 -0
  30. data/app/models/blog_basic/session.rb +5 -0
  31. data/app/models/blog_basic/user.rb +22 -0
  32. data/app/views/blog_basic/blog_comments/_new_blog_comment.html.erb +43 -0
  33. data/app/views/blog_basic/blog_posts/_admin_links.html.erb +9 -0
  34. data/app/views/blog_basic/blog_posts/_blog_post.html.erb +62 -0
  35. data/app/views/blog_basic/blog_posts/_comment.html.erb +18 -0
  36. data/app/views/blog_basic/blog_posts/_comments.html.erb +6 -0
  37. data/app/views/blog_basic/blog_posts/_form.html.erb +133 -0
  38. data/app/views/blog_basic/blog_posts/_image.html.erb +20 -0
  39. data/app/views/blog_basic/blog_posts/drafts.html.erb +21 -0
  40. data/app/views/blog_basic/blog_posts/edit.html.erb +6 -0
  41. data/app/views/blog_basic/blog_posts/index.atom.builder +12 -0
  42. data/app/views/blog_basic/blog_posts/index.html.erb +31 -0
  43. data/app/views/blog_basic/blog_posts/new.html.erb +6 -0
  44. data/app/views/blog_basic/blog_posts/show.html.erb +8 -0
  45. data/app/views/blog_basic/shared/_footer.html.erb +15 -0
  46. data/app/views/blog_basic/shared/_index_top.html.erb +12 -0
  47. data/app/views/blog_basic/shared/_topbar.html.erb +24 -0
  48. data/app/views/layouts/application.html.erb +14 -0
  49. data/blog_basic.gemspec +57 -0
  50. data/config/routes.rb +21 -0
  51. data/db/migrate/1_blog_tables.rb +86 -0
  52. data/init.rb +9 -0
  53. data/lib/akismetor.rb +77 -0
  54. data/lib/blog_basic/active_admin.rb +103 -0
  55. data/lib/blog_basic/blog_basic_model_helper.rb +85 -0
  56. data/lib/blog_basic/blog_conf.rb +36 -0
  57. data/lib/blog_basic/engine.rb +13 -0
  58. data/lib/blog_basic/engine.rb.backup +80 -0
  59. data/lib/blog_basic.rb +16 -0
  60. data/lib/generators/blog_basic/create_assets/blog_assets_generator.rb +49 -0
  61. data/lib/generators/blog_basic/create_assets/templates/blog_comments_migration.rb +23 -0
  62. data/lib/generators/blog_basic/create_assets/templates/blog_images_migration.rb +19 -0
  63. data/lib/generators/blog_basic/create_assets/templates/blog_posts_migration.rb +17 -0
  64. data/lib/generators/blog_basic/create_assets/templates/config/blog_basic.yml +52 -0
  65. data/lib/generators/blog_basic/create_assets/templates/syntax/active4d.css +114 -0
  66. data/lib/generators/blog_basic/create_assets/templates/syntax/all_hallows_eve.css +72 -0
  67. data/lib/generators/blog_basic/create_assets/templates/syntax/amy.css +147 -0
  68. data/lib/generators/blog_basic/create_assets/templates/syntax/blackboard.css +88 -0
  69. data/lib/generators/blog_basic/create_assets/templates/syntax/brilliance_black.css +605 -0
  70. data/lib/generators/blog_basic/create_assets/templates/syntax/brilliance_dull.css +599 -0
  71. data/lib/generators/blog_basic/create_assets/templates/syntax/cobalt.css +149 -0
  72. data/lib/generators/blog_basic/create_assets/templates/syntax/dawn.css +121 -0
  73. data/lib/generators/blog_basic/create_assets/templates/syntax/eiffel.css +121 -0
  74. data/lib/generators/blog_basic/create_assets/templates/syntax/espresso_libre.css +109 -0
  75. data/lib/generators/blog_basic/create_assets/templates/syntax/idle.css +62 -0
  76. data/lib/generators/blog_basic/create_assets/templates/syntax/iplastic.css +80 -0
  77. data/lib/generators/blog_basic/create_assets/templates/syntax/lazy.css +73 -0
  78. data/lib/generators/blog_basic/create_assets/templates/syntax/mac_classic.css +123 -0
  79. data/lib/generators/blog_basic/create_assets/templates/syntax/magicwb_amiga.css +104 -0
  80. data/lib/generators/blog_basic/create_assets/templates/syntax/pastels_on_dark.css +188 -0
  81. data/lib/generators/blog_basic/create_assets/templates/syntax/slush_poppies.css +85 -0
  82. data/lib/generators/blog_basic/create_assets/templates/syntax/spacecadet.css +51 -0
  83. data/lib/generators/blog_basic/create_assets/templates/syntax/sunburst.css +180 -0
  84. data/lib/generators/blog_basic/create_assets/templates/syntax/twilight.css +137 -0
  85. data/lib/generators/blog_basic/create_assets/templates/syntax/zenburnesque.css +91 -0
  86. data/lib/generators/blog_basic/install/install_generator.rb +53 -0
  87. data/lib/generators/blog_basic/install/templates/active_admin.rb +103 -0
  88. data/lib/generators/blog_basic/install/templates/blog_basic.yml +52 -0
  89. data/lib/generators/blog_basic/install/templates/blog_kit.css +75 -0
  90. data/lib/generators/blog_basic/install/templates/devise.en.yml +58 -0
  91. data/lib/generators/blog_basic/install/templates/devise.rb +209 -0
  92. data/lib/generators/blog_basic/install/templates/migrations/1_blog_tables.rb +86 -0
  93. data/lib/generators/blog_basic/install/templates/migrations/20111213104240_devise_create_admin_users.rb +28 -0
  94. data/lib/generators/blog_basic/install/templates/migrations/20111213114257_create_admin_notes.rb +16 -0
  95. data/lib/generators/blog_basic/install/templates/migrations/20111213114258_move_admin_notes_to_comments.rb +25 -0
  96. data/lib/generators/blog_basic/install/templates/omniauth.rb.erb +10 -0
  97. data/lib/tasks/blog_basic_tasks.rake +0 -0
  98. data/lib/url_validator.rb +24 -0
  99. data/test/database.yml +4 -0
  100. data/test/fixtures/admin_users.yml +11 -0
  101. data/test/functional/blog_assets_generator_test.rb +35 -0
  102. data/test/functional/blog_comments_controller_test.rb +0 -0
  103. data/test/functional/blog_posts_controller_test.rb +84 -0
  104. data/test/performance/browsing_test.rb +12 -0
  105. data/test/schema.rb +61 -0
  106. data/test/test_helper.rb +13 -0
  107. data/test/unit/admin_user_test.rb +7 -0
  108. data/uninstall.rb +1 -0
  109. metadata +310 -0
data/Gemfile ADDED
@@ -0,0 +1,24 @@
1
+ source :rubygems
2
+ gemspec
3
+
4
+ gem 'json'
5
+ gem 'sass'
6
+ gem 'coffee-script'
7
+ gem 'uglifier'
8
+ gem 'jquery-rails'
9
+
10
+ gem 'acts-as-taggable-on'
11
+ gem 'sass-rails'
12
+ gem "meta_search", '>= 1.1.0.pre'
13
+
14
+ gem "bluecloth", "~> 2.2.0"
15
+ gem 'will_paginate'
16
+ gem "paperclip", "~> 2.3"
17
+
18
+ gem "omniauth", "~> 1.0.0"
19
+ gem "omniauth-openid", "~> 1.0.0"
20
+ gem "omniauth-github", "~> 1.0.0"
21
+
22
+ gem 'activeadmin'
23
+ gem 'sass-rails'
24
+ gem 'meta_search', '>= 1.1.0.pre'
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 [name of plugin creator]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest ADDED
File without changes
data/README.md ADDED
@@ -0,0 +1,186 @@
1
+ blog_basic
2
+ =======
3
+
4
+ blog_basic is a fork of the rails plugin BlogKit (https://github.com/ryanstout/blog_kit)
5
+
6
+ While I really liked the idea if BlogKit it was unmaintained, lacked some essential features and had a few
7
+ security vurnabilities which has not been adressed yet.
8
+
9
+
10
+ blog_basic
11
+ ========
12
+
13
+ BlogKitty is a rails plugin to add a blog to your application. The goal is to provide common blog
14
+ functionality that integrates into your existing app while keeping things simple.
15
+
16
+ BlogKitty has the following features.
17
+
18
+ + Admin for Blog Articles
19
+ + Search engine friendly urls
20
+ + Uses existing user model
21
+ + Comments via existing user model
22
+ + Uses your existing layouts
23
+ + Easily customizable css
24
+ + Akismet (spam filtering) Support
25
+ + Markdown (default) or just plain html parsing
26
+ + Image and Gravatar support
27
+ + Anonymous Comments (optional)
28
+ + Atom Feeds
29
+ + Tags
30
+ + Image upload (via paperclip, or something that adds has_attached_file to models)
31
+
32
+
33
+ Install for Rails3
34
+ ==================
35
+
36
+ Add blog_basic to your Gemfile
37
+
38
+ gem 'blog_basic'
39
+
40
+ then run "bundle install" to make sure you are up to date. Install blog_basic my running the generator blog_basic:install
41
+
42
+ rails g blog_basic:install
43
+
44
+ and migrate your database
45
+
46
+ rake db:migrate
47
+
48
+ Now adjust config/routes.rb for your desired path and config/blog_basic.yml for the rest of the configuration
49
+
50
+ Assumptions
51
+ ===========
52
+
53
+ BlogKit makes the following assumptions
54
+
55
+ + flash messages displaying is handled via the layout
56
+
57
+
58
+ Setup
59
+ =====
60
+
61
+ BlogKit is designed to work with your existing user model, at the moment, it assumes this will be
62
+ called User. Your User class and application controller simply need to respond to some methods to
63
+ be able to use BlogKit. These methods, while not standardized are very common, and come with plugins
64
+ like Authlogic and restful_authentication.
65
+
66
+ ApplicationController should respond to:
67
+ #require_user
68
+ #current_user
69
+ #title - (optional passes in the pages title as the first argument)
70
+
71
+ User model should respond to:
72
+ #admin? - returns true if the user can edit posts and delete comments
73
+ #name - the users name
74
+ #blog_image_url (optional, the users photo, show next to comments/posts)
75
+ #email (options - for gravatar support)
76
+
77
+ Once you have everything setup, you can see and manage the blog at /blog_posts Make sure that you have
78
+ all of the requirements below met.
79
+
80
+ Rails 3 is supported via the rails3 branch, if you are using legacy routing, you may need to copy in routes
81
+ from config/routes.rb to your main routes.rb file.
82
+
83
+ To be able to use the delete links on posts, you will need to add the following to the top of your layout:
84
+
85
+ <%= csrf_meta_tag %>
86
+
87
+ Also be sure that you have the proper javascript handling code for link_to '', :method => destroy
88
+
89
+ Requirements
90
+ ============
91
+
92
+ Rails 3.x
93
+
94
+ - Will_Paginate
95
+
96
+ Optional:
97
+
98
+ - Ultraviolet (and its deps, for code highlighting)
99
+
100
+ Install Oniguruma if 1.8.x
101
+ http://www.geocities.jp/kosako3/oniguruma/
102
+
103
+ source 'http://gems.github.com'
104
+ gem "spox-ultraviolet", :require => false
105
+
106
+ - BlueCloth 2 (for markdown)
107
+
108
+ gem 'bluecloth'
109
+
110
+ - Paperclip
111
+
112
+ gem 'paperclip', :git => 'http://github.com/thoughtbot/paperclip.git', :branch => 'rails3'
113
+
114
+ Customization
115
+ =============
116
+
117
+ Be sure to edit config/blog_kit.yml, many common settings can be changed there.
118
+
119
+ ** View Customization **
120
+
121
+ BlogKit is built as a rails engine plugin (for rails 2.3.x, not the previous engines plugin). You can see
122
+ the models, views, and controllers in vendor/plugins/blog_kit/app/ You can change them by copying any of
123
+ them into your apps /app directory. Rails will look in /app before looking in vendor/plugins/blog_kit/app/
124
+ Once they are copied into /app, you can customize the appearance/behavior of the blog pages.
125
+
126
+ Troubleshooting
127
+ ===============
128
+
129
+ Q. Creating a blog post does not work, it instead renders the index page.
130
+ A. Make sure you aren't using the old style default routes in rails (match '/:controller(/:action(/:id))')
131
+ If you are using default routes, then simply copy the following into your routes.rb file before the default route
132
+
133
+ resources :blog_posts do
134
+ resources :blog_comments
135
+ resources :blog_images
136
+
137
+ collection do
138
+ get :drafts
139
+ end
140
+
141
+ member do
142
+ get :tag
143
+ end
144
+ end
145
+
146
+ Tag List
147
+ ========
148
+
149
+ By default, the layout does not display a list of all tags. This can be easily added to any layout in the
150
+ application by including this in the controller:
151
+
152
+ helper :blog
153
+
154
+ Then in the view:
155
+
156
+ <%= blog_tags_list %>
157
+
158
+ You can optionally pass in a limit on the number of tags to show.
159
+
160
+ Also keep in mind that you can specify a layout just for the blog kit pages.
161
+
162
+ Titles
163
+ ======
164
+
165
+ You can have blog_kit set the page title, just create a method in application_helper like:
166
+
167
+ def title(ttl)
168
+ @page_title = ttl
169
+ end
170
+
171
+ If anyone knows of a better convention for this, let me know. This is what nifty_generators uses
172
+
173
+ Code Highlighting Example
174
+ =========================
175
+
176
+ To get code highlighted, place the following tag:
177
+
178
+ <code lang="ruby">
179
+
180
+ </code>
181
+
182
+ You can find a list of languages (syntaxes) under doc/SYNTAXES and a list of themes (colors) under
183
+ doc/THEMES
184
+
185
+
186
+ Copyright (c) 2010 Ryan Stout, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,47 @@
1
+ require 'rake'
2
+ require "bundler/gem_tasks"
3
+ require 'rake/testtask'
4
+ #require 'rdoc/task'
5
+ #require 'spec'
6
+ #require 'spec/rake/spectask'
7
+
8
+ require 'rubygems'
9
+ require 'echoe'
10
+
11
+ Echoe.new('blog_basic', '0.1.6') do |p|
12
+ p.description = "Sets up a basic but functional blogging platform."
13
+ p.url = "http://bottiger.org/made/blog_basic"
14
+ p.author = "Arvid Boettiger"
15
+ p.email = "bottiger@gmail.com"
16
+ p.ignore_pattern = ["tmp/*", "script/*"]
17
+ p.runtime_dependencies = ['bluecloth ~>2.2.0', 'will_paginate', "paperclip >=2.3", "sass-rails", "meta_search ~>1.1.1", "acts-as-taggable-on ~>2.1.1", "omniauth ~>1.0.0", "omniauth-openid ~>1.0.0", "omniauth-github ~>1.0.0"]
18
+ end
19
+
20
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
21
+
22
+
23
+ #desc 'Test the blog_kit plugin.'
24
+ #Rake::TestTask.new(:test) do |t|
25
+ # t.libs << 'lib'
26
+ # t.libs << 'test'
27
+ # t.pattern = 'test/**/*_test.rb'
28
+ # t.verbose = true
29
+ #end
30
+
31
+ desc 'Generate documentation for the blog_basic plugin.'
32
+ RDoc::Task.new(:rdoc) do |rdoc|
33
+ rdoc.rdoc_dir = 'rdoc'
34
+ rdoc.title = 'BlogBasic'
35
+ rdoc.options << '--line-numbers' << '--inline-source'
36
+ rdoc.rdoc_files.include('README')
37
+ rdoc.rdoc_files.include('lib/**/*.rb')
38
+ end
39
+
40
+ #desc 'Default: run specs.'
41
+ #task :default => :spec
42
+
43
+ #desc "Run the specs under spec/models"
44
+ #Spec::Rake::SpecTask.new do |t|
45
+ # t.spec_opts = ['--options', "spec/spec.opts"]
46
+ # t.spec_files = FileList['spec/*_spec.rb', 'spec/**/*_spec.rb']
47
+ #end
@@ -0,0 +1,9 @@
1
+ #ActiveAdmin.register BlogBasic::BlogPost do
2
+ # #scope :unreleased
3
+
4
+ # index do
5
+ # column :title
6
+ # column "Published", :published_at
7
+ # default_actions
8
+ # end
9
+ #end
@@ -0,0 +1,38 @@
1
+ #ActiveAdmin::Dashboards.build do
2
+
3
+ # Define your dashboard sections here. Each block will be
4
+ # rendered on the dashboard in the context of the view. So just
5
+ # return the content which you would like to display.
6
+
7
+ # == Simple Dashboard Section
8
+ # Here is an example of a simple dashboard section
9
+ #
10
+ # section "Recent Posts" do
11
+ # ul do
12
+ # Post.recent(5).collect do |post|
13
+ # li link_to(post.title, admin_post_path(post))
14
+ # end
15
+ # end
16
+ # end
17
+
18
+ # == Render Partial Section
19
+ # The block is rendered within the context of the view, so you can
20
+ # easily render a partial rather than build content in ruby.
21
+ #
22
+ # section "Recent Posts" do
23
+ # div do
24
+ # render 'recent_posts' # => this will render /app/views/admin/dashboard/_recent_posts.html.erb
25
+ # end
26
+ # end
27
+
28
+ # == Section Ordering
29
+ # The dashboard sections are ordered by a given priority from top left to
30
+ # bottom right. The default priority is 10. By giving a section numerically lower
31
+ # priority it will be sorted higher. For example:
32
+ #
33
+ # section "Recent Posts", :priority => 10
34
+ # section "Recent User", :priority => 1
35
+ #
36
+ # Will render the "Recent Users" then the "Recent Posts" sections on the dashboard.
37
+
38
+ #end
Binary file
@@ -0,0 +1 @@
1
+ //= require active_admin/base
@@ -0,0 +1,9 @@
1
+ // This is a manifest file that'll be compiled into including all the files listed below.
2
+ // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
3
+ // be included in the compiled file accessible from http://example.com/assets/application.js
4
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
5
+ // the compiled file.
6
+ //
7
+ //= require jquery
8
+ //= require jquery_ujs
9
+ //= require_tree .
@@ -0,0 +1,6 @@
1
+ // Active Admin CSS Styles
2
+ @import "active_admin/mixins";
3
+ @import "active_admin/base";
4
+
5
+ // To customize the Active Admin interfaces, add your
6
+ // styles here:
@@ -0,0 +1,7 @@
1
+ /*
2
+ * This is a manifest file that'll automatically include all the stylesheets available in this directory
3
+ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
4
+ * the top of the compiled file, but it's generally better to create a new file per style scope.
5
+ *= require_self
6
+ *= require_tree .
7
+ */
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,27 @@
1
+ module BlogBasic
2
+ class AppController < ActionController::Base
3
+ protect_from_forgery
4
+ helper :all
5
+
6
+ def require_user
7
+ User.new
8
+ end
9
+
10
+ def signed_in?
11
+ !session[:user_id].nil?
12
+ end
13
+
14
+ def current_user
15
+ logger.info "Current user ID: " + session[:user_id].to_s
16
+ if signed_in?
17
+ @current_user ||= User.find(session[:user_id])
18
+ end
19
+ end
20
+
21
+ # def current_user
22
+ # logger.info "(from app_controller.rb) Current user ID: " + session[:user_id].to_s
23
+ # return session[:user_id].nil? ? User.new : User.find(session[:user_id])
24
+ # end
25
+
26
+ end
27
+ end
@@ -0,0 +1,4 @@
1
+ module BlogBasic
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,69 @@
1
+ module BlogBasic
2
+ class BlogCommentsController < ApplicationController
3
+ unloadable
4
+
5
+ helper :blog
6
+
7
+ layout(BlogConf.data['layout'] || 'application')
8
+
9
+ before_filter :require_user, :only => [:destroy]
10
+ before_filter :require_admin, :only => [:destroy]
11
+ before_filter :require_blog_post
12
+
13
+ def create
14
+ @blog_comment = @blog_post.blog_comments.new(params[:blog_comment])
15
+ @blog_comment.user_id = current_user.id if current_user
16
+ @blog_comment.request = request
17
+
18
+ respond_to do |format|
19
+ if @blog_comment.save
20
+ flash[:notice] = 'Your comments has been posted.'
21
+ format.html { redirect_to(@blog_post) }
22
+ format.xml { render :xml => @blog_comment, :status => :created, :location => @blog_comment }
23
+ else
24
+ format.html do
25
+ @blog_comments = @blog_post.blog_comments.paginate(:page => params[:page], :order => 'created_at DESC')
26
+ render :template => '../views/blog_posts/show.html.erb'
27
+ end
28
+ format.xml { render :xml => @blog_comment.errors, :status => :unprocessable_entity }
29
+ end
30
+ end
31
+ end
32
+
33
+
34
+ def destroy
35
+ @blog_comment = BlogComment.find(params[:id])
36
+ @blog_comment.destroy
37
+
38
+ flash[:notice] = 'The comment has been deleted'
39
+
40
+ respond_to do |format|
41
+ format.html { redirect_to(blog_post_url(@blog_post)) }
42
+ format.xml { head :ok }
43
+ end
44
+ end
45
+
46
+ private
47
+ def require_blog_post
48
+ @blog_post = BlogPost.find(params[:blog_post_id])
49
+
50
+ unless @blog_post
51
+ flash[:notice] = 'The post you were looking for could not be found'
52
+ redirect_to :controller => 'blog_posts'
53
+ return false
54
+ end
55
+
56
+ return true
57
+ end
58
+
59
+ def require_admin
60
+ if !current_user || !current_user.admin?
61
+ flash[:notice] = 'You must be an admin to view this page'
62
+ redirect_to blog_posts_path
63
+ return false
64
+ end
65
+
66
+ return true
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,149 @@
1
+ module BlogBasic
2
+ class BlogPostsController < AppController
3
+ unloadable
4
+
5
+ helper :all #blog, shared
6
+ #include BlogBasic::Helpers
7
+
8
+ layout :choose_layout
9
+
10
+ before_filter :require_full_url, :only => [:show]
11
+ before_filter :require_user, :except => [:index, :show]
12
+ before_filter :require_admin, :except => [:index, :show]
13
+ before_filter :setup_image_template, :only => [:new, :edit, :create, :update]
14
+
15
+ def index
16
+ @blog_posts = BlogPost.published.paginate(:page => params[:page], :per_page => 5)
17
+ @index_title = BlogConf.data['blog_name'] || 'Blog'
18
+ @ads = false
19
+
20
+ respond_to do |format|
21
+ format.html # index.html.erb
22
+ format.xml { render :xml => @blog_posts }
23
+ format.atom
24
+ end
25
+ end
26
+
27
+ def drafts
28
+ @blog_posts = BlogPost.drafts.paginate(:page => params[:page], :order => 'updated_at DESC')
29
+
30
+ respond_to do |format|
31
+ format.html # index.html.erb
32
+ format.xml { render :xml => @blog_posts }
33
+ end
34
+ end
35
+
36
+ def show
37
+ @blog_post = BlogPost.find(params[:id])
38
+
39
+ unless @blog_post.published == 1
40
+ return unless require_admin
41
+ end
42
+ @blog_comment = @blog_post.blog_comments.new
43
+ @blog_comments = @blog_post.blog_comments.paginate(:page => params[:page], :order => 'created_at DESC')
44
+ @ads = true
45
+ respond_to do |format|
46
+ format.html # show.html.erb
47
+ format.xml { render :xml => @blog_post }
48
+ end
49
+ end
50
+
51
+ def new
52
+ @blog_post = BlogPost.new
53
+
54
+ respond_to do |format|
55
+ format.html # new.html.erb
56
+ format.xml { render :xml => @blog_post }
57
+ end
58
+ end
59
+
60
+ def edit
61
+ @blog_post = BlogPost.find(params[:id])
62
+ end
63
+
64
+ def create
65
+ @blog_post = BlogPost.new(params[:blog_post])
66
+ @blog_post.user_id = current_user.id
67
+ logger.debug "value: #{params[:blog_post][:published]}"
68
+ @blog_post.published_at = Time.now if params[:blog_post][:published].to_i > 0 && @blog_post.published_at.nil?
69
+
70
+ respond_to do |format|
71
+ if @blog_post.save
72
+ flash[:notice] = 'BlogPost was successfully created.'
73
+ format.html { redirect_to(@blog_post) }
74
+ format.xml { render :xml => @blog_post, :status => :created, :location => @blog_post }
75
+ else
76
+ format.html { render :action => "new" }
77
+ format.xml { render :xml => @blog_post.errors, :status => :unprocessable_entity }
78
+ end
79
+ end
80
+ end
81
+
82
+ def update
83
+ @blog_post = BlogPost.find(params[:id])
84
+
85
+ blog_log = BlogContent.create()
86
+ blog_log.title = @blog_post.title
87
+ blog_log.content = @blog_post.body
88
+ blog_log.blog_post_id = params[:id]
89
+ blog_log.save
90
+
91
+ respond_to do |format|
92
+ @blog_post.published_at = Time.now if params[:blog_post][:published].to_i > 0 && @blog_post.published_at.nil?
93
+ if @blog_post.update_attributes(params[:blog_post])
94
+ flash[:notice] = 'BlogPost was successfully updated.'
95
+ format.html { redirect_to(@blog_post) }
96
+ format.xml { head :ok }
97
+ else
98
+ format.html { render :action => "edit" }
99
+ format.xml { render :xml => @blog_post.errors, :status => :unprocessable_entity }
100
+ end
101
+ end
102
+ end
103
+
104
+ def destroy
105
+ @blog_post = BlogPost.find(params[:id])
106
+ #@blog_post.destroy
107
+
108
+ flash[:notice] = 'The blog post has been deleted'
109
+
110
+ respond_to do |format|
111
+ format.html { redirect_to(blog_posts_url) }
112
+ format.xml { head :ok }
113
+ end
114
+ end
115
+
116
+ private
117
+ def require_full_url
118
+ if params[:id].to_i.to_s == params[:id]
119
+ redirect_to BlogPost.find(params[:id]), :status => 301
120
+ return true
121
+ end
122
+
123
+ return false
124
+ end
125
+
126
+ def require_admin
127
+ if !current_user || !current_user.admin?
128
+ flash[:notice] = 'You must be an admin to view this page'
129
+ redirect_to blog_posts_path
130
+ return false
131
+ end
132
+
133
+ return true
134
+ end
135
+
136
+ def choose_layout
137
+ if ['new', 'edit', 'create', 'update'].include?(params[:action])
138
+ BlogConf.data['admin_layout'] || 'application'
139
+ else
140
+ BlogConf.data['layout'] || 'application'
141
+ end
142
+ end
143
+
144
+ def setup_image_template
145
+ @empty_blog_post = BlogPost.new
146
+ @empty_blog_post.blog_images.build
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,32 @@
1
+ module BlogBasic
2
+ class SessionsController < ApplicationController
3
+ skip_before_filter :verify_authenticity_token
4
+
5
+ def new
6
+ end
7
+
8
+ def create
9
+ auth = request.env["omniauth.auth"]
10
+ logger.debug "Auth:" + auth.inspect
11
+ user = User.where(:identifier_url => auth["uid"].to_s).first
12
+ logger.debug "newlinedddd"
13
+ logger.debug "Here, uid:" + auth["uid"].to_s + ", email:" + auth["info"].inspect
14
+ user ||= User.create!(:identifier_url => auth["uid"].to_s)
15
+ logger.debug "userid" + user.id.to_s
16
+ #user ||= User.create!(:identifier_url => auth["uid"],
17
+ # :email => auth["info"]["email"],
18
+ # :first_name => auth["info"]["first_name"],
19
+ # :last_name => auth["info"]["last_name"])
20
+ #user = User.create_with_omniauth(auth)
21
+ session[:user_id] = user.id
22
+ logger.debug "before"
23
+ redirect_to '/', :notice => "Signed in!"
24
+ logger.debug "after"
25
+ end
26
+
27
+ def destroy
28
+ session[:user_id] = nil
29
+ redirect_to main_app.root_url, :notice => "Signed out!"
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,11 @@
1
+ module BlogBasic
2
+ class TagsController < AppController
3
+ layout 'application'
4
+
5
+ def show
6
+ @blog_posts = BlogPost.published.tagged_with(params[:id]).paginate(:page => params[:page], :per_page => 5)
7
+ render :template => 'blog_basic/blog_posts/index', :layout => true
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end