carload 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8f8cf9b142c5e13784ccffe393d2d9645655887f
4
- data.tar.gz: 0aa2c2d084dd387f84f40e6f6aae4019257e7fe2
3
+ metadata.gz: 6050c145967b23fa0d4d7f7a2d889cdf182a818e
4
+ data.tar.gz: 204ebca653c8f0268157b62bde3d11722a13e0fe
5
5
  SHA512:
6
- metadata.gz: a7850af28727246a420c16a7cda6bc024b46c22350784e4f7197c0e1801ad8b0cb3c14b4480e7163d7f86d8ca53d6406cd1a80180bd5e9f88d445f3e3df5534d
7
- data.tar.gz: e1198767a2f476a07434960bec5c83386eb88f69f31d489ed06690accace7da7413494145dc06067054ff0910e804fd1b243b76695fdacb09323195120772949
6
+ metadata.gz: 20ebcfbd2520b19b94b0936174e039962475fb991b45a14738d96c1945f2756ed283a390e6407cfeb0f09ec916ef82bf0679c0bf13d82ce54fa2e80f65887d0a
7
+ data.tar.gz: 0bd18274a4164a9a3741387fbda4f0daf9ee181064ed0fcebbada84c8090827b8be12d6f1894943e71f6a730019451fc1f1623ced440ba00616056526cc3aa5e
data/README.md CHANGED
@@ -10,7 +10,7 @@ DEMO: [https://carload-demo.herokuapp.com/carload/dashboard/](https://carload-de
10
10
  ![](http://7xvqi7.com1.z0.glb.clouddn.com/carload.dashboard.snapshot.zh-CN.png)
11
11
 
12
12
  ## Usage
13
- - Run `rails g carload:install` to mount engine routes, add require statement and add initializer.
13
+ - Run `rails g carload:install` to mount engine routes, add require statement, initializer, and `Dashboard` class file.
14
14
 
15
15
  You can edit the initializer `config/initializers/carload.rb` for example:
16
16
 
@@ -35,7 +35,7 @@ Carload.setup do |config|
35
35
  end
36
36
  ```
37
37
 
38
- - Run `rails g carload:dashboard` to generate `app/carload/dashboard.rb`, and edit that file for example:
38
+ Edit `app/carload/dashboard.rb` to adapt for your needs, for example:
39
39
 
40
40
  ```ruby
41
41
  # Dashboard class is used to tell Carload what models are needed to administrated,
@@ -118,8 +118,8 @@ Or install it yourself as:
118
118
  $ gem install carload
119
119
  ```
120
120
 
121
- ## Contributing
122
- Contribution directions go here.
121
+ ## TODO List
122
+ - Support upload file (using `carrierwave`)
123
123
 
124
124
  ## License
125
125
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -3,6 +3,7 @@
3
3
  //= require turbolinks
4
4
  //= require bootstrap-sprockets
5
5
  //= require select2
6
+ //= require upload-image
6
7
  //= require_tree .
7
8
 
8
9
  $(document).on('turbolinks:load', function() {
@@ -1,6 +1,7 @@
1
1
  //= require font-awesome
2
2
  //= require select2
3
3
  //= require select2-bootstrap
4
+ //= require upload-image
4
5
 
5
6
  $spacing: 16px;
6
7
 
@@ -41,6 +42,8 @@ $spacing: 16px;
41
42
 
42
43
  #main-container {
43
44
  width: 100%;
45
+ padding-left: $spacing;
46
+ padding-right: $spacing;
44
47
  #main-content {
45
48
  margin-top: 50px;
46
49
  }
@@ -8,6 +8,7 @@ module Carload
8
8
 
9
9
  before_action :set_model
10
10
  before_action :set_object, only: [:edit, :update, :destroy]
11
+ include Croppable
11
12
 
12
13
  def index
13
14
  authorize :dashboard, :index? unless Carload.auth_solution == :none
@@ -1,4 +1,15 @@
1
1
  module Carload
2
2
  module ApplicationHelper
3
+ def needs_upload? model_name, attribute_name
4
+ case Carload.upload_solution
5
+ when :carrierwave
6
+ model_class = model_name.to_s.classify.constantize
7
+ not model_class.instance_methods.map(&:to_s).select { |x| x =~ /#{attribute_name}_url/ }.empty?
8
+ end
9
+ end
10
+
11
+ def image? attribute_name
12
+ attribute_name.to_s =~ /image|logo|img/
13
+ end
3
14
  end
4
15
  end
@@ -13,6 +13,8 @@ module Carload
13
13
  placeholder: t('carload.placeholder.select', thing: t("activerecord.attributes.#{associated_model}.#{label_attribute}"))
14
14
  }
15
15
  }
16
+ elsif needs_upload?(model_name, attribute_name) and image?(attribute_name)
17
+ upload_image form: form, image_name: attribute_name, width: 150, height: 150
16
18
  else
17
19
  form.input attribute_name
18
20
  end
@@ -1,3 +1,3 @@
1
1
  module Carload
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
data/lib/carload.rb CHANGED
@@ -17,6 +17,9 @@ module Carload
17
17
  if not [:devise, :none].include? @@config[:auth_solution]
18
18
  raise UnsupportedError.new("authentication solution #{@@config[:auth_solution]}")
19
19
  end
20
+ if not [:carrierwave].include? @@config[:upload_solution]
21
+ raise UnsupportedError.new("upload solution #{@@config[:upload_solution]}")
22
+ end
20
23
 
21
24
  @@config.each do |key, value|
22
25
  define_singleton_method key do
@@ -1,7 +1,11 @@
1
1
  Description:
2
- Mount Carload routes.
2
+ This generator does the following jobs:
3
3
 
4
- Copy initializer and dashboard template files.
4
+ - Mount Carload routes.
5
+
6
+ - Add require statement.
7
+
8
+ - Copy initializer and dashboard template files.
5
9
 
6
10
  Example:
7
11
  rails generate carload:install
@@ -2,6 +2,9 @@ Carload.setup do |config|
2
2
  # Specify which authentication solution is used. Currently, we only support Devise.
3
3
  config.auth_solution = :devise
4
4
 
5
+ # Specify which file upload solution is used. Currently, we only support Carrierwave.
6
+ config.upload_solution = :carrierwave
7
+
5
8
  # Set the actions used to discern user's permission to access dashboard.
6
9
  #
7
10
  # config.dashboard.permits_user.<method> = '...'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carload
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Li Dong
@@ -184,6 +184,20 @@ dependencies:
184
184
  - - "~>"
185
185
  - !ruby/object:Gem::Version
186
186
  version: '4.0'
187
+ - !ruby/object:Gem::Dependency
188
+ name: upload-image
189
+ requirement: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - "~>"
192
+ - !ruby/object:Gem::Version
193
+ version: '0.1'
194
+ type: :runtime
195
+ prerelease: false
196
+ version_requirements: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - "~>"
199
+ - !ruby/object:Gem::Version
200
+ version: '0.1'
187
201
  description: Carload is built with taste, and tries to be just right!
188
202
  email:
189
203
  - dongli.init@gmail.com