lasha 0.2.3 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +33 -2
- data/app/assets/stylesheets/lasha.sass +5 -0
- data/app/views/shared/_index_generator.html.slim +24 -0
- data/lib/lasha/version.rb +1 -1
- data/lib/lasha.rb +65 -2
- metadata +4 -3
- data/app/views/shared/_table.html.slim +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ab27f8003cdc41c6b993553160462e0159a4c8aace65109905a1bcef545444e
|
4
|
+
data.tar.gz: 6a9c564ec9b76857660ce86f62d4468277301c8a96d5e9cce1851fbc5fd568ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbb6c791ffdeba8ffb9cc770b45bab9ac37fda819583a3127801a7fa8e2d370a10279ad22722632ed1d20cccbd285278e40858f54b924c4498a56c332b180ea9
|
7
|
+
data.tar.gz: c3f140510674723659f56e5ed93134ff0238f80e06d60d9b7042a43695cbe9b85c186f9aa625cd59a0632f939e45a05c9f10143682388fc68ba4e89d95571653
|
data/README.md
CHANGED
@@ -2,7 +2,31 @@
|
|
2
2
|
Short description and motivation.
|
3
3
|
|
4
4
|
## Usage
|
5
|
-
|
5
|
+
Controller `index` action
|
6
|
+
```
|
7
|
+
@data = Lasha.index_data(
|
8
|
+
controller: self,
|
9
|
+
# namespace: :admin, # optional
|
10
|
+
# model: TxFee, # optional
|
11
|
+
collection: TxFee.all.order(created_at: :desc).limit(20),
|
12
|
+
attributes: %i[amount node_id created_at],
|
13
|
+
# actions: %i[show] # optional
|
14
|
+
)
|
15
|
+
```
|
16
|
+
`index_data` input options
|
17
|
+
```
|
18
|
+
controller: (required) used to derive namespace and index actions
|
19
|
+
collection: (required) array or AR collection
|
20
|
+
attributes: (required) model attributes determine which index columns are shown
|
21
|
+
namespace-: (optional) controller namespace (derive from controller)
|
22
|
+
model-----: (optional) derive from collection
|
23
|
+
actions---: (optional) derive from controller, can contain %i[new show edit destroy]
|
24
|
+
```
|
25
|
+
|
26
|
+
index view `index.html.slim`
|
27
|
+
```
|
28
|
+
= render partial: "shared/index_generator", locals: { data: @data }
|
29
|
+
```
|
6
30
|
|
7
31
|
## Installation
|
8
32
|
Add this line to your application's Gemfile:
|
@@ -21,8 +45,15 @@ Or install it yourself as:
|
|
21
45
|
$ gem install lasha
|
22
46
|
```
|
23
47
|
|
48
|
+
## Development Helpers
|
49
|
+
Snippet for quickly rebuilding gem
|
50
|
+
```
|
51
|
+
cd ~/gem_dir
|
52
|
+
gem uninstall lasha; rake build; gem install pkg/lasha-0.2.4.gem
|
53
|
+
```
|
54
|
+
|
24
55
|
## Contributing
|
25
|
-
|
56
|
+
PR will do. Also, you can contact me if you want to discuss large scale ideas.
|
26
57
|
|
27
58
|
## License
|
28
59
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -0,0 +1,24 @@
|
|
1
|
+
h2.text-center Listing #{data[:model]}-s
|
2
|
+
.row
|
3
|
+
.col-sm-12
|
4
|
+
.table-responsive
|
5
|
+
table.table.table-bordered.table-hover.table-sm
|
6
|
+
thead.thead-dark
|
7
|
+
tr
|
8
|
+
- data[:attributes].each do |attribute|
|
9
|
+
th.text-center = attribute
|
10
|
+
- data[:actions].each do |action|
|
11
|
+
th.text-center
|
12
|
+
|
13
|
+
tbody
|
14
|
+
- data[:collection].each do |item|
|
15
|
+
tr
|
16
|
+
- data[:attributes].each do |attribute|
|
17
|
+
- attribute = item.read_attribute(attribute)
|
18
|
+
- if attribute.is_a? ActiveSupport::TimeWithZone
|
19
|
+
td = l attribute, format: :short
|
20
|
+
- else
|
21
|
+
td = attribute
|
22
|
+
|
23
|
+
- data[:actions].each do |action|
|
24
|
+
td = link_to action, url_for([data[:namespace], item]), class: "btn btn-light btn-xs btn-block"
|
data/lib/lasha/version.rb
CHANGED
data/lib/lasha.rb
CHANGED
@@ -1,7 +1,70 @@
|
|
1
1
|
require "lasha/engine"
|
2
2
|
|
3
3
|
module Lasha
|
4
|
-
|
5
|
-
|
4
|
+
@index_actions = %i[new show edit destroy]
|
5
|
+
|
6
|
+
def self.index_data(
|
7
|
+
controller:,
|
8
|
+
namespace: nil,
|
9
|
+
model: nil,
|
10
|
+
actions: nil,
|
11
|
+
collection:,
|
12
|
+
attributes:
|
13
|
+
)
|
14
|
+
index_data_hash = {
|
15
|
+
namespace: set_or_guess_namespace(namespace, controller),
|
16
|
+
model: set_or_guess_model(model, collection),
|
17
|
+
collection: collection,
|
18
|
+
attributes: attributes,
|
19
|
+
actions: set_or_guess_actions(actions, controller)
|
20
|
+
}
|
21
|
+
raise ArgumentError if index_data_invalid?(**index_data_hash)
|
22
|
+
|
23
|
+
index_data_hash
|
24
|
+
rescue ArgumentError => e
|
25
|
+
puts "***** index_data argument error report"
|
26
|
+
puts "#{e} #{e.message}"
|
27
|
+
puts e.backtrace
|
6
28
|
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def self.set_or_guess_namespace(namespace, controller)
|
33
|
+
if namespace.present?
|
34
|
+
namespace
|
35
|
+
elsif controller.class.name.include?("::")
|
36
|
+
controller.class.name.deconstantize.underscore.to_sym
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.set_or_guess_model(model, collection)
|
41
|
+
model.present? ? model : collection.first.class
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.set_or_guess_actions(actions, controller)
|
45
|
+
if actions.present?
|
46
|
+
actions
|
47
|
+
else
|
48
|
+
controller.action_methods.to_a.map(&:to_sym) & @index_actions
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.index_data_invalid?(**index_data_hash)
|
53
|
+
truthy_array = []
|
54
|
+
index_data_hash.each do |key, value|
|
55
|
+
case key
|
56
|
+
when :model
|
57
|
+
truthy_array << (value.blank? || index_data_hash[:collection].blank?)
|
58
|
+
when :actions
|
59
|
+
truthy_array << (value - @index_actions).any?
|
60
|
+
# when :namespace
|
61
|
+
# truthy_array << false
|
62
|
+
# when :collection
|
63
|
+
# truthy_array << false
|
64
|
+
# when :attributes
|
65
|
+
# truthy_array << false
|
66
|
+
end
|
67
|
+
end
|
68
|
+
truthy_array.include?(true)
|
69
|
+
end
|
7
70
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lasha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lasha Abulashvili
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-07-
|
11
|
+
date: 2019-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -49,7 +49,8 @@ files:
|
|
49
49
|
- README.md
|
50
50
|
- Rakefile
|
51
51
|
- app/assets/config/lasha_manifest.js
|
52
|
-
- app/
|
52
|
+
- app/assets/stylesheets/lasha.sass
|
53
|
+
- app/views/shared/_index_generator.html.slim
|
53
54
|
- config/routes.rb
|
54
55
|
- lib/lasha.rb
|
55
56
|
- lib/lasha/engine.rb
|