blogmodule 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +3 -0
  3. data/Rakefile +39 -0
  4. data/app/assets/javascripts/categories.js +2 -0
  5. data/app/assets/javascripts/posts.js +2 -0
  6. data/app/assets/stylesheets/categories.css +4 -0
  7. data/app/assets/stylesheets/scaffold.css +56 -0
  8. data/app/controllers/categories_controller.rb +77 -0
  9. data/app/controllers/posts_controller.rb +94 -0
  10. data/app/controllers/posts_controller.rb~ +92 -0
  11. data/app/helpers/categories_helper.rb +2 -0
  12. data/app/helpers/posts_helper.rb +2 -0
  13. data/app/models/category.rb +4 -0
  14. data/app/models/category.rb~ +3 -0
  15. data/app/models/post.rb +14 -0
  16. data/app/models/post.rb~ +12 -0
  17. data/app/views/categories/_form.html.erb +21 -0
  18. data/app/views/categories/edit.html.erb +6 -0
  19. data/app/views/categories/index.html.erb +14 -0
  20. data/app/views/categories/new.html.erb +5 -0
  21. data/app/views/categories/show.html.erb +7 -0
  22. data/app/views/posts/_categories.html.erb +5 -0
  23. data/app/views/posts/_categories.html.erb~ +5 -0
  24. data/app/views/posts/_form.html.erb +42 -0
  25. data/app/views/posts/_form.html.erb~ +40 -0
  26. data/app/views/posts/edit.html.erb +6 -0
  27. data/app/views/posts/index.html.erb +17 -0
  28. data/app/views/posts/index.html.erb~ +20 -0
  29. data/app/views/posts/new.html.erb +5 -0
  30. data/app/views/posts/show.html.erb +27 -0
  31. data/app/views/posts/show.html.erb~ +30 -0
  32. data/config/routes.rb +6 -0
  33. data/db/migrate/20111231175637_create_categories.rb +13 -0
  34. data/db/migrate/20111231175637_create_categories.rb~ +9 -0
  35. data/db/migrate/20111231181111_create_posts.rb +17 -0
  36. data/db/migrate/20111231181111_create_posts.rb~ +17 -0
  37. data/db/migrate/20111231183528_add_categories_to_post.rb~ +7 -0
  38. data/db/migrate/20111231183528_create_categories_posts.rb +12 -0
  39. data/db/migrate/20111231183528_create_categories_posts.rb~ +7 -0
  40. data/lib/blogmodule.rb +4 -0
  41. data/lib/blogmodule/engine.rb +4 -0
  42. data/lib/blogmodule/version.rb +3 -0
  43. data/lib/tasks/blogmodule_tasks.rake +4 -0
  44. data/test/blogmodule_test.rb +7 -0
  45. data/test/dummy/Rakefile +7 -0
  46. data/test/dummy/app/assets/javascripts/application.js +9 -0
  47. data/test/dummy/app/assets/stylesheets/application.css +7 -0
  48. data/test/dummy/app/controllers/application_controller.rb +3 -0
  49. data/test/dummy/app/helpers/application_helper.rb +2 -0
  50. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  51. data/test/dummy/config.ru +4 -0
  52. data/test/dummy/config/application.rb +45 -0
  53. data/test/dummy/config/boot.rb +10 -0
  54. data/test/dummy/config/database.yml +25 -0
  55. data/test/dummy/config/environment.rb +5 -0
  56. data/test/dummy/config/environments/development.rb +30 -0
  57. data/test/dummy/config/environments/production.rb +60 -0
  58. data/test/dummy/config/environments/test.rb +39 -0
  59. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  60. data/test/dummy/config/initializers/inflections.rb +10 -0
  61. data/test/dummy/config/initializers/mime_types.rb +5 -0
  62. data/test/dummy/config/initializers/secret_token.rb +7 -0
  63. data/test/dummy/config/initializers/session_store.rb +8 -0
  64. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  65. data/test/dummy/config/locales/en.yml +5 -0
  66. data/test/dummy/config/routes.rb +58 -0
  67. data/test/dummy/db/development.sqlite3 +0 -0
  68. data/test/dummy/db/schema.rb +37 -0
  69. data/test/dummy/log/development.log +10438 -0
  70. data/test/dummy/public/404.html +26 -0
  71. data/test/dummy/public/422.html +26 -0
  72. data/test/dummy/public/500.html +26 -0
  73. data/test/dummy/public/favicon.ico +0 -0
  74. data/test/dummy/script/rails +6 -0
  75. data/test/dummy/tmp/cache/assets/BAD/970/sprockets%2F9a5112306a4228313104b6e694330675 +378 -0
  76. data/test/dummy/tmp/cache/assets/CD1/FE0/sprockets%2Fa933373e0504e8cd28ab26932e144bb1 +9289 -0
  77. data/test/dummy/tmp/cache/assets/CD8/430/sprockets%2F2859ec948a5d3b35fed62400c142008c +0 -0
  78. data/test/dummy/tmp/cache/assets/CD8/710/sprockets%2F4597cff24032334bc3e3542f0754bac8 +395 -0
  79. data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +38 -0
  80. data/test/dummy/tmp/cache/assets/D54/ED0/sprockets%2F71c9fa01091d432b131da3bb73faf3d4 +10 -0
  81. data/test/dummy/tmp/cache/assets/D84/210/sprockets%2Fabd0103ccec2b428ac62c94e4c40b384 +9652 -0
  82. data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  83. data/test/dummy/tmp/cache/assets/E2C/A10/sprockets%2F9accda57c2c3dd81f1fadc6e19c55c90 +13 -0
  84. data/test/dummy/tmp/cache/assets/E3E/820/sprockets%2F5a1c7de58da1288fd9f29b75aeedf6ea +9272 -0
  85. data/test/fixtures/categories.yml +7 -0
  86. data/test/fixtures/posts.yml +15 -0
  87. data/test/functional/categories_controller_test.rb +49 -0
  88. data/test/functional/posts_controller_test.rb +49 -0
  89. data/test/integration/navigation_test.rb +10 -0
  90. data/test/test_helper.rb +10 -0
  91. data/test/unit/category_test.rb +7 -0
  92. data/test/unit/helpers/categories_helper_test.rb +4 -0
  93. data/test/unit/helpers/posts_helper_test.rb +4 -0
  94. data/test/unit/post_test.rb +7 -0
  95. metadata +212 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2011 YOURNAME
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/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = Blogmodule
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Blogmodule'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+
27
+ Bundler::GemHelper.install_tasks
28
+
29
+ require 'rake/testtask'
30
+
31
+ Rake::TestTask.new(:test) do |t|
32
+ t.libs << 'lib'
33
+ t.libs << 'test'
34
+ t.pattern = 'test/**/*_test.rb'
35
+ t.verbose = false
36
+ end
37
+
38
+
39
+ task :default => :test
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,56 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ div.field, div.actions {
20
+ margin-bottom: 10px;
21
+ }
22
+
23
+ #notice {
24
+ color: green;
25
+ }
26
+
27
+ .field_with_errors {
28
+ padding: 2px;
29
+ background-color: red;
30
+ display: table;
31
+ }
32
+
33
+ #error_explanation {
34
+ width: 450px;
35
+ border: 2px solid red;
36
+ padding: 7px;
37
+ padding-bottom: 0;
38
+ margin-bottom: 20px;
39
+ background-color: #f0f0f0;
40
+ }
41
+
42
+ #error_explanation h2 {
43
+ text-align: left;
44
+ font-weight: bold;
45
+ padding: 5px 5px 5px 15px;
46
+ font-size: 12px;
47
+ margin: -7px;
48
+ margin-bottom: 0px;
49
+ background-color: #c00;
50
+ color: #fff;
51
+ }
52
+
53
+ #error_explanation ul li {
54
+ font-size: 12px;
55
+ list-style: square;
56
+ }
@@ -0,0 +1,77 @@
1
+ class CategoriesController < ApplicationController
2
+ # GET /categories
3
+ # GET /categories.json
4
+ def index
5
+ @categories = Category.all
6
+
7
+ respond_to do |format|
8
+ format.html # index.html.erb
9
+ format.json { render json: @categories }
10
+ end
11
+ end
12
+
13
+ def show
14
+ @category = Category.find(params[:id])
15
+ end
16
+
17
+
18
+ # GET /categories/new
19
+ # GET /categories/new.json
20
+ def new
21
+ @category = Category.new
22
+
23
+ respond_to do |format|
24
+ format.html # new.html.erb
25
+ format.json { render json: @category }
26
+ end
27
+ end
28
+
29
+ # GET /categories/1/edit
30
+ def edit
31
+ @category = Category.find(params[:id])
32
+ end
33
+
34
+ # POST /categories
35
+ # POST /categories.json
36
+ def create
37
+ @category = Category.new(params[:category])
38
+
39
+ respond_to do |format|
40
+ if @category.save
41
+ format.html { redirect_to @category, notice: 'Category was successfully created.' }
42
+ format.json { render json: @category, status: :created, location: @category }
43
+ else
44
+ format.html { render action: "new" }
45
+ format.json { render json: @category.errors, status: :unprocessable_entity }
46
+ end
47
+ end
48
+ end
49
+
50
+ # PUT /categories/1
51
+ # PUT /categories/1.json
52
+ def update
53
+ @category = Category.find(params[:id])
54
+
55
+ respond_to do |format|
56
+ if @category.update_attributes(params[:category])
57
+ format.html { redirect_to @category, notice: 'Category was successfully updated.' }
58
+ format.json { head :ok }
59
+ else
60
+ format.html { render action: "edit" }
61
+ format.json { render json: @category.errors, status: :unprocessable_entity }
62
+ end
63
+ end
64
+ end
65
+
66
+ # DELETE /categories/1
67
+ # DELETE /categories/1.json
68
+ def destroy
69
+ @category = Category.find(params[:id])
70
+ @category.destroy
71
+
72
+ respond_to do |format|
73
+ format.html { redirect_to categories_url }
74
+ format.json { head :ok }
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,94 @@
1
+ class PostsController < ApplicationController
2
+
3
+ before_filter :load_categories
4
+ # GET /posts
5
+ # GET /posts.json
6
+ def index
7
+ @posts = Post.scoped
8
+ @posts = Post.published
9
+ @posts = @category.posts if @category.present?
10
+
11
+ respond_to do |format|
12
+ format.html # index.html.erb
13
+ format.json { render json: @posts }
14
+ end
15
+ end
16
+
17
+ # GET /posts/1
18
+ # GET /posts/1.json
19
+ def show
20
+ @post = Post.published.find(params[:id])
21
+
22
+ respond_to do |format|
23
+ format.html # show.html.erb
24
+ format.json { render json: @post }
25
+ end
26
+ end
27
+
28
+ # GET /posts/new
29
+ # GET /posts/new.json
30
+ def new
31
+ @post = Post.new
32
+
33
+ respond_to do |format|
34
+ format.html # new.html.erb
35
+ format.json { render json: @post }
36
+ end
37
+ end
38
+
39
+ # GET /posts/1/edit
40
+ def edit
41
+ @post = Post.find(params[:id])
42
+ end
43
+
44
+ # POST /posts
45
+ # POST /posts.json
46
+ def create
47
+ @post = Post.new(params[:post])
48
+
49
+ respond_to do |format|
50
+ if @post.save
51
+ format.html { redirect_to @post, notice: 'Post was successfully created.' }
52
+ format.json { render json: @post, status: :created, location: @post }
53
+ else
54
+ format.html { render action: "new" }
55
+ format.json { render json: @post.errors, status: :unprocessable_entity }
56
+ end
57
+ end
58
+ end
59
+
60
+ # PUT /posts/1
61
+ # PUT /posts/1.json
62
+ def update
63
+ params[:post][:category_ids] ||= []
64
+
65
+ @post = Post.find(params[:id])
66
+
67
+ respond_to do |format|
68
+ if @post.update_attributes(params[:post])
69
+ format.html { redirect_to @post, notice: 'Post was successfully updated.' }
70
+ format.json { head :ok }
71
+ else
72
+ format.html { render action: "edit" }
73
+ format.json { render json: @post.errors, status: :unprocessable_entity }
74
+ end
75
+ end
76
+ end
77
+
78
+ # DELETE /posts/1
79
+ # DELETE /posts/1.json
80
+ def destroy
81
+ @post = Post.find(params[:id])
82
+ @post.destroy
83
+
84
+ respond_to do |format|
85
+ format.html { redirect_to posts_url }
86
+ format.json { head :ok }
87
+ end
88
+ end
89
+ protected
90
+ def load_categories
91
+ @categories = Category.all
92
+ @category = Category.find(params[:category_id]) if params[:category_id]
93
+ end
94
+ end
@@ -0,0 +1,92 @@
1
+ class PostsController < ApplicationController
2
+
3
+ before_filter :load_categories
4
+ # GET /posts
5
+ # GET /posts.json
6
+ def index
7
+ @posts = Post.scoped
8
+ @posts = Post.published
9
+ @posts = @categories.posts if @category.present?
10
+
11
+ respond_to do |format|
12
+ format.html # index.html.erb
13
+ format.json { render json: @posts }
14
+ end
15
+ end
16
+
17
+ # GET /posts/1
18
+ # GET /posts/1.json
19
+ def show
20
+ @post = Post.published.find(params[:id])
21
+
22
+ respond_to do |format|
23
+ format.html # show.html.erb
24
+ format.json { render json: @post }
25
+ end
26
+ end
27
+
28
+ # GET /posts/new
29
+ # GET /posts/new.json
30
+ def new
31
+ @post = Post.new
32
+
33
+ respond_to do |format|
34
+ format.html # new.html.erb
35
+ format.json { render json: @post }
36
+ end
37
+ end
38
+
39
+ # GET /posts/1/edit
40
+ def edit
41
+ @post = Post.find(params[:id])
42
+ end
43
+
44
+ # POST /posts
45
+ # POST /posts.json
46
+ def create
47
+ @post = Post.new(params[:post])
48
+
49
+ respond_to do |format|
50
+ if @post.save
51
+ format.html { redirect_to @post, notice: 'Post was successfully created.' }
52
+ format.json { render json: @post, status: :created, location: @post }
53
+ else
54
+ format.html { render action: "new" }
55
+ format.json { render json: @post.errors, status: :unprocessable_entity }
56
+ end
57
+ end
58
+ end
59
+
60
+ # PUT /posts/1
61
+ # PUT /posts/1.json
62
+ def update
63
+ @post = Post.find(params[:id])
64
+
65
+ respond_to do |format|
66
+ if @post.update_attributes(params[:post])
67
+ format.html { redirect_to @post, notice: 'Post was successfully updated.' }
68
+ format.json { head :ok }
69
+ else
70
+ format.html { render action: "edit" }
71
+ format.json { render json: @post.errors, status: :unprocessable_entity }
72
+ end
73
+ end
74
+ end
75
+
76
+ # DELETE /posts/1
77
+ # DELETE /posts/1.json
78
+ def destroy
79
+ @post = Post.find(params[:id])
80
+ @post.destroy
81
+
82
+ respond_to do |format|
83
+ format.html { redirect_to posts_url }
84
+ format.json { head :ok }
85
+ end
86
+ end
87
+ protected
88
+ def load_categories
89
+ @categories = Category.all
90
+ @category = Category.find(params[:category_id]) if params[:category_id]
91
+ end
92
+ end
@@ -0,0 +1,2 @@
1
+ module CategoriesHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module PostsHelper
2
+ end
@@ -0,0 +1,4 @@
1
+ class Category < ActiveRecord::Base
2
+ has_and_belongs_to_many :posts
3
+ validates_uniqueness_of :name
4
+ end
@@ -0,0 +1,3 @@
1
+ class Category < ActiveRecord::Base
2
+ has_and_belongs_to_many :posts
3
+ end
@@ -0,0 +1,14 @@
1
+ class Post < ActiveRecord::Base
2
+
3
+ has_and_belongs_to_many :categories
4
+
5
+ validates_uniqueness_of :title
6
+
7
+ def to_param
8
+ "#{id}-#{title}".parameterize
9
+ end
10
+
11
+ scope :published, lambda {
12
+ where("published = ? AND date < ?", true, Time.current)
13
+ }
14
+ end
@@ -0,0 +1,12 @@
1
+ class Post < ActiveRecord::Base
2
+ has_and_belongs_to_many :category
3
+ validates_presence_of :title
4
+
5
+ def to_param
6
+ "#{id}-#{title}".parameterize
7
+ end
8
+
9
+ scope :published, lambda {
10
+ where("published = ? AND date < ?", true, Time.current)
11
+ }
12
+ end