Class: Ideyabox::Generators::CropGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/ideyabox/crop/crop_generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(args, *options) ⇒ CropGenerator

Returns a new instance of CropGenerator.



14
15
16
17
# File 'lib/generators/ideyabox/crop/crop_generator.rb', line 14

def initialize(args, *options)
  super(args, *options)
  initialize_views_variables
end

Instance Method Details

#copy_viewsObject



19
20
21
# File 'lib/generators/ideyabox/crop/crop_generator.rb', line 19

def copy_views
  generate_views
end

#updating_edit_viewObject



57
58
59
60
# File 'lib/generators/ideyabox/crop/crop_generator.rb', line 57

def updating_edit_view
  inject_into_file "app/views/admin/#{plural_resource_name}/edit.html.haml", "(:large), :id=>'cropbox'\n          = render 'crop', :#{resource_name} => @#{resource_name}\n", :after => "          = image_tag @#{resource_name}.image_url"

end

#updating_modelsObject



23
24
25
26
27
# File 'lib/generators/ideyabox/crop/crop_generator.rb', line 23

def updating_models
  inject_into_file "app/models/#{resource_name}.rb", " :crop_x, :crop_y, :crop_w, :crop_h,", :after => "  attr_accessible"
  inject_into_file "app/models/#{resource_name}.rb", "\n  attr_accessor :crop_x, :crop_y, :crop_w, :crop_h\n  after_update :crop_image\n  def crop_image\n    image.recreate_versions! if crop_x.present?\n  end\n", :after => "class #{@model_name.demodulize} < ActiveRecord::Base"
  
end

#updating_uploaderObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/generators/ideyabox/crop/crop_generator.rb', line 29

def updating_uploader
  inject_into_file "app/uploaders/#{resource_name}_uploader.rb", "\n  
  version :large do
    process :resize_to_limit => [500, 500]
  end

  version :crop do
    process :crop
    resize_to_fill(300, 200)
  end

  def crop
    if model.crop_x.present?
resize_to_limit(500, 500)
  manipulate! do |img|
  x = model.crop_x.to_i
  y = model.crop_y.to_i
  w = model.crop_w.to_i
  h = model.crop_h.to_i
  img.crop(\"\#{w}x\#{h}+\#{x}+\#{y}\")
  img
end
    end
  end
  \n", :after => "process :resize_to_fill => [160, 100]\n  end"

end