poodle-rb 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/poodle/application.js +1 -2
- data/app/assets/javascripts/poodle/cropper.js +1525 -0
- data/app/assets/javascripts/poodle/utilities.js +23 -7
- data/app/assets/stylesheets/poodle/poodle-theme.css +18 -1
- data/app/controllers/poodle/admin_controller.rb +0 -26
- data/app/controllers/poodle/images_controller.rb +65 -0
- data/app/helpers/poodle/image_helper.rb +171 -31
- data/app/helpers/poodle/render_helper.rb +31 -0
- data/{spec/dummy/app → app}/uploaders/image_uploader.rb +19 -22
- data/app/views/layouts/poodle/application/_footer.html.erb +1 -1
- data/app/views/layouts/poodle/application.html.erb +7 -3
- data/app/views/layouts/poodle/image_upload.html.erb +16 -0
- data/app/views/layouts/poodle/public/_footer.html.erb +2 -4
- data/app/views/layouts/poodle/public/_header.html.erb +1 -3
- data/app/views/layouts/poodle/public/public.html.erb +51 -0
- data/app/views/layouts/poodle/public.html.erb +8 -5
- data/lib/poodle/action_view/theme_helper.rb +0 -76
- data/lib/poodle/engine.rb +2 -0
- data/lib/poodle/version.rb +1 -1
- data/spec/dummy/app/controllers/profile_pictures_controller.rb +2 -0
- data/spec/dummy/app/models/image/base.rb +30 -0
- data/spec/dummy/app/models/image/profile_picture.rb +2 -0
- data/spec/dummy/app/models/user.rb +1 -1
- data/spec/dummy/app/views/profile_pictures/_crop_form.html.erb +44 -0
- data/spec/dummy/app/views/profile_pictures/_form.html.erb +41 -0
- data/spec/dummy/app/views/profile_pictures/_new.html.erb +9 -0
- data/spec/dummy/app/views/profile_pictures/_photos.html.erb +16 -0
- data/spec/dummy/app/views/profile_pictures/create.html.erb +10 -0
- data/spec/dummy/app/views/profile_pictures/crop.html.erb +5 -0
- data/spec/dummy/app/views/profile_pictures/edit.js.erb +7 -0
- data/spec/dummy/app/views/profile_pictures/new.js.erb +7 -0
- data/spec/dummy/app/views/profile_pictures/update.html.erb +10 -0
- data/spec/dummy/app/views/profile_pictures/update.js.erb +2 -0
- data/spec/dummy/config/initializers/carrier_wave.rb +2 -0
- data/spec/dummy/config/routes.rb +15 -1
- data/spec/dummy/db/migrate/20131108102728_create_images.rb +12 -0
- data/spec/dummy/db/schema.rb +5 -2
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/{app/assets/javascripts/poodle/common.js → spec/dummy/log/development.log} +0 -0
- data/spec/dummy/log/test.log +11173 -0
- data/spec/dummy/spec/controllers/profile_pictures_controller_spec.rb +50 -0
- data/spec/dummy/spec/helpers/image_helper_spec.rb +129 -0
- data/spec/dummy/spec/helpers/theme_helper_spec.rb +14 -43
- data/spec/dummy/spec/support/factories/profile_pictures.rb +2 -2
- data/spec/dummy/spec/support/factories/users.rb +1 -1
- data/spec/dummy/{public/uploads/profile_picture/image → uploads/image/profile_picture}/1/large_test.jpg +0 -0
- data/spec/dummy/uploads/image/profile_picture/1/medium_test.jpg +0 -0
- data/spec/dummy/{public/uploads/profile_picture/image → uploads/image/profile_picture}/1/test.jpg +0 -0
- data/spec/dummy/{public/uploads/profile_picture/image → uploads/image/profile_picture}/1/thumb_test.jpg +0 -0
- data/spec/dummy/uploads/image/profile_picture/2/large_test.jpg +0 -0
- data/spec/dummy/uploads/image/profile_picture/2/medium_test.jpg +0 -0
- data/spec/dummy/uploads/image/profile_picture/2/test.jpg +0 -0
- data/spec/dummy/uploads/image/profile_picture/2/thumb_test.jpg +0 -0
- metadata +60 -18
- data/app/assets/javascripts/poodle/photo_upload.js +0 -104
- data/spec/dummy/app/models/profile_picture.rb +0 -8
- data/spec/dummy/db/migrate/20131108102728_create_profile_pictures.rb +0 -9
- data/spec/dummy/public/uploads/profile_picture/image/1/medium_test.jpg +0 -0
@@ -282,82 +282,6 @@ module Poodle
|
|
282
282
|
content_tag(:div, text, class: classes)
|
283
283
|
end
|
284
284
|
|
285
|
-
# Example
|
286
|
-
# theme_image(@project, admin_project_path(@project), :url, "logo.image.url", change_picture_url: change_picture_url)
|
287
|
-
# is equivalent to:
|
288
|
-
# ---------------------------
|
289
|
-
# <% img_tag = display_image(@project, "logo.image.url", width: "100%", place_holder: {width: 300, height: 180, text: "<No Image>"}) %>
|
290
|
-
# <%= link_to img_tag, change_picture_url, :remote => true %>
|
291
|
-
# <%= link_to raw("<i class=\"fa fa-photo mr-5\"></i> Change Picture"), change_picture_url, :class=>"btn btn-default btn-xs mt-10", :remote=>true %>
|
292
|
-
def theme_image(object, url, assoc_name, assoc_url, **options)
|
293
|
-
options.reverse_merge!(
|
294
|
-
width: "100%",
|
295
|
-
ph: {
|
296
|
-
width: 300,
|
297
|
-
height: 180,
|
298
|
-
text: "<No Image>"
|
299
|
-
},
|
300
|
-
remote: true,
|
301
|
-
text: "Change Image",
|
302
|
-
icon: "photo",
|
303
|
-
classes: "btn btn-default btn-xs mt-10",
|
304
|
-
change_picture_url: nil
|
305
|
-
)
|
306
|
-
img_tag = display_image(object, assoc_url, width: options[:width], place_holder: options[:ph])
|
307
|
-
btn_display = raw(theme_fa_icon(options[:icon])+theme_button_text(options[:text]))
|
308
|
-
link_to(img_tag, options[:change_picture_url], :remote => options[:remote]) +
|
309
|
-
link_to(btn_display, options[:change_picture_url], :class=>options[:classes], :remote=>options[:remote])
|
310
|
-
end
|
311
|
-
|
312
|
-
# Example
|
313
|
-
# place_holder(width: 60, height: 40, text: "Not Found")
|
314
|
-
# is equivalent to:
|
315
|
-
# "http://placehold.it/60x40&text=Not Found"
|
316
|
-
def palceholdit(**options)
|
317
|
-
options.reverse_merge!( width: 60, height: 60, text: "<No Image>" )
|
318
|
-
"http://placehold.it/#{options[:width]}x#{options[:height]}&text=#{options[:text]}"
|
319
|
-
end
|
320
|
-
|
321
|
-
# Example
|
322
|
-
# theme_user_image(@user)
|
323
|
-
# is equivalent to:
|
324
|
-
def theme_user_image(user, method_name, **options)
|
325
|
-
|
326
|
-
url_domain = defined?(QAuthRubyClient) ? QAuthRubyClient.configuration.q_auth_url : "http://localhost:9001"
|
327
|
-
|
328
|
-
options.reverse_merge!(
|
329
|
-
width: 60,
|
330
|
-
height: options[:width],
|
331
|
-
url_domain: url_domain,
|
332
|
-
place_holder: { width: options[:width], height: options[:height], text: "<No Image>" },
|
333
|
-
html_options: { class: "", style: "width:100%;height:auto;cursor:pointer;" }
|
334
|
-
)
|
335
|
-
|
336
|
-
options[:place_holder].reverse_merge!(
|
337
|
-
width: options[:width],
|
338
|
-
height: options[:height],
|
339
|
-
text: "<No Image>"
|
340
|
-
)
|
341
|
-
|
342
|
-
options[:html_options].reverse_merge!(
|
343
|
-
"data-toggle" => "popover",
|
344
|
-
"data-placement" => "bottom",
|
345
|
-
"title" => user.name,
|
346
|
-
"data-content" => options[:popover] === true ? "" : options[:popover].to_s
|
347
|
-
) if options[:popover]
|
348
|
-
|
349
|
-
begin
|
350
|
-
url = options[:url_domain] + user.send(:eval, method_name)
|
351
|
-
rescue
|
352
|
-
url = palceholdit()
|
353
|
-
end
|
354
|
-
|
355
|
-
content_tag(:div) do
|
356
|
-
content_tag(:div, class: "rounded", style: "width:#{options[:width]}px;height:#{options[:width]}px;") do
|
357
|
-
image_tag(url, options[:html_options])
|
358
|
-
end
|
359
|
-
end
|
360
|
-
end
|
361
285
|
end
|
362
286
|
end
|
363
287
|
end
|
data/lib/poodle/engine.rb
CHANGED
@@ -27,6 +27,7 @@ module Poodle
|
|
27
27
|
include Poodle::ParamsParserHelper
|
28
28
|
include Poodle::TitleHelper
|
29
29
|
include Poodle::UrlHelper
|
30
|
+
include Poodle::RenderHelper
|
30
31
|
helper Poodle::DisplayHelper
|
31
32
|
helper Poodle::FlashHelper
|
32
33
|
helper Poodle::ImageHelper
|
@@ -35,6 +36,7 @@ module Poodle
|
|
35
36
|
helper Poodle::ParamsParserHelper
|
36
37
|
helper Poodle::TitleHelper
|
37
38
|
helper Poodle::UrlHelper
|
39
|
+
helper Poodle::RenderHelper
|
38
40
|
end
|
39
41
|
|
40
42
|
end
|
data/lib/poodle/version.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
class Image::Base < ActiveRecord::Base
|
2
|
+
|
3
|
+
self.table_name = "images"
|
4
|
+
mount_uploader :image, ImageUploader
|
5
|
+
attr_accessor :crop_x, :crop_y, :crop_w, :crop_h
|
6
|
+
|
7
|
+
# Associations
|
8
|
+
belongs_to :imageable, :polymorphic => true
|
9
|
+
|
10
|
+
# Callbacks
|
11
|
+
after_save :crop_image
|
12
|
+
|
13
|
+
def crop_image
|
14
|
+
image.recreate_versions! if crop_x.present?
|
15
|
+
end
|
16
|
+
|
17
|
+
#one convenient method to pass jq_upload the necessary information
|
18
|
+
def to_jq_upload
|
19
|
+
{
|
20
|
+
"name" => read_attribute(:image),
|
21
|
+
"size" => image.size,
|
22
|
+
"full_url" => image.url,
|
23
|
+
"thumbnail_url" => image.thumb.url,
|
24
|
+
"large_url" => image.large.url,
|
25
|
+
"url" => "/admin/images/#{id}",
|
26
|
+
"delete_type" => "DELETE"
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
<%= form_for(@image, :as => :image,
|
2
|
+
:url => main_app.crop_admin_image_path(@image),
|
3
|
+
:method => :put,
|
4
|
+
:html => {:id=>"form_crop_photo", :class=>"mb-0 form-horizontal", :multipart => true, :target => "iframe_crop_photo"}) do |f| %>
|
5
|
+
|
6
|
+
<div class="modal-body">
|
7
|
+
|
8
|
+
<%= @image.errors[:base].to_sentence %>
|
9
|
+
|
10
|
+
<%= hidden_field_tag :imageable_id, params[:imageable_id] %>
|
11
|
+
<%= hidden_field_tag :imageable_type, params[:imageable_type] %>
|
12
|
+
<%= hidden_field_tag :redirect_url, params[:redirect_url] %>
|
13
|
+
<%= hidden_field_tag :image_type, params[:image_type] %>
|
14
|
+
|
15
|
+
<% %w[x y w h].each do |i| %>
|
16
|
+
<%= f.hidden_field "crop_#{i}", class: "crop_#{i}" %>
|
17
|
+
<% end %>
|
18
|
+
|
19
|
+
<div class="add-photos-path">
|
20
|
+
<div class="row">
|
21
|
+
<%= image_tag @image.image.present? ?
|
22
|
+
(@image.image_url) :
|
23
|
+
('http://placehold.it/220x220'), :alt => '', :id => "new_photos", :class=>"img-thumbnail" %>
|
24
|
+
</div>
|
25
|
+
</div>
|
26
|
+
|
27
|
+
</div>
|
28
|
+
|
29
|
+
<div class="modal-footer">
|
30
|
+
<div class="pull-right">
|
31
|
+
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
|
32
|
+
<%= submit_tag "Crop Image", "data-reset-text"=>"Crop Image", "data-loading-text"=>"Cropping ...", :class=>"btn btn-primary ml-10" %>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
</div>
|
36
|
+
|
37
|
+
<div class="cl-10"></div>
|
38
|
+
|
39
|
+
<% end %>
|
40
|
+
|
41
|
+
<!-- when the form is submitted, the server response will appear in this iframe -->
|
42
|
+
<iframe id="iframe_crop_photo" name="iframe_crop_photo" width="100%" style="display:none;">
|
43
|
+
</iframe>
|
44
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
<%= form_for(@image, :as => :image,
|
2
|
+
:url => (@image.new_record? ? main_app.admin_images_path : main_app.admin_image_path),
|
3
|
+
:method => (@image.new_record? ? :post : :put),
|
4
|
+
:html => {:id=>"form_photo", :class=>"mb-0 form-horizontal", :multipart => true, :target => "iframe_photo"}) do |f| %>
|
5
|
+
|
6
|
+
<div class="modal-body">
|
7
|
+
|
8
|
+
<%= @image.errors[:base].to_sentence %>
|
9
|
+
|
10
|
+
<%= hidden_field_tag :faction, @image.new_record? ? main_app.admin_images_path : main_app.admin_image_path(@image) %>
|
11
|
+
<%= hidden_field_tag :fmethod, @image.new_record? ? "POST" : "PUT" %>
|
12
|
+
|
13
|
+
<%= hidden_field_tag :imageable_id, params[:imageable_id] %>
|
14
|
+
<%= hidden_field_tag :imageable_type, params[:imageable_type] %>
|
15
|
+
<%= hidden_field_tag :redirect_url, params[:redirect_url] %>
|
16
|
+
<%= hidden_field_tag :image_type, params[:image_type] %>
|
17
|
+
|
18
|
+
<div class="add-photos-path">
|
19
|
+
|
20
|
+
<div class="row">
|
21
|
+
<div class="col-md-12">
|
22
|
+
<%= theme_form_field(@image, :image, html_options: {type: 'file'}, label: "Upload a new Image", param_name: "image") %>
|
23
|
+
</div>
|
24
|
+
</div>
|
25
|
+
|
26
|
+
</div>
|
27
|
+
|
28
|
+
</div>
|
29
|
+
|
30
|
+
<div class="modal-footer">
|
31
|
+
<div class="pull-right">
|
32
|
+
<% button_text = "#{@image.new_record? ? "Create" : "Update"} Photo" %>
|
33
|
+
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
|
34
|
+
<%= submit_tag button_text, "data-reset-text"=>button_text, "data-loading-text"=>"Saving ...", :class=>"btn btn-primary ml-10" %>
|
35
|
+
</div>
|
36
|
+
|
37
|
+
</div>
|
38
|
+
|
39
|
+
<div class="cl-10"></div>
|
40
|
+
|
41
|
+
<% end %>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<% if photo_album.photos.any? %>
|
2
|
+
|
3
|
+
<div id="links">
|
4
|
+
<% photo_album.photos.each do |photo| %>
|
5
|
+
<a class="" href="<%= photo.image_url %>"
|
6
|
+
title="<%= photo_album.name%>" data-gallery="">
|
7
|
+
<%= display_photo(photo, 200) %>
|
8
|
+
</a>
|
9
|
+
<% end %>
|
10
|
+
</div>
|
11
|
+
|
12
|
+
<% else %>
|
13
|
+
<p>Photos are not available yet. Please upload photos</p>
|
14
|
+
<% end %>
|
15
|
+
|
16
|
+
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<%= content_for :javascript_footer do %>
|
2
|
+
<script type="text/javascript">
|
3
|
+
|
4
|
+
var heading = "Crop Image";
|
5
|
+
var bodyContent = "<%= escape_javascript(render(:partial=>"crop_form")) %>";
|
6
|
+
this.parent.showModal(heading, bodyContent);
|
7
|
+
this.parent.cropImage("form_crop_photo");
|
8
|
+
|
9
|
+
</script>
|
10
|
+
<% end %>
|
@@ -0,0 +1,7 @@
|
|
1
|
+
// Show the new form in the right box.
|
2
|
+
heading = "Edit a photo";
|
3
|
+
bodyContent = "<%= escape_javascript(render(:partial=>"form")) %>";
|
4
|
+
showModal(heading, bodyContent);
|
5
|
+
|
6
|
+
// When the image upload form is submitted, the server response will appear in this iframe -->
|
7
|
+
var $div = $('<iframe id="iframe_photo" name="iframe_photo" width="100%" style="display:none"></iframe>').appendTo('body');
|
@@ -0,0 +1,7 @@
|
|
1
|
+
// Show the new form in the right box.
|
2
|
+
heading = "Add a photo";
|
3
|
+
bodyContent = "<%= escape_javascript(render(:partial=>"form")) %>";
|
4
|
+
showModal(heading, bodyContent);
|
5
|
+
|
6
|
+
// When the image upload form is submitted, the server response will appear in this iframe -->
|
7
|
+
var $div = $('<iframe id="iframe_photo" name="iframe_photo" width="100%" style="display:none"></iframe>').appendTo('body');
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<%= content_for :javascript_footer do %>
|
2
|
+
<script type="text/javascript">
|
3
|
+
|
4
|
+
var heading = "Crop Image";
|
5
|
+
var bodyContent = "<%= escape_javascript(render(:partial=>"crop_form")) %>";
|
6
|
+
this.parent.showModal(heading, bodyContent);
|
7
|
+
this.parent.cropImage("form_crop_photo");
|
8
|
+
|
9
|
+
</script>
|
10
|
+
<% end %>
|
data/spec/dummy/config/routes.rb
CHANGED
@@ -1,4 +1,18 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
|
-
|
3
2
|
mount Poodle::Engine => "/poodle"
|
3
|
+
|
4
|
+
resources :images, controller: "profile_pictures" do
|
5
|
+
member do
|
6
|
+
put :crop
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
namespace :custom do
|
11
|
+
resources :images do
|
12
|
+
member do
|
13
|
+
put :crop
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
4
18
|
end
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -13,13 +13,16 @@
|
|
13
13
|
|
14
14
|
ActiveRecord::Schema.define(version: 20140402113213) do
|
15
15
|
|
16
|
-
create_table "
|
16
|
+
create_table "images", force: :cascade do |t|
|
17
17
|
t.string "image"
|
18
|
-
t.integer "
|
18
|
+
t.integer "imageable_id"
|
19
|
+
t.string "imageable_type"
|
19
20
|
t.datetime "created_at"
|
20
21
|
t.datetime "updated_at"
|
21
22
|
end
|
22
23
|
|
24
|
+
add_index "images", ["imageable_id", "imageable_type"], name: "index_images_on_imageable_id_and_imageable_type"
|
25
|
+
|
23
26
|
create_table "users", force: :cascade do |t|
|
24
27
|
t.string "name", limit: 255
|
25
28
|
t.datetime "created_at"
|
data/spec/dummy/db/test.sqlite3
CHANGED
Binary file
|
File without changes
|