variants 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.autotest ADDED
@@ -0,0 +1,8 @@
1
+ Autotest.add_hook(:initialize) do |at|
2
+ at.add_exception %r{^\.git}
3
+ at.add_exception %r{^./tmp}
4
+ at.add_mapping(%r{^lib/.*\.rb$}) do |f, _|
5
+ Dir['spec/**/*.rb']
6
+ end
7
+ nil
8
+ end
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile CHANGED
@@ -2,3 +2,6 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in variants.gemspec
4
4
  gemspec
5
+
6
+ gem 'rspec'
7
+ gem 'ZenTest'
data/lib/variants.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require 'action_view'
2
+
3
+ require 'variants/helpers'
4
+
1
5
  module Variants
2
- # Your code goes here...
3
6
  end
@@ -0,0 +1,40 @@
1
+ module Variants
2
+ module Helpers
3
+ extend ActiveSupport::Concern
4
+
5
+ module InstanceMethods
6
+ def variant name, condition = nil
7
+
8
+ # If Rails env is development
9
+ if Rails.env.development?
10
+ # Override conditions if params[:variant_name] is presented
11
+ if self.respond_to?(:params) and not self.params[name.to_sym].nil?
12
+ return self.params[name.to_sym].to_s == 'true'
13
+ end
14
+ end
15
+
16
+ # If condition is presented, return it
17
+ unless condition.nil?
18
+ return condition
19
+ end
20
+
21
+ # Add ? to end of name
22
+ method_name = "#{name.to_s}?"
23
+ # And try to call it
24
+ if self.respond_to?(method_name)
25
+ return self.send(method_name)
26
+ end
27
+
28
+ # Else return false
29
+ return false
30
+ end
31
+
32
+ alias_method :v, :variant
33
+ end
34
+
35
+ end
36
+ end
37
+
38
+ module ActionView::Helpers
39
+ include Variants::Helpers
40
+ end
@@ -1,3 +1,3 @@
1
1
  module Variants
2
- VERSION = "0.0.0"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -0,0 +1,84 @@
1
+ require 'spec_helper'
2
+
3
+ describe Variants do
4
+
5
+ describe 'ActionView::Helpers' do
6
+
7
+ describe 'variant' do
8
+
9
+ before :each do
10
+ Rails.stub_chain(:env, :development?).and_return(true)
11
+ end
12
+
13
+ it 'should respond to variant' do
14
+ self.should respond_to(:variant)
15
+ end
16
+
17
+ it 'should respond to v' do
18
+ self.should respond_to(:v)
19
+ end
20
+
21
+ it 'v should be alias to variant' do
22
+ self.method(:v).should eq self.method(:variant)
23
+ end
24
+
25
+ it 'should accept symbol' do
26
+ lambda {
27
+ self.variant :variant_name
28
+ }.should_not raise_error
29
+ end
30
+
31
+ it 'should accept string' do
32
+ lambda {
33
+ self.variant 'variant_name'
34
+ }.should_not raise_error
35
+ end
36
+
37
+ it 'should accept boolean' do
38
+ lambda {
39
+ self.variant :variant_name, true
40
+ }.should_not raise_error
41
+ end
42
+
43
+ it 'should return false if variant and condition is not presented' do
44
+ self.variant(:variant_name).should eql false
45
+ end
46
+
47
+ it 'should return condition value if variant is not overrided' do
48
+ self.variant(:variant_name, true).should eql true
49
+ self.variant(:variant_name, false).should eql false
50
+ end
51
+
52
+ it 'should call method_name? for :method_name' do
53
+ self.stub!(:variant_name?).and_return(true)
54
+ self.variant(:variant_name).should eql true
55
+ end
56
+
57
+ it 'should return condition before calling method' do
58
+ self.stub!(:variant_name?).and_return(true)
59
+ self.variant(:variant_name, false).should eql false
60
+ end
61
+
62
+ it 'should look for params[:variant_name]' do
63
+ self.stub!(:params).and_return( { :variant_name => true } )
64
+ self.variant(:variant_name).should eql true
65
+ self.variant(:variant_name, false).should eql true
66
+ end
67
+
68
+ it 'should convert params[:variant_name] to boolean' do
69
+ self.stub!(:params).and_return( { :variant_name => 'true' } )
70
+ self.variant(:variant_name).should eql true
71
+ end
72
+
73
+ it 'should look for params only if Rails.env.delevopment?' do
74
+ Rails.stub_chain(:env, :development?).and_return(false)
75
+ self.stub!(:params).and_return( { :variant_name => true } )
76
+ self.variant(:variant_name).should eql false
77
+ self.variant(:variant_name, false).should eql false
78
+ end
79
+
80
+ end
81
+
82
+ end
83
+
84
+ end
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'action_view'
5
+ require 'active_support/inflector'
6
+ require 'variants'
7
+
8
+ # Load support files
9
+ Dir[ File.join(File.dirname(__FILE__), 'support/**/*.rb') ].each { |f| require f }
10
+
11
+ # Include Rails internals
12
+ include ActionView::Helpers
13
+
14
+ RSpec.configure do |config|
15
+ end
@@ -0,0 +1 @@
1
+ module Rails; end
data/variants.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.email = ['kossnocorp@gmail.com']
11
11
  s.homepage = ""
12
12
  s.summary = %q{Be boss of your views}
13
- s.description = %q{Be boss of your view}
13
+ s.description = %q{Be boss of your views}
14
14
 
15
15
  s.rubyforge_project = "variants"
16
16
 
@@ -18,4 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
+
22
+ s.add_dependency 'activesupport', '>= 3.0.7'
23
+ s.add_dependency 'actionpack', '>= 3.0.7'
21
24
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: variants
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 0
10
- version: 0.0.0
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sasha Koss
@@ -15,10 +15,41 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-30 00:00:00 Z
19
- dependencies: []
20
-
21
- description: Be boss of your view
18
+ date: 2011-05-01 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: activesupport
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 9
29
+ segments:
30
+ - 3
31
+ - 0
32
+ - 7
33
+ version: 3.0.7
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: actionpack
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 9
45
+ segments:
46
+ - 3
47
+ - 0
48
+ - 7
49
+ version: 3.0.7
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ description: Be boss of your views
22
53
  email:
23
54
  - kossnocorp@gmail.com
24
55
  executables: []
@@ -28,11 +59,17 @@ extensions: []
28
59
  extra_rdoc_files: []
29
60
 
30
61
  files:
62
+ - .autotest
31
63
  - .gitignore
64
+ - .rspec
32
65
  - Gemfile
33
66
  - Rakefile
34
67
  - lib/variants.rb
68
+ - lib/variants/helpers.rb
35
69
  - lib/variants/version.rb
70
+ - spec/actionview_extensions_spec.rb
71
+ - spec/spec_helper.rb
72
+ - spec/support/rails.rb
36
73
  - variants.gemspec
37
74
  homepage: ""
38
75
  licenses: []
@@ -67,5 +104,7 @@ rubygems_version: 1.7.2
67
104
  signing_key:
68
105
  specification_version: 3
69
106
  summary: Be boss of your views
70
- test_files: []
71
-
107
+ test_files:
108
+ - spec/actionview_extensions_spec.rb
109
+ - spec/spec_helper.rb
110
+ - spec/support/rails.rb