slotmachine 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -5
- data/lib/slot_machine/config.rb +16 -1
- data/lib/slot_machine/controller_concern.rb +5 -5
- data/lib/slot_machine/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf639bac3299c0dec8fa7bab50b6544ee7b0a674
|
4
|
+
data.tar.gz: bd7560301c0078a6990c0d2ce619c20ea25a1f8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e05e7c98c3a20c6ef4e73671afb8d150cd98a5546ec815ff920b6fd870492c22012931b9acaa092c69a04dcc6efc216af3e9e9ce51f6d88e5d217da7a45c67c5
|
7
|
+
data.tar.gz: 3a658580b2aaceb1972b04f6c8861282a144cbdc35676a7d238650a905f232236e1c7007d9fbb95908efb335ea6f4cb4ddb4fee9f33331b44035033b0ac24c54
|
data/README.md
CHANGED
@@ -30,11 +30,28 @@ SlotMachine::Config.path = MyEngine::Engine.root.join('app/views/slots/_*')
|
|
30
30
|
```
|
31
31
|
|
32
32
|
And then in your application controller
|
33
|
+
```ruby
|
34
|
+
include SlotMachine::ControllerConcern
|
35
|
+
helper slot_machine_helper()
|
36
|
+
```
|
37
|
+
|
38
|
+
You can also override the path there...
|
33
39
|
```ruby
|
34
40
|
include SlotMachine::ControllerConcern
|
35
41
|
helper slot_machine_helper(path: 'you_can_override_the_path_of_the_slots_here/_*')
|
36
42
|
```
|
37
43
|
|
44
|
+
...and give it a name and have a different one in another controller
|
45
|
+
```ruby
|
46
|
+
include SlotMachine::ControllerConcern
|
47
|
+
helper slot_machine_helper(path: 'you_can_override_the_path_of_the_slots_here/_*', name: :main)
|
48
|
+
```
|
49
|
+
|
50
|
+
Path can also be an Array
|
51
|
+
```ruby
|
52
|
+
include SlotMachine::ControllerConcern
|
53
|
+
helper slot_machine_helper(path: ['my_path/_*','my_other_path/_*' ], name: :main)
|
54
|
+
```
|
38
55
|
|
39
56
|
## Usage
|
40
57
|
|
@@ -113,11 +130,11 @@ With the two partials from before (modal and card) we can now do this:
|
|
113
130
|
|
114
131
|
```slim
|
115
132
|
= modal title: 'foo' do |modal|
|
116
|
-
= card title: 'a card in a modal do
|
133
|
+
= card title: 'a card in a modal' do
|
117
134
|
div And wait there is still more
|
118
135
|
|
119
136
|
- modal.slot :footer
|
120
|
-
= card title: 'a card in a modal's foot do
|
137
|
+
= card title: 'a card in a modal\'s foot' do
|
121
138
|
div My example are getting a bit far fetched
|
122
139
|
```
|
123
140
|
|
@@ -125,10 +142,10 @@ There is a shortener for that last one
|
|
125
142
|
|
126
143
|
```slim
|
127
144
|
= modal title: 'foo' do |modal|
|
128
|
-
- modal.card slot: :main, title: 'a card in a modal do
|
145
|
+
- modal.card slot: :main, title: 'a card in a modal' do
|
129
146
|
div And wait there is still more
|
130
147
|
|
131
|
-
- modal.card slot: :footer title: 'a card in a modal's foot do
|
148
|
+
- modal.card slot: :footer title: 'a card in a modal\'s foot' do
|
132
149
|
div My example are getting a bit far fetched
|
133
150
|
```
|
134
151
|
|
@@ -143,7 +160,7 @@ You can also call the slot several times like thus:
|
|
143
160
|
|
144
161
|
## What else?
|
145
162
|
|
146
|
-
You noticed all my
|
163
|
+
You noticed all my examples are with slim. But it work great with yaml or erb.
|
147
164
|
|
148
165
|
I also name my partials with the [BEM notation](http://getbem.com/). I find it easier to organise them by components specialy if you already use this same notation with your css.
|
149
166
|
|
data/lib/slot_machine/config.rb
CHANGED
@@ -1,7 +1,14 @@
|
|
1
1
|
# Config where is store all informations
|
2
2
|
module SlotMachine::Config
|
3
3
|
def self.read_slots(custom_path = nil)
|
4
|
-
|
4
|
+
globs = (custom_path || path)
|
5
|
+
globs = [globs] unless globs.is_a?(Array)
|
6
|
+
|
7
|
+
paths_array = globs.map do |g|
|
8
|
+
Dir[g]
|
9
|
+
end.flatten
|
10
|
+
|
11
|
+
slots_array = paths_array.map do |p|
|
5
12
|
basename = File.basename(p, File.extname(p))
|
6
13
|
basename = basename.split('.').first
|
7
14
|
basename.slice!(0)
|
@@ -25,4 +32,12 @@ module SlotMachine::Config
|
|
25
32
|
def self.path
|
26
33
|
@path || Rails.root.join('app/views/slots/_*')
|
27
34
|
end
|
35
|
+
|
36
|
+
def self.helper_modules
|
37
|
+
@helper_modules ||= {}
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.helper_modules=(val)
|
41
|
+
@helper_modules = val
|
42
|
+
end
|
28
43
|
end
|
@@ -42,15 +42,15 @@ module SlotMachine::ControllerConcern
|
|
42
42
|
# include SlotMachine::ControllerConcern
|
43
43
|
# helper slot_machine_create_module(my_path)
|
44
44
|
# ````
|
45
|
-
def slot_machine_helper(path: nil)
|
46
|
-
return
|
45
|
+
def slot_machine_helper(path: nil, name: :main)
|
46
|
+
return SlotMachine::Config.helper_modules[name] unless SlotMachine::Config.helper_modules[name].nil?
|
47
47
|
|
48
48
|
# Read slot on the custom path
|
49
49
|
slots = SlotMachine::Config.read_slots(path)
|
50
50
|
method_names = slots.keys
|
51
51
|
|
52
52
|
# Instantiate the new module
|
53
|
-
|
53
|
+
SlotMachine::Config.helper_modules[name] = Module.new
|
54
54
|
|
55
55
|
# Create a child builder class with all the methods
|
56
56
|
builder_class = Class.new(Builder)
|
@@ -67,7 +67,7 @@ module SlotMachine::ControllerConcern
|
|
67
67
|
|
68
68
|
# Add 1 method per partial in the module as well
|
69
69
|
method_names.each do |method_name|
|
70
|
-
|
70
|
+
SlotMachine::Config.helper_modules[name].module_eval do
|
71
71
|
# this one should be in the builder but it doesnt have the builder method
|
72
72
|
def get_buffer(string = nil, &block)
|
73
73
|
return string unless block
|
@@ -96,7 +96,7 @@ module SlotMachine::ControllerConcern
|
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
-
|
99
|
+
SlotMachine::Config.helper_modules[name]
|
100
100
|
end
|
101
101
|
end
|
102
102
|
end
|
data/lib/slot_machine/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slotmachine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cedric Feyaerts
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|