Skip to content

Commit

Permalink
Merge 518acca into 91ee591
Browse files Browse the repository at this point in the history
  • Loading branch information
tilsammans committed Dec 31, 2017
2 parents 91ee591 + 518acca commit f9ff2ed
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 103 deletions.
Expand Up @@ -40,6 +40,9 @@ $loading-spinner-glow-color: rgba(117, 149, 160, 0.8) !default;
/// Apply opacity animation to glow or background image.
$loading-spinner-animate-background: true !default;

/// Size of the actual glowing area
$loading-spinner-glow-size: 140px !default;

@if not $custom-loading-spinner {
.loading_spinner {
// scss-lint:disable ImportantRule
Expand All @@ -59,7 +62,7 @@ $loading-spinner-animate-background: true !default;
content: "";
@include radial-gradient(circle,
$loading-spinner-glow-color 0%,
$loading-spinner-background-color 140px);
$loading-spinner-background-color $loading-spinner-glow-size);
background-size: 100% 100%;
} @else if $loading-spinner-background == "custom" {
content: "";
Expand Down
12 changes: 5 additions & 7 deletions config/initializers/paperclip.rb
@@ -1,4 +1,5 @@
require 'socket'
require 'pageflow/paperclip_interpolations/support'

Pageflow.configure do |config|
config.paperclip_attachments_version = 'v1'
Expand Down Expand Up @@ -107,20 +108,17 @@ def bucket_name
end
end

# Turns +Pageflow::VideoFile+ into +video_files+.
Paperclip.interpolates(:class_basename) do |attachment, style|
plural_cache.underscore_and_pluralize(attachment.instance.class.name.split('::').last)
Pageflow::PaperclipInterpolations::Support.new(attachment, style).class_basename
end

Paperclip.interpolates(:pageflow_placeholder) do |attachment, style|
"pageflow/placeholder_#{style}.jpg"
Pageflow::PaperclipInterpolations::Support.new(attachment, style).pageflow_placeholder
end

Paperclip.interpolates(:pageflow_attachments_version) do |attachment, style|
version = Pageflow.config.paperclip_attachments_version

if version.present? && style != :original
"#{version}/"
end
Pageflow::PaperclipInterpolations::Support.new(attachment, style).pageflow_attachments_version
end

Paperclip.configure do |config|
Expand Down
34 changes: 34 additions & 0 deletions lib/pageflow/paperclip_interpolations/support.rb
@@ -0,0 +1,34 @@
module Pageflow
module PaperclipInterpolations
class Support
attr_reader :attachment, :style

def initialize(attachment, style)
@attachment = attachment
@style = style
end

def pageflow_placeholder
"pageflow/placeholder_#{style}.jpg"
end

def pageflow_attachments_version
version = Pageflow.config.paperclip_attachments_version

if version.present? && style != :original
"#{version}/"
end
end

def class_basename
attachment \
.instance
.class
.name
.demodulize
.underscore
.pluralize
end
end
end
end
2 changes: 1 addition & 1 deletion pageflow.gemspec
Expand Up @@ -49,7 +49,7 @@ Gem::Specification.new do |s|
s.add_dependency 'state_machine_job', ['>= 0.2.0', '< 2']

# File attachments
s.add_dependency 'paperclip', '~> 4.2.4'
s.add_dependency 'paperclip', '~> 4.3.7'

# zencoder
s.add_dependency 'zencoder', '~> 2.5'
Expand Down
6 changes: 6 additions & 0 deletions spec/factories/video_files.rb
Expand Up @@ -31,6 +31,12 @@ module Pageflow
state 'not_uploaded_to_s3'
end

trait :numeric_filename_on_filesystem do
attachment_on_filesystem File.open(Engine.root.join('spec', 'fixtures', '123.mp4'))
attachment_on_s3 nil
state 'not_uploaded_to_s3'
end

trait :uploading_to_s3_failed do
attachment_on_filesystem File.open(Engine.root.join('spec', 'fixtures', 'video.mp4'))
attachment_on_s3 nil
Expand Down
Binary file added spec/fixtures/123.mp4
Binary file not shown.
48 changes: 19 additions & 29 deletions spec/models/pageflow/url_template_spec.rb
Expand Up @@ -3,50 +3,40 @@
module Pageflow
describe UrlTemplate do
describe '.from_attachment' do
def create_attachment(url:, filename: 'file.png')
Class.new(ActiveRecord::Base) {
self.table_name = 'pageflow_pages'

has_attached_file(:thumbnail, url: url)
attr_accessor(:thumbnail_file_name)

def self.to_s
'Page'
end
}.new(id: 5, thumbnail_file_name: filename).thumbnail
end
let(:video_file) { create(:video_file, :on_filesystem) }

it 'returns url with :id_partition placeholder' do
attachment = create_attachment(url: '/:class/:attachment/:id_partition/:style/:filename')

result = UrlTemplate.from_attachment(attachment)
VideoFile.has_attached_file :attachment_on_filesystem,
url: '/:class/:attachment/:id_partition/:style/:filename'
result = described_class.from_attachment(video_file.attachment_on_filesystem)

expect(result).to eq('/pages/thumbnails/:id_partition/original/file.png')
expect(result).to eq('/pageflow/video_files/attachment_on_filesystems/:id_partition/original/video.mp4?1356994800')
end

it 'only replaces last set of digits' do
attachment = create_attachment(url: '/123/:class/:id_partition/:style/:filename')
VideoFile.has_attached_file :attachment_on_filesystem,
url: '/123/:class/:id_partition/:style/:filename'
result = described_class.from_attachment(video_file.attachment_on_filesystem)

result = UrlTemplate.from_attachment(attachment)

expect(result).to eq('/123/pages/:id_partition/original/file.png')
expect(result).to eq('/123/pageflow/video_files/:id_partition/original/video.mp4?1356994800')
end

it 'ignores other numeric values in url pattern' do
attachment = create_attachment(url: '/_a123/_e1001/:class/:id_partition/:style/:filename')

result = UrlTemplate.from_attachment(attachment)
VideoFile.has_attached_file :attachment_on_filesystem,
url: '/_a123/_e1001/:class/:id_partition/:style/:filename'
result = described_class.from_attachment(video_file.attachment_on_filesystem)

expect(result).to eq('/_a123/_e1001/pages/:id_partition/original/file.png')
expect(result).to eq('/_a123/_e1001/pageflow/video_files/:id_partition/original/video.mp4?1356994800')
end

it 'ignores numeric file names' do
attachment = create_attachment(url: '/:class/:id_partition/:style/:filename',
filename: '123')

result = UrlTemplate.from_attachment(attachment)
VideoFile.has_attached_file :attachment_on_filesystem,
url: '/:class/:id_partition/:style/:filename',
filename: '123'
video_file = create(:video_file, :numeric_filename_on_filesystem)
result = described_class.from_attachment(video_file.attachment_on_filesystem)

expect(result).to eq('/pages/:id_partition/original/123')
expect(result).to eq('/pageflow/video_files/:id_partition/original/123.mp4?1356994800')
end
end
end
Expand Down

0 comments on commit f9ff2ed

Please sign in to comment.