active_path 0.0.4 → 0.1.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: 8794ff562056311cf10ac54cf375f96986a96de3
4
- data.tar.gz: 176ef110a98d119a2f15329d39fdc631754bb87e
3
+ metadata.gz: 124267c58ac6278a25fc0853a51167798b436159
4
+ data.tar.gz: 266eff44ed2a63433dd38a6899c80f94a7143bbe
5
5
  SHA512:
6
- metadata.gz: da11c5dddf9a1ab9abec7da09634a2e4c9eb066e9b7e2068ae2f749249210f6008c096daa7368fa147bd02504f5fab6c653aa19535ace0ecebf72d5984bb2774
7
- data.tar.gz: e362383364329d229a2844f317f433daa3ebd6dd1dcbdeedcd89689dafee359c8715f35d51b75731ad185c591fad478beef18a0bea2b301f9928c63beb178ddc
6
+ metadata.gz: d53d65cf58285a8d789bdd58e18d53ec38bb785dd160762a5272a6ad73fa0fea0d1fc8134ad2bcb8850c1592f35d28c0733de810b45f2c2fa1dfaa91beac7377
7
+ data.tar.gz: ca00811278457c196942dc910786aaf95d72eb6d1a2f24f415566a148bf20b637bf6f6c7d2a12f869ba2661fd08b71a6c626538d7d1e7f1bfa1cdcd84b21ae4a
data/README.md CHANGED
@@ -1,6 +1,5 @@
1
1
  # ActivePath:
2
- View injection and path hints for Rails 5.
3
-
2
+ ActivePath provides an interface for rendering your partials.
4
3
 
5
4
  ## Installation
6
5
 
@@ -22,84 +21,21 @@ end
22
21
 
23
22
  ```
24
23
 
24
+ ## Product Roadmap (TODO)
25
25
 
26
- ## Configuration
27
-
28
- **View injection:**
29
-
30
- ```ruby
31
-
32
- ActivePath.configure do |config|
33
-
34
- ...
35
-
36
- config.partials.prepend('pages/content').with('example/test')
37
-
38
- end
39
-
40
- ```
41
-
42
- The above example assumes your application renders a partial called 'pages/content' and you want to `prepend` a partial called 'example/test'.
43
-
44
- Your partial will have the same local parameters access as the prepended partial. You can also use `append`:
45
-
46
- ```ruby
47
-
48
- config.partials.append('pages/content').with('example/test')
49
-
50
- ```
51
-
52
-
53
- The above renders 'example/test' after 'pages/content'.
54
-
55
- --
56
-
57
- **Conditions:**
58
-
59
- The `when` method allows you to conditionally inject your view. Consider this partial:
60
-
61
- ```ruby
62
- render partial: 'pages/content', locals: { page_id: 9 }
63
- ```
64
-
65
- You can pass in a hash which must match the local variables.
66
-
67
- ```ruby
26
+ * User docs
27
+ * Specs and CI build
68
28
 
69
- config.partials.append('pages/content').with('example/test').when(page_id: 9)
70
29
 
71
- ```
30
+ ## View Injection
72
31
 
73
- Or pass in a block for more flexibility with your conditions:
32
+ https://github.com/active-path/view-injection
74
33
 
75
- ```ruby
76
34
 
77
- config.partials.append('pages/content').with('example/test').when do |locals|
78
- locals[:page_id] == 9
79
- end
35
+ ## Path Hints:
80
36
 
