smithycms 0.5.99.3 → 0.6.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 +13 -0
- data/app/assets/javascripts/smithy/application.js +5 -2
- data/app/assets/javascripts/smithy/asset_uploads.coffee +35 -0
- data/app/assets/javascripts/smithy/assets.js.coffee +45 -37
- data/app/assets/javascripts/smithy/copy_link.js.coffee.erb +17 -12
- data/app/assets/javascripts/smithy/pages.js +1 -1
- data/app/assets/stylesheets/smithy/{application.css.scss → application.scss} +2 -0
- data/app/assets/stylesheets/smithy/assets.scss +28 -0
- data/app/controllers/smithy/asset_sources_controller.rb +25 -0
- data/app/controllers/smithy/assets_controller.rb +30 -18
- data/app/controllers/smithy/page_contents_controller.rb +2 -1
- data/app/helpers/smithy/assets_helper.rb +15 -1
- data/app/models/smithy/asset.rb +21 -46
- data/app/models/smithy/asset_source.rb +7 -0
- data/app/models/smithy/assets_datatable.rb +75 -0
- data/app/models/smithy/content.rb +1 -1
- data/app/models/smithy/content_block_template.rb +1 -5
- data/app/models/smithy/page_content.rb +2 -0
- data/app/models/smithy/permitted_params.rb +4 -0
- data/app/models/smithy/template.rb +1 -5
- data/app/views/layouts/smithy/modal.html.erb +14 -10
- data/app/views/smithy/asset_sources/_presigned_upload_field.html.erb +5 -0
- data/app/views/smithy/asset_sources/presigned_upload_field.js.erb +1 -0
- data/app/views/smithy/assets/_actions.html.erb +4 -0
- data/app/views/smithy/assets/_form.html.erb +20 -11
- data/app/views/smithy/assets/index.html.erb +23 -7
- data/config/initializers/refile.rb +21 -0
- data/config/routes.rb +11 -1
- data/db/migrate/20150420145923_update_to_refile.rb +7 -0
- data/db/migrate/20150427185319_migrate_dragonfly_images.rb +28 -0
- data/db/migrate/20160122152402_create_smithy_asset_sources.rb +14 -0
- data/db/migrate/20160127160513_look_for_direct_asset_links.rb +13 -0
- data/lib/smithy/dependencies.rb +4 -2
- data/lib/smithy/engine.rb +1 -1
- data/lib/smithy/formatter.rb +1 -6
- data/lib/smithy/liquid/database.rb +1 -1
- data/lib/smithy/liquid/filters/resize.rb +1 -1
- data/lib/smithy/liquid/tags/asset.rb +16 -14
- data/lib/smithy/version.rb +1 -1
- data/lib/smithy.rb +0 -2
- data/lib/tasks/smithy_tasks.rake +4 -32
- metadata +107 -48
- data/app/assets/stylesheets/smithy/assets.css.scss +0 -3
- data/app/views/smithy/assets/_asset.html.erb +0 -19
- data/app/views/smithy/assets/_upload_form.html.erb +0 -13
- data/app/views/smithy/assets/create.js.erb +0 -6
- data/app/views/smithy/assets/new.html.erb +0 -7
- data/config/initializers/dragonfly.rb +0 -26
- data/lib/smithy/asset_link.rb +0 -7
- data/lib/smithy/dragonfly/asset_helper.rb +0 -67
- data/lib/smithy/dragonfly/remote_data_store.rb +0 -27
- data/lib/smithy/dragonfly.rb +0 -30
- /data/app/assets/stylesheets/smithy/{bootstrap_and_overrides.css.scss → bootstrap_and_overrides.scss} +0 -0
- /data/app/assets/stylesheets/smithy/{content_blocks.css.scss → content_blocks.scss} +0 -0
- /data/app/assets/stylesheets/smithy/{forms.css.scss → forms.scss} +0 -0
- /data/app/assets/stylesheets/smithy/{guides.css.scss → guides.scss} +0 -0
- /data/app/assets/stylesheets/smithy/{layout.css.scss → layout.scss} +0 -0
- /data/app/assets/stylesheets/smithy/{pages.css.scss → pages.scss} +0 -0
- /data/app/assets/stylesheets/smithy/{templates.css.scss → templates.scss} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5729808381e189d354b575a074129abbb0bd33b6
|
4
|
+
data.tar.gz: 49a72ccb62fb0f11a31edf3f70cc2f1af81fd372
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 390e6f97961063ad08c0e2d673c01896e4f296b9ffe4e37c5384033ebfde23f04fcee62f2c0b31bd787f4508900099a05c5a45d4db8236cb8c4589ff3ba55539
|
7
|
+
data.tar.gz: 2dd09ff917ef0d96379610d38b29b7af7d78cd95cb5e1d983b4d80972d416e99f640c8e328df21eeebb96f2b14348eb1cac7765cab0f4e5243a33888678f3083
|
data/README.md
CHANGED
@@ -74,6 +74,19 @@ Alternatively, you can add a boolean field (via migration) named `smithy_admin`
|
|
74
74
|
|
75
75
|
Restart your local server and you should be good to go.
|
76
76
|
|
77
|
+
## Upgrading from 0.5.* to 0.6+
|
78
|
+
|
79
|
+
In version 0.6, Smithy switched it's asset engine from Dragonfly to Refile. Your assets should automatically be migrated to Refile, but if you have any direct links to assets in your content, the migration will warn you that they need to be changed. Refile doesn't store images the same way, so it isn't possible to link directly to them.
|
80
|
+
|
81
|
+
Pay close attention to the database migration. If any warnings come up, make sure you follow the instructions to fix them.
|
82
|
+
|
83
|
+
There are two different errors that might occur:
|
84
|
+
|
85
|
+
1. Dragonfly asset not found. If this occurs, you need to find the asset on S3, and manually move it to the new path provided in the message. If the asset no longer exists, you will need to remove it manually from the console for the smithy assets page to load properly.
|
86
|
+
`[WARNING] Asset Not Found in S3`
|
87
|
+
2. Direct link found in the content. This message will point out places in the smithy content that link directly to S3 images. Replace these links in the content with the links provided in the message to fix.
|
88
|
+
`[WARNING] Direct Link found in the page`
|
89
|
+
|
77
90
|
### Templates
|
78
91
|
|
79
92
|
Create your first Template, naming it whatever you want ("Home" or "Default" or something equally original). In the content, add `{{ page.container.main_content }}`. In the background, this will auto-create a container that will be used by any page using your template. You can name your container whatever you would like: `{{ page.container.foo }}` works as well. After you have created new page containers, they will automatically show up on the Page edit screen and allow you to add content to the container.
|
@@ -1,9 +1,11 @@
|
|
1
1
|
//= require jquery
|
2
2
|
//= require jquery_ujs
|
3
|
+
//= require jquery.remotipart
|
3
4
|
//= require 'smithy/jquery-ui.min'
|
4
|
-
//= require jquery-fileupload/basic
|
5
|
-
//= require jquery-fileupload/vendor/tmpl
|
6
5
|
//= require bootstrap-sprockets
|
6
|
+
//= require dataTables/jquery.dataTables
|
7
|
+
//= require dataTables/bootstrap/3/jquery.dataTables.bootstrap
|
8
|
+
//= require dataTables/extras/dataTables.responsive
|
7
9
|
//= require ace-1.1.3/ace
|
8
10
|
//= require ace-1.1.3/mode-css.js
|
9
11
|
//= require ace-1.1.3/mode-html.js
|
@@ -11,4 +13,5 @@
|
|
11
13
|
//= require ace-1.1.3/mode-liquid.js
|
12
14
|
//= require ace-1.1.3/mode-markdown.js
|
13
15
|
//= require zeroclipboard-2.2.0/ZeroClipboard.min.js
|
16
|
+
//= require refile
|
14
17
|
//= require_tree .
|
@@ -0,0 +1,35 @@
|
|
1
|
+
$upload_button = $('#choose-files')
|
2
|
+
$upload_form = $upload_button.closest('form')
|
3
|
+
$file_input = $('#presigned_upload_field').find('input[type="file"]')
|
4
|
+
presigned_upload_field_url = $upload_button.attr('data-presigned-upload-field-url')
|
5
|
+
|
6
|
+
$upload_button.on 'click', (e) ->
|
7
|
+
$file_input.click();
|
8
|
+
|
9
|
+
upload_files = (e) ->
|
10
|
+
files = e.target.files
|
11
|
+
if files.length
|
12
|
+
$upload_form.submit()
|
13
|
+
|
14
|
+
# Reset the file input, so that it can be used again
|
15
|
+
$.get presigned_upload_field_url, ->
|
16
|
+
$file_input = $('#presigned_upload_field').find('input[type="file"]')
|
17
|
+
bind_file_input()
|
18
|
+
|
19
|
+
$progress_bar = $($upload_form).append('<div class="progress"><div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0;"></div></div>').find('.progress-bar')
|
20
|
+
total_size = 0; (total_size += file.size for file in files)
|
21
|
+
total_uploaded = 0
|
22
|
+
|
23
|
+
$(this).find("input[type=submit]").attr("disabled", true)
|
24
|
+
$(document).on "upload:success", $upload_form, (e) ->
|
25
|
+
total_uploaded += e.originalEvent.detail.file.size
|
26
|
+
progress = parseInt(total_uploaded/total_size * 100, 10)
|
27
|
+
$progress_bar.css('width', "#{progress}%").attr('aria-valuenow', progress)
|
28
|
+
setTimeout((-> $progress_bar.parent().remove()), 2000) if progress >= 100
|
29
|
+
$(document).on "upload:failed", $upload_form, (e) ->
|
30
|
+
$(this).addClass("upload-failed").append("<p>Something went wrong, please check your connection and try again</p>")
|
31
|
+
|
32
|
+
bind_file_input = ->
|
33
|
+
$file_input.on 'change', upload_files
|
34
|
+
|
35
|
+
bind_file_input()
|
@@ -1,37 +1,45 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
1
|
+
$select_all_checkbox = $('#assets_table_select_all')
|
2
|
+
$delete_selected_button = $('#delete_selected_assets')
|
3
|
+
|
4
|
+
$('#assets').DataTable {
|
5
|
+
"responsive": true,
|
6
|
+
"serverSide": true,
|
7
|
+
"processing": true,
|
8
|
+
"ajax": $('#assets').attr('data-source'),
|
9
|
+
"order": [[2, 'asc']],
|
10
|
+
"columnDefs": [
|
11
|
+
{ "targets": [0,1,5], "searchable": false, "orderable": false },
|
12
|
+
{ "targets": [1], "className": "preview" }
|
13
|
+
],
|
14
|
+
"language": {
|
15
|
+
"emptyTable": "No assets have been added yet. Upload files above to create new assets.",
|
16
|
+
"processing": "<span>Processing...</span>"
|
17
|
+
},
|
18
|
+
"dom": 'l<"toolbar">frtip'
|
19
|
+
}
|
20
|
+
|
21
|
+
window.$assets_table = $('#assets').dataTable()
|
22
|
+
window.assets_table_api = $assets_table.api()
|
23
|
+
|
24
|
+
$('#assets_wrapper').find('.toolbar').append($delete_selected_button.remove())
|
25
|
+
|
26
|
+
$(document).on 'click', '#assets_table_select_all', (e) ->
|
27
|
+
$checkbox = $(e.target)
|
28
|
+
$assets_table.find('input.delete').prop('checked', $checkbox.prop('checked'))
|
29
|
+
|
30
|
+
$(document).on 'click', '#assets_wrapper input[type="checkbox"]', (e) ->
|
31
|
+
if $('#assets_wrapper input[type="checkbox"]:checked').length > 0
|
32
|
+
$delete_selected_button.show()
|
33
|
+
else
|
34
|
+
$delete_selected_button.hide()
|
35
|
+
|
36
|
+
$assets_table.on 'draw.dt', ->
|
37
|
+
$(document).trigger('updateCopyLinks')
|
38
|
+
|
39
|
+
window.assets_table_add_rows = (rows) ->
|
40
|
+
assets_table_api.rows.add(rows).draw()
|
41
|
+
|
42
|
+
window.assets_table_delete_rows = () ->
|
43
|
+
assets_table_api.draw()
|
44
|
+
$select_all_checkbox.prop('checked', false)
|
45
|
+
$delete_selected_button.hide()
|
@@ -5,15 +5,20 @@ jQuery ->
|
|
5
5
|
swfPath: '<%= image_path "ZeroClipboard.swf" %>'
|
6
6
|
});
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
$
|
12
|
-
|
13
|
-
|
14
|
-
clip.
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
8
|
+
setup_copy_links = ->
|
9
|
+
($ 'body').on "click", ".copy-to-clipboard", (e) ->
|
10
|
+
e.preventDefault()
|
11
|
+
$('.copy-to-clipboard').each ->
|
12
|
+
$link = ($ this)
|
13
|
+
clip = new ZeroClipboard( this )
|
14
|
+
clip.on "copy", (e) ->
|
15
|
+
clip.setText($link.data('clipboard-text'))
|
16
|
+
saved_text = $link.text()
|
17
|
+
$link.text 'Copied!'
|
18
|
+
setTimeout ->
|
19
|
+
$link.text(saved_text)
|
20
|
+
, 2000
|
21
|
+
setup_copy_links()
|
22
|
+
|
23
|
+
$(document).on 'updateCopyLinks', ->
|
24
|
+
setup_copy_links()
|
@@ -8,7 +8,7 @@ $(function() {
|
|
8
8
|
$(url).modal('open');
|
9
9
|
} else {
|
10
10
|
$.get(url, function(data) {
|
11
|
-
$('<div class="modal
|
11
|
+
$('<div class="modal fade">' + data + '</div>').modal();
|
12
12
|
}).success(function() { $('input:text:visible:first').focus(); });
|
13
13
|
}
|
14
14
|
});
|
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
// .table-striped > tbody > tr:nth-child(odd) > td,
|
4
|
+
// .table-striped > tbody > tr:nth-child(odd) > th { background:darken($table-bg-accent, 5%); }
|
5
|
+
|
6
|
+
table#assets {
|
7
|
+
td { vertical-align:middle; }
|
8
|
+
.preview a {
|
9
|
+
height:30px; width:30px; display:block; position:relative;
|
10
|
+
img { position:absolute; bottom:0; top:0; left:0; right:0; margin:auto; max-width:100%; max-height:100%; }
|
11
|
+
}
|
12
|
+
}
|
13
|
+
|
14
|
+
#assets_wrapper {
|
15
|
+
position:relative;
|
16
|
+
#assets_processing {
|
17
|
+
width:100%; height:100%; top:0; left:0; text-align:center; margin:0; padding:0;
|
18
|
+
&:before { display:inline-block; vertical-align:middle; content:""; height:100%; }
|
19
|
+
span { display:inline-block; vertical-align:middle; }
|
20
|
+
}
|
21
|
+
|
22
|
+
#assets_length,
|
23
|
+
.toolbar { float:left; margin-right:10px; }
|
24
|
+
th.column_delete {
|
25
|
+
padding:8px;
|
26
|
+
input { margin-right:5px; }
|
27
|
+
}
|
28
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_dependency "smithy/base_controller"
|
2
|
+
|
3
|
+
module Smithy
|
4
|
+
class AssetSourcesController < BaseController
|
5
|
+
respond_to :html, :json, :js
|
6
|
+
|
7
|
+
def update
|
8
|
+
@asset_source = AssetSource.find(params[:id])
|
9
|
+
if @asset_source.update_attributes(filtered_params)
|
10
|
+
flash.notice = "Your assets were saved"
|
11
|
+
@assets = @asset_source.assets
|
12
|
+
end
|
13
|
+
respond_with @asset_source do |format|
|
14
|
+
format.js { render json: AssetsDatatable.new(view_context).new_row(@assets), callback: 'assets_table_add_rows' }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def presigned_upload_field
|
19
|
+
@asset_source = AssetSource.find(params[:id])
|
20
|
+
respond_to do |format|
|
21
|
+
format.js
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -2,11 +2,16 @@ require_dependency "smithy/base_controller"
|
|
2
2
|
|
3
3
|
module Smithy
|
4
4
|
class AssetsController < BaseController
|
5
|
+
skip_before_filter :authenticate_smithy_admin, :only => [ :url ]
|
5
6
|
before_filter :load_assets, :only => :index
|
6
7
|
respond_to :html, :json, :js
|
7
8
|
|
8
9
|
def index
|
9
|
-
|
10
|
+
@asset_source = AssetSource.first
|
11
|
+
respond_with @assets, :layout => 'smithy/wide' do |format|
|
12
|
+
format.html
|
13
|
+
format.json { render json: ::Smithy::AssetsDatatable.new(view_context) }
|
14
|
+
end
|
10
15
|
end
|
11
16
|
|
12
17
|
def new
|
@@ -14,23 +19,17 @@ module Smithy
|
|
14
19
|
respond_with @asset
|
15
20
|
end
|
16
21
|
|
17
|
-
def
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
format.html {
|
29
|
-
flash.notice = "Your asset was created" if @asset.persisted?
|
30
|
-
redirect_to assets_path
|
31
|
-
}
|
32
|
-
end
|
33
|
-
end
|
22
|
+
# def create
|
23
|
+
# @asset = Asset.new(filtered_params)
|
24
|
+
# @asset.save
|
25
|
+
# respond_with @asset do |format|
|
26
|
+
# format.html {
|
27
|
+
# flash.notice = "Your asset was created" if @asset.persisted?
|
28
|
+
# redirect_to assets_path
|
29
|
+
# }
|
30
|
+
# format.js { render json: ::Smithy::AssetsDatatable.new(view_context).new_row(@asset), callback: 'assets_table_add_row' }
|
31
|
+
# end
|
32
|
+
# end
|
34
33
|
|
35
34
|
def edit
|
36
35
|
@asset = Asset.find(params[:id])
|
@@ -51,6 +50,19 @@ module Smithy
|
|
51
50
|
respond_with @asset
|
52
51
|
end
|
53
52
|
|
53
|
+
def batch_destroy
|
54
|
+
@assets = Asset.where(id: params[:ids])
|
55
|
+
@assets.destroy_all
|
56
|
+
respond_with @assets do |format|
|
57
|
+
format.js { render json: { ids: params[:ids] }, callback: "assets_table_delete_rows" }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def data
|
62
|
+
@asset = Asset.find(params[:id])
|
63
|
+
send_data @asset.data, filename: @asset.file_filename, disposition: "inline", type: ::File.extname(@asset.file_filename).downcase.sub(/^\./, '').to_sym
|
64
|
+
end
|
65
|
+
|
54
66
|
private
|
55
67
|
def load_assets
|
56
68
|
@assets = Asset.order(:name).page(params[:page])
|
@@ -2,6 +2,7 @@ require_dependency "smithy/base_controller"
|
|
2
2
|
|
3
3
|
module Smithy
|
4
4
|
class PageContentsController < BaseController
|
5
|
+
include Smithy::Liquid::Rendering
|
5
6
|
before_filter :load_page
|
6
7
|
before_filter :load_page_content, :only => [ :edit, :update, :destroy, :preview ]
|
7
8
|
before_filter :build_content_block, :only => [ :edit, :update ]
|
@@ -50,7 +51,7 @@ module Smithy
|
|
50
51
|
|
51
52
|
def preview
|
52
53
|
respond_with @page_content do |format|
|
53
|
-
format.html { render :text => @page_content.render, :layout => 'smithy/modal' }
|
54
|
+
format.html { render :text => @page_content.render(liquid_context), :layout => 'smithy/modal' }
|
54
55
|
end
|
55
56
|
end
|
56
57
|
|
@@ -3,7 +3,21 @@ module Smithy
|
|
3
3
|
def asset_image_tag(asset_id)
|
4
4
|
asset = Smithy::Asset.find_by_id(asset_id)
|
5
5
|
return unless asset
|
6
|
-
image_tag(asset.
|
6
|
+
image_tag(asset.url, :alt => asset.name)
|
7
|
+
end
|
8
|
+
|
9
|
+
def asset_preview_link(asset_id)
|
10
|
+
asset = Smithy::Asset.find_by_id(asset_id)
|
11
|
+
return unless asset
|
12
|
+
link_to attachment_url(asset, :file) do
|
13
|
+
if asset.file_type == :image
|
14
|
+
attachment_image_tag(asset, :file, :fit, 30, 30, alt: '')
|
15
|
+
elsif asset.file_type == :direct_image
|
16
|
+
attachment_image_tag(asset, :file, width: 30, alt: '')
|
17
|
+
else
|
18
|
+
image_tag file_type_icon(asset), alt: ''
|
19
|
+
end
|
20
|
+
end
|
7
21
|
end
|
8
22
|
|
9
23
|
def file_type_icon(asset)
|
data/app/models/smithy/asset.rb
CHANGED
@@ -1,47 +1,32 @@
|
|
1
1
|
module Smithy
|
2
2
|
class Asset < ActiveRecord::Base
|
3
3
|
validates_presence_of :file, :name
|
4
|
-
|
4
|
+
belongs_to :asset_source
|
5
5
|
has_many :images, :dependent => :destroy
|
6
6
|
|
7
|
-
|
8
|
-
dragonfly_accessor :file
|
9
|
-
include ::Smithy::Dragonfly::AssetHelper
|
7
|
+
attachment :file
|
10
8
|
|
11
9
|
before_validation :set_name
|
12
|
-
before_save :set_file_uid_manually
|
13
10
|
|
14
11
|
default_scope -> { order(:name) }
|
15
12
|
|
16
|
-
def file
|
17
|
-
# check for the jquery uploaded file first, just in case one got past the manual check. Also keeps backwards-compatibility
|
18
|
-
if self.uploaded_file_url?
|
19
|
-
dragonfly_attachments[:file].app.datastore = self.class.dragonfly_remote_datastore
|
20
|
-
self.file_url = URI.escape(self.uploaded_file_url)
|
21
|
-
elsif dragonfly_attachments[:file].to_value
|
22
|
-
dragonfly_attachments[:file].app.datastore = self.class.dragonfly_datastore
|
23
|
-
end
|
24
|
-
dragonfly_attachments[:file].to_value
|
25
|
-
end
|
26
|
-
|
27
13
|
def file_type
|
28
|
-
|
29
|
-
|
30
|
-
when 'jpg', 'jpeg', 'gif', 'png'
|
31
|
-
:image
|
32
|
-
when 'svg', 'svgz'
|
14
|
+
case file_content_type
|
15
|
+
when /^image\/svg/
|
33
16
|
:direct_image
|
34
|
-
when
|
17
|
+
when /^image\/?/
|
18
|
+
:image
|
19
|
+
when /pdf/
|
35
20
|
:pdf
|
36
|
-
when
|
21
|
+
when /msword|wordprocessing/
|
37
22
|
:word
|
38
|
-
when
|
23
|
+
when /excel|spreadsheet/
|
39
24
|
:excel
|
40
|
-
when
|
25
|
+
when /powerpoint|presentation/
|
41
26
|
:powerpoint
|
42
|
-
when
|
27
|
+
when /txt/
|
43
28
|
:text
|
44
|
-
when
|
29
|
+
when /rtf/
|
45
30
|
:document
|
46
31
|
else
|
47
32
|
:default
|
@@ -52,41 +37,31 @@ module Smithy
|
|
52
37
|
{
|
53
38
|
'id' => self.id,
|
54
39
|
'name' => self.name,
|
55
|
-
'content_type' => self.
|
40
|
+
'content_type' => self.file_content_type,
|
56
41
|
'file' => self.file,
|
57
|
-
'file_name' => self.
|
42
|
+
'file_name' => self.file_filename,
|
58
43
|
'file_width' => self.file_width,
|
59
44
|
'file_height' => self.file_height,
|
60
45
|
'file_size' => self.file_size,
|
61
|
-
'remote_url' => self.
|
46
|
+
'remote_url' => self.url,
|
62
47
|
'url' => self.url
|
63
48
|
}
|
64
49
|
end
|
65
50
|
|
66
51
|
def url
|
67
|
-
self
|
52
|
+
Refile.attachment_url(self, :file)
|
68
53
|
end
|
69
54
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
end
|
74
|
-
|
75
|
-
# this allows dragonfly to take over management of the uploaded file. We are
|
76
|
-
# assuming that jquery-upload and dragonfly are using the same data storage...
|
77
|
-
def set_file_uid_manually
|
78
|
-
if self.uploaded_file_url? # this means it was uploaded via jquery-upload
|
79
|
-
uri = URI.parse(URI.encode(self.uploaded_file_url))
|
80
|
-
self.file_uid = self.uploaded_file_url.sub("#{uri.scheme}://#{uri.host}/", '')
|
81
|
-
self.uploaded_file_url = nil
|
82
|
-
end
|
83
|
-
end
|
55
|
+
def data
|
56
|
+
file.read
|
57
|
+
end
|
84
58
|
|
59
|
+
private
|
85
60
|
def set_name
|
86
61
|
if self.uploaded_file_url?
|
87
62
|
self.name = File.basename(self.uploaded_file_url, '.*').titleize unless self.name?
|
88
63
|
elsif self.file.present?
|
89
|
-
self.name = File.basename(self.
|
64
|
+
self.name = File.basename(self.file_filename, '.*').titleize unless self.name?
|
90
65
|
end
|
91
66
|
end
|
92
67
|
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Smithy
|
2
|
+
class AssetsDatatable
|
3
|
+
include AssetsHelper
|
4
|
+
delegate :params, :link_to, :image_tag, :number_to_human_size, :attachment_url, :attachment_image_tag, :file_type_icon, :check_box_tag, :render, to: :@view
|
5
|
+
|
6
|
+
def initialize(view)
|
7
|
+
@view = view
|
8
|
+
end
|
9
|
+
|
10
|
+
def as_json(options = {})
|
11
|
+
{
|
12
|
+
draw: params[:draw].to_i,
|
13
|
+
recordsTotal: Asset.count,
|
14
|
+
recordsFiltered: assets.total_count,
|
15
|
+
data: data
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def new_row(assets)
|
20
|
+
assets.map do |asset|
|
21
|
+
render_asset(asset)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def data
|
28
|
+
assets.map do |asset|
|
29
|
+
render_asset asset
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def render_asset(asset)
|
34
|
+
[
|
35
|
+
check_box_tag('ids[]', asset.id, false, class: "delete"),
|
36
|
+
asset_preview_link(asset),
|
37
|
+
asset.name,
|
38
|
+
number_to_human_size(asset.file_size),
|
39
|
+
asset.file_content_type,
|
40
|
+
"#{render(partial: '/smithy/assets/actions', formats: :html, locals: { asset: asset })}"
|
41
|
+
]
|
42
|
+
end
|
43
|
+
|
44
|
+
def assets
|
45
|
+
@assets ||= fetch_assets
|
46
|
+
end
|
47
|
+
|
48
|
+
def fetch_assets
|
49
|
+
assets = Asset.unscoped.order("#{sort_column} #{sort_direction}")
|
50
|
+
assets = assets.page(page).per(per_page)
|
51
|
+
# TODO: need to check for regex flag
|
52
|
+
if params[:search][:value].present?
|
53
|
+
assets = assets.where("name like :search or content_type like :search", search: "%#{params[:search][:value]}%")
|
54
|
+
end
|
55
|
+
assets
|
56
|
+
end
|
57
|
+
|
58
|
+
def page
|
59
|
+
params[:start].to_i/per_page + 1
|
60
|
+
end
|
61
|
+
|
62
|
+
def per_page
|
63
|
+
params[:length].to_i > 0 ? params[:length].to_i : 10
|
64
|
+
end
|
65
|
+
|
66
|
+
def sort_column
|
67
|
+
columns = %w[delete preview name file_size file_content_type actions]
|
68
|
+
columns[params[:order][:"0"][:column].to_i]
|
69
|
+
end
|
70
|
+
|
71
|
+
def sort_direction
|
72
|
+
params[:order][:"0"][:dir] == "desc" ? "desc" : "asc"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -12,14 +12,10 @@ module Smithy
|
|
12
12
|
default_scope -> { order(:name) }
|
13
13
|
|
14
14
|
def liquid_template
|
15
|
-
@liquid_template ||= ::Liquid::Template.parse(
|
15
|
+
@liquid_template ||= ::Liquid::Template.parse(self.content)
|
16
16
|
end
|
17
17
|
|
18
18
|
private
|
19
|
-
def content_with_fixed_asset_links
|
20
|
-
Smithy::AssetLink.fix(self.content)
|
21
|
-
end
|
22
|
-
|
23
19
|
def touch_page_contents
|
24
20
|
self.page_contents.each(&:touch)
|
25
21
|
end
|
@@ -16,6 +16,8 @@ module Smithy
|
|
16
16
|
scope :for_container, ->(container) { where(:container => container) }
|
17
17
|
scope :publishable, -> { where(:publishable => true) }
|
18
18
|
|
19
|
+
delegate :name, to: :content_block, prefix: :content_block
|
20
|
+
|
19
21
|
def attributes=(attributes = {})
|
20
22
|
self.content_block_type = attributes[:content_block_type]
|
21
23
|
super
|
@@ -26,14 +26,10 @@ module Smithy
|
|
26
26
|
|
27
27
|
def liquid_template
|
28
28
|
@liquid_template ||= Rails.cache.fetch("#{self.cache_key}-liquid_template") do
|
29
|
-
::Liquid::Template.parse(self.
|
29
|
+
::Liquid::Template.parse(self.content)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
def content_with_fixed_asset_links
|
34
|
-
Smithy::AssetLink.fix(self.content)
|
35
|
-
end
|
36
|
-
|
37
33
|
private
|
38
34
|
def load_containers
|
39
35
|
return unless self.template_type == 'template'
|