bongo 0.0.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -11
- data/app/assets/config/bongo_manifest.js +1 -0
- data/app/assets/javascripts/bongo/application.js +1 -0
- data/app/assets/javascripts/bongo/attachments.js.erb +51 -0
- data/app/assets/javascripts/bongo/trix.js +21 -0
- data/app/assets/stylesheets/bongo/application.css +0 -11
- data/app/assets/stylesheets/bongo/trix.css +374 -0
- data/app/controllers/bongo/application_controller.rb +1 -2
- data/app/controllers/bongo/articles_controller.rb +15 -1
- data/app/controllers/bongo/drafts_controller.rb +7 -0
- data/app/controllers/bongo/files_controller.rb +22 -0
- data/app/models/bongo/article.rb +17 -0
- data/app/policies/bongo/article_policy.rb +29 -0
- data/app/views/bongo/articles/_article.html.erb +9 -0
- data/app/views/bongo/articles/_form.html.erb +3 -2
- data/app/views/bongo/articles/_hr.html +1 -0
- data/app/views/bongo/articles/index.html.erb +8 -13
- data/app/views/bongo/articles/index.rss.builder +18 -0
- data/app/views/bongo/articles/show.html.erb +16 -18
- data/app/views/bongo/drafts/index.html.erb +16 -0
- data/app/views/layouts/bongo/application.html.erb +4 -0
- data/config/routes.rb +2 -0
- data/lib/bongo.rb +1 -0
- data/lib/bongo/version.rb +1 -1
- metadata +59 -6
@@ -7,21 +7,32 @@ module Bongo
|
|
7
7
|
before_action :set_article, only: [:show, :edit, :update, :destroy]
|
8
8
|
|
9
9
|
def index
|
10
|
-
@articles = Article.
|
10
|
+
@articles = policy_scope(Article).published.order(publish_at: :desc)
|
11
|
+
respond_to do |format|
|
12
|
+
format.html
|
13
|
+
format.rss do
|
14
|
+
@articles = @articles.published.order(publish_at: :desc)
|
15
|
+
render layout: false
|
16
|
+
end
|
17
|
+
end
|
11
18
|
end
|
12
19
|
|
13
20
|
def show
|
21
|
+
authorize @article
|
14
22
|
end
|
15
23
|
|
16
24
|
def new
|
17
25
|
@article = Article.new
|
26
|
+
authorize @article
|
18
27
|
end
|
19
28
|
|
20
29
|
def edit
|
30
|
+
authorize @article
|
21
31
|
end
|
22
32
|
|
23
33
|
def create
|
24
34
|
@article = Article.new(article_params)
|
35
|
+
authorize @article
|
25
36
|
|
26
37
|
if @article.save
|
27
38
|
redirect_to @article, notice: 'Article was successfully created.'
|
@@ -31,6 +42,8 @@ module Bongo
|
|
31
42
|
end
|
32
43
|
|
33
44
|
def update
|
45
|
+
authorize @article
|
46
|
+
|
34
47
|
if @article.update(article_params)
|
35
48
|
redirect_to @article, notice: 'Article was successfully updated.'
|
36
49
|
else
|
@@ -39,6 +52,7 @@ module Bongo
|
|
39
52
|
end
|
40
53
|
|
41
54
|
def destroy
|
55
|
+
authorize @article
|
42
56
|
@article.destroy
|
43
57
|
redirect_to articles_url, notice: 'Article was successfully destroyed.'
|
44
58
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_dependency "bongo/application_controller"
|
2
|
+
|
3
|
+
require "aws-sdk-s3"
|
4
|
+
|
5
|
+
module Bongo
|
6
|
+
class FilesController < ApplicationController
|
7
|
+
before_action :authenticate_user!
|
8
|
+
|
9
|
+
skip_before_action :verify_authenticity_token
|
10
|
+
|
11
|
+
def create
|
12
|
+
extension = File.extname(params[:file].original_filename)
|
13
|
+
s3 = Aws::S3::Resource.new
|
14
|
+
obj = s3.bucket(ENV["AWS_S3_BUCKET"]).object(SecureRandom.uuid + extension)
|
15
|
+
obj.upload_file(params[:file])
|
16
|
+
|
17
|
+
respond_to do |format|
|
18
|
+
format.json { render json: obj.public_url }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/app/models/bongo/article.rb
CHANGED
@@ -1,9 +1,26 @@
|
|
1
1
|
module Bongo
|
2
2
|
class Article
|
3
3
|
include Mongoid::Document
|
4
|
+
include Mongoid::Timestamps::Updated
|
5
|
+
include Mongoid::Slug
|
6
|
+
|
7
|
+
slug :title, history: true
|
4
8
|
|
5
9
|
field :title, type: String
|
6
10
|
field :text, type: String
|
7
11
|
field :publish_at, type: Date
|
12
|
+
|
13
|
+
scope :published, -> { where(:publish_at.lte => Date.today) }
|
14
|
+
|
15
|
+
# Mongoid (v7.0.8) doesn't have a cache_version method on its document.
|
16
|
+
# This causes https://jira.mongodb.org/browse/MONGOID-4680 when trying to
|
17
|
+
# use Rails collection caching.
|
18
|
+
def cache_version
|
19
|
+
if respond_to?(:updated_at)
|
20
|
+
updated_at.utc.to_s(:usec)
|
21
|
+
else
|
22
|
+
nil
|
23
|
+
end
|
24
|
+
end
|
8
25
|
end
|
9
26
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Bongo
|
2
|
+
class ArticlePolicy < ApplicationPolicy
|
3
|
+
class Scope < Scope
|
4
|
+
def resolve
|
5
|
+
if user&.admin?
|
6
|
+
scope.all
|
7
|
+
else
|
8
|
+
scope.published
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def show?
|
14
|
+
true
|
15
|
+
end
|
16
|
+
|
17
|
+
def create?
|
18
|
+
user&.admin?
|
19
|
+
end
|
20
|
+
|
21
|
+
def update?
|
22
|
+
user&.admin?
|
23
|
+
end
|
24
|
+
|
25
|
+
def destroy?
|
26
|
+
user&.admin?
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<article>
|
2
|
+
<header>
|
3
|
+
<h2><%= link_to article.title, article %></h2>
|
4
|
+
<small><%= article.publish_at ? l(article.publish_at, format: :long) : "Unpublished draft"%></small>
|
5
|
+
</header>
|
6
|
+
<div class="trix-content">
|
7
|
+
<%= article.text.html_safe %>
|
8
|
+
</div>
|
9
|
+
</article>
|
@@ -15,7 +15,8 @@
|
|
15
15
|
<%= form.text_field :title, required: true %>
|
16
16
|
|
17
17
|
<%= form.label :text %>
|
18
|
-
<%= form.
|
18
|
+
<%= form.hidden_field :text %>
|
19
|
+
<trix-editor input="article_text" class="trix-content" required></trix-editor>
|
19
20
|
|
20
21
|
<%= form.label :publish_at %>
|
21
22
|
<%= form.date_field :publish_at %>
|
@@ -23,6 +24,6 @@
|
|
23
24
|
<button type="submit">Save</button>
|
24
25
|
|
25
26
|
<%= link_to articles_path do %>
|
26
|
-
<em>
|
27
|
+
<em>Cancel</em>
|
27
28
|
<% end %>
|
28
29
|
<% end %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<hr>
|
@@ -1,14 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
<% end %>
|
1
|
+
<header>
|
2
|
+
<% if policy(Bongo::Article).create? %>
|
3
|
+
<%= link_to drafts_url do %>
|
4
|
+
<i>Drafts</i>
|
5
|
+
<% end %>
|
6
|
+
<% end %>
|
7
|
+
</header>
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
<%= link_to new_article_path do %>
|
13
|
-
<b>New Article</b>
|
14
|
-
<% end %>
|
9
|
+
<%= render(collection: @articles, partial: 'article', spacer_template: "hr", cached: true) || "There are no articles yet." %>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
xml.instruct! :xml, version: "1.0"
|
2
|
+
xml.rss version: "2.0" do
|
3
|
+
xml.channel do
|
4
|
+
xml.title (Front.config.name rescue "My Blog")
|
5
|
+
xml.description (Front.config.description rescue "A bongo blog")
|
6
|
+
xml.link root_url
|
7
|
+
|
8
|
+
@articles.each do |article|
|
9
|
+
xml.item do
|
10
|
+
xml.title article.title
|
11
|
+
xml.description ActionView::Base.full_sanitizer.sanitize(article.text).truncate(180)
|
12
|
+
xml.pubDate article.publish_at.to_s(:rfc822)
|
13
|
+
xml.link article_url(article)
|
14
|
+
xml.guid article_url(article)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,21 +1,19 @@
|
|
1
|
-
|
2
|
-
<header>
|
3
|
-
<h2><%= @article.title %></h2>
|
4
|
-
<small><%= @article.publish_at ? l(@article.publish_at, format: :long) : "Unpublished draft"%></small>
|
5
|
-
</header>
|
6
|
-
<main><%= simple_format @article.text %></main>
|
7
|
-
</article>
|
1
|
+
<%= render @article %>
|
8
2
|
|
9
|
-
<
|
3
|
+
<footer>
|
4
|
+
<% if policy(@article).update? %>
|
5
|
+
<%= link_to edit_article_path(@article) do %>
|
6
|
+
<b>Edit</b>
|
7
|
+
<% end %>
|
8
|
+
<% end %>
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
<% if policy(@article).destroy? %>
|
11
|
+
<%= link_to @article, method: :delete, data: {confirm: "Are you sure?"} do %>
|
12
|
+
<em>Delete</em>
|
13
|
+
<% end %>
|
14
|
+
<% end %>
|
14
15
|
|
15
|
-
<%= link_to
|
16
|
-
|
17
|
-
<% end %>
|
18
|
-
|
19
|
-
<%= link_to articles_path do %>
|
20
|
-
<em>Back</em>
|
21
|
-
<% end %>
|
16
|
+
<%= link_to articles_path do %>
|
17
|
+
<i>Back</i>
|
18
|
+
<% end %>
|
19
|
+
</footer>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<header>
|
2
|
+
<% if policy(Bongo::Article).create? %>
|
3
|
+
<%= link_to new_article_path do %>
|
4
|
+
<b>New Article</b>
|
5
|
+
<% end %>
|
6
|
+
<% end %>
|
7
|
+
</header>
|
8
|
+
|
9
|
+
<ul>
|
10
|
+
<% @drafts.each do |draft| %>
|
11
|
+
<li>
|
12
|
+
<%= link_to draft.title, draft %><br>
|
13
|
+
<small>last modified <%= distance_of_time_in_words_to_now(draft.updated_at) %> ago</small>
|
14
|
+
</li>
|
15
|
+
<% end %>
|
16
|
+
</ul>
|
data/config/routes.rb
CHANGED
data/lib/bongo.rb
CHANGED
data/lib/bongo/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bongo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Hutterer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05
|
11
|
+
date: 2020-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -38,7 +38,49 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 7.0.5
|
41
|
-
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mongoid-slug
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '6'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: aws-sdk-s3
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pundit
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.1'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.1'
|
83
|
+
description: Rails engine for blogging using MongoDB.
|
42
84
|
email:
|
43
85
|
- tohu@tuta.io
|
44
86
|
executables: []
|
@@ -49,27 +91,38 @@ files:
|
|
49
91
|
- README.md
|
50
92
|
- Rakefile
|
51
93
|
- app/assets/config/bongo_manifest.js
|
94
|
+
- app/assets/javascripts/bongo/application.js
|
95
|
+
- app/assets/javascripts/bongo/attachments.js.erb
|
96
|
+
- app/assets/javascripts/bongo/trix.js
|
52
97
|
- app/assets/stylesheets/bongo/application.css
|
98
|
+
- app/assets/stylesheets/bongo/trix.css
|
53
99
|
- app/controllers/bongo/application_controller.rb
|
54
100
|
- app/controllers/bongo/articles_controller.rb
|
101
|
+
- app/controllers/bongo/drafts_controller.rb
|
102
|
+
- app/controllers/bongo/files_controller.rb
|
55
103
|
- app/helpers/bongo/application_helper.rb
|
56
104
|
- app/helpers/bongo/articles_helper.rb
|
57
105
|
- app/jobs/bongo/application_job.rb
|
58
106
|
- app/mailers/bongo/application_mailer.rb
|
59
107
|
- app/models/bongo/article.rb
|
108
|
+
- app/policies/bongo/article_policy.rb
|
109
|
+
- app/views/bongo/articles/_article.html.erb
|
60
110
|
- app/views/bongo/articles/_form.html.erb
|
111
|
+
- app/views/bongo/articles/_hr.html
|
61
112
|
- app/views/bongo/articles/_notice.html.erb
|
62
113
|
- app/views/bongo/articles/edit.html.erb
|
63
114
|
- app/views/bongo/articles/index.html.erb
|
115
|
+
- app/views/bongo/articles/index.rss.builder
|
64
116
|
- app/views/bongo/articles/new.html.erb
|
65
117
|
- app/views/bongo/articles/show.html.erb
|
118
|
+
- app/views/bongo/drafts/index.html.erb
|
66
119
|
- app/views/layouts/bongo/application.html.erb
|
67
120
|
- config/routes.rb
|
68
121
|
- lib/bongo.rb
|
69
122
|
- lib/bongo/engine.rb
|
70
123
|
- lib/bongo/version.rb
|
71
124
|
- lib/tasks/bongo_tasks.rake
|
72
|
-
homepage: https://
|
125
|
+
homepage: https://github.com/thutterer/bongo
|
73
126
|
licenses:
|
74
127
|
- MIT
|
75
128
|
metadata: {}
|
@@ -88,8 +141,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
141
|
- !ruby/object:Gem::Version
|
89
142
|
version: '0'
|
90
143
|
requirements: []
|
91
|
-
rubygems_version: 3.
|
144
|
+
rubygems_version: 3.0.3
|
92
145
|
signing_key:
|
93
146
|
specification_version: 4
|
94
|
-
summary: A blogging engine
|
147
|
+
summary: A blogging engine for Rails
|
95
148
|
test_files: []
|