Guest User

Untitled

a guest
Dec 11th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. class App.Attachment extends Tower.Model
  2. @attachment styles:
  3. thumb: ['25x25', 'png']
  4. small: ['50x50', 'png']
  5. medium: ['125x125', 'png']
  6. large: ['300x300', 'png']
  7.  
  8. @DELAYED_POST_PROCESSING = false
  9.  
  10. @defaults
  11. path: ':root/public:url'
  12. storage: 's3'
  13. url: '/uploads/:class/:style/:name' # '/uploads/:class/:name-:style-:geometry.:format'
  14.  
  15. @timestamps()
  16.  
  17. @belongsTo 'resource', polymorphic: true, embedded: true
  18.  
  19. thumb: Ember.computed(->
  20. @get('styles.thumb')
  21. )
  22.  
  23. # @todo Imagemagick not working on heroku yet
  24. # postProcessAndSave: (callback) ->
  25. # callback() if callback
  26. # true
  27.  
  28. # Styles are bindable, so in your ember views you can bind to each url:
  29. # <ul id='image-sizes'>
  30. # <li><a {{bindAttr href='thumb.url'}}>Thumb</a></li>
  31. # <li><a {{bindAttr href='original.url'}}>Original</a></li>
  32. # </ul>
  33. normalizedStyles: Ember.computed(->
  34. @normalizeStyles(@get('styles'))
  35. ).cacheable()
  36.  
  37. normalizeStyles: (styles) ->
  38. processors = @get('processors')
  39.  
  40. for key, value of styles
  41. if _.isArray(value)
  42. # width, height
  43. style = @constructor.parseDimensions(value[0])
  44. style.format = value[1] if value[1]?
  45. else if _.isHash(value)
  46. style = value
  47.  
  48. style.url = @urlFor(key)
  49. style.name = key
  50. style.processors ||= processors
  51. style.animated ||= false
  52.  
  53. styles[key] = style
  54.  
  55. styles
  56.  
  57. App.Attachment.fileStore = new Tower.StoreS3(name: 'attachments', type: 'Attachment') if Tower.isServer
Add Comment
Please, Sign In to add comment