active_helper 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -50,7 +50,7 @@ begin
50
50
  spec.authors = ["Nick Sutterer"]
51
51
  spec.email = "apotonick@gmail.com"
52
52
 
53
- spec.files = FileList["[A-Z]*", File.join(*%w[{lib,test} ** *]).to_s]
53
+ spec.files = FileList["[A-Z]*", File.join(*%w[{lib,test,rails} ** *]).to_s]
54
54
 
55
55
  spec.add_dependency 'activesupport', '>= 2.3.0' # Dependencies and minimum versions?
56
56
  end
@@ -0,0 +1,32 @@
1
+ class ActionController::Base
2
+
3
+ class_inheritable_array :active_helpers
4
+ self.active_helpers = []
5
+
6
+ class << self
7
+ # The passed helpers will be imported in the view and thus be available in
8
+ # your template.
9
+ #
10
+ # Example:
11
+ # class BeerController < ActionController::Base
12
+ # active_helper ThirstyHelper
13
+ #
14
+ # The helper file usually resides in app/active_helpers/, baby.
15
+ def active_helper(*classes)
16
+ active_helpers.push(*classes).uniq!
17
+ end
18
+ end
19
+
20
+ def initialize_template_class_with_active_helper(response)
21
+ initialize_template_class_without_active_helper(response)
22
+ response.template.use *self.class.active_helpers
23
+ end
24
+
25
+ alias_method_chain :initialize_template_class, :active_helper
26
+ end
27
+
28
+ class ActionView::Base
29
+ include ActiveHelper
30
+ end
31
+
32
+ ActiveSupport::Dependencies.load_paths << Rails.root.join(*%w[app active_helpers]) if defined?(Rails)
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module ActiveHelper
4
- VERSION = '0.1.1'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -0,0 +1 @@
1
+ require 'active_helper/rails'
@@ -1,15 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/test_helper'
2
2
 
3
3
  class ActiveHelperTest < Test::Unit::TestCase
4
- class GreedyHelper < ::ActiveHelper::Base
5
- provides :eat
6
- end
7
-
8
- class ThirstyHelper < ::ActiveHelper::Base
9
- provides :drink, :booze
10
- end
11
-
12
-
13
4
  def helper_mock(*args)
14
5
  Class.new(::ActiveHelper::Base).new(*args)
15
6
  end
@@ -0,0 +1,7 @@
1
+ class GreedyHelper < ::ActiveHelper::Base
2
+ provides :eat
3
+ end
4
+
5
+ class ThirstyHelper < ::ActiveHelper::Base
6
+ provides :drink, :booze
7
+ end
@@ -0,0 +1,57 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ require 'action_controller'
4
+ require 'action_view'
5
+ require 'active_helper/rails' # usually happens in active_helper.rb
6
+
7
+ class BeerController < ActionController::Base
8
+ def drink
9
+ end
10
+ end
11
+
12
+ ActionController::Routing::Routes.draw do |map|
13
+ map.connect 'beer/:action', :controller => 'beer'
14
+ end
15
+
16
+
17
+ class RailsTest < ActionController::TestCase
18
+ context "The ActionController::Base class" do
19
+ should "respond to active_helper" do
20
+ assert_respond_to ActionController::Base, :active_helper
21
+ end
22
+
23
+ should "store helper constants from active_helper" do
24
+ @controller = Class.new(BeerController)
25
+ @controller.active_helper ThirstyHelper
26
+ assert_equal [ThirstyHelper], @controller.active_helpers
27
+ end
28
+
29
+ should "inherit helper constants from active_helper" do
30
+ @base_controller = Class.new(BeerController)
31
+ @base_controller.active_helper GreedyHelper
32
+ @controller = Class.new(@base_controller)
33
+ @controller.active_helper ThirstyHelper
34
+ assert_equal [GreedyHelper, ThirstyHelper], @controller.active_helpers
35
+ end
36
+ end
37
+
38
+ context "An ActionView::Base instance" do
39
+ should "respond to use" do
40
+ @view = ActionView::Base
41
+ assert_respond_to @view, :use
42
+ end
43
+
44
+ end
45
+
46
+ context "The view rendered by the controller" do
47
+ should "respond to used helper methods" do
48
+ @controller = BeerController.new
49
+ @controller.class.active_helper ThirstyHelper
50
+
51
+ get 'drink'
52
+
53
+ @view = @controller.response.template
54
+ assert_respond_to @view, :booze # from the ThirstyHelper
55
+ end
56
+ end
57
+ end
@@ -1,4 +1,5 @@
1
1
  require 'rubygems'
2
2
  require 'shoulda'
3
3
 
4
- require 'active_helper'
4
+ require 'active_helper'
5
+ require File.dirname(__FILE__) + '/helpers/helpers.rb'
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
5
10
  platform: ruby
6
11
  authors:
7
12
  - Nick Sutterer
@@ -9,19 +14,23 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-04-01 00:00:00 +02:00
17
+ date: 2010-04-10 00:00:00 +02:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: activesupport
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 2
29
+ - 3
30
+ - 0
23
31
  version: 2.3.0
24
- version:
32
+ type: :runtime
33
+ version_requirements: *id001
25
34
  description: Finally - helpers with proper encapsulation, delegation, interfaces and inheritance!
26
35
  email: apotonick@gmail.com
27
36
  executables: []
@@ -35,8 +44,12 @@ files:
35
44
  - Rakefile
36
45
  - lib/active_helper.rb
37
46
  - lib/active_helper/base.rb
47
+ - lib/active_helper/rails.rb
38
48
  - lib/active_helper/version.rb
49
+ - rails/init.rb
39
50
  - test/active_helper_test.rb
51
+ - test/helpers/helpers.rb
52
+ - test/rails_test.rb
40
53
  - test/test_helper.rb
41
54
  has_rdoc: true
42
55
  homepage: http://github.com/apotonick/active_helper
@@ -51,21 +64,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
51
64
  requirements:
52
65
  - - ">="
53
66
  - !ruby/object:Gem::Version
67
+ segments:
68
+ - 0
54
69
  version: "0"
55
- version:
56
70
  required_rubygems_version: !ruby/object:Gem::Requirement
57
71
  requirements:
58
72
  - - ">="
59
73
  - !ruby/object:Gem::Version
74
+ segments:
75
+ - 0
60
76
  version: "0"
61
- version:
62
77
  requirements: []
63
78
 
64
79
  rubyforge_project:
65
- rubygems_version: 1.3.5
80
+ rubygems_version: 1.3.6
66
81
  signing_key:
67
82
  specification_version: 3
68
83
  summary: Finally - helpers with proper encapsulation, delegation, interfaces and inheritance!
69
84
  test_files:
85
+ - test/rails_test.rb
70
86
  - test/active_helper_test.rb
71
87
  - test/test_helper.rb
88
+ - test/helpers/helpers.rb