rails_pattern_view 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 +4 -4
- data/README.md +6 -0
- data/lib/rails_pattern_view/version.rb +1 -1
- data/lib/rails_pattern_view.rb +20 -6
- 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: 8a5808fc068e23665701db7839bd1e8214cea286
|
4
|
+
data.tar.gz: 529fb73740e059b096a3e72b90f0a16401400d55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 992b5a7120bc0f49cd821e868450205dfc5b6eff5b83da6770c4d6af7369eed77e2be5c7781534ba11e624d58023580a285ac8024dc75d6fafaced1cfcd53b89
|
7
|
+
data.tar.gz: 9579f236743db5c9fcb2418d0ed4d804d9935f4057f96680053f69fc475a0fc5900067add15b840845a736dc6eaf554abba6eae870c29d73657fd7c4218b4e74
|
data/README.md
CHANGED
@@ -58,6 +58,12 @@ except
|
|
58
58
|
user_pattern :ajax_table, except: [:some_action]
|
59
59
|
```
|
60
60
|
|
61
|
+
mapping: Share 1 template for all actions
|
62
|
+
```
|
63
|
+
use_pattern :ajax_table, mapping: {:refresh => [:create, :update, :destroy]}
|
64
|
+
```
|
65
|
+
all "create/update/destroy" actions will now render "views/patterns/ajax_table/refresh"
|
66
|
+
|
61
67
|
## Development
|
62
68
|
|
63
69
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/rails_pattern_view.rb
CHANGED
@@ -5,18 +5,31 @@ module RailsPatternView
|
|
5
5
|
|
6
6
|
module ClassMethods
|
7
7
|
def use_pattern(pattern, opts = {})
|
8
|
-
only
|
9
|
-
except
|
8
|
+
only = opts[:only] || []
|
9
|
+
except = opts[:except] || []
|
10
|
+
mapping = opts[:mapping] || {}
|
10
11
|
raise 'cannot mix `only` & `except`' if only.present? && except.present?
|
11
12
|
raise '`only` must be Array type' if !only.is_a? Array
|
12
13
|
raise '`except` must be Array type' if !except.is_a? Array
|
14
|
+
raise '`mapping` must be Hash type' if !mapping.is_a? Hash
|
15
|
+
mappings = resolve_mapping(mapping)
|
13
16
|
|
14
17
|
define_method(:pattern_name) { pattern }
|
15
|
-
|
18
|
+
define_method(:pattern_actions_mapping) { mappings }
|
16
19
|
|
17
|
-
|
20
|
+
private :pattern_name, :pattern_actions_mapping
|
18
21
|
actions = (only.present? ? only : action_methods.to_a) - except
|
19
|
-
before_filter :filter_render, only
|
22
|
+
before_filter :filter_render, :only => actions
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def resolve_mapping(mapping)
|
28
|
+
pattern_actions_mapping = {}
|
29
|
+
mapping.each do |template, actions|
|
30
|
+
actions.each { |action| pattern_actions_mapping[action] = template }
|
31
|
+
end
|
32
|
+
pattern_actions_mapping
|
20
33
|
end
|
21
34
|
end
|
22
35
|
|
@@ -25,7 +38,8 @@ module RailsPatternView
|
|
25
38
|
def filter_render
|
26
39
|
instance_eval do
|
27
40
|
def default_render
|
28
|
-
|
41
|
+
action_name = pattern_actions_mapping[params[:action]] || params[:action]
|
42
|
+
render :template => "patterns/#{pattern_name}/#{action_name}"
|
29
43
|
end
|
30
44
|
end
|
31
45
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_pattern_view
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tien Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|