bootswatch_rails 3.1.1.10 → 3.1.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/bootswatch_rails/version.rb +1 -1
- data/lib/generators/bootswatch_rails/carrierwave/carrierwave_generator.rb +73 -0
- data/lib/generators/bootswatch_rails/carrierwave/templates/carrierwave_migration.rb +5 -0
- data/lib/generators/bootswatch_rails/carrierwave/templates/document_uploader.rb +51 -0
- data/lib/generators/bootswatch_rails/carrierwave/templates/picture_uploader.rb +62 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d292cd0ac0502d539ba38469e004f251b674d568
|
4
|
+
data.tar.gz: 3e0147c90db10cbda94cd6fd83e253def48ab807
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a01fcf1875935a31e1802631ced3df739e4a9c38e28f884c9bb2810e540786a87b4ad9a492e46f1495019152d9f2b06ab0054aa8abfcfd237e31d9e3a17978f
|
7
|
+
data.tar.gz: c3c17f7bbd24e92e2bf0d627f928d752963d3ff23b2ade8824e7eac12586ef764da0727ffdfcd3c227f1379d6e43aeb4bd3d62618ea7b3351100110738f5a864
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
|
3
|
+
module BootswatchRails
|
4
|
+
module Generators
|
5
|
+
class CarrierwaveGenerator < ActiveRecord::Generators::Base
|
6
|
+
desc "Add carrierwave uploader to resource"
|
7
|
+
argument :name, type: :string,
|
8
|
+
desc: "The object that will have an attachment"
|
9
|
+
argument :column, type: :string,
|
10
|
+
desc: 'The column name for the attachment'
|
11
|
+
class_option :uploader, type: :boolean, default: true,
|
12
|
+
desc: 'Add an appropriate uploader'
|
13
|
+
class_option :migration, type: :boolean, default: false,
|
14
|
+
desc: 'Create a migration for added attributes'
|
15
|
+
class_option :permit, type: :boolean, default: false,
|
16
|
+
desc: 'Allow mass assignment for added attributes'
|
17
|
+
class_option :before, type: :boolean, default: false,
|
18
|
+
desc: 'Add a line before generated text in model'
|
19
|
+
class_option :after, type: :boolean, default: false,
|
20
|
+
desc: 'Add a line after generated text in model'
|
21
|
+
source_root File.expand_path('../templates', __FILE__)
|
22
|
+
|
23
|
+
def add_uploader
|
24
|
+
if picture?
|
25
|
+
template "picture_uploader.rb", "app/uploaders/#{column}_uploader.rb"
|
26
|
+
elsif document?
|
27
|
+
template "document_uploader.rb", "app/uploaders/#{column}_uploader.rb"
|
28
|
+
else
|
29
|
+
run "rails generate uploader #{column.camelize}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def add_migration
|
34
|
+
return unless options.migration?
|
35
|
+
migration_template "carrierwave_migration.rb", "db/migrate/#{migration_name}.rb"
|
36
|
+
end
|
37
|
+
|
38
|
+
def add_to_model
|
39
|
+
inject_into_class "app/models/#{name}.rb", class_name do
|
40
|
+
text = options.before? ? "\n" : ""
|
41
|
+
text << " mount_uploader :#{column}, #{column.camelize}Uploader\n"
|
42
|
+
text << "\n" if options.after?
|
43
|
+
text
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def add_to_permit
|
48
|
+
file = "app/controllers/#{table_name}_controller.rb"
|
49
|
+
if options.permit?
|
50
|
+
gsub_file file, /(permit\(.*)\)/, "\\1, :#{column})"
|
51
|
+
# Special case: no previous permit
|
52
|
+
gsub_file file, /^(\s*params)\[:#{name}\]$/, "\\1.require(:#{name}).permit(:#{column})"
|
53
|
+
end
|
54
|
+
gsub_file file, /(permit.*)(:#{column})(.*)/, "\\1\\2, :#{column}_cache, :remove_#{column}\\3"
|
55
|
+
end
|
56
|
+
|
57
|
+
protected
|
58
|
+
|
59
|
+
def picture?
|
60
|
+
column.include?("picture")
|
61
|
+
end
|
62
|
+
|
63
|
+
def document?
|
64
|
+
column.include?("document")
|
65
|
+
end
|
66
|
+
|
67
|
+
def migration_name
|
68
|
+
"add_#{column}_to_#{table_name}"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class <%= column.camelize %>Uploader < CarrierWave::Uploader::Base
|
4
|
+
|
5
|
+
# Include RMagick or MiniMagick support:
|
6
|
+
# include CarrierWave::RMagick
|
7
|
+
# include CarrierWave::MiniMagick
|
8
|
+
|
9
|
+
# Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:
|
10
|
+
## Seems to be gone in Rails 4.0 ???
|
11
|
+
## include Sprockets::Helpers::RailsHelper
|
12
|
+
## include Sprockets::Helpers::IsolatedHelper
|
13
|
+
|
14
|
+
# Choose what kind of storage to use for this uploader:
|
15
|
+
storage :file
|
16
|
+
# storage :fog
|
17
|
+
|
18
|
+
# Override the directory where uploaded files will be stored.
|
19
|
+
# This is a sensible default for uploaders that are meant to be mounted:
|
20
|
+
def store_dir
|
21
|
+
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
22
|
+
end
|
23
|
+
|
24
|
+
# Provide a default URL as a default if there hasn't been a file uploaded:
|
25
|
+
# def default_url
|
26
|
+
# # For Rails 3.1+ asset pipeline compatibility:
|
27
|
+
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
|
28
|
+
#
|
29
|
+
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
|
30
|
+
# end
|
31
|
+
|
32
|
+
# Process files as they are uploaded:
|
33
|
+
# process :scale => [200, 300]
|
34
|
+
#
|
35
|
+
# def scale(width, height)
|
36
|
+
# # do something
|
37
|
+
# end
|
38
|
+
|
39
|
+
# Add a white list of extensions which are allowed to be uploaded.
|
40
|
+
# For images you might use something like this:
|
41
|
+
# def extension_white_list
|
42
|
+
# %w(jpg jpeg gif png)
|
43
|
+
# end
|
44
|
+
|
45
|
+
# Override the filename of the uploaded files:
|
46
|
+
# Avoid using model.id or version_name here, see uploader/store.rb for details.
|
47
|
+
# def filename
|
48
|
+
# "something.jpg" if original_filename
|
49
|
+
# end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class <%= column.camelize %>Uploader < CarrierWave::Uploader::Base
|
4
|
+
|
5
|
+
# Include RMagick or MiniMagick support:
|
6
|
+
# include CarrierWave::RMagick
|
7
|
+
include CarrierWave::MiniMagick
|
8
|
+
|
9
|
+
# Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:
|
10
|
+
## Seems to be gone in Rails 4.0 ???
|
11
|
+
## include Sprockets::Helpers::RailsHelper
|
12
|
+
## include Sprockets::Helpers::IsolatedHelper
|
13
|
+
|
14
|
+
# Choose what kind of storage to use for this uploader:
|
15
|
+
storage :file
|
16
|
+
# storage :fog
|
17
|
+
|
18
|
+
# Override the directory where uploaded files will be stored.
|
19
|
+
# This is a sensible default for uploaders that are meant to be mounted:
|
20
|
+
def store_dir
|
21
|
+
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
22
|
+
end
|
23
|
+
|
24
|
+
# Provide a default URL as a default if there hasn't been a file uploaded:
|
25
|
+
# def default_url
|
26
|
+
# # For Rails 3.1+ asset pipeline compatibility:
|
27
|
+
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
|
28
|
+
#
|
29
|
+
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
|
30
|
+
# end
|
31
|
+
|
32
|
+
# Process files as they are uploaded:
|
33
|
+
# process :scale => [200, 300]
|
34
|
+
#
|
35
|
+
# def scale(width, height)
|
36
|
+
# # do something
|
37
|
+
# end
|
38
|
+
|
39
|
+
# Create different versions of your uploaded files:
|
40
|
+
version :thumb do
|
41
|
+
process :resize_to_limit => [100, 100]
|
42
|
+
end
|
43
|
+
version :carousel do
|
44
|
+
process :resize_to_fill => [600, 400]
|
45
|
+
end
|
46
|
+
version :display do
|
47
|
+
process :resize_to_limit => [600, 600]
|
48
|
+
end
|
49
|
+
|
50
|
+
# Add a white list of extensions which are allowed to be uploaded.
|
51
|
+
# For images you might use something like this:
|
52
|
+
def extension_white_list
|
53
|
+
%w(jpg jpeg gif png)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Override the filename of the uploaded files:
|
57
|
+
# Avoid using model.id or version_name here, see uploader/store.rb for details.
|
58
|
+
# def filename
|
59
|
+
# "something.jpg" if original_filename
|
60
|
+
# end
|
61
|
+
|
62
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bootswatch_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.1.
|
4
|
+
version: 3.1.1.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Volker Wiegand
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -85,6 +85,10 @@ files:
|
|
85
85
|
- lib/bootswatch_rails.rb
|
86
86
|
- lib/bootswatch_rails/engine.rb
|
87
87
|
- lib/bootswatch_rails/version.rb
|
88
|
+
- lib/generators/bootswatch_rails/carrierwave/carrierwave_generator.rb
|
89
|
+
- lib/generators/bootswatch_rails/carrierwave/templates/carrierwave_migration.rb
|
90
|
+
- lib/generators/bootswatch_rails/carrierwave/templates/document_uploader.rb
|
91
|
+
- lib/generators/bootswatch_rails/carrierwave/templates/picture_uploader.rb
|
88
92
|
- lib/generators/bootswatch_rails/install/install_generator.rb
|
89
93
|
- lib/generators/bootswatch_rails/install/templates/app/assets/images/Rails_logo_80.jpg
|
90
94
|
- lib/generators/bootswatch_rails/install/templates/app/helpers/application_helper.rb
|