blog-gem 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +98 -0
  4. data/Rakefile +37 -0
  5. data/app/assets/config/blog_gem_manifest.js +2 -0
  6. data/app/assets/javascripts/blog.js +15 -0
  7. data/app/assets/stylesheets/blog.sass +199 -0
  8. data/app/controllers/blog/gem/application_controller.rb +15 -0
  9. data/app/controllers/blog/gem/authors_controller.rb +93 -0
  10. data/app/controllers/blog/gem/blog_controller.rb +60 -0
  11. data/app/controllers/blog/gem/posts_controller.rb +63 -0
  12. data/app/helpers/blog/gem/application_helper.rb +13 -0
  13. data/app/models/blog/gem/application_record.rb +7 -0
  14. data/app/models/blog/gem/author.rb +34 -0
  15. data/app/models/blog/gem/post.rb +48 -0
  16. data/app/views/blog/_blog_archive.slim +7 -0
  17. data/app/views/blog/_posts_box.slim +15 -0
  18. data/app/views/blog/gem/authors/_avatar.slim +21 -0
  19. data/app/views/blog/gem/authors/_contact.slim +15 -0
  20. data/app/views/blog/gem/authors/_form.slim +17 -0
  21. data/app/views/blog/gem/authors/_user.slim +9 -0
  22. data/app/views/blog/gem/authors/edit.html.slim +5 -0
  23. data/app/views/blog/gem/authors/index.html.slim +37 -0
  24. data/app/views/blog/gem/authors/login.slim +8 -0
  25. data/app/views/blog/gem/authors/new.html.slim +7 -0
  26. data/app/views/blog/gem/blog/_author.slim +12 -0
  27. data/app/views/blog/gem/blog/_item.slim +15 -0
  28. data/app/views/blog/gem/blog/_sidebar.slim +54 -0
  29. data/app/views/blog/gem/blog/index.atom.builder +16 -0
  30. data/app/views/blog/gem/blog/index.slim +50 -0
  31. data/app/views/blog/gem/blog/show.slim +54 -0
  32. data/app/views/blog/gem/posts/_form.html.slim +15 -0
  33. data/app/views/blog/gem/posts/edit.html.slim +4 -0
  34. data/app/views/blog/gem/posts/new.html.slim +6 -0
  35. data/config/locales/de.yml +75 -0
  36. data/config/routes.rb +16 -0
  37. data/db/migrate/20160315062930_create_posts_and_authors.rb +50 -0
  38. data/lib/blog/gem/engine.rb +7 -0
  39. data/lib/blog/gem/version.rb +5 -0
  40. data/lib/blog/gem.rb +44 -0
  41. data/lib/tasks/blog/gem_tasks.rake +4 -0
  42. metadata +255 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cef6e4b266765034e04aa5c3dc0650c33bf95ef3
4
+ data.tar.gz: 7a6b02293f613b3fafaa99656f669d60ac38a6f1
5
+ SHA512:
6
+ metadata.gz: 8a14ac003f9f58ef7ac8e3bf621090016ebe6df446c2acbb2c486fe01679a2b237597167d673899169acd8387ab22f41c6768fa640b029beb546f73e12315f89
7
+ data.tar.gz: 36bf48da51a6d0fbdec9e562bbf0a2bef6ffde0b9a2854b59da7ae6c31ace1991505fce90881cfc2cd68dd5b5539556df11f3f2093de17e71f4fbb95aeb7c75b
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017 Vincent
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,98 @@
1
+ # Shubbl - Blog::Gem
2
+ Blog Tool for the Shubbl Homepage
3
+
4
+ ## Demo: https://www.shubbl.de/blog
5
+
6
+ ## Installation
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'blog-gem'
11
+ ```
12
+
13
+ And then execute:
14
+ ```bash
15
+ $ bundle
16
+ ```
17
+
18
+ Or install it yourself as:
19
+ ```bash
20
+ $ gem install blog-gem
21
+ ```
22
+
23
+ ## Setup
24
+
25
+
26
+ ### Install the migration to create the data table:
27
+
28
+ For Acts as taggable on
29
+ ```bash
30
+ rake acts_as_taggable_on_engine:install:migrations
31
+ ```
32
+ ```bash
33
+ rake blog_gem:install:migrations
34
+ rake db:migrate
35
+ ```
36
+
37
+ ### Into your routes.rb
38
+ ```ruby
39
+ mount Blog::Gem::Engine => "/blog", :as => :blogs
40
+ ```
41
+
42
+ ### Into your style.sass
43
+ ```
44
+ @import blog
45
+ ```
46
+ ###Into your application.js
47
+ ```
48
+ //= require blog
49
+ ```
50
+ ### Into rails c
51
+ ```ruby
52
+ Blog::Gem::Author.create_admin(name: "", password: "", email: "")
53
+ ```
54
+
55
+ ### Add to your Meta Tag View
56
+ ```ruby
57
+ <%= yield :meta %>
58
+ ```
59
+ ### You can use the globel variabel outside of the blog#show
60
+ ```ruby
61
+ @page_title: title
62
+ @description: teaser
63
+ @keywords: tag_list (join with ',' )
64
+ @image: thumbnail_url
65
+ @current_path
66
+ ```
67
+
68
+ ## Config
69
+
70
+ ## Create config/initializers/blog.rb, yout can modify:
71
+
72
+ ```ruby
73
+ Blog::Gem.setup do |config|
74
+ config.categories = {
75
+ "name of the categorie" => id,
76
+ "shubbl" => 0,
77
+ "tipps" => 1,
78
+ "story" => 2,
79
+ "porträt" => 3,
80
+ "dating" => 4,
81
+ "lifestyle" => 5,
82
+ "kolumne" => 6,
83
+ "spotlight" => 7,
84
+ }
85
+ config.url = "https://www.shubbl.de" # In development: http://localhost:3000
86
+ config.archive_count = 13
87
+ config.home_posts_count = 6
88
+ config.tags_count = 24
89
+ config.widget_posts_count = 6
90
+ config.path = "/blog"
91
+ config.image_path = "/uploads"
92
+ config.title_enable = true
93
+
94
+ end
95
+ ```
96
+
97
+ ## License
98
+ 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,37 @@
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 = 'Blog::Gem'
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 << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+
37
+ task default: :test
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts/blog/gem .js
2
+ //= link_directory ../stylesheets/blog/gem .css
@@ -0,0 +1,15 @@
1
+ document.addEventListener("turbolinks:load", function() {
2
+ $( "#blog-archive-trigger" ).click(function() {
3
+ var c = $(this).data("current")
4
+ $(this).text($(this).data(c))
5
+ if (c == "show"){
6
+ $(".blog-gem-taglist-first").removeClass("hidden")
7
+ $(".blog-gem-taglist-all").addClass("hidden")
8
+ $(this).data("current", "hidden")
9
+ }else{
10
+ $(".blog-gem-taglist-first").addClass("hidden")
11
+ $(".blog-gem-taglist-all").removeClass("hidden")
12
+ $(this).data("current", "show")
13
+ }
14
+ });
15
+ })
@@ -0,0 +1,199 @@
1
+ .blog-container
2
+ @extend .container
3
+ margin-top: 30px
4
+
5
+ .blog
6
+ .blog-item
7
+ h2
8
+ margin-top: 0
9
+ .tag
10
+ margin-top: 5px
11
+ .avatar
12
+ margin-top: 5px
13
+ .widget .date
14
+ width: 80px
15
+ .blog-content
16
+ h3
17
+ margin-top: 20px
18
+ margin-bottom: 10px
19
+ .blog-news
20
+ .created
21
+ font-size: 18px
22
+ color: $brand-primary
23
+
24
+ .well-blog
25
+ background: none
26
+ min-height: 20px
27
+ padding: 19px
28
+ margin-bottom: 20px
29
+ border: 1px solid #e3e3e3
30
+ border-radius: 4px
31
+ -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,0.05)
32
+ box-shadow: inset 0 1px 1px rgba(0,0,0,0.05)
33
+
34
+ .blog-meta-margin
35
+ margin-right: 5px
36
+ margin-left: 5px
37
+
38
+ .blog-page-title
39
+ margin-top: 20px
40
+ font-size: 44px
41
+
42
+ .blog-page-text
43
+ margin-bottom: 44px
44
+
45
+ .author-img
46
+ margin-top: 5px
47
+
48
+ .widget
49
+ margin-bottom: 30px
50
+ >h3
51
+ font-size: 16px
52
+ margin-top: 0
53
+ h5
54
+ margin-top: 10px
55
+ .date
56
+ margin-top: 5px
57
+ padding: 10px 8px
58
+ background: $brand-primary
59
+ >span
60
+ display: block
61
+ text-align: center
62
+ font-family: sans-serif
63
+ color: #fff
64
+ &.month
65
+ font-size: 13px
66
+ line-height: 13px
67
+ font-weight: 700
68
+ text-transform: uppercase
69
+ &.day
70
+ margin-top: 5px
71
+ font-size: 18px
72
+ line-height: 18px
73
+ font-weight: 700
74
+ .btn-lg-group
75
+ .btn.btn-large
76
+ height: 50px
77
+ width: 25%
78
+ border-top-left-radius: 0px
79
+ border-bottom-left-radius: 0px
80
+ margin: 0px
81
+ input.input-block-level
82
+ border-right-width: 0px
83
+ width: 75%
84
+ height: 50px
85
+
86
+ .btn
87
+ margin-right: 5px
88
+ margin-bottom: 5px
89
+
90
+ ul li
91
+ font-size: 15px
92
+
93
+ ul
94
+ &.arrow,
95
+ &.arrow-double,
96
+ &.tick,
97
+ &.cross,
98
+ &.star,
99
+ &.rss
100
+ list-style: none
101
+ padding: 0
102
+ margin: 0
103
+ li::before,
104
+ li::after
105
+ font-family: FontAwesome
106
+ font-size: 16px
107
+ .widget
108
+ ul
109
+ &.arrow,
110
+ &.arrow-double,
111
+ &.tick,
112
+ &.cross,
113
+ &.star,
114
+ &.rss
115
+ li::before
116
+ margin-right: 5px
117
+ &.arrow
118
+ li::before
119
+ content: "\f105"
120
+ &.arrow-double
121
+ li::before
122
+ content: "\f101"
123
+ &.tick
124
+ li::before
125
+ content: "\f00c"
126
+ &.cross
127
+ li::before
128
+ content: "\f00d"
129
+ &.star
130
+ li::before
131
+ content: "\f006"
132
+ &.rss
133
+ li::before
134
+ content: "\f09e"
135
+
136
+
137
+ $facebook: #4f7dd4
138
+ $twitter: #5bceff
139
+ $linkedin: #21a6d8
140
+ $google: #dc422b
141
+ $instagram: #4d423c
142
+ $phone: #00bf8f
143
+ $homepage: $brand-primary
144
+ $github: #4f7dd4
145
+ $youtube: #bb0000
146
+ $mobile: #4dc247
147
+ $xing: #CFDC00
148
+
149
+ .btn-social
150
+ margin: 5px
151
+ border: 0
152
+ color: #fff
153
+ text-shadow: 0 1px rgba(0, 0, 0, 0.5)
154
+ &.btn-facebook
155
+ background: $facebook
156
+ &:hover
157
+ background: lighten($facebook, 10%)
158
+ &.btn-twitter
159
+ background: $twitter
160
+ &:hover
161
+ background: lighten($twitter, 10%)
162
+ &.btn-linkedin
163
+ background: $linkedin
164
+ &:hover
165
+ background: lighten($linkedin, 10%)
166
+ &.btn-google-plus
167
+ background: $google
168
+ &:hover
169
+ background: lighten($google, 10%)
170
+ &.btn-instagram
171
+ background: $instagram
172
+ &:hover
173
+ background: lighten($instagram, 10%)
174
+ &.btn-phone
175
+ background: $phone
176
+ &:hover
177
+ background: lighten($phone, 10%)
178
+ &.btn-homepage
179
+ background: $homepage
180
+ &:hover
181
+ background: lighten($homepage, 10%)
182
+ &.btn-github
183
+ background: $github
184
+ &:hover
185
+ background: lighten($github, 10%)
186
+ &.btn-youtube
187
+ background: $youtube
188
+ &:hover
189
+ background: lighten($youtube, 10%)
190
+ &.btn-mobile
191
+ background: $mobile
192
+ &:hover
193
+ background: lighten($mobile, 10%)
194
+ &.btn-xing
195
+ background: $xing
196
+ &:hover
197
+ background: lighten($xing, 10%)
198
+ &:hover
199
+ color: #fff
@@ -0,0 +1,15 @@
1
+ class Blog::Gem::ApplicationController < ::ApplicationController
2
+ helper_method :current_author
3
+
4
+ def login_as_author
5
+ current_author = Blog::Gem::Author.find_by_id(session[:author_id])
6
+ if current_author.blank?
7
+ redirect_to blogs_path
8
+ end
9
+ end
10
+
11
+ def current_author
12
+ return @current_author if @current_author.present?
13
+ @current_author = Blog::Gem::Author.find_by_id(session[:author_id])
14
+ end
15
+ end
@@ -0,0 +1,93 @@
1
+ class Blog::Gem::AuthorsController < Blog::Gem::ApplicationController
2
+ before_action :login_as_author, except: [:login, :login_submit]
3
+ before_action :admin, only: [:index, :new, :create, :destroy]
4
+ before_action :set_author, only: [:edit, :update, :destroy]
5
+ before_action :disable_breadcrumb if defined?(disable_breadcrumb)
6
+
7
+ def login_submit
8
+ @page_title = "Author Login"
9
+ if Blog::Gem::Author.find_by(public_email: params[:email]).try(:authenticate, params[:password])
10
+ session[:author_id] = Blog::Gem::Author.find_by(public_email: params[:email]).id
11
+ redirect_to blogs_path, notice: "You are Logged in!"
12
+ else
13
+ flash[:error] = "The password or email is incorrect."
14
+ render :login
15
+ end
16
+ end
17
+
18
+ def login
19
+ if session[:author_id].present?
20
+ redirect_to blogs_path
21
+ end
22
+ @page_title = "Author Login"
23
+ end
24
+
25
+ def logout
26
+ session[:author_id] = nil
27
+ redirect_to blogs_path
28
+ end
29
+
30
+
31
+ def index
32
+ @authors = Blog::Gem::Author.all
33
+ @page_title = "Listing Authors"
34
+ end
35
+
36
+ def new
37
+ @author = Blog::Gem::Author.new
38
+ @page_title = "New Authors"
39
+ end
40
+
41
+ def edit
42
+ end
43
+
44
+ def create
45
+ @author = Blog::Gem::Author.new(author_params)
46
+ respond_to do |format|
47
+ if @author.save
48
+ format.html { redirect_to "#{Blog::Gem.path}/authors/me/edit", notice: 'Author was successfully created.' }
49
+ else
50
+ format.html { render :new }
51
+ end
52
+ end
53
+ end
54
+
55
+ def update
56
+ respond_to do |format|
57
+ if @author.update(author_params)
58
+ format.html { redirect_to "#{Blog::Gem.path}/authors/me/edit", notice: 'Author was successfully updated.' }
59
+ else
60
+ format.html { render :edit }
61
+ end
62
+ end
63
+ end
64
+
65
+ def destroy
66
+ @author.destroy
67
+ respond_to do |format|
68
+ format.html { redirect_to authors_url, notice: 'Author was successfully destroyed.' }
69
+ format.json { head :no_content }
70
+ end
71
+ end
72
+
73
+ private
74
+
75
+ def admin
76
+ if !current_author.admin?
77
+ redirect_to blogs_path
78
+ end
79
+ end
80
+
81
+ def set_author
82
+ if current_author.admin? && params[:id] != "me"
83
+ @author = Blog::Gem::Author.find(params[:id])
84
+ else
85
+ @author = @current_author
86
+ end
87
+ @page_title = "Edit #{@author.name}"
88
+ end
89
+
90
+ def author_params
91
+ params.require(:author).permit(:name, :private_email, :public_email, :password, :password_confirmation, :description, :shubbl_id, :facebook, :twitter, :xing, :instagram, :homepage, :github, :google_plus, :linkedin, :youtube, :phone, :mobile, :avatar_or_gravatar)
92
+ end
93
+ end
@@ -0,0 +1,60 @@
1
+ class Blog::Gem::BlogController < Blog::Gem::ApplicationController
2
+
3
+ def index
4
+ posts = Blog::Gem::Post
5
+ title = [t("blog.index.page_title")]
6
+ if params[:q].present?
7
+ title << "#{t("blog.search_by")} #{params[:q].humanize}"
8
+ posts = posts.search(params[:q])
9
+ elsif params[:tag].present?
10
+ title << "#{t("blog.tagged_with")} #{params[:tag].humanize}"
11
+ posts = posts.tagged_with(params[:tag])
12
+ elsif params[:category].present?
13
+ title << "#{t("blog.categoryed_with")} #{params[:category].humanize}"
14
+ posts = posts.find_by_category(params[:category])
15
+ elsif params[:author].present?
16
+ @author = Blog::Gem::Author.find_by_url(params[:author])
17
+ if @author.present?
18
+ title << "#{t("blog.by_author")} #{@author.name}"
19
+ posts = @author.posts
20
+ end
21
+ elsif params[:date].present?
22
+ dt = DateTime.parse("3-#{params[:date]}")
23
+ if dt.present?
24
+ date = "#{I18n.l(dt, format: :month)} #{dt.year}"
25
+ title << "#{t("blog.from_month")} #{date}"
26
+ posts = posts.by_datetime(dt)
27
+ else
28
+ post = []
29
+ end
30
+ end
31
+ @page_title = title.join(" ")
32
+ respond_to do |format|
33
+ format.atom do
34
+ @posts = posts.published.all
35
+ render layout: false
36
+ end
37
+ format.json do
38
+ @posts = posts.published.all
39
+ render json: @posts.map{|x| {title: x.title, teaser: x.teaser, url: x.url, tags: x.tags, category: x.category, author: x.author_name, thumbnail: x.thumbnail.url(:medium)}}
40
+ end
41
+ format.html do
42
+ @posts = posts.published.paginate(:page => params[:page], :per_page => 30)
43
+ end
44
+ end
45
+ end
46
+
47
+ def show
48
+ @post = Blog::Gem::Post.find_by_url(params[:name])
49
+ if @post.present? && (current_author.present? || @post.published_at <= Time.now)
50
+ @page_title = @post.title
51
+ @description = @post.teaser
52
+ @keywords = @post.tag_list.join(", ")
53
+ @image = @post.thumbnail.url(:medium)
54
+ @breadcrumbs_params = {name: @post.title}
55
+ @current_path = blogs_path
56
+ else
57
+ render "layouts/application/not_found"
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,63 @@
1
+ class Blog::Gem::PostsController < Blog::Gem::ApplicationController
2
+ before_action :login_as_author
3
+ before_action :set_post, only: [:edit, :update, :destroy]
4
+ before_action :disable_breadcrumb if defined?(disable_breadcrumb)
5
+
6
+ def new
7
+ @post = Blog::Gem::Post.new(author_id: current_author.id, show_author: true)
8
+ @page_title = "New Blog Post"
9
+ end
10
+
11
+ def edit
12
+ end
13
+
14
+ def create
15
+ @post = Blog::Gem::Post.new(post_params)
16
+
17
+ if !current_author.admin?
18
+ @post.author_id = current_author.id
19
+ end
20
+
21
+ respond_to do |format|
22
+ if @post.save
23
+ format.html { redirect_to @post.to_path, notice: 'Post was successfully created.' }
24
+ else
25
+ format.html { render :new }
26
+ end
27
+ end
28
+ end
29
+
30
+ def update
31
+ if !current_author.admin?
32
+ post_params[:author_id] = current_author.id
33
+ end
34
+ respond_to do |format|
35
+ if @post.update(post_params)
36
+ format.html { redirect_to @post.to_path, notice: 'Post was successfully updated.' }
37
+ else
38
+ format.html { render :edit }
39
+ end
40
+ end
41
+ end
42
+
43
+ def destroy
44
+ @post.destroy
45
+ respond_to do |format|
46
+ format.html { redirect_to blogs_url, notice: 'Post was successfully destroyed.' }
47
+ end
48
+ end
49
+
50
+ private
51
+ def set_post
52
+ if current_author.admin?
53
+ @post = Blog::Gem::Post.find(params[:id])
54
+ else
55
+ @post = current_author.posts.find(params[:id])
56
+ end
57
+ @page_title = "Edit #{@post.title}"
58
+ end
59
+
60
+ def post_params
61
+ params.require(:post).permit(:title, :body, :teaser, :published_at, :author_id, :category_id, :tag_list, :thumbnail, :show_author, :path)
62
+ end
63
+ end
@@ -0,0 +1,13 @@
1
+ module Blog
2
+ module Gem
3
+ module ApplicationHelper
4
+ def facebook_html(html)
5
+ doc = Nokogiri::HTML(html)
6
+ doc.search('a').each do |link|
7
+ link.content = "#{link.content} (#{link.attributes["href"].value})"
8
+ end
9
+ doc.to_html
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ module Blog
2
+ module Gem
3
+ class ApplicationRecord < ActiveRecord::Base
4
+ self.abstract_class = true
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,34 @@
1
+ class Blog::Gem::Author < Blog::Gem::ApplicationRecord
2
+ include Gravtastic
3
+
4
+ size = 512
5
+
6
+ gravtastic :private_email, size: size
7
+
8
+ has_secure_password
9
+ has_many :posts
10
+
11
+ acts_as_taggable_on :keywords
12
+ has_attached_file :avatar, styles: {image: "#{size}x#{size}>" }, path: ":rails_root/public#{Blog::Gem.image_path}/authors/:id/:style.:extension", url: "#{Blog::Gem.image_path}/authors/:id/:style.:extension"
13
+ validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\Z/
14
+
15
+ acts_as_url :name
16
+
17
+ before_save{self.url = self.name.to_url}
18
+
19
+ def to_path
20
+ "#{Blog::Gem.path}/author/#{url}"
21
+ end
22
+
23
+ def self.create_admin(name:, password:, email:)
24
+ create(name: name, password: password, password_confirmation: password, private_email: email, public_email: email, admin: true)
25
+ end
26
+
27
+ def image
28
+ if avatar_or_gravatar == "avatar"
29
+ avatar.url(:image)
30
+ else
31
+ gravatar_url
32
+ end
33
+ end
34
+ end