Sha256: 980cdf3b8f4bffb3d9f1c87b4d912e04e9c78ceea5d352e49907b21a921577c1
Contents?: true
Size: 1.86 KB
Versions: 1
Compression:
Stored size: 1.86 KB
Contents
class Formtastic::Inputs::SingleFileInput include Formtastic::Inputs::Base def to_html object = builder.object param_key = "#{object.class.table_name.singularize}[#{method}]" title = method.to_s.titleize asset = object.send(method) profile_name = object.class.haraway_assets[method.to_s] profile = Haraway.configuration.profiles[profile_name] accepts = profile.try(:accepted_file_types) accepts = accepts.join(", ") if accepts versions = compile_versions_array(profile) <<-HTML <x-files single-file profile="#{profile_name}" accept="#{accepts}" name="#{param_key}"> <div class="association">#{ title }</div> <div class="buttons"> <a class="choose">Browse file</a> </div> <div class="content"> <div class="image">#{ asset ? image_html(asset, versions) : "" }</div> <div class="status"> <div class="status-title"></div> <div class="status-bar"> <div class="upload-bar"></div> <div class="process-bar"></div> </div> </div> <div class="name"></div> </div> </x-files> HTML end def compile_versions_array(profile) if profile versions = profile.versions.keys.map do |key| version = profile.versions[key.to_s] OpenStruct.new( name: version.name, params: version.steps.first.try(:[], "params") ) end.compact else versions = [] end # return versions end def image_html(asset, versions) if versions.select { |v| v.name == "thumb" }.length >= 1 asset_url_thumb = asset.url(:thumb) end if asset_url_thumb html = "<div class=\"thumb\" style=\"background-image: " + "url(#{ asset_url_thumb });\"></div>" else html = "<div class=\"thumb no-image\"></div>" end html end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
lalala-4.1.0.dev.305 | lib/formtastic/inputs/single_file_input.rb |