rails-presenter 0.1.2 → 0.1.3

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: 8634186ddde1925543d31f95d933e8fa08d58c99
4
- data.tar.gz: ec310225f643038bf050fe95bb75dc15169e7ba3
3
+ metadata.gz: 1187d84b167f923d52a8ddccb57fd0b310edfc2e
4
+ data.tar.gz: ffa4fb67f693da74fdbc76225a8f1c8d01ef50d8
5
5
  SHA512:
6
- metadata.gz: 6c84551b1b706113368a34074f5ebc8df5779d7d0ce973c9a2ad177fddc9145ac2869ff00ec94e1122c1a3205014f047c3279c2075970a52435dfd9d4ea988bc
7
- data.tar.gz: c722b5692b1d8bdb055dbb4eb7760c049e9d4c47c95074f7ee3343fe9072d6b0c0998dd7402845312fe2d0f5c18161a48a2de2720b25f7a09b4a4fa3517e5448
6
+ metadata.gz: 70d36f09420ee59ca8a4af9a1517db76a5f3e39b0a9bfb91689c22b68537576d4f8af700a5d12071db062fad388be0ea129594b5280b7e76a6d55a57ed6d3b78
7
+ data.tar.gz: fe8f01219dbc56910d3e930e378547ae8059788f7e6ac8cc50f5ae5902b87de96362632dc669b58027edd00629522ae377bf6c6d8af3f0dd0ab1514b104894bc
@@ -1,6 +1,9 @@
1
1
  class RailsPresenter::Base
2
- include ActionView::Context
3
- include Sprockets::Rails::Helper
2
+ include ActionView::Context # fix output_buffer to be able to capture yielded block
3
+ if defined? Haml
4
+ include Haml::Helpers # add capture_haml support
5
+ end
6
+ include Sprockets::Rails::Helper # add asset pipeline support
4
7
  def initialize
5
8
  self.debug_assets = Rails.application.config.assets.debug
6
9
  self.digest_assets = Rails.application.config.assets.digest
@@ -12,4 +15,26 @@ class RailsPresenter::Base
12
15
  def t(*args)
13
16
  I18n.t(*args)
14
17
  end
18
+
19
+ def capture_haml(*args, &block)
20
+ buffer = eval('if defined? _hamlout then _hamlout else nil end', block.binding) || haml_buffer
21
+ with_haml_buffer(buffer) do
22
+ position = haml_buffer.buffer.length
23
+
24
+ haml_buffer.capture_position = position
25
+ value = block.call(*args)
26
+
27
+ captured = haml_buffer.buffer.slice!(position..-1)
28
+
29
+ if captured == '' and value != haml_buffer.buffer
30
+ captured = (value.is_a?(String) ? value : nil)
31
+ end
32
+
33
+ return nil if captured.nil?
34
+ return (haml_buffer.options[:ugly] ? captured : prettify(captured))
35
+ end
36
+ # https://github.com/haml/haml/issues/822
37
+ #ensure
38
+ #haml_buffer.capture_position = nil
39
+ end
15
40
  end
@@ -1,3 +1,3 @@
1
1
  module RailsPresenter
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-presenter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathieu Jobin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-24 00:00:00.000000000 Z
11
+ date: 2014-12-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler