bootsy 2.0.11 → 2.0.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,7 +11,7 @@ module Bootsy
11
11
 
12
12
  format.json do
13
13
  render json: {
14
- images: @images.map {|image| image_markup(image) },
14
+ images: @images.map { |image| image_markup(image) },
15
15
  form: new_image_markup(@gallery)
16
16
  }
17
17
  end
@@ -20,25 +20,10 @@ module Bootsy
20
20
 
21
21
  def create
22
22
  @gallery = find_gallery
23
- @gallery.save! unless @gallery.persisted?
23
+ @gallery.save!
24
24
  @image = @gallery.images.new(image_params)
25
25
 
26
- respond_to do |format|
27
- if @image.save
28
- format.json {
29
- render json: {
30
- image: image_markup(@image),
31
- form: new_image_markup(@gallery),
32
- gallery_id: @gallery.id
33
- }
34
- }
35
- else
36
- format.json {
37
- render json: @image.errors,
38
- status: :unprocessable_entity
39
- }
40
- end
41
- end
26
+ create_and_respond
42
27
  end
43
28
 
44
29
  def destroy
@@ -46,9 +31,9 @@ module Bootsy
46
31
  @image.destroy
47
32
 
48
33
  respond_to do |format|
49
- format.json {
34
+ format.json do
50
35
  render json: { id: params[:id] }
51
- }
36
+ end
52
37
 
53
38
  format.html { redirect_to images_url }
54
39
  end
@@ -86,9 +71,26 @@ module Bootsy
86
71
  )
87
72
  end
88
73
 
89
- # Never trust parameters from the scary internet, only allow the white list through.
90
74
  def image_params
91
75
  params.require(:image).permit(:image_file)
92
76
  end
77
+
78
+ def create_and_respond
79
+ respond_to do |format|
80
+ if @image.save
81
+ format.json do
82
+ render json: {
83
+ image: image_markup(@image),
84
+ form: new_image_markup(@gallery),
85
+ gallery_id: @gallery.id
86
+ }
87
+ end
88
+ else
89
+ format.json do
90
+ render json: @image.errors, status: :unprocessable_entity
91
+ end
92
+ end
93
+ end
94
+ end
93
95
  end
94
96
  end
@@ -1,10 +1,12 @@
1
1
  module Bootsy
2
2
  module ApplicationHelper
3
3
  def refresh_btn
4
- link_to t('bootsy.action.refresh'), '#refresh-gallery', class: 'btn btn-default btn-sm refresh-btn'
4
+ link_to t('bootsy.action.refresh'),
5
+ '#refresh-gallery',
6
+ class: 'btn btn-default btn-sm refresh-btn'
5
7
  end
6
8
 
7
- def resource_or_nil resource
9
+ def resource_or_nil(resource)
8
10
  resource if resource.present? && resource.persisted?
9
11
  end
10
12
  end
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  module Bootsy
3
2
  class ImageUploader < CarrierWave::Uploader::Base
4
3
  include CarrierWave::MiniMagick
@@ -9,19 +8,24 @@ module Bootsy
9
8
  "#{Bootsy.store_dir}/#{model.class.to_s.underscore}/#{model.id}"
10
9
  end
11
10
 
12
- # Process files as they are uploaded:
13
11
  process resize_to_limit: [1160, 2000]
14
12
 
15
13
  version :large do
16
- process resize_to_fit: [Bootsy.large_image[:width], Bootsy.large_image[:height]]
14
+ process resize_to_fit: [
15
+ Bootsy.large_image[:width], Bootsy.large_image[:height]
16
+ ]
17
17
  end
18
18
 
19
19
  version :medium do
20
- process resize_to_fit: [Bootsy.medium_image[:width], Bootsy.medium_image[:height]]
20
+ process resize_to_fit: [
21
+ Bootsy.medium_image[:width], Bootsy.medium_image[:height]
22
+ ]
21
23
  end
22
24
 
23
25
  version :small do
24
- process resize_to_fit: [Bootsy.small_image[:width], Bootsy.small_image[:height]]
26
+ process resize_to_fit: [
27
+ Bootsy.small_image[:width], Bootsy.small_image[:height]
28
+ ]
25
29
  end
26
30
 
27
31
  version :thumb do
@@ -1,12 +1,14 @@
1
- <div class="modal fade bootsy-modal" tabindex="-1"
2
- role="dialog" aria-hidden="true" data-no-turbolink
1
+ <div class="modal fade bootsy-modal"
2
+ data-no-turbolink
3
3
  data-gallery-id="<%= container.bootsy_image_gallery_id %>">
4
4
  <div class="modal-dialog">
5
5
  <div class="modal-content">
6
6
  <div class="modal-header">
7
- <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
7
+ <button type="button" class="close" data-dismiss="modal">
8
+ <span aria-hidden="true">&times;</span>
9
+ </button>
8
10
 
9
- <h3 class="modal-title"><%= t 'bootsy.image.p' %></h3>
11
+ <h4 class="modal-title"><%= t 'bootsy.image.p' %></h4>
10
12
  </div>
11
13
 
12
14
  <div class="modal-body">
@@ -8,6 +8,7 @@ require 'bootsy/core_ext'
8
8
 
9
9
  autoload :BootsyInput, 'bootsy/simple_form/bootsy_input'
10
10
 
11
+ # Public: Top Bootsy module
11
12
  module Bootsy
12
13
  ## CONFIGURATION OPTIONS
13
14
 
@@ -33,15 +34,15 @@ module Bootsy
33
34
 
34
35
  # Settings for small images
35
36
  mattr_accessor :small_image
36
- @@small_image = {width: 160, height: 160}
37
+ @@small_image = { width: 160, height: 160 }
37
38
 
38
39
  # Settings for medium images
39
40
  mattr_accessor :medium_image
40
- @@medium_image = {width: 360, height: 360}
41
+ @@medium_image = { width: 360, height: 360 }
41
42
 
42
43
  # Settings for large images
43
44
  mattr_accessor :large_image
44
- @@large_image = {width: 760, height: 760}
45
+ @@large_image = { width: 760, height: 760 }
45
46
 
46
47
  # Settings for the original version of images
47
48
  mattr_accessor :original_image
@@ -55,9 +56,6 @@ module Bootsy
55
56
  mattr_accessor :store_dir
56
57
  @@store_dir = 'uploads'
57
58
 
58
-
59
- ## SETUP
60
-
61
59
  # Default way to setup Bootsy. Run rails generate bootsy:install
62
60
  # to create a fresh initializer with all configuration values.
63
61
  def self.setup
@@ -13,8 +13,11 @@ module Bootsy
13
13
  belongs_to :bootsy_resource, polymorphic: true, autosave: false
14
14
  has_many :images, dependent: :destroy
15
15
 
16
- scope :destroy_orphans, ->(time_limit) {
17
- where('created_at < ? AND bootsy_resource_id IS NULL', time_limit).destroy_all
16
+ scope :destroy_orphans, lambda { |time_limit|
17
+ where(
18
+ 'created_at < ? AND bootsy_resource_id IS NULL',
19
+ time_limit
20
+ ).destroy_all
18
21
  }
19
22
  end
20
23
  end
@@ -13,16 +13,16 @@ module Bootsy
13
13
  included do
14
14
  class_eval do
15
15
  has_one :bootsy_image_gallery,
16
- class_name: 'Bootsy::ImageGallery',
17
- as: :bootsy_resource,
18
- dependent: :destroy
16
+ class_name: 'Bootsy::ImageGallery',
17
+ as: :bootsy_resource,
18
+ dependent: :destroy
19
19
 
20
20
  # Public: Get the `id` attribute of the image gallery.
21
21
  #
22
22
  # Returns an Integer id or nil when there is
23
23
  # not an image gallery.
24
24
  def bootsy_image_gallery_id
25
- self.bootsy_image_gallery.try(:id)
25
+ bootsy_image_gallery.try(:id)
26
26
  end
27
27
 
28
28
  # Public: Set the image gallery `id` and save
@@ -40,11 +40,12 @@ module Bootsy
40
40
  # gallery.bootsy_resource.id
41
41
  # # => 34
42
42
  def bootsy_image_gallery_id=(value)
43
- if self.bootsy_image_gallery.nil? && !value.blank?
44
- image_gallery = Bootsy::ImageGallery.find(value)
45
- self.bootsy_image_gallery = image_gallery
46
- image_gallery.bootsy_resource = self
47
- image_gallery.save
43
+ if bootsy_image_gallery.nil? && value.present?
44
+ self.bootsy_image_gallery = Bootsy::ImageGallery.find(value)
45
+ bootsy_image_gallery.bootsy_resource = self
46
+ bootsy_image_gallery.save
47
+ else
48
+ value
48
49
  end
49
50
  end
50
51
  end
@@ -25,7 +25,9 @@ module Bootsy
25
25
  # Require Active Record models. Other ORMs must
26
26
  # include their own Bootsy models.
27
27
  if orm == :activerecord
28
- Dir[File.expand_path('../activerecord/*.rb', __FILE__)].each {|f| require f }
28
+ Dir[File.expand_path('../activerecord/*.rb', __FILE__)].each do |f|
29
+ require f
30
+ end
29
31
  end
30
32
  end
31
33
  end
@@ -12,30 +12,35 @@ module Bootsy
12
12
  #
13
13
  # options - The Hash of options used to enable/disable features of
14
14
  # the editor (default: {}):
15
- # :container - The `Bootsy::Container` instance model that
16
- # will be referenced by the editor's image
17
- # gallery. Defaults to the object assigned to
18
- # the template, if it is a `Container`.
19
- # :uploader - The Boolean value used to enable/disable the
20
- # image upload feature. Default: true, if a
21
- # `Container` is found. false otherwise.
22
- # :editor_options - The Hash of options with Boolean values used
23
- # to enable/disable features of the editor.
24
- # Available options are described in the Bootsy
25
- # initializer file (which is the default for
26
- # this argument).
15
+ # :container - The `Bootsy::Container` instance model
16
+ # that will be referenced by the editor's
17
+ # image gallery. Defaults to the object
18
+ # assigned to the template, if it is a
19
+ # `Container`.
20
+ # :uploader - The Boolean value used to enable/disable
21
+ # the image upload feature. Default: true,
22
+ # if a`Container` is found, false otherwise.
23
+ # :editor_options - The Hash of options with Boolean values
24
+ # usedto enable/disable features of the
25
+ # editor. Available options are described ib
26
+ # the Bootsyinitializer file (which is the
27
+ # default for this argument).
27
28
  def bootsy_area(object_name, method, options = {})
28
29
  container = options[:container] || options[:object]
29
30
 
30
- output = self.text_area(object_name, method, text_area_options(options))
31
+ output = text_area(object_name, method, text_area_options(options))
31
32
 
32
33
  if output.present? && enable_uploader?(options)
33
34
  container.bootsy_image_gallery_id ||= Bootsy::ImageGallery.create!.id
34
35
 
35
- output += self.render('bootsy/images/modal', container: container)
36
+ output += render('bootsy/images/modal', container: container)
36
37
 
37
38
  if container.new_record?
38
- output += self.hidden_field(object_name, :bootsy_image_gallery_id, class: 'bootsy_image_gallery_id')
39
+ output += hidden_field(
40
+ object_name,
41
+ :bootsy_image_gallery_id,
42
+ class: 'bootsy_image_gallery_id'
43
+ )
39
44
  end
40
45
  end
41
46
 
@@ -57,25 +62,30 @@ module Bootsy
57
62
  end
58
63
 
59
64
  def tag_class(options)
60
- classes = if options[:class].blank?
61
- []
62
- elsif options[:class].kind_of?(Array)
63
- options[:class]
64
- else
65
- [options[:class]]
66
- end
65
+ classes =
66
+ if options[:class].blank?
67
+ []
68
+ elsif options[:class].is_a?(Array)
69
+ options[:class]
70
+ else
71
+ [options[:class]]
72
+ end
67
73
 
68
74
  classes << 'bootsy_text_area'
69
75
  end
70
76
 
71
77
  def data_options(options)
72
- (options[:data] || {}).merge Hash[ bootsy_options(options).map { |k,v| ["bootsy-#{k}", v] } ]
78
+ (options[:data] || {}).merge(
79
+ Hash[bootsy_options(options).map do |key, value|
80
+ ["bootsy-#{key}", value]
81
+ end]
82
+ )
73
83
  end
74
84
 
75
85
  def bootsy_options(options)
76
- Bootsy.editor_options.
77
- merge(options[:editor_options] || {}).
78
- merge(uploader: enable_uploader?(options))
86
+ Bootsy.editor_options
87
+ .merge(options[:editor_options] || {})
88
+ .merge(uploader: enable_uploader?(options))
79
89
  end
80
90
 
81
91
  def text_area_options(options)
@@ -1,19 +1,23 @@
1
1
  require 'simple_form'
2
2
 
3
+ # Public: A SimpleForm Input to wrap Bootsy areas
3
4
  class BootsyInput < SimpleForm::Inputs::Base
4
5
  enable :placeholder, :maxlength, :container, :editor_options, :uploader
5
6
 
6
7
  def input(wrapper_options = nil)
7
8
  bootsy_params = [:editor_options, :container, :uploader]
8
- input_html_options.merge!(input_options.select {|k,v| bootsy_params.include?(k) })
9
+ input_html_options.merge!(
10
+ input_options.select { |key, _| bootsy_params.include?(key) }
11
+ )
9
12
 
10
13
  # Check presence of `merge_wrapper_options` to keep
11
14
  # compatibility with both Simple Form 3.0 and 3.1.
12
- merged_input_options = if respond_to?(:merge_wrapper_options, true)
13
- merge_wrapper_options(input_html_options, wrapper_options)
14
- else
15
- input_html_options
16
- end
15
+ merged_input_options =
16
+ if respond_to?(:merge_wrapper_options, true)
17
+ merge_wrapper_options(input_html_options, wrapper_options)
18
+ else
19
+ input_html_options
20
+ end
17
21
 
18
22
  @builder.bootsy_area(attribute_name, merged_input_options)
19
23
  end
@@ -1,3 +1,4 @@
1
+ # Public: The gem version
1
2
  module Bootsy
2
- VERSION = '2.0.11'
3
+ VERSION = '2.0.12'
3
4
  end
@@ -1,5 +1,7 @@
1
1
  module Bootsy
2
2
  module Generators
3
+ # Public: A Rails Generator to copy translations, assets and routes to
4
+ # the host app.
3
5
  class InstallGenerator < Rails::Generators::Base
4
6
  source_root File.expand_path('../templates', __FILE__)
5
7
 
@@ -8,42 +10,54 @@ module Bootsy
8
10
  end
9
11
 
10
12
  def copy_locale
11
- copy_file '../../../../config/locales/bootsy.en.yml', 'config/locales/bootsy.en.yml'
13
+ copy_file '../../../../config/locales/bootsy.en.yml',
14
+ 'config/locales/bootsy.en.yml'
12
15
  end
13
16
 
14
17
  def add_assets
18
+ assets_entries.each do |params|
19
+ if File.exist?(params[:original])
20
+ insert_into_file(params)
21
+ else
22
+ say_status('not found', "#{params[:original]} not found. You must
23
+ manually require Bootsy in your assets pipeline.", :red)
24
+ end
25
+ end
26
+ end
27
+
28
+ def copy_config
29
+ template 'bootsy.rb', 'config/initializers/bootsy.rb'
30
+ end
31
+
32
+ def insert_into_file(params)
33
+ if File.binread(params[:original]).include?(params[:skip_if])
34
+ say_status('skipped', "insert into #{params[:original]}", :yellow)
35
+ else
36
+ super(
37
+ params[:original],
38
+ params[:content],
39
+ params[:position]
40
+ )
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def assets_entries
15
47
  [
16
48
  {
17
49
  original: 'app/assets/javascripts/application.js',
18
50
  skip_if: 'require bootsy',
19
51
  content: "\n//= require bootsy",
20
- position: {
21
- after: '//= require jquery_ujs'
22
- }
52
+ position: { after: '//= require jquery_ujs' }
23
53
  },
24
54
  {
25
55
  original: 'app/assets/stylesheets/application.css',
26
56
  skip_if: 'require bootsy',
27
57
  content: "\n *= require bootsy",
28
- position: {
29
- after: '*= require_self'
30
- }
58
+ position: { after: '*= require_self' }
31
59
  }
32
- ].each do |params|
33
- if File.exists?(params[:original])
34
- if File.binread(params[:original]).include?(params[:skip_if])
35
- say_status('skipped', "insert into #{params[:original]}", :yellow)
36
- else
37
- insert_into_file(params[:original], params[:content], params[:position])
38
- end
39
- else
40
- say_status('not found', "#{params[:original]} not found. You must manually require Bootsy in your assets pipeline.", :red)
41
- end
42
- end
43
- end
44
-
45
- def copy_config
46
- template 'bootsy.rb', 'config/initializers/bootsy.rb'
60
+ ]
47
61
  end
48
62
  end
49
63
  end