mini_blog 0.1.0

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 (64) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +34 -0
  4. data/Rakefile +36 -0
  5. data/app/assets/config/mini_blog_manifest.js +2 -0
  6. data/app/assets/javascripts/mini_blog/application.js +27 -0
  7. data/app/assets/stylesheets/mini_blog/application.scss +30 -0
  8. data/app/controllers/mini_blog/application_controller.rb +5 -0
  9. data/app/controllers/mini_blog/articles_controller.rb +56 -0
  10. data/app/controllers/mini_blog/users/confirmations_controller.rb +34 -0
  11. data/app/controllers/mini_blog/users/omniauth_callbacks_controller.rb +34 -0
  12. data/app/controllers/mini_blog/users/passwords_controller.rb +39 -0
  13. data/app/controllers/mini_blog/users/registrations_controller.rb +66 -0
  14. data/app/controllers/mini_blog/users/sessions_controller.rb +32 -0
  15. data/app/controllers/mini_blog/users/unlocks_controller.rb +34 -0
  16. data/app/helpers/mini_blog/application_helper.rb +4 -0
  17. data/app/jobs/mini_blog/application_job.rb +4 -0
  18. data/app/mailers/mini_blog/application_mailer.rb +6 -0
  19. data/app/models/mini_blog/application_record.rb +5 -0
  20. data/app/models/mini_blog/article.rb +10 -0
  21. data/app/models/mini_blog/article_tag_relation.rb +9 -0
  22. data/app/models/mini_blog/image.rb +6 -0
  23. data/app/models/mini_blog/tag.rb +8 -0
  24. data/app/models/mini_blog/user.rb +10 -0
  25. data/app/uploaders/mini_blog/image_content_uploader.rb +49 -0
  26. data/app/views/kaminari/bootstrap4/_first_page.html.slim +2 -0
  27. data/app/views/kaminari/bootstrap4/_gap.html.slim +2 -0
  28. data/app/views/kaminari/bootstrap4/_last_page.html.slim +2 -0
  29. data/app/views/kaminari/bootstrap4/_next_page.html.slim +2 -0
  30. data/app/views/kaminari/bootstrap4/_page.html.slim +6 -0
  31. data/app/views/kaminari/bootstrap4/_paginator.html.slim +12 -0
  32. data/app/views/kaminari/bootstrap4/_prev_page.html.slim +2 -0
  33. data/app/views/layouts/mini_blog/application.html.slim +28 -0
  34. data/app/views/mini_blog/articles/_form.html.slim +9 -0
  35. data/app/views/mini_blog/articles/edit.html.slim +1 -0
  36. data/app/views/mini_blog/articles/index.html.slim +14 -0
  37. data/app/views/mini_blog/articles/new.html.slim +1 -0
  38. data/app/views/mini_blog/articles/show.json.ruby +3 -0
  39. data/app/views/mini_blog/users/confirmations/new.html.erb +16 -0
  40. data/app/views/mini_blog/users/mailer/confirmation_instructions.html.erb +5 -0
  41. data/app/views/mini_blog/users/mailer/email_changed.html.erb +7 -0
  42. data/app/views/mini_blog/users/mailer/password_change.html.erb +3 -0
  43. data/app/views/mini_blog/users/mailer/reset_password_instructions.html.erb +8 -0
  44. data/app/views/mini_blog/users/mailer/unlock_instructions.html.erb +7 -0
  45. data/app/views/mini_blog/users/passwords/edit.html.slim +22 -0
  46. data/app/views/mini_blog/users/passwords/new.html.slim +10 -0
  47. data/app/views/mini_blog/users/registrations/edit.html.erb +43 -0
  48. data/app/views/mini_blog/users/registrations/new.html.erb +29 -0
  49. data/app/views/mini_blog/users/sessions/new.html.slim +17 -0
  50. data/app/views/mini_blog/users/shared/_links.html.erb +25 -0
  51. data/app/views/mini_blog/users/unlocks/new.html.erb +16 -0
  52. data/config/initializers/devise.rb +279 -0
  53. data/config/locales/devise.en.yml +64 -0
  54. data/config/routes.rb +7 -0
  55. data/db/migrate/20180224022923_create_mini_blog_articles.rb +12 -0
  56. data/db/migrate/20180224025140_create_mini_blog_images.rb +9 -0
  57. data/db/migrate/20180224090210_devise_create_mini_blog_users.rb +45 -0
  58. data/db/migrate/20180224112101_create_mini_blog_tags.rb +9 -0
  59. data/db/migrate/20180224113006_create_mini_blog_article_tag_relations.rb +12 -0
  60. data/lib/mini_blog.rb +11 -0
  61. data/lib/mini_blog/engine.rb +5 -0
  62. data/lib/mini_blog/version.rb +3 -0
  63. data/lib/tasks/mini_blog_tasks.rake +4 -0
  64. metadata +260 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d228563f2da2e3c951926d730c171d870b9ecaf0
