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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 30ccbc8a99437bc761fefa90e9281b31b134e85e
4
- data.tar.gz: 450ca133f3655ba73512cc45bd860ecb6a595933
3
+ metadata.gz: 8a5808fc068e23665701db7839bd1e8214cea286
4
+ data.tar.gz: 529fb73740e059b096a3e72b90f0a16401400d55
5
5
  SHA512:
6
- metadata.gz: 35d421fff0eaeba435b59db872141d5eee85e05c2a44b678a23ae54eae6589ea454cbd6fea79e18dc1aec2a65bef308c9f2ba1a0b7dd02916dfe225d12394d98
7
- data.tar.gz: 7d857fa6526e69cfcaaa2347a1e6f093d86cfd9abf99bdfa840611aca046b4c7da0986fea1995b86edf2440690ac9999841d86869ad668508d35f872289b64ea
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.
@@ -1,3 +1,3 @@
1
1
  module RailsPatternView
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -5,18 +5,31 @@ module RailsPatternView
5
5
 
6
6
  module ClassMethods
7
7
  def use_pattern(pattern, opts = {})
8
- only = opts[:only] || []
9
- except = opts[: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
- private :pattern_name
18
+ define_method(:pattern_actions_mapping) { mappings }
16
19
 
17
- #at this point, only & except must be arrays
20
+ private :pattern_name, :pattern_actions_mapping
18
21
  actions = (only.present? ? only : action_methods.to_a) - except
19
- before_filter :filter_render, only: actions
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
- render :template => "patterns/#{pattern_name}/#{params[:action]}"
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.1.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-24 00:00:00.000000000 Z
11
+ date: 2015-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler