tanga_namespaced_helpers 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in tanga_namespaced_helpers.gemspec
4
+ gemspec
data/README ADDED
@@ -0,0 +1,27 @@
1
+
2
+ No longer suffer the tyranny of 10 billion helper methods scattered throughout
3
+ files without hierarchy.
4
+
5
+ Your Code in lib/your_app/helpers/links.rb:
6
+ module YourApp::Helpers::Links
7
+ extend TangaNamespacedHelpers
8
+
9
+ def self.tanga_points user
10
+ link_to(pluralize(user.total_points, "Tanga Point"),
11
+ leaderboards_path(:user_id => user.id))
12
+
13
+ # You can also access the view directory with:
14
+ view.link_to(view.pluralize(user.total_points, "Tanga Point"),
15
+ view.leaderboards_path(:user_id => user.id))
16
+ # I'm not sure which is better here. The first is less magic, more explicit.
17
+ end
18
+ end
19
+
20
+
21
+ Your View:
22
+ <%= YourApp::Helpers::Links.tanga_points(user) %>
23
+
24
+ For shorter code, in an initializer or something, do:
25
+ H = YourApp::Helpers
26
+ Then your views can do:
27
+ <%= H::Links.tanga_points(user)
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,3 @@
1
+ module TangaNamespacedHelpers
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,35 @@
1
+ require "tanga_namespaced_helpers/version"
2
+
3
+ # This probably isn't the best way to structure the code.
4
+ # Stupid name, bad code, no tests, etc.
5
+ module TangaNamespacedHelpers
6
+ def self.reset! controller
7
+ @view = controller.view_context
8
+ end
9
+
10
+ def self.view
11
+ @view
12
+ end
13
+
14
+ # TODO Gotta be a better way to do this.
15
+ def view
16
+ TangaNamespacedHelpers.view
17
+ end
18
+
19
+ def method_missing *args, &block
20
+ view.send *args, &block
21
+ end
22
+
23
+ module ControllerMethods
24
+ def self.included base
25
+ base.before_filter :reset_namespace_view_context
26
+ end
27
+
28
+ def reset_namespace_view_context
29
+ TangaNamespacedHelpers.reset! self
30
+ end
31
+ end
32
+ end
33
+
34
+
35
+ ActionController::Base.send :include, TangaNamespacedHelpers::ControllerMethods
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "tanga_namespaced_helpers/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "tanga_namespaced_helpers"
7
+ s.version = TangaNamespacedHelpers::VERSION
8
+ s.authors = ["Joe Van Dyk"]
9
+ s.email = ["joe@tanga.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Namespace your Rails helper methods}
12
+ s.description = %q{Namespace your Rails helper methods}
13
+
14
+ s.rubyforge_project = "tanga_namespaced_helpers"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tanga_namespaced_helpers
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Joe Van Dyk
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-08-25 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Namespace your Rails helper methods
23
+ email:
24
+ - joe@tanga.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - README
35
+ - Rakefile
36
+ - lib/tanga_namespaced_helpers.rb
37
+ - lib/tanga_namespaced_helpers/version.rb
38
+ - tanga_namespaced_helpers.gemspec
39
+ has_rdoc: true
40
+ homepage: ""
41
+ licenses: []
42
+
43
+ post_install_message:
44
+ rdoc_options: []
45
+
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ hash: 3
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 3
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ requirements: []
67
+
68
+ rubyforge_project: tanga_namespaced_helpers
69
+ rubygems_version: 1.5.2
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Namespace your Rails helper methods
73
+ test_files: []
74
+