4
+ data.tar.gz: a5297225f2ec1edc0bdbf9e0f4fc8ccf57c40614
5
+ SHA512:
6
+ metadata.gz: 10054f38b98aedfb7595dab1cfb91593070b1ab3aeb8d4ddc491b689297e04f4831a79248bfb48ff09719034451188b0bd476a915a5dfbf5a521104e95c53148
7
+ data.tar.gz: e9a4f73a0036611d02f25ae940631902c320df7c920bc2ad78e9650fd225936df55534f00a92058df7da274a16489531967fa1cd6f9e81fd5f60007e4a6bbdf9
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2018
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.md ADDED
@@ -0,0 +1,34 @@
1
+ # MiniBlog
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'mini_blog'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install mini_blog
22
+ ```
23
+
24
+ To create user, in `seeds.rb`.And `rails db:seed`
25
+
26
+ ```rb:seeds.rb
27
+ User.create(email: 'yours@example.com', password: 'password', name: 'name')
28
+ ```
29
+
30
+ ## Contributing
31
+ Contribution directions go here.
32
+
33
+ ## License
34
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,36 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'MiniBlog'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ require 'bundler/gem_tasks'
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'test'
31
+ t.pattern = 'test/**/*_test.rb'
32
+ t.verbose = false
33
+ end
34
+
35
+
36
+ task default: :test
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts/mini_blog .js
2
+ //= link_directory ../stylesheets/mini_blog .css
@@ -0,0 +1,27 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require jquery3
14
+ //= require jquery_ujs
15
+ //= require popper
16
+ //= require bootstrap-sprockets
17
+ //= require_tree .
18
+
19
+ window.addEventListener('load', () => {
20
+ $('.article').on('show.bs.collapse', e => {
21
+ const target = e.currentTarget;
22
+ const articleId = target.dataset.id;
23
+ target.textContent = 'loading...';
24
+
25
+ fetch(`/articles/${articleId}.json`).then(r => r.json()).then(r => target.innerHTML = r.body).catch(() => console.log('error'));
26
+ });
27
+ });
@@ -0,0 +1,30 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ */
14
+ @import "bootstrap";
15
+
16
+ ul {
17
+ padding: 0;
18
+ }
19
+
20
+ .main-contents {
21
+ margin-top: 1rem;
22
+ }
23
+
24
+ .tag {
25
+ margin-right: 0.5rem;
26
+ }
27
+
28
+ .card {
29
+ margin-top: 1rem;
30
+ }
@@ -0,0 +1,5 @@
1
+ module MiniBlog
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception
4
+ end
5
+ end
@@ -0,0 +1,56 @@
1
+ require_dependency 'mini_blog/application_controller'
2
+
3
+ module MiniBlog
4
+ class ArticlesController < ApplicationController
5
+ before_action :authenticate_user!, except: [:index, :show]
6
+
7
+ def index
8
+ @articles = Article.includes(:tags).page(params[:page]).per(10)
9
+ end
10
+
11
+ def show
12
+ @article = Article.find(params[:id])
13
+ end
14
+
15
+ def new
16
+ @article = Article.new
17
+ end
18
+
19
+ def create
20
+ @article = Article.new(article_params)
21
+
22
+ if @article.save
23
+ redirect_to root_path
24
+ else
25
+ render 'new'
26
+ end
27
+ end
28
+
29
+ def edit
30
+ @article = Article.find(params[:id])
31
+ end
32
+
33
+ def update
34
+ @article = Article.find(params[:id])
35
+
36
+ if @article.update(article_params)
37
+ redirect_to root_path
38
+ else
39
+ render 'edit'
40
+ end
41
+ end
42
+
43
+ def destroy
44
+ article = Article.find(params[:id])
45
+
46
+ article.destroy
47
+
48
+ head :accepted
49
+ end
50
+
51
+ private
52
+ def article_params
53
+ params.require(:article).permit(:title, :body).merge(tags: params[:article][:tags].split(/;\s*/).map { |tag| MiniBlog::Tag.find_or_initialize_by(name: tag) })
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MiniBlog
4
+ module Users
5
+ class ConfirmationsController < Devise::ConfirmationsController
6
+ # GET /resource/confirmation/new
7
+ # def new
8
+ # super
9
+ # end
10
+
11
+ # POST /resource/confirmation
12
+ # def create
13
+ # super
14
+ # end
15
+
16
+ # GET /resource/confirmation?confirmation_token=abcdef
17
+ # def show
18
+ # super
19
+ # end
20
+
21
+ # protected
22
+
23
+ # The path used after resending confirmation instructions.
24
+ # def after_resending_confirmation_instructions_path_for(resource_name)
25
+ # super(resource_name)
26
+ # end
27
+
28
+ # The path used after confirmation.
29
+ # def after_confirmation_path_for(resource_name, resource)
30
+ # super(resource_name, resource)
31
+ # end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MiniBlog
4
+ module Users
5
+ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
6
+ # You should configure your model like this:
7
+ # devise :omniauthable, omniauth_providers: [:twitter]
8
+
9
+ # You should also create an action method in this controller like this:
10
+ # def twitter
11
+ # end
12
+
13
+ # More info at:
14
+ # https://github.com/plataformatec/devise#omniauth
15
+
16
+ # GET|POST /resource/auth/twitter
17
+ # def passthru
18
+ # super
19
+ # end
20
+
21
+ # GET|POST /users/auth/twitter/callback
22
+ # def failure
23
+ # super
24
+ # end
25
+
26
+ # protected
27
+
28
+ # The path used when OmniAuth fails
29
+ # def after_omniauth_failure_path_for(scope)
30
+ # super(scope)
31
+ # end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MiniBlog
4
+ module Users
5
+ class PasswordsController < Devise::PasswordsController
6
+ layout 'mini_blog/application'
7
+ # GET /resource/password/new
8
+ # def new
9
+ # super
10
+ # end
11
+
12
+ # POST /resource/password
13
+ # def create
14
+ # super
15
+ # end
16
+
17
+ # GET /resource/password/edit?reset_password_token=abcdef
18
+ # def edit
19
+ # super
20
+ # end
21
+
22
+ # PUT /resource/password
23
+ # def update
24
+ # super
25
+ # end
26
+
27
+ # protected
28
+
29
+ # def after_resetting_password_path_for(resource)
30
+ # super(resource)
31
+ # end
32
+
33
+ # The path used after sending reset password instructions
34
+ # def after_sending_reset_password_instructions_path_for(resource_name)
35
+ # super(resource_name)
36
+ # end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MiniBlog
4
+ module Users
5
+ class RegistrationsController < Devise::RegistrationsController
6
+ # before_action :configure_sign_up_params, only: [:create]
7
+ # before_action :configure_account_update_params, only: [:update]
8
+
9
+ # GET /resource/sign_up
10
+ # def new
11
+ # super
12
+ # end
13
+
14
+ # POST /resource
15
+ # def create
16
+ # super
17
+ # end
18
+
19
+ # GET /resource/edit
20
+ # def edit
21
+ # super
22
+ # end
23
+
24
+ # PUT /resource
25
+ # def update
26
+ # super
27
+ # end
28
+
29
+ # DELETE /resource
30
+ # def destroy
31
+ # super
32
+ # end
33
+
34
+ # GET /resource/cancel
35
+ # Forces the session data which is usually expired after sign
36
+ # in to be expired now. This is useful if the user wants to
37
+ # cancel oauth signing in/up in the middle of the process,
38
+ # removing all OAuth session data.
39
+ # def cancel
40
+ # super
41
+ # end
42
+
43
+ # protected
44
+
45
+ # If you have extra params to permit, append them to the sanitizer.
46
+ # def configure_sign_up_params
47
+ # devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute])
48
+ # end
49
+
50
+ # If you have extra params to permit, append them to the sanitizer.
51
+ # def configure_account_update_params
52
+ # devise_parameter_sanitizer.permit(:account_update, keys: [:attribute])
53
+ # end
54
+
55
+ # The path used after sign up.
56
+ # def after_sign_up_path_for(resource)
57
+ # super(resource)
58
+ # end
59
+
60
+ # The path used after sign up for inactive accounts.
61
+ # def after_inactive_sign_up_path_for(resource)
62
+ # super(resource)
63
+ # end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MiniBlog
4
+ module Users
5
+ class SessionsController < Devise::SessionsController
6
+ layout 'mini_blog/application'
7
+ # before_action :configure_sign_in_params, only: [:create]
8
+
9
+ # GET /resource/sign_in
10
+ # def new
11
+ # super
12
+ # end
13
+
14
+ # POST /resource/sign_in
15
+ # def create
16
+ # super
17
+ # end
18
+
19
+ # DELETE /resource/sign_out
20
+ # def destroy
21
+ # super
22
+ # end
23
+
24
+ # protected
25
+
26
+ # If you have extra params to permit, append them to the sanitizer.
27
+ # def configure_sign_in_params
28
+ # devise_parameter_sanitizer.permit(:sign_in, keys: [:attribute])
29
+ # end
30
+ end
31
+ end
32
+ end