cadmus_files 0.1.0 → 0.2.0

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
- SHA1:
3
- metadata.gz: bb30739f67050580cdc34306a443a103009b8b7f
4
- data.tar.gz: ae0f9f9bb0855f9d93f6fddde7cd22fff02df114
2
+ SHA256:
3
+ metadata.gz: b66960b34fb7cfe8ec30d47bc293ecb0346d22ae2d2cc1af3392833e4dd090cd
4
+ data.tar.gz: '05934849c9e3b843f6cad133bc49196968d29ffbc90c3ec82f25ee0f0c43141c'
5
5
  SHA512:
6
- metadata.gz: a8ce7909deb16aae83534260e270e95d8b0fc89fa407a35a15ac7bceb618f2645b49027b24f60b2e6f3a72c6b087e20cfac46faab2ee219592a65d349d698a89
7
- data.tar.gz: 5943e016986d994e8fd7c32c80293990a47f3676e3fd4dbb1cf0db81139231b047f9246f0a88242e7965e980792b0c466f8c87392a8006c80a2b36533e7eae07
6
+ metadata.gz: 5b066dedb5bcf6ff6bcd318a180c6b0b605a0e1823b17940c324e0cd45c59cafc88878789ef1ddd24890da923028a196818f2ae0ea62ccd183e7565d7905a4af
7
+ data.tar.gz: 016e24731fd5e9ed78bf2e85f6ecf42e2bddf588a555d72710a1bf558f760bf6e8d0faa959ca6c0c896b7a5ebd58c5d2af2f5a8999e88419372dad832e454e21
@@ -0,0 +1,4 @@
1
+ # Version 0.2.0 - not yet released
2
+
3
+ * Internal refactor for Cadmus 0.6.0 support
4
+ * BUGFIX: Admin controller now correctly scopes to the parent you're using
@@ -0,0 +1,28 @@
1
+ <% file = cms_file.public_send(cms_file.class.cadmus_file_field) -%>
2
+
3
+ <div class="card">
4
+ <div class="card-header">
5
+ <div class="float-right">
6
+ <%= link_to url_for(action: 'destroy', id: cms_file), class: 'btn btn-secondary px-2 py-1', method: 'DELETE', "data-confirm" => "Are you sure you want to delete #{cms_file.filename}?" do %>
7
+ <i class="fa fa-trash" aria-hidden="true"></i>
8
+ <% end -%>
9
+ </div>
10
+ <small style="font-weight: bold; word-wrap: break-word;">
11
+ <%= cms_file.filename %>
12
+ </small>
13
+ </div>
14
+ <div class="card-block text-center">
15
+ <%= link_to file.url do %>
16
+ <% if cms_file.is_image? -%>
17
+ <%= image_tag file.url, class: 'img-responsive', style: 'max-height: 100px; max-width: 100px;' %>
18
+ <% else -%>
19
+ <i class="fa fa-<%= icon_for_content_type(file.content_type) %>" style="font-size: 100px" aria-hidden="true"></i>
20
+ <% end -%>
21
+ <% end %>
22
+ </div>
23
+ <div class="card-footer text-right">
24
+ <small>
25
+ <%= number_to_human_size file.size %>
26
+ </small>
27
+ </div>
28
+ </div>
@@ -0,0 +1,7 @@
1
+ <% cms_files.each_slice(4) do |slice| -%>
2
+ <div class="card-deck mb-4">
3
+ <% slice.each do |cms_file| -%>
4
+ <%= render partial: 'cadmus/files/file_card', locals: { cms_file: cms_file } %>
5
+ <% end -%>
6
+ </div>
7
+ <% end -%>
@@ -0,0 +1,11 @@
1
+ <div class="card">
2
+ <div class="card-header">Upload a file</div>
3
+ <div class="card-block">
4
+ <%= form_for :cms_file, url: url_for(action: 'create'), method: 'POST', multipart: true do |f| %>
5
+ <div class="form-group">
6
+ <%= f.file_field :file, class: 'form-control-file' %>
7
+ </div>
8
+ <%= f.submit "Upload", class: 'btn btn-primary' %>
9
+ <% end %>
10
+ </div>
11
+ </div>
@@ -1,48 +1,4 @@
1
1
  <h1 class="mb-4">Files</h1>
2
2
 
3
- <% @cms_files.each_slice(4) do |slice| -%>
4
- <div class="card-deck mb-4">
5
- <% slice.each do |cms_file| -%>
6
- <% file = cms_file.public_send(cms_file.class.cadmus_file_field) -%>
7
-
8
- <div class="card">
9
- <div class="card-header">
10
- <div class="float-right">
11
- <%= link_to url_for(action: 'destroy', id: cms_file), class: 'btn btn-secondary px-2 py-1', method: 'DELETE', "data-confirm" => "Are you sure you want to delete #{cms_file.filename}?" do %>
12
- <i class="fa fa-trash" aria-hidden="true"></i>
13
- <% end -%>
14
- </div>
15
- <small style="font-weight: bold; word-wrap: break-word;">
16
- <%= cms_file.filename %>
17
- </small>
18
- </div>
19
- <div class="card-block text-center">
20
- <%= link_to file.url do %>
21
- <% if cms_file.is_image? -%>
22
- <%= image_tag file.url, class: 'img-responsive', style: 'max-height: 100px; max-width: 100px;' %>
23
- <% else -%>
24
- <i class="fa fa-<%= icon_for_content_type(file.content_type) %>" style="font-size: 100px" aria-hidden="true"></i>
25
- <% end -%>
26
- <% end %>
27
- </div>
28
- <div class="card-footer text-right">
29
- <small>
30
- <%= number_to_human_size file.size %>
31
- </small>
32
- </div>
33
- </div>
34
- <% end -%>
35
- </div>
36
- <% end -%>
37
-
38
- <div class="card">
39
- <div class="card-header">Upload a file</div>
40
- <div class="card-block">
41
- <%= form_for :cms_file, url: url_for(action: 'create'), method: 'POST', multipart: true do |f| %>
42
- <div class="form-group">
43
- <%= f.file_field :file, class: 'form-control-file' %>
44
- </div>
45
- <%= f.submit "Upload", class: 'btn btn-primary' %>
46
- <% end %>
47
- </div>
48
- </div>
3
+ <%= render partial: 'cadmus/files/grid', locals: { cms_files: @cms_files } %>
4
+ <%= render partial: 'cadmus/files/upload_form' %>
@@ -1,24 +1,13 @@
1
1
  require "cadmus_files/version"
2
+
3
+ require "cadmus"
4
+
2
5
  require "cadmus_files/engine"
3
6
  require "cadmus_files/file"
4
7
  require "cadmus_files/file_url_tag"
5
8
  require "cadmus_files/admin_controller"
6
9
 
7
10
  module CadmusFiles
8
- class << self
9
- def file_model
10
- @_file_model ||= @_file_model_name.safe_constantize
11
- end
12
-
13
- def file_model=(file_model)
14
- @_file_model_name = case file_model
15
- when Class then file_model.name
16
- else file_model
17
- end
18
- end
19
-
20
- def clear_file_model_cache!
21
- @_file_model = nil
22
- end
23
- end
11
+ extend Cadmus::Concerns::OtherClassAccessor
12
+ other_class_accessor :file_model
24
13
  end
@@ -1,6 +1,7 @@
1
1
  module CadmusFiles
2
2
  module AdminController
3
3
  extend ActiveSupport::Concern
4
+ include Cadmus::Concerns::ControllerWithParent
4
5
 
5
6
  included do
6
7
  helper 'cadmus_files/admin'
@@ -28,7 +29,7 @@ module CadmusFiles
28
29
  protected
29
30
 
30
31
  def cms_file_scope
31
- CadmusFiles.file_model.all
32
+ @cms_file_scope = parent_model ? parent_model.cms_files : CadmusFiles.file_model.global
32
33
  end
33
34
 
34
35
  def cms_file_params
@@ -1,6 +1,7 @@
1
1
  module CadmusFiles
2
2
  module File
3
3
  extend ActiveSupport::Concern
4
+ include Cadmus::Concerns::ModelWithParent
4
5
 
5
6
  module ClassMethods
6
7
  def cadmus_file(file_field = 'file')
@@ -9,7 +10,7 @@ module CadmusFiles
9
10
  end
10
11
  self.cadmus_file_field = file_field
11
12
 
12
- belongs_to :parent, polymorphic: true
13
+ model_with_parent
13
14
 
14
15
  validates_integrity_of file_field
15
16
  validates_processing_of file_field
@@ -32,7 +33,8 @@ module CadmusFiles
32
33
  define_method :validate_file_name_is_unique do
33
34
  the_filename = send(file_field).filename
34
35
 
35
- if self.class.base_class.where(file_field => the_filename).any?
36
+ scope = parent ? self.class.base_class.where(parent: parent) : self.class.global
37
+ if scope.where(file_field => the_filename).any?
36
38
  errors.add file_field, "'#{the_filename}' already exists"
37
39
  end
38
40
  end
@@ -40,5 +42,3 @@ module CadmusFiles
40
42
  end
41
43
  end
42
44
  end
43
-
44
- ActiveRecord::Base.send :include, CadmusFiles::File
@@ -16,10 +16,14 @@ module CadmusFiles
16
16
  return "Error: CadmusFiles.file_model not set. Please set it to your file model in an initializer."
17
17
  end
18
18
 
19
- parent = context.registers['parent']
20
- cms_file = file_model.find_by(file_model.cadmus_file_field => filename, parent: parent)
19
+ cache = context.registers[:cached_files] || {}
20
+ cms_file = cache[filename]
21
21
  unless cms_file
22
- return "Error: file #{filename} not found"
22
+ parent = context.registers['parent']
23
+ cms_file = file_model.find_by(file_model.cadmus_file_field => filename, parent: parent)
24
+ unless cms_file
25
+ return "Error: file #{filename} not found"
26
+ end
23
27
  end
24
28
 
25
29
  cms_file.file.url
@@ -28,4 +32,3 @@ module CadmusFiles
28
32
 
29
33
  Liquid::Template.register_tag('file_url', FileUrlTag)
30
34
  end
31
-
@@ -1,3 +1,3 @@
1
1
  module CadmusFiles
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cadmus_files
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nat Budin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-29 00:00:00.000000000 Z
11
+ date: 2018-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -117,10 +117,14 @@ extra_rdoc_files: []
117
117
  files:
118
118
  - ".gitignore"
119
119
  - ".travis.yml"
120
+ - CHANGELOG.md
120
121
  - Gemfile
121
122
  - README.md
122
123
  - Rakefile
123
124
  - app/helpers/cadmus_files/admin_helper.rb
125
+ - app/views/cadmus/files/_file_card.html.erb
126
+ - app/views/cadmus/files/_grid.html.erb
127
+ - app/views/cadmus/files/_upload_form.html.erb
124
128
  - app/views/cadmus/files/index.html.erb
125
129
  - bin/console
126
130
  - bin/setup
@@ -150,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
154
  version: '0'
151
155
  requirements: []
152
156
  rubyforge_project:
153
- rubygems_version: 2.6.4
157
+ rubygems_version: 2.7.3
154
158
  signing_key:
155
159
  specification_version: 4
156
160
  summary: File uploads for Cadmus sites