Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class App.Attachment extends Tower.Model
- @attachment styles:
- thumb: ['25x25', 'png']
- small: ['50x50', 'png']
- medium: ['125x125', 'png']
- large: ['300x300', 'png']
- @DELAYED_POST_PROCESSING = false
- @defaults
- path: ':root/public:url'
- storage: 's3'
- url: '/uploads/:class/:style/:name' # '/uploads/:class/:name-:style-:geometry.:format'
- @timestamps()
- @belongsTo 'resource', polymorphic: true, embedded: true
- thumb: Ember.computed(->
- @get('styles.thumb')
- )
- # @todo Imagemagick not working on heroku yet
- # postProcessAndSave: (callback) ->
- # callback() if callback
- # true
- # Styles are bindable, so in your ember views you can bind to each url:
- # <ul id='image-sizes'>
- # <li><a {{bindAttr href='thumb.url'}}>Thumb</a></li>
- # <li><a {{bindAttr href='original.url'}}>Original</a></li>
- # </ul>
- normalizedStyles: Ember.computed(->
- @normalizeStyles(@get('styles'))
- ).cacheable()
- normalizeStyles: (styles) ->
- processors = @get('processors')
- for key, value of styles
- if _.isArray(value)
- # width, height
- style = @constructor.parseDimensions(value[0])
- style.format = value[1] if value[1]?
- else if _.isHash(value)
- style = value
- style.url = @urlFor(key)
- style.name = key
- style.processors ||= processors
- style.animated ||= false
- styles[key] = style
- styles
- App.Attachment.fileStore = new Tower.StoreS3(name: 'attachments', type: 'Attachment') if Tower.isServer
Add Comment
Please, Sign In to add comment