81
- ```
37
+ https://github.com/active-path/path-hints
82
38
 
83
39
  --
84
40
 
85
- **Path hints:** (use in development only)
86
-
87
-
88
- ```ruby
89
-
90
- config.path_hints = true
91
-
92
- ```
93
-
94
- HTML comments are added before and after each partial. Here is the output from our above examples:
95
-
96
- ```html
97
- <!-- start pages/content -->
98
- <p>page content</p>
99
- <!-- end pages/content -->
100
- <!-- start example/test -->
101
- <p>example content</p>
102
- <!-- end example/test -->
103
-
104
- ```
105
- Feel free to [submit issues](https://github.com/ryaan-anthony/active-path/issues) or [help make it better](https://github.com/ryaan-anthony/active-path/pulls).
41
+ Feel free to [submit issues](https://github.com/active-path/core/issues) or [help make it better](https://github.com/active-path/core/pulls).
@@ -1,10 +1,8 @@
1
- require 'active_path/configuration/partials'
2
1
  module ActivePath
3
2
  module Configuration
4
3
  class << self
5
4
  def setup_defaults
6
5
  configuration.active_path = ActiveSupport::Configurable::Configuration.new
7
- configuration.active_path.partials = Partials.new
8
6
  end
9
7
 
10
8
  def config
@@ -1,5 +1,3 @@
1
- require 'active_path/subscribers/view_injection'
2
- require 'active_path/subscribers/path_hints'
3
1
  require 'active_path/helpers/rendering_helper'
4
2
  module ActivePath
5
3
  class Engine < Rails::Engine
@@ -7,19 +5,11 @@ module ActivePath
7
5
 
8
6
  config.before_configuration do
9
7
  Configuration.setup_defaults
10
-
11
8
  # Include the render helper in the controller
12
9
  ActiveSupport.on_load(:action_controller_base) do
13
10
  next unless ActivePath.config.enabled
14
11
  _helpers.module_eval { include ActivePath::Helpers::RenderingHelper }
15
12
  end
16
13
  end
17
-
18
- config.after_initialize do
19
- if ActivePath.config.path_hints
20
- ActiveSupport::Notifications.subscribe(:render_partial, Subscribers::PathHints.new)
21
- end
22
- ActiveSupport::Notifications.subscribe(:render_partial, Subscribers::ViewInjection.new)
23
- end
24
14
  end
25
15
  end
@@ -7,7 +7,9 @@ module ActivePath
7
7
  @buffer = payload[:buffer]
8
8
  @context = payload[:context]
9
9
  @options = payload[:options]
10
- perform
10
+ perform and begin
11
+ @buffer = @context = @options = nil
12
+ end
11
13
  end
12
14
 
13
15
  def partial
@@ -1,3 +1,3 @@
1
1
  module ActivePath
2
- VERSION = '0.0.4'
2
+ VERSION = '0.1.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_path
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Tulino
@@ -35,16 +35,10 @@ files:
35
35
  - Rakefile
36
36
  - active_path.gemspec
37
37
  - lib/active_path.rb
38
- - lib/active_path/conditions/conditional.rb
39
38
  - lib/active_path/configuration.rb
40
- - lib/active_path/configuration/attachment.rb
41
- - lib/active_path/configuration/partial.rb
42
- - lib/active_path/configuration/partials.rb
43
39
  - lib/active_path/engine.rb
44
40
  - lib/active_path/helpers/rendering_helper.rb
45
- - lib/active_path/subscribers/path_hints.rb
46
41
  - lib/active_path/subscribers/subscriber.rb
47
- - lib/active_path/subscribers/view_injection.rb
48
42
  - lib/active_path/version.rb
49
43
  homepage: http://rubygems.org/gems/active_path
50
44
  licenses: []
@@ -1,29 +0,0 @@
1
- module ActivePath
2
- module Conditions
3
- module Conditional
4
- def conditions_match?(conditions)
5
- conditions.all? do |condition|
6
- condition_match?(condition)
7
- end
8
- end
9
-
10
- def condition_match?(condition)
11
- if condition.is_a?(Hash)
12
- hash_match?(condition)
13
- elsif condition.is_a?(Proc)
14
- proc_match?(condition)
15
- end
16
- end
17
-
18
- def hash_match?(condition)
19
- condition.all? do |k,v|
20
- options[:locals][k] == v
21
- end
22
- end
23
-
24
- def proc_match?(condition)
25
- condition.call(options[:locals])
26
- end
27
- end
28
- end
29
- end
@@ -1,17 +0,0 @@
1
- module ActivePath
2
- module Configuration
3
- class Attachment
4
- attr_reader :partial, :conditions
5
-
6
- def initialize(partial)
7
- @partial = partial
8
- @conditions = []
9
- end
10
-
11
- def when(condition = nil, &block)
12
- @conditions << (condition || block)
13
- self
14
- end
15
- end
16
- end
17
- end
@@ -1,17 +0,0 @@
1
- require 'active_path/configuration/attachment'
2
- module ActivePath
3
- module Configuration
4
- class Partial
5
- attr_reader :attachments
6
-
7
- def initialize
8
- @attachments = []
9
- end
10
-
11
- def with(partial_name)
12
- @attachments << Attachment.new(partial_name)
13
- @attachments.last
14
- end
15
- end
16
- end
17
- end
@@ -1,26 +0,0 @@
1
- require 'active_path/configuration/partial'
2
- module ActivePath
3
- module Configuration
4
- class Partials
5
- attr_reader :partials
6
-
7
- def initialize
8
- @partials = {}
9
- end
10
-
11
- def prepend(key)
12
- partial(key, true)
13
- end
14
-
15
- def append(key)
16
- partial(key, false)
17
- end
18
-
19
- private
20
-
21
- def partial(key, prepend = true)
22
- @partials["#{key}/#{prepend}"] ||= Partial.new
23
- end
24
- end
25
- end
26
- end
@@ -1,23 +0,0 @@
1
- require 'active_path/subscribers/subscriber'
2
- module ActivePath
3
- module Subscribers
4
- class PathHints < Subscriber
5
- def perform
6
- buffer.prepend("<!-- start #{partial}#{with_local_variables.to_s} --!>".html_safe)
7
- buffer.concat("<!-- end #{partial} --!>".html_safe)
8
- end
9
-
10
- private
11
-
12
- def with_local_variables
13
- if options.is_a?(Hash)
14
- variables = options[:locals].map do |k,v|
15
- count = (" (#{v.count})" if v.is_a?(Array)).to_s
16
- "#{k} => #{v.class}#{count}"
17
- end
18
- "\nwith local variables: #{JSON.pretty_generate(variables)}"
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,41 +0,0 @@
1
- require 'active_path/subscribers/subscriber'
2
- require 'active_path/conditions/conditional'
3
- module ActivePath
4
- module Subscribers
5
- class ViewInjection < Subscriber
6
- include Conditions::Conditional
7
-
8
- def perform
9
- prepend_attachments.each do |attachment|
10
- buffer.prepend(render_attachment(attachment))
11
- end
12
-
13
- append_attachments.each do |attachment|
14
- buffer.concat(render_attachment(attachment))
15
- end
16
- end
17
-
18
- private
19
-
20
- def append_attachments
21
- attachments(ActivePath.config.partials.append(partial))
22
- end
23
-
24
- def prepend_attachments
25
- attachments(ActivePath.config.partials.prepend(partial))
26
- end
27
-
28
- def attachments(configuration)
29
- configuration.attachments.select do |attachment|
30
- conditions_match?(attachment.conditions)
31
- end
32
- end
33
-
34
- def render_attachment(attachment)
35
- hash = { partial: attachment.partial }
36
- options_hash = options.is_a?(Hash) ? options.merge(hash) : hash
37
- context.render(options_hash)
38
- end
39
- end
40
- end
41
- end