thredded-post_attachments 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.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +29 -0
- data/Rakefile +37 -0
- data/app/assets/config/thredded_post_attachments_manifest.js +2 -0
- data/app/assets/stylesheets/thredded/post_attachments/application.css +15 -0
- data/app/controllers/thredded/post_attachments/application_controller.rb +7 -0
- data/app/helpers/thredded/post_attachments/application_helper.rb +6 -0
- data/app/jobs/thredded/post_attachments/application_job.rb +6 -0
- data/app/mailers/thredded/post_attachments/application_mailer.rb +8 -0
- data/app/models/thredded/post_attachments/application_record.rb +7 -0
- data/app/models/thredded/post_attachments/attachment.rb +11 -0
- data/app/uploaders/thredded/post_attachments/attachment_uploader.rb +60 -0
- data/app/views/layouts/thredded/post_attachments/application.html.erb +14 -0
- data/config/routes.rb +2 -0
- data/lib/tasks/thredded/post_attachments_tasks.rake +4 -0
- data/lib/thredded/post_attachments.rb +117 -0
- data/lib/thredded/post_attachments/engine.rb +11 -0
- data/lib/thredded/post_attachments/version.rb +5 -0
- metadata +104 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: a0d7ce15119a3a750a57615cbe7f455e7032bbae
|
|
4
|
+
data.tar.gz: c04aa8775597320072df89b522265a1898696ce3
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: bb8fe224cfeeda28a470c2cb7b14d6078e7b7ed1842362356c6d6e5d1829f4cbf58b3aaa8590a56e0bc77117e49c9dd949400a3943bc09af3d3df9d573fd411f
|
|
7
|
+
data.tar.gz: 0f2684ba60905bdb0269af4a7913370f870435591675948a9f88e98b6cf1f66702e7169ffc9900ea0497703e21b945cb61315a25a63632216bc1e8d988dd7c93
|
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright 2017 Paul Hendrick
|
|
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,29 @@
|
|
|
1
|
+
# Thredded::PostAttachments
|
|
2
|
+
Allows images to be attached to a Thredded post (Work in progress)
|
|
3
|
+
|
|
4
|
+
## Usage
|
|
5
|
+
Create a thredded_attachments table migration in your app
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'thredded-post_attachments'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
```bash
|
|
17
|
+
$ bundle
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Or install it yourself as:
|
|
21
|
+
```bash
|
|
22
|
+
$ gem install thredded-post_attachments
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Contributing
|
|
26
|
+
Contribution directions go here.
|
|
27
|
+
|
|
28
|
+
## License
|
|
29
|
+
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 = 'Thredded::PostAttachments'
|
|
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,15 @@
|
|
|
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
|
+
*= require_tree .
|
|
14
|
+
*= require_self
|
|
15
|
+
*/
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module Thredded
|
|
2
|
+
module PostAttachments
|
|
3
|
+
class Attachment < ApplicationRecord
|
|
4
|
+
self.table_name = :thredded_attachments
|
|
5
|
+
|
|
6
|
+
mount_uploader :attachment, Thredded::PostAttachments::AttachmentUploader
|
|
7
|
+
|
|
8
|
+
belongs_to :post, class_name: "::Thredded::Post"
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
module Thredded
|
|
2
|
+
module PostAttachments
|
|
3
|
+
class AttachmentUploader < CarrierWave::Uploader::Base
|
|
4
|
+
|
|
5
|
+
# Include RMagick or MiniMagick support:
|
|
6
|
+
include CarrierWave::RMagick
|
|
7
|
+
# include CarrierWave::MiniMagick
|
|
8
|
+
|
|
9
|
+
# Choose what kind of storage to use for this uploader:
|
|
10
|
+
storage :file
|
|
11
|
+
# storage :fog
|
|
12
|
+
|
|
13
|
+
# Override the directory where uploaded files will be stored.
|
|
14
|
+
# This is a sensible default for uploaders that are meant to be mounted:
|
|
15
|
+
def store_dir
|
|
16
|
+
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
version :thumb do
|
|
20
|
+
process resize_to_fill: [400,400]
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
version :max_size do
|
|
24
|
+
process resize_to_fit: [1024,1024]
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Provide a default URL as a default if there hasn't been a file uploaded:
|
|
28
|
+
# def default_url
|
|
29
|
+
# # For Rails 3.1+ asset pipeline compatibility:
|
|
30
|
+
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
|
|
31
|
+
#
|
|
32
|
+
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
|
|
33
|
+
# end
|
|
34
|
+
|
|
35
|
+
# Process files as they are uploaded:
|
|
36
|
+
# process scale: [200, 300]
|
|
37
|
+
#
|
|
38
|
+
# def scale(width, height)
|
|
39
|
+
# # do something
|
|
40
|
+
# end
|
|
41
|
+
|
|
42
|
+
# Create different versions of your uploaded files:
|
|
43
|
+
# version :thumb do
|
|
44
|
+
# process resize_to_fit: [50, 50]
|
|
45
|
+
# end
|
|
46
|
+
|
|
47
|
+
# Add a white list of extensions which are allowed to be uploaded.
|
|
48
|
+
# For images you might use something like this:
|
|
49
|
+
def extension_whitelist
|
|
50
|
+
%w(jpg jpeg gif png)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Override the filename of the uploaded files:
|
|
54
|
+
# Avoid using model.id or version_name here, see uploader/store.rb for details.
|
|
55
|
+
# def filename
|
|
56
|
+
# "something.jpg" if original_filename
|
|
57
|
+
# end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>Thredded post attachments</title>
|
|
5
|
+
<%= stylesheet_link_tag "thredded/post_attachments/application", media: "all" %>
|
|
6
|
+
<%= javascript_include_tag "thredded/post_attachments/application" %>
|
|
7
|
+
<%= csrf_meta_tags %>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
|
|
11
|
+
<%= yield %>
|
|
12
|
+
|
|
13
|
+
</body>
|
|
14
|
+
</html>
|
data/config/routes.rb
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
require "thredded/post_attachments/engine"
|
|
2
|
+
|
|
3
|
+
module Thredded
|
|
4
|
+
module PostAttachments
|
|
5
|
+
|
|
6
|
+
module AttachmentAssociations
|
|
7
|
+
extend ActiveSupport::Concern
|
|
8
|
+
|
|
9
|
+
included do
|
|
10
|
+
has_one :attachment, class_name: "::Thredded::PostAttachments::Attachment", dependent: :destroy
|
|
11
|
+
accepts_nested_attributes_for :attachment, allow_destroy: true
|
|
12
|
+
|
|
13
|
+
after_save -> {
|
|
14
|
+
Rails.cache.delete_matched("views/en/thredded/posts/#{self.id}*")
|
|
15
|
+
}, on: :update
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
module PostParams
|
|
20
|
+
extend ActiveSupport::Concern
|
|
21
|
+
|
|
22
|
+
def post_params
|
|
23
|
+
p = params.require(:post)
|
|
24
|
+
.permit(:content, attachment_attributes: [:id, :_destroy, :attachment])
|
|
25
|
+
.merge(user: thredded_current_user, ip: request.remote_ip)
|
|
26
|
+
p = p.merge(messageboard: messageboard) unless for_a_private_topic?
|
|
27
|
+
|
|
28
|
+
p
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
module TopicActions
|
|
33
|
+
extend ActiveSupport::Concern
|
|
34
|
+
|
|
35
|
+
def create
|
|
36
|
+
@new_topic = Thredded::TopicForm.new(self.new_topic_params)
|
|
37
|
+
authorize_creating @new_topic.topic
|
|
38
|
+
if @new_topic.save
|
|
39
|
+
post = @new_topic.topic.posts.last
|
|
40
|
+
redirect_to post_path(post, user: thredded_current_user)
|
|
41
|
+
else
|
|
42
|
+
render :new
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
module TopicFormAttributes
|
|
48
|
+
extend ActiveSupport::Concern
|
|
49
|
+
|
|
50
|
+
def initialize(params = {})
|
|
51
|
+
@title = params[:title]
|
|
52
|
+
@category_ids = params[:category_ids]
|
|
53
|
+
@locked = params[:locked] || false
|
|
54
|
+
@sticky = params[:sticky] || false
|
|
55
|
+
@content = params[:content]
|
|
56
|
+
@user = params[:user] || fail('user is required')
|
|
57
|
+
@messageboard = params[:messageboard]
|
|
58
|
+
|
|
59
|
+
if params.has_key?(:post)
|
|
60
|
+
@attachment = params[:post].try(:[], :attachment)
|
|
61
|
+
elsif params.has_key?(:attachment_attributes)
|
|
62
|
+
@attachment = params[:attachment_attributes]
|
|
63
|
+
else
|
|
64
|
+
@attachment = nil
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def post
|
|
69
|
+
@post ||= topic.posts.build(
|
|
70
|
+
content: content,
|
|
71
|
+
user: non_null_user,
|
|
72
|
+
messageboard: messageboard
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
if @attachment.present?
|
|
76
|
+
@post.attachment_attributes = @attachment
|
|
77
|
+
else
|
|
78
|
+
@post.build_attachment
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
@post
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
module PostViewAttributes
|
|
86
|
+
extend ActiveSupport::Concern
|
|
87
|
+
|
|
88
|
+
def self.prepended(base)
|
|
89
|
+
base.class_eval do
|
|
90
|
+
delegate :attachment, to: :@post
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def self.setup!
|
|
96
|
+
Thredded::Post.send(:include, Thredded::PostAttachments::AttachmentAssociations)
|
|
97
|
+
Thredded::PostsController.send(:prepend, Thredded::PostAttachments::PostParams)
|
|
98
|
+
Thredded::TopicForm.send(:prepend, Thredded::PostAttachments::TopicFormAttributes)
|
|
99
|
+
Thredded::PostView.send(:prepend, Thredded::PostAttachments::PostViewAttributes)
|
|
100
|
+
|
|
101
|
+
Thredded::TopicsController.send(:prepend, Thredded::PostAttachments::TopicActions)
|
|
102
|
+
|
|
103
|
+
Thredded::NewTopicParams.module_eval do
|
|
104
|
+
def new_topic_params
|
|
105
|
+
params
|
|
106
|
+
.fetch(:topic, {})
|
|
107
|
+
.permit(:title, :locked, :sticky, :content, category_ids: [], attachment_attributes: [:id, :_destroy, :attachment])
|
|
108
|
+
.merge(
|
|
109
|
+
messageboard: messageboard,
|
|
110
|
+
user: thredded_current_user,
|
|
111
|
+
ip: request.remote_ip,
|
|
112
|
+
)
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: thredded-post_attachments
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Paul Hendrick
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-03-24 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rails
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '5.0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '5.0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: carrierwave
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '1.0'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: sqlite3
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
description: Description of Thredded::PostAttachments.
|
|
56
|
+
email:
|
|
57
|
+
- paul@errorstudio.co.uk
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- MIT-LICENSE
|
|
63
|
+
- README.md
|
|
64
|
+
- Rakefile
|
|
65
|
+
- app/assets/config/thredded_post_attachments_manifest.js
|
|
66
|
+
- app/assets/stylesheets/thredded/post_attachments/application.css
|
|
67
|
+
- app/controllers/thredded/post_attachments/application_controller.rb
|
|
68
|
+
- app/helpers/thredded/post_attachments/application_helper.rb
|
|
69
|
+
- app/jobs/thredded/post_attachments/application_job.rb
|
|
70
|
+
- app/mailers/thredded/post_attachments/application_mailer.rb
|
|
71
|
+
- app/models/thredded/post_attachments/application_record.rb
|
|
72
|
+
- app/models/thredded/post_attachments/attachment.rb
|
|
73
|
+
- app/uploaders/thredded/post_attachments/attachment_uploader.rb
|
|
74
|
+
- app/views/layouts/thredded/post_attachments/application.html.erb
|
|
75
|
+
- config/routes.rb
|
|
76
|
+
- lib/tasks/thredded/post_attachments_tasks.rake
|
|
77
|
+
- lib/thredded/post_attachments.rb
|
|
78
|
+
- lib/thredded/post_attachments/engine.rb
|
|
79
|
+
- lib/thredded/post_attachments/version.rb
|
|
80
|
+
homepage: http://error.agency
|
|
81
|
+
licenses:
|
|
82
|
+
- MIT
|
|
83
|
+
metadata: {}
|
|
84
|
+
post_install_message:
|
|
85
|
+
rdoc_options: []
|
|
86
|
+
require_paths:
|
|
87
|
+
- lib
|
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
89
|
+
requirements:
|
|
90
|
+
- - ">="
|
|
91
|
+
- !ruby/object:Gem::Version
|
|
92
|
+
version: '0'
|
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
|
+
requirements:
|
|
95
|
+
- - ">="
|
|
96
|
+
- !ruby/object:Gem::Version
|
|
97
|
+
version: '0'
|
|
98
|
+
requirements: []
|
|
99
|
+
rubyforge_project:
|
|
100
|
+
rubygems_version: 2.4.8
|
|
101
|
+
signing_key:
|
|
102
|
+
specification_version: 4
|
|
103
|
+
summary: Summary of Thredded::PostAttachments.
|
|
104
|
+
test_files: []
|