Module: Poodle::ImageHelper
- Defined in:
- app/helpers/poodle/image_helper.rb
Instance Method Summary collapse
-
#display_image(object, method_name, **options) ⇒ Object
This method will render the image with required width and height.
- #display_user_image(user, method_name, **options) ⇒ Object
-
#edit_image(object, method_name, edit_url, **options) ⇒ Object
Displays the image with a edit button below it.
-
#edit_user_image(object, method_name, edit_url, **options) ⇒ Object
Displays the user image in a rounded frame with a edit button below it.
-
#image_url(object, method_name, **options) ⇒ Object
image_url is a helper method which can be used along with carrier_wave gem Suppose, you have an object ‘user’ which has a profile_picture image_url will return you placehold.it image if profile_picture is not set else it will return you the carrier wave url.
-
#namify(name) ⇒ Object
namify returns the first letters of first name and last name.
-
#placeholdit(**options) ⇒ Object
placeholdit is a helper method used to return placechold.it urls with custom width, height and text It is quite useful for POC Applications to get started with place holder images while developing views.
-
#upload_image_link(object, assoc_name = :photo, scope = :admin) ⇒ Object
Returns new photo url or edit existing photo url based on object is associated with photo or not.
Instance Method Details
#display_image(object, method_name, **options) ⇒ Object
This method will render the image with required width and height. The image url will be set to the placeholder url if the object doesn’t respond to the image method
75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/helpers/poodle/image_helper.rb', line 75 def display_image(object, method_name, **) .reverse_merge!( width: "100%", height: "auto", place_holder: {}, class: object.persisted? ? "#{object.id}-poodle-thumb-image" : "" ) img_url = image_url(object, method_name, **[:place_holder]) return image_tag(img_url, class: [:class], width: [:width], height: [:height]) end |
#display_user_image(user, method_name, **options) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'app/helpers/poodle/image_helper.rb', line 96 def display_user_image(user, method_name, **) url_domain = defined?(QAuthRubyClient) ? QAuthRubyClient.configuration.q_auth_url : "" .reverse_merge!( width: "60px", height: "auto", url_domain: url_domain, place_holder: {}, html_options: {} ) [:html_options].reverse_merge!( style: "width:100%;height:auto;cursor:#{.has_key?(:popover) ? "pointer" : "default"};", class: user.persisted? ? "#{user.id}-poodle-thumb-image" : "" ) if user.respond_to?(:name) [:place_holder].reverse_merge!(text: namify(user.name)) end [:html_options].reverse_merge!( "data-toggle" => "popover", "data-placement" => "bottom", "title" => user.name, "data-content" => [:popover] === true ? "" : [:popover].to_s ) if [:popover] begin image_path = user.send(:eval, method_name) if image_path.starts_with?(:http) url = image_path else url = [:url_domain] + image_path end rescue url = placeholdit(**[:place_holder]) end content_tag(:div) do content_tag(:div, class: "rounded", style: "width:#{[:width]};height:#{[:height]}") do image_tag(url, [:html_options]) end end end |
#edit_image(object, method_name, edit_url, **options) ⇒ Object
Displays the image with a edit button below it
146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'app/helpers/poodle/image_helper.rb', line 146 def edit_image(object, method_name, edit_url, **) .reverse_merge!( remote: true, text: "Change Image", icon: "photo", classes: "btn btn-default btn-xs mt-10" ) img_tag = display_image(object, method_name, **) btn_display = raw(theme_fa_icon([:icon]) + ([:text])) link_to(img_tag, edit_url, :remote => [:remote]) + link_to(btn_display, edit_url, :class=>[:classes], :remote=>[:remote]) end |
#edit_user_image(object, method_name, edit_url, **options) ⇒ Object
Displays the user image in a rounded frame with a edit button below it
163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'app/helpers/poodle/image_helper.rb', line 163 def edit_user_image(object, method_name, edit_url, **) .reverse_merge!( remote: true, text: "Change Image", icon: "photo", classes: "btn btn-default btn-xs mt-10" ) img_tag = display_user_image(object, method_name, **) btn_display = raw(theme_fa_icon([:icon]) + ([:text])) link_to(img_tag, edit_url, :remote => [:remote]) + link_to(btn_display, edit_url, :class=>[:classes], :remote=>[:remote]) end |
#image_url(object, method_name, **options) ⇒ Object
image_url is a helper method which can be used along with carrier_wave gem Suppose, you have an object ‘user’ which has a profile_picture image_url will return you placehold.it image if profile_picture is not set else it will return you the carrier wave url
48 49 50 51 52 53 54 55 56 |
# File 'app/helpers/poodle/image_helper.rb', line 48 def image_url(object, method_name, **) begin url = object.send :eval, method_name raise if url.blank? rescue url = placeholdit(**) end return url end |
#namify(name) ⇒ Object
namify returns the first letters of first name and last name
9 10 11 |
# File 'app/helpers/poodle/image_helper.rb', line 9 def namify(name) name.split(" ").map{|x| x.first.capitalize}[0..1].join("") end |
#placeholdit(**options) ⇒ Object
placeholdit is a helper method used to return placechold.it urls with custom width, height and text It is quite useful for POC Applications to get started with place holder images while developing views
25 26 27 28 |
# File 'app/helpers/poodle/image_helper.rb', line 25 def placeholdit(**) .reverse_merge!( width: 60, height: 60, text: "<No Image>" ) "http://placehold.it/#{[:width]}x#{[:height]}&text=#{[:text]}" end |
#upload_image_link(object, assoc_name = :photo, scope = :admin) ⇒ Object
Returns new photo url or edit existing photo url based on object is associated with photo or not
192 193 194 195 196 197 198 199 200 201 |
# File 'app/helpers/poodle/image_helper.rb', line 192 def upload_image_link(object, assoc_name=:photo, scope=:admin) photo_object = nil photo_object = object.send(assoc_name) if object.respond_to?(assoc_name) if photo_object.present? && photo_object.persisted? url_for([:edit, scope, :image, id: photo_object.id, imageable_id: object.id, imageable_type: object.class.to_s, image_type: photo_object.class.name]) else photo_object = object.send("build_#{assoc_name}") url_for([:new, scope, :image, imageable_id: object.id, imageable_type: object.class.to_s, image_type: photo_object.class.name]) end end |