tanga_namespaced_helpers 0.0.6 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5849a60b093b3846289497670f4dbb37203fe30e
4
+ data.tar.gz: e2624e05b3b89c0d962ddf71be5ef7eeb83b9e21
5
+ SHA512:
6
+ metadata.gz: 6b64bc490293ef76805ae6af0df77c6b208d74457400415c3035a6a1071f621bb0a62b3b78ef865fc1c4ef6a3739fdbf90b4660e653dfb99773a8b78bbef7719
7
+ data.tar.gz: 0312c50d77e616a230546fe46071a7662fc6f0fccf0c72e1733d77f6a0b6127def7ef72cf6b2da83272dc5b3b3d319560f78a4df7594cf47c11adb2ecbf2d10c
data/README CHANGED
@@ -1,23 +1,16 @@
1
1
  No longer suffer the tyranny of 10 billion helper methods scattered throughout
2
2
  files without hierarchy.
3
3
 
4
- Your Code in lib/your_app/helpers/links.rb:
5
- module YourApp::Helpers::Links
4
+ Your Code in app/helpers/links_helper.rb:
5
+ module LinksHelper
6
6
  extend TangaNamespacedHelpers
7
7
 
8
8
  def self.tanga_points user
9
- link_to(pluralize(user.total_points, "Tanga Point"), leaderboards_path(:user_id => user.id))
9
+ link_to(pluralize(user.total_points, "Tanga Point"),
10
+ leaderboards_path(:user_id => user.id))
10
11
  end
11
12
  end
12
13
 
13
14
 
14
15
  Your View:
15
- <%= YourApp::Helpers::Links.tanga_points(user) %>
16
-
17
- For shorter code, in an initializer or something, do:
18
-
19
- H = YourApp::Helpers
20
-
21
- Then your views can do:
22
-
23
- <%= H::Links.tanga_points(user) %>
16
+ <%= LinksHelper.tanga_points(user) %>
@@ -1,34 +1,54 @@
1
1
  require "tanga_namespaced_helpers/version"
2
+ require 'request_store'
3
+
4
+ module Rooster
5
+ def self.view_context
6
+ RequestStore.store[:view_context]
7
+ end
8
+
9
+ def self.view_context= context
10
+ RequestStore.store[:view_context] = context
11
+ end
12
+
13
+ # Workaround for ActionMMailer apparently resetting some of the view context sometimes.
14
+ def self.original_view_context
15
+ RequestStore.store[:original_view_context]
16
+ end
17
+
18
+ def self.original_view_context= context
19
+ RequestStore.store[:original_view_context] = context
20
+ end
21
+ end
2
22
 
3
23
  # This probably isn't the best way to structure the code.
4
24
  # Stupid name, bad code, no tests, etc.
5
25
  module TangaNamespacedHelpers
6
26
  def self.reset! controller
7
- @view = controller.view_context
8
- if controller.is_a?(ActionController::Base)
9
- @original_context = @view
10
- end
27
+ view_context = controller.view_context
11
28
 
12
29
  # Hack to get Haml helpers available
13
30
  if defined? Haml
14
- class << @view
31
+ class << view_context
15
32
  include Haml::Helpers
16
33
  end
17
- @view.init_haml_helpers
34
+ view_context.init_haml_helpers
35
+ end
36
+ Rooster.view_context = view_context
37
+
38
+ if controller.is_a?(ActionController::Base)
39
+ Rooster.original_view_context = view_context
18
40
  end
19
- end
20
41
 
21
- def self.view
22
- @view
23
42
  end
24
43
 
25
44
  def self.use_controller!
26
- @view = @original_context if @original_context
45
+ if Rooster.original_view_context
46
+ Rooster.view_context = Rooster.original_view_context
47
+ end
27
48
  end
28
49
 
29
- # TODO Gotta be a better way to do this.
30
50
  def view
31
- TangaNamespacedHelpers.view
51
+ Rooster.view_context
32
52
  end
33
53
 
34
54
  def method_missing *args, &block
@@ -51,15 +71,15 @@ module TangaNamespacedHelpers
51
71
  end
52
72
 
53
73
  def reset_namespace_view_context
54
- TangaNamespacedHelpers.reset! self
74
+ TangaNamespacedHelpers.reset!(self)
55
75
  end
56
76
  end
57
77
  end
58
78
 
59
-
60
79
  ActionController::Base.send :include, TangaNamespacedHelpers::ControllerMethods
61
80
 
62
81
  class ActionMailer::Base
63
82
  # This is necessary to use namespaced helpers from the actionmailer views
64
83
  default 'init-view' => Proc.new { TangaNamespacedHelpers.reset!(self) }
65
84
  end
85
+
@@ -1,3 +1,3 @@
1
1
  module TangaNamespacedHelpers
2
- VERSION = "0.0.6"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -17,4 +17,5 @@ Gem::Specification.new do |s|
17
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
+ s.add_dependency 'request_store', '=1.0.5'
20
21
  end
metadata CHANGED
@@ -1,16 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tanga_namespaced_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
5
- prerelease:
4
+ version: 0.1.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Joe Van Dyk
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-03-08 00:00:00.000000000 Z
13
- dependencies: []
11
+ date: 2013-10-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: request_store
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.5
14
27
  description: Namespace your Rails helper methods
15
28
  email:
16
29
  - joe@tanga.com
@@ -27,27 +40,25 @@ files:
27
40
  - tanga_namespaced_helpers.gemspec
28
41
  homepage: ''
29
42
  licenses: []
43
+ metadata: {}
30
44
  post_install_message:
31
45
  rdoc_options: []
32
46
  require_paths:
33
47
  - lib
34
48
  required_ruby_version: !ruby/object:Gem::Requirement
35
- none: false
36
49
  requirements:
37
- - - ! '>='
50
+ - - '>='
38
51
  - !ruby/object:Gem::Version
39
52
  version: '0'
40
53
  required_rubygems_version: !ruby/object:Gem::Requirement
41
- none: false
42
54
  requirements:
43
- - - ! '>='
55
+ - - '>='
44
56
  - !ruby/object:Gem::Version
45
57
  version: '0'
46
58
  requirements: []
47
59
  rubyforge_project: tanga_namespaced_helpers
48
- rubygems_version: 1.8.10
60
+ rubygems_version: 2.1.9
49
61
  signing_key:
50
- specification_version: 3
62
+ specification_version: 4
51
63
  summary: Namespace your Rails helper methods
52
64
  test_files: []
53
- has_rdoc: