Class: Dato::Local::FieldType::File
- Inherits:
-
Object
- Object
- Dato::Local::FieldType::File
- Defined in:
- lib/dato/local/field_type/file.rb
Class Method Summary collapse
Instance Method Summary collapse
- #alt ⇒ Object
- #author ⇒ Object
- #copyright ⇒ Object
- #custom_data ⇒ Object
- #file ⇒ Object
- #format ⇒ Object
- #height ⇒ Object
- #id ⇒ Object
-
#initialize(upload, alt, title, custom_data, imgix_host) ⇒ File
constructor
A new instance of File.
- #notes ⇒ Object
- #path ⇒ Object
- #size ⇒ Object
- #title ⇒ Object
- #to_hash(*_args) ⇒ Object
- #url(opts = {}) ⇒ Object
- #width ⇒ Object
Constructor Details
#initialize(upload, alt, title, custom_data, imgix_host) ⇒ File
Returns a new instance of File.
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/dato/local/field_type/file.rb', line 27 def initialize( upload, alt, title, custom_data, imgix_host ) @upload = upload @alt = alt @title = title @custom_data = custom_data @imgix_host = imgix_host end |
Class Method Details
.parse(value, repo) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/dato/local/field_type/file.rb', line 9 def self.parse(value, repo) if value v = value.with_indifferent_access upload = repo.entities_repo.find_entity('upload', v[:upload_id]) if upload new( upload, v[:alt], v[:title], v[:custom_data], repo.site.entity.imgix_host ) end end end |
Instance Method Details
#alt ⇒ Object
77 78 79 80 |
# File 'lib/dato/local/field_type/file.rb', line 77 def alt = @upload..deep_stringify_keys.fetch(I18n.locale.to_s, {}) @alt || ["alt"] end |
#author ⇒ Object
65 66 67 |
# File 'lib/dato/local/field_type/file.rb', line 65 def @upload. end |
#copyright ⇒ Object
73 74 75 |
# File 'lib/dato/local/field_type/file.rb', line 73 def copyright @upload.copyright end |
#custom_data ⇒ Object
87 88 89 90 |
# File 'lib/dato/local/field_type/file.rb', line 87 def custom_data = @upload..deep_stringify_keys.fetch(I18n.locale.to_s, {}) @custom_data.merge(.fetch("custom_data", {})) end |
#file ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/dato/local/field_type/file.rb', line 92 def file Imgix::Client.new( host: @imgix_host, secure: true, include_library_param: false ).path(path) end |
#format ⇒ Object
49 50 51 |
# File 'lib/dato/local/field_type/file.rb', line 49 def format @upload.format end |
#height ⇒ Object
61 62 63 |
# File 'lib/dato/local/field_type/file.rb', line 61 def height @upload.height end |
#id ⇒ Object
41 42 43 |
# File 'lib/dato/local/field_type/file.rb', line 41 def id @upload.id end |
#notes ⇒ Object
69 70 71 |
# File 'lib/dato/local/field_type/file.rb', line 69 def notes @upload.notes end |
#path ⇒ Object
45 46 47 |
# File 'lib/dato/local/field_type/file.rb', line 45 def path @upload.path end |
#size ⇒ Object
53 54 55 |
# File 'lib/dato/local/field_type/file.rb', line 53 def size @upload.size end |
#title ⇒ Object
82 83 84 85 |
# File 'lib/dato/local/field_type/file.rb', line 82 def title = @upload..deep_stringify_keys.fetch(I18n.locale.to_s, {}) @title || ["title"] end |
#to_hash(*_args) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/dato/local/field_type/file.rb', line 104 def to_hash(*_args) { id: id, format: format, size: size, width: width, height: height, alt: alt, title: title, custom_data: custom_data, url: url } end |
#url(opts = {}) ⇒ Object
100 101 102 |
# File 'lib/dato/local/field_type/file.rb', line 100 def url(opts = {}) file.to_url(opts) end |
#width ⇒ Object
57 58 59 |
# File 'lib/dato/local/field_type/file.rb', line 57 def width @upload.width end |