{"id":22606677,"url":"https://github.com/benjaminmedia/imaginable","last_synced_at":"2025-03-28T22:15:23.916Z","repository":{"id":140156553,"uuid":"1541591","full_name":"BenjaminMedia/Imaginable","owner":"BenjaminMedia","description":"A gem for hooking your rails project up to the Imagination image server","archived":false,"fork":false,"pushed_at":"2013-10-24T11:01:20.000Z","size":520,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-03-26T14:54:34.426Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BenjaminMedia.png","metadata":{"files":{"readme":"README.textile","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-03-29T14:13:58.000Z","updated_at":"2013-10-24T11:01:25.000Z","dependencies_parsed_at":"2023-03-13T10:44:20.883Z","dependency_job_id":null,"html_url":"https://github.com/BenjaminMedia/Imaginable","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenjaminMedia%2FImaginable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenjaminMedia%2FImaginable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenjaminMedia%2FImaginable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenjaminMedia%2FImaginable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BenjaminMedia","download_url":"https://codeload.github.com/BenjaminMedia/Imaginable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246106689,"owners_count":20724401,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-08T14:14:34.572Z","updated_at":"2025-03-28T22:15:23.886Z","avatar_url":"https://github.com/BenjaminMedia.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"h1. Imaginable\n\nImaginable is a gem for Rails, which allows your apps to store and view images with the CDN Connect cloud-based content delivery network.\n\nh2. Compatibility\n\nImaginable is currently only compatible with Rails 3 and 4.\n\nImaginable requires that you use jQuery. You can do this easily with the jquery-rails gem, if your version of Rails doesn't already use jQuery by default.\n\nh2. Dependencies\n\nImaginable requires that you have installed and configured the Fancybox2 jQuery plugin:\nhttp://fancyapps.com/fancybox/\n\nh2. Installation\n\nSimply add Imaginable to your Gemfile and bundle it up:\n\n\u003cpre\u003e\n  gem 'imaginable'\n\u003c/pre\u003e\n\nThen run the generator:\n\n\u003cpre\u003e\n  $ rails generate imaginable:install\n\u003c/pre\u003e\n\nThe generator will install JavaScripts, stylesheets, as well as two controllers needed for AJAX uploading/cropping of images.\n\nConfigure Imaginable in config/initializers/imaginable.rb, and set any named aspect ratios (like square, widescreen, etc.) if you need them. These are handy when fitting user-uploaded images into a standardized layout.\n\nIn addition, you will have to add the following to your routes.rb:\n\n\u003cpre\u003e\n  imaginable_routes\n\u003c/pre\u003e\n\nh2. Usage\n\nIt is really easy to make a model Imaginable.\n\nIf you are creating a new model, there are even some handy migration helpers.\n\n\u003cpre\u003e\n  class CreateArticles \u003c ActiveRecord::Migration\n    def self.up\n      create_table :articles do |t|\n        t.string :title\n        t.text :body\n        t.imaginable :photo\n        t.timestamps\n      end\n    end\n\n    def self.down\n      drop_table :articles\n    end\n  end\n\u003c/pre\u003e\n\nThe @t.imaginable@ helper above, will create two columns: @photo_uuid@ and @photo_token@ which Imaginable needs to keep track of the images used by this model.\n\nWe then need to mark our model as Imaginable\n\n\u003cpre\u003e\n  class Article \u003c ActiveRecord::Base\n    has_imagination :photo\n  end\n\u003c/pre\u003e\n\nFinally we just need to add a field to our form, which let's the user upload a photo. This is also really easy thanks to the form helper:\n\n\u003cpre\u003e\n  \u003c%= form_for(@article) do |f| %\u003e\n    \u003cdiv class=\"field\"\u003e\n      \u003c%= f.label :title %\u003e\u003cbr /\u003e\n      \u003c%= f.text_field :title %\u003e\n    \u003c/div\u003e\n    \u003cdiv class=\"field\"\u003e\n      \u003c%= f.label :body %\u003e\u003cbr /\u003e\n      \u003c%= f.text_area :body %\u003e\n    \u003c/div\u003e\n    \u003cdiv class=\"field\"\u003e\n      \u003c%= f.label :photo %\u003e\u003cbr /\u003e\n      \u003c%= f.image_field :photo, :crop =\u003e :square %\u003e\n    \u003c/div\u003e\n    \u003cdiv class=\"actions\"\u003e\n      \u003c%= f.submit %\u003e\n    \u003c/div\u003e\n  \u003c% end %\u003e\n\u003c/pre\u003e\n\nPlease note, that you need to include the Imaginable javascripts in your layout, or by other means.\nHere is an example of what you could do, if you had a @yield(:head)@ in the @head@ section of your layout:\n\n\u003cpre\u003e\n  \u003c% content_for(:head) do %\u003e\n    \u003c%= imaginable_includes_tag %\u003e\n  \u003c% end %\u003e\n\u003c/pre\u003e\n\nThat's all there is to it!\n\nh2. Validation\n\nIf you require the user to upload an image, you can use this handy validation helper.\n\n\u003cpre\u003e\n  class Article \u003c ActiveRecord::Base\n\n    has_imagination :photo\n\n    validates_presence_of :title\n    validates_presence_of :body\n    validates_imagination :photo\n\n  end\n\u003c/pre\u003e\n\nh2. Showing images\n\nTo show an image, you simply call the imaginable method of your model.\nThe method will have the name that you have configured in your model.\nIn the above examples, this would be @@article.photo@.\n\n\u003cpre\u003e\n  \u003c%= image_tag @article.photo.url(:crop =\u003e 'square', :width =\u003e 500) %\u003e\n\u003c/pre\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenjaminmedia%2Fimaginable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbenjaminmedia%2Fimaginable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenjaminmedia%2Fimaginable/lists"}