Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #725 from kanaabe/remove-embedly
@craigspaeth Remove Embedly
- Loading branch information
Showing
15 changed files
with
178 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
{ NODE_ENV, GEMINI_CLOUDFRONT_URL } = require('sharify').data | ||
qs = require 'qs' | ||
{ compact } = require 'underscore' | ||
|
||
warn = (message) -> | ||
console.warn message if NODE_ENV is 'development' | ||
|
||
endpoint = GEMINI_CLOUDFRONT_URL | ||
|
||
defaults = | ||
quality: 95 | ||
color: 'fff' | ||
|
||
module.exports = gemini = | ||
|
||
resize: (url, options = {}) => | ||
|
||
resize_to = if width? and not height? | ||
'width' | ||
else if height? and not width? | ||
'height' | ||
else | ||
'fit' | ||
|
||
{ width, height, quality } = options | ||
|
||
unless width? or height? | ||
warn 'requires `width || height`' | ||
return url | ||
|
||
if width? and width is 0 | ||
warn '`width` must be non-zero' | ||
return url | ||
|
||
if height? and height is 0 | ||
warn '`height` must be non-zero' | ||
return url | ||
|
||
resize_to = if width? and not height? | ||
'width' | ||
else if height? and not width? | ||
'height' | ||
else | ||
'fit' | ||
|
||
options = | ||
resize_to: resize_to | ||
src: url | ||
width: width if width? | ||
height: height if height? | ||
quality: quality or defaults.quality | ||
|
||
[endpoint , qs.stringify options].join '?' | ||
|
||
crop: (url, options = {}) => | ||
{ width, height, quality } = options | ||
|
||
unless width? and height? | ||
warn 'requires `width && height`' | ||
return url | ||
|
||
if width is 0 | ||
warn '`width` must be non-zero' | ||
return url | ||
|
||
if height is 0 | ||
warn '`height` must be non-zero' | ||
return url | ||
|
||
options = | ||
resize_to: 'fill' | ||
src: url | ||
width: width | ||
height: height | ||
quality: quality or defaults.quality | ||
|
||
[endpoint , qs.stringify options].join '?' | ||
|
||
fill: (url, options = {}) => | ||
gemini.crop(url, options) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ extend } = require 'underscore' | ||
sinon = require 'sinon' | ||
rewire = require 'rewire' | ||
resizer = rewire '../index' | ||
|
||
describe 'resizer', -> | ||
|
||
before -> | ||
@src = 'https://d32dm0rphc51dk.cloudfront.net/RhCPuRWITO6WFW2Zu_u3EQ/large.jpg' | ||
resizer.__set__ 'endpoint', 'https://d7hftxdivxxvm.cloudfront.net' | ||
|
||
describe 'using the gemini proxy', -> | ||
|
||
describe '#resize', -> | ||
it 'returns the appropriate URL when no width is specified', -> | ||
resizer.resize @src, height: 300 | ||
.should.equal 'https://d7hftxdivxxvm.cloudfront.net?resize_to=height&src=https%3A%2F%2Fd32dm0rphc51dk.cloudfront.net%2FRhCPuRWITO6WFW2Zu_u3EQ%2Flarge.jpg&height=300&quality=95' | ||
|
||
it 'returns the appropriate URL when no height is specified', -> | ||
resizer.resize @src, width: 300 | ||
.should.equal 'https://d7hftxdivxxvm.cloudfront.net?resize_to=width&src=https%3A%2F%2Fd32dm0rphc51dk.cloudfront.net%2FRhCPuRWITO6WFW2Zu_u3EQ%2Flarge.jpg&width=300&quality=95' | ||
|
||
it 'returns the appropriate URL when both a height and width are specified', -> | ||
resizer.resize @src, width: 300, height: 200 | ||
.should.equal 'https://d7hftxdivxxvm.cloudfront.net?resize_to=fit&src=https%3A%2F%2Fd32dm0rphc51dk.cloudfront.net%2FRhCPuRWITO6WFW2Zu_u3EQ%2Flarge.jpg&width=300&height=200&quality=95' | ||
|
||
describe '#crop', -> | ||
it 'returns the appropriate URL', -> | ||
resizer.crop @src, width: 32, height: 32 | ||
.should.equal 'https://d7hftxdivxxvm.cloudfront.net?resize_to=fill&src=https%3A%2F%2Fd32dm0rphc51dk.cloudfront.net%2FRhCPuRWITO6WFW2Zu_u3EQ%2Flarge.jpg&width=32&height=32&quality=95' | ||
|
||
describe '#fill', -> | ||
it 'is not really supported and falls back to crop', -> | ||
resizer.fill @src, width: 32, height: 32 | ||
.should.equal 'https://d7hftxdivxxvm.cloudfront.net?resize_to=fill&src=https%3A%2F%2Fd32dm0rphc51dk.cloudfront.net%2FRhCPuRWITO6WFW2Zu_u3EQ%2Flarge.jpg&width=32&height=32&quality=95' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.