blog_boi 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9edccc6733c4fd1af893fd5f01ee68ee9f47a9d44a35fa1c67f9024314607552
4
- data.tar.gz: 9521dcbf140d316907f8b26dd64470e10b8726bd9068f627ae05c3f73dffedd8
3
+ metadata.gz: 4a456021f5a432830adc986e89735e394c7b33173fcedce3e61a2816f0f0b53d
4
+ data.tar.gz: 8986ef7e0032f0a6c0441ffa4b1373fa0e58764e48d1f7544313610844ef0037
5
5
  SHA512:
6
- metadata.gz: cc9ed6b88e1041a55f2a6f79878d0602e4e7129a1196d76022662c09081480921c6bf0a8864778c0d467bb67a140cd6e8a8a35e0984569f9aea43cd729484ed4
7
- data.tar.gz: 9fc77ff8add34fa38b08b4828ffec34241742e3e092a2b483f4c5832c5292c8aae0bda1c316439ef92c5ca6334b09e30d157807e942bddb6bcf31f66cc22ae0e
6
+ metadata.gz: ea17c3c5344b1a36749734d75b797f6e187a8c8f59d4559b00ee81a9fe413fc2cd47f44f6c0bc1dcf159b5ca916ec362cc958c4b0076268305e9e761b3df0c02
7
+ data.tar.gz: 4f925f2a73151ce58c697763fdc3d1962541618c20433527be70718b8f814aefe971e40bcd45e3b4ec948844697b481b08209d737d1cab561ae17cf4a6ecd91e
data/README.md CHANGED
@@ -2,9 +2,7 @@
2
2
 
3
3
  BlogBoi is a rails gem / engine that provides out-of-the-box blogging functionality to your rails application
4
4
 
5
- WARNING: v0.0.1 and v0.0.2 are not yet stable / production ready
6
-
7
- ## A) Installation
5
+ ## Installation
8
6
 
9
7
  1. Add this line to your application's Gemfile:
10
8
 
@@ -65,20 +63,27 @@ BlogBoi.author_class = "User" # name of active record model containing authors w
65
63
 
66
64
  See lib/blog_boi.rb for all customization options.
67
65
 
68
- ## B) Running tests
66
+ 7. Finally, your parent application must define the method `admin_signed_in?`. If you are using Devise, this method may already exist. It should return true if the blog admin is signed in, and false if not. When it returns true, you may create, update, and destroy blog articles. It should be available in controllers and views; it should be defined in ApplicationController, and should be marked a helper method. E.g.
69
67
 
70
- - Run all tests other than system: `rake app:test`
71
- - Run system tests: `rake app:test:system`
72
- - Run all tests: `rake` or `rake test`
73
- - In normal rails apps: running single test is possible, but not sure how (or if functionality included out of box for engine). Can also run a particular test method from the test case by providing the -n or --name flag. Can also run an entire directory of tests by providing the path to the directory. I don't think any of this works out of the box for engines. How can I get this to work?
68
+ ```
69
+ class ApplicationController < ActionController::Base
74
70
 
75
- **B.1 Test coverage**
71
+ helper_method :admin_signed_in?
76
72
 
77
- Exists in `coverage` folder in root directory.
73
+ def admin_signed_in?
74
+ ...
75
+ end
78
76
 
79
- To view in a browser, execute from root directory: `open coverage/index.html`
77
+ end
78
+ ```
79
+
80
+ ## View partial hooks
81
+
82
+ List of view partial hooks that are rendered if they exist in parent application:
80
83
 
81
- ## C) Custom style / SCSS
84
+ - `layouts/blog_boi/head_extension`: (for adding html to head of blog_boi application layout in `layouts/blog_boi/application`)
85
+
86
+ ## Custom style / SCSS
82
87
 
83
88
  To override SCSS bootstrap mixins / styles, add a file in parent application called blog_boi/bootstrap_overrides.scss.
84
89
  - See test/dummy app for example
@@ -86,36 +91,43 @@ To override SCSS bootstrap mixins / styles, add a file in parent application cal
86
91
 
87
92
  Override the header or footer by placing your own files at `views/layouts/_header` or `views/layouts/_footer`
88
93
 
89
- ## D) Other useful commands
94
+ ## Running tests
95
+
96
+ - Run all tests other than system: `rake app:test`
97
+ - Run system tests: `rake app:test:system`
98
+ - Run all tests: `rake` or `rake test`
90
99
 
91
- - `rake db:drop db:create db:migrate db:seed` or `db:migrate:reset db:seed` will remove and recreate and reseed db. Avoid using if possible.
92
- - `rake db:migrate:reset db:seed`
100
+ **Test coverage**
101
+
102
+ Exists in `coverage` folder in root directory.
103
+
104
+ To view in a browser, execute from root directory: `open coverage/index.html`
93
105
 
94
- ## E) License
106
+ ## License
95
107
 
96
108
  The gem is currently available as open source software under the terms of the [MIT License](https://opensource.org/licenses/MIT).
97
109
 
98
- ## F) Contributing
110
+ ## Contributing
99
111
 
100
112
  This gem is currently not actively accepting contributions.
101
113
 
102
114
  With that in mind, if you'd like to make a fix / change, please create a pull request (and when I have a moment - probably in a couple weeks time - I'll have a look)!
103
115
 
104
- ## G) Updating gem version (for maintainers)
116
+ ## Updating gem version (for maintainers)
105
117
 
106
- **G.1 Update version**
118
+ **1. Update version**
107
119
 
108
120
  In `lib/blog_boi/version.rb` update version.
109
121
 
110
- **G.2 Build gem**
122
+ **2. Build gem**
111
123
 
112
124
  `gem build blog_boi.gemspec`
113
125
 
114
- **G.3 Push gem**
126
+ **3. Push gem**
115
127
 
116
128
  `gem push blog_boi-X.X.X.gem` (replace X's with version)
117
129
 
118
- **G.4 Tag GitHub**
130
+ **4. Tag GitHub**
119
131
 
120
132
  `git tag -a vX.X.X -m "Msg"`
121
133
  `git push --tags`
@@ -4,12 +4,14 @@ module BlogBoi
4
4
  before_action :create_meta_tags_obj
5
5
 
6
6
  # TBU
7
- def is_admin
8
- if true
7
+ def authenticate_admin
8
+ if !defined?(admin_signed_in?)
9
+ raise BlogBoi::MethodNotImplementedByParentApplication, "admin_signed_in?"
10
+ elsif admin_signed_in?
9
11
  true
10
12
  else
11
13
  redirect_to root_path
12
- end
14
+ end
13
15
  end
14
16
 
15
17
  protected
@@ -4,7 +4,7 @@ module BlogBoi
4
4
  class ArticlesController < ApplicationController
5
5
  before_action :set_article, only: [:edit, :update, :destroy]
6
6
  before_action :set_article_by_slug, only: [:show]
7
- before_action :is_admin, only: [:new, :create, :edit, :update, :destroy]
7
+ before_action :authenticate_admin, only: [:new, :create, :edit, :update, :destroy]
8
8
  before_action :set_categories
9
9
 
10
10
  # GET /articles
@@ -2,7 +2,7 @@ require_dependency "blog_boi/application_controller"
2
2
 
3
3
  module BlogBoi
4
4
  class CommentsController < ApplicationController
5
- before_action :set_categories, :is_admin
5
+ before_action :set_categories, :authenticate_admin
6
6
 
7
7
  def create
8
8
  @article = Article.find(params[:article_id])
@@ -1,5 +1,3 @@
1
- require 'byebug'
2
-
3
1
  module BlogBoi
4
2
 
5
3
  module ApplicationHelper
@@ -17,9 +15,12 @@ module BlogBoi
17
15
 
18
16
  end
19
17
 
20
- # TBU
21
- def is_admin
22
- true
18
+ def is_admin?
19
+ if defined?(admin_signed_in?)
20
+ admin_signed_in?
21
+ else
22
+ raise BlogBoi::MethodNotImplementedByParentApplication, "admin_signed_in?"
23
+ end
23
24
  end
24
25
 
25
26
  def controller_action
@@ -1,4 +1,7 @@
1
1
  module BlogBoi
2
2
  module ArticlesHelper
3
+ def str_of_authors
4
+ BlogBoi.author_class.all.pluck(:name).join(',')
5
+ end
3
6
  end
4
7
  end
@@ -28,10 +28,10 @@
28
28
  </div>
29
29
 
30
30
 
31
- <% if is_admin %>
31
+ <% if is_admin? %>
32
32
 
33
33
  <div class="mt-2">
34
- <%= link_to 'Show', article %> |
34
+ <%= link_to 'Show', article_path(article.slug) %> |
35
35
  <%= link_to 'Edit', edit_article_path(article) %> |
36
36
  <%= link_to 'Destroy', article, method: :delete, data: { confirm: 'Are you sure?' } %>
37
37
  </div>
@@ -15,6 +15,8 @@
15
15
  <div class="field mt-3">
16
16
  <%= form.label :author_name %><br>
17
17
  <%= form.text_field :author_name, placeholder: 'e.g. Charlie Reese', class: 'form-control' %>
18
+ <small class="d-block">Existing authors: <%= str_of_authors %></small>
19
+ <small class="d-block"><span class="text-danger">Warning</span>: entering a new name will create a new <%= BlogBoi.author_class || '' %> entry in DB with only name filled in.</small>
18
20
  </div>
19
21
 
20
22
  <div class="field mt-3">
@@ -6,7 +6,7 @@
6
6
 
7
7
  <div class="row">
8
8
 
9
- <% if is_admin %>
9
+ <% if is_admin? %>
10
10
 
11
11
  <div class="col-12 mt-4">
12
12
  <%= link_to 'New Article', new_article_path, class: 'btn-primary rounded' %>
@@ -43,16 +43,17 @@
43
43
 
44
44
  <%= render 'article_body' %>
45
45
 
46
- <% if is_admin %>
46
+ <div class="mt-5">
47
+
48
+ <% if is_admin? %>
47
49
 
48
- <div class="mt-5">
49
-
50
50
  <%= link_to 'Edit', edit_article_path(@article) %> |
51
- <%= link_to 'Back', articles_path %>
52
51
 
53
- </div>
54
-
55
- <% end %>
52
+ <% end %>
53
+
54
+ <%= link_to 'Back', articles_path %>
55
+
56
+ </div>
56
57
 
57
58
  </div>
58
59
 
@@ -10,6 +10,8 @@
10
10
  <%= stylesheet_link_tag "blog_boi/application", media: "all" %>
11
11
  <%= stylesheet_link_tag "bootstrap_customizer", media: "all" %>
12
12
  <%= javascript_include_tag "blog_boi/application" %>
13
+
14
+ <%= render 'layouts/blog_boi/head_extension' if lookup_context.exists?('layouts/blog_boi/_head_extension') %>
13
15
  </head>
14
16
  <body>
15
17
 
@@ -1,8 +1,8 @@
1
1
  class CreateJoinTableArticleCategory < ActiveRecord::Migration[5.2]
2
2
  def change
3
3
  create_join_table :blog_boi_articles, :blog_boi_categories do |t|
4
- t.index [:article_id, :category_id], name: 'index_blog_boi_article_id_category_id'
5
- t.index [:category_id, :article_id], name: 'index_blog_boi_category_id_article_id'
4
+ t.index [:blog_boi_article_id, :blog_boi_category_id], name: 'index_blog_boi_article_id_category_id'
5
+ t.index [:blog_boi_category_id, :blog_boi_article_id], name: 'index_blog_boi_category_id_article_id'
6
6
  end
7
7
  end
8
8
  end
data/lib/blog_boi.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "blog_boi/engine"
2
+ require "blog_boi/error_classes"
2
3
 
3
4
  module BlogBoi
4
5
  mattr_accessor :author_class, :company_name, :company_logo_path, :company_description, :blog_description,
@@ -0,0 +1,18 @@
1
+ module BlogBoi
2
+
3
+ class MethodNotImplementedByParentApplication < ::StandardError
4
+ attr_reader :method_missing
5
+
6
+ def initialize(method)
7
+ @method_missing = method
8
+
9
+ super(
10
+ 'Parent application must implement the method ' +
11
+ method_missing +
12
+ " - See BlogBoi README for requirement."
13
+ )
14
+ end
15
+
16
+ end
17
+
18
+ end
@@ -1,3 +1,3 @@
1
1
  module BlogBoi
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blog_boi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charlie Reese
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-23 00:00:00.000000000 Z
11
+ date: 2019-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kramdown
@@ -172,6 +172,7 @@ files:
172
172
  - db/seeds.rb
173
173
  - lib/blog_boi.rb
174
174
  - lib/blog_boi/engine.rb
175
+ - lib/blog_boi/error_classes.rb
175
176
  - lib/blog_boi/version.rb
176
177
  - lib/tasks/blog_boi_tasks.rake
177
178
  homepage: https://github.com/charliereese/blog_boi