active_path 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c266106395a8b3ddf51e549973c80c6ec6dc7579
4
- data.tar.gz: 2e87efdefac0cbaf5ea7beeff94d6c72e0288fab
3
+ metadata.gz: 11521118a9c1286cbef1df712f650ecad8e146c8
4
+ data.tar.gz: c669aa1ecef84937035bba5a4a8ed457671ee7a1
5
5
  SHA512:
6
- metadata.gz: b4404aac557635185c5137d150998b1109d157f1483fef74e607c407a66c8d35c113e6d12a7c0d975d1d886e764df1424309b3798d8f7abeccdacb8b4649df5f
7
- data.tar.gz: 66bd5809c1fad03f9ac28ab528b6018bc4b7d908e33b74746d3c3535a8647e6195d79accd5ebf6eaf45f7d55c957cfb4689962747fea7a561a8d98e62509723b
6
+ metadata.gz: 6748d8386d87b2d375110dc783a02dd38904fedfe7d383631a820cbfec33be4faf45f0da1a9d5bcaf72ec7542ccce781eea389d4361e9e8cc7213bf195ed8422
7
+ data.tar.gz: '048da2e8401bb24de04b27d6a9f280dd6cbfa33f4780ba7dfbca9da86d4493ae419bd4f05959149c6f1b7ef8f83aad396333c650047873b8c004479ac12ba5f2'
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  View injection and path hints for Rails 5.
3
3
 
4
4
 
5
- ##Installation
5
+ ## Installation
6
6
 
7
7
  Add to your Gemfile:
8
8
 
@@ -23,9 +23,9 @@ end
23
23
  ```
24
24
 
25
25
 
26
- ##Configuration
26
+ ## Configuration
27
27
 
28
- **Basic view injection.**
28
+ **View injection:**
29
29
 
30
30
  ```ruby
31
31
 
@@ -43,26 +43,6 @@ The above example assumes your application renders a partial called 'page_conten
43
43
 
44
44
  Your partial will have the same local parameters access as the prepended partial.
45
45
 
46
- --
47
-
48
- **More ways to inject content into views**
49
-
50
- ```ruby
51
-
52
- ActivePath.configure do |config|
53
-
54
- ...
55
-
56
- config.partials.prepend('page_content').with(
57
- partial: 'example/test',
58
- helper: ExampleHelper
59
- )
60
-
61
- end
62
-
63
- ```
64
-
65
- The above example is similar to the first but also adds your helper to the view.
66
46
 
67
47
  --
68
48
 
@@ -81,6 +61,6 @@ end
81
61
 
82
62
  ```
83
63
 
84
- All partials will be wrapped in a border, red for uncached, green for cached.
64
+ HTML comments are added before and after each partial.
85
65
 
86
66
  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).
@@ -3,17 +3,12 @@ module ActivePath
3
3
  module Helpers
4
4
  module RenderingHelper
5
5
  extend ActionView::Helpers::RenderingHelper
6
+ # Delegate rendering to the activepath renderer
6
7
  def render(options = {}, locals = {}, &block)
7
- active_path_renderer(options, locals).render do
8
+ Renderer::PartialRenderer.new(self, options).render do
8
9
  super
9
10
  end
10
11
  end
11
-
12
- private
13
-
14
- def active_path_renderer(options, locals)
15
- Renderer::PartialRenderer.new(options, locals)
16
- end
17
12
  end
18
13
  end
19
14
  end
@@ -1,26 +1,22 @@
1
1
  module ActivePath
2
2
  module Renderer
3
3
  class PartialRenderer
4
- attr_reader :options, :locals
4
+ attr_reader :context, :options
5
5
 
6
- def initialize(options, locals)
6
+ def initialize(context, options = {})
7
+ @context = context
7
8
  @options = options
8
- @locals = locals
9
9
  end
10
10
 
11
11
  def render
12
- buffer = yield
13
- before.each { |output| buffer.prepend(output) }
14
- after.each { |output| buffer.concat(output) }
15
- buffer
16
- end
17
-
18
- def before
19
- partials.prepend(partial).attachments
20
- end
21
-
22
- def after
23
- partials.append(partial).attachments
12
+ output_buffer = yield
13
+ partials.prepend(partial_name).attachments.each do |attachment|
14
+ output_buffer.prepend(render_attachment(attachment))
15
+ end
16
+ partials.append(partial_name).attachments.each do |attachment|
17
+ output_buffer.concat(render_attachment(attachment))
18
+ end
19
+ output_buffer
24
20
  end
25
21
 
26
22
  private
@@ -29,9 +25,19 @@ module ActivePath
29
25
  ActivePath.config.partials
30
26
  end
31
27
 
32
- def partial
28
+ def partial_name
33
29
  options.is_a?(Hash) ? options[:partial] : options.to_s
34
30
  end
31
+
32
+ def render_attachment(attachment)
33
+ options_hash = attachment_options(attachment)
34
+ context.render(options_hash)
35
+ end
36
+
37
+ def attachment_options(attachment)
38
+ hash = { partial: attachment }
39
+ options.is_a?(Hash) ? options.merge(hash) : hash
40
+ end
35
41
  end
36
42
  end
37
43
  end
@@ -1,3 +1,3 @@
1
1
  module ActivePath
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
data/lib/active_path.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'active_path/engine'
2
2
  require 'active_path/configuration'
3
-
4
3
  module ActivePath
5
4
  def self.config
6
5
  Configuration.config
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.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Tulino