something_and_nothing 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +8 -0
- data/Rakefile +14 -0
- data/lib/something_and_nothing.rb +17 -0
- data/lib/something_and_nothing/list_display_helper.rb +25 -0
- data/lib/something_and_nothing/view_helper.rb +8 -0
- data/something_and_nothing.gemspec +30 -0
- data/spec/something_and_nothing/list_display_helper_spec.rb +51 -0
- data/spec/something_and_nothing/view_helper_spec.rb +23 -0
- data/tasks/rspec.rake +21 -0
- metadata +71 -0
data/Manifest
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
Rakefile
|
2
|
+
lib/something_and_nothing.rb
|
3
|
+
lib/something_and_nothing/list_display_helper.rb
|
4
|
+
lib/something_and_nothing/view_helper.rb
|
5
|
+
spec/something_and_nothing/list_display_helper_spec.rb
|
6
|
+
spec/something_and_nothing/view_helper_spec.rb
|
7
|
+
tasks/rspec.rake
|
8
|
+
Manifest
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
6
|
+
|
7
|
+
Echoe.new('something_and_nothing', '0.1.0') do |p|
|
8
|
+
p.description = "Helps display array results in action view"
|
9
|
+
p.url = "http://github.com/robertoles/something_and_nothing"
|
10
|
+
p.author = "Robert Oles"
|
11
|
+
p.email = "robertoles@me.com"
|
12
|
+
p.ignore_pattern = ["tmp/*", "script/*", "spec/*"]
|
13
|
+
p.development_dependencies = []
|
14
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'actionpack'
|
2
|
+
require 'action_view'
|
3
|
+
require 'something_and_nothing/view_helper'
|
4
|
+
|
5
|
+
module SomethingAndNothing
|
6
|
+
class << self
|
7
|
+
def enable_actionview
|
8
|
+
return if ActionView::Base.include? SomethingAndNothing::ViewHelper
|
9
|
+
require 'something_and_nothing/view_helper'
|
10
|
+
ActionView::Base.send :include, ViewHelper
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
if defined? ActionView
|
16
|
+
SomethingAndNothing.enable_actionview
|
17
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module SomethingAndNothing
|
2
|
+
class ListDisplayHelper
|
3
|
+
attr_reader :list
|
4
|
+
|
5
|
+
def initialize(list)
|
6
|
+
@list = list
|
7
|
+
end
|
8
|
+
|
9
|
+
def populated
|
10
|
+
yield if block_given? && @list.length > 0
|
11
|
+
end
|
12
|
+
|
13
|
+
def unpopulated
|
14
|
+
yield if block_given? && @list.length == 0
|
15
|
+
end
|
16
|
+
|
17
|
+
def single
|
18
|
+
yield if block_given? && @list.length == 1
|
19
|
+
end
|
20
|
+
|
21
|
+
def more_than_one
|
22
|
+
yield if block_given? && @list.length > 1
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{something_and_nothing}
|
5
|
+
s.version = "0.1.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Robert Oles"]
|
9
|
+
s.date = %q{2010-02-08}
|
10
|
+
s.description = %q{Helps display array results in action view}
|
11
|
+
s.email = %q{robertoles@me.com}
|
12
|
+
s.extra_rdoc_files = ["lib/something_and_nothing.rb", "lib/something_and_nothing/list_display_helper.rb", "lib/something_and_nothing/view_helper.rb", "tasks/rspec.rake"]
|
13
|
+
s.files = ["Rakefile", "lib/something_and_nothing.rb", "lib/something_and_nothing/list_display_helper.rb", "lib/something_and_nothing/view_helper.rb", "spec/something_and_nothing/list_display_helper_spec.rb", "spec/something_and_nothing/view_helper_spec.rb", "tasks/rspec.rake", "Manifest", "something_and_nothing.gemspec"]
|
14
|
+
s.homepage = %q{http://github.com/robertoles/something_and_nothing}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Something_and_nothing", "--main", "README.rdoc"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{something_and_nothing}
|
18
|
+
s.rubygems_version = %q{1.3.5}
|
19
|
+
s.summary = %q{Helps display array results in action view}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
26
|
+
else
|
27
|
+
end
|
28
|
+
else
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe SomethingAndNothing::ListDisplayHelper do
|
4
|
+
describe "#populated" do
|
5
|
+
it "should yield result if array has any elements" do
|
6
|
+
SomethingAndNothing::ListDisplayHelper.new([1]).populated {"result"}.should == "result"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should not yield the result if the array has no elements" do
|
10
|
+
SomethingAndNothing::ListDisplayHelper.new([]).populated {"result"}.should be_nil
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#unpopulated" do
|
15
|
+
it "should yield result if array has no elements" do
|
16
|
+
SomethingAndNothing::ListDisplayHelper.new([]).unpopulated {"result"}.should == "result"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should not yield result if array has elements" do
|
20
|
+
SomethingAndNothing::ListDisplayHelper.new([1]).unpopulated {"result"}.should be_nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#single" do
|
25
|
+
it "should yield result if array has single element" do
|
26
|
+
SomethingAndNothing::ListDisplayHelper.new([1]).single {"result"}.should == "result"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should not yield result if array more than one" do
|
30
|
+
SomethingAndNothing::ListDisplayHelper.new([1,2]).single {"result"}.should be_nil
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should not yield result if array has no elements" do
|
34
|
+
SomethingAndNothing::ListDisplayHelper.new([]).single {"result"}.should be_nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#more_than_one" do
|
39
|
+
it "should yield result if array has more than one element" do
|
40
|
+
SomethingAndNothing::ListDisplayHelper.new([1,2]).more_than_one {"result"}.should == "result"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should not yield result if array has single element" do
|
44
|
+
SomethingAndNothing::ListDisplayHelper.new([1]).more_than_one {"result"}.should be_nil
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should not yield result if array has no elements" do
|
48
|
+
SomethingAndNothing::ListDisplayHelper.new([]).more_than_one {"result"}.should be_nil
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
include SomethingAndNothing::ViewHelper
|
3
|
+
|
4
|
+
describe SomethingAndNothing::ViewHelper do
|
5
|
+
describe "#display_for" do
|
6
|
+
it "yields an instance of ListDisplayHelper" do
|
7
|
+
display_for [] do |result|
|
8
|
+
result.should be_instance_of(SomethingAndNothing::ListDisplayHelper)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should set the array used for the list helper" do
|
13
|
+
list = []
|
14
|
+
display_for list do |result|
|
15
|
+
result.list.should equal(list)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should respond to display_content_for" do
|
20
|
+
SomethingAndNothing::ViewHelper.respond_to?(:display_content_for).should be_true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/tasks/rspec.rake
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
begin
|
2
|
+
require 'spec'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems' unless ENV['NO_RUBYGEMS']
|
5
|
+
require 'spec'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'spec/rake/spectask'
|
9
|
+
rescue LoadError
|
10
|
+
puts <<-EOS
|
11
|
+
To use rspec for testing you must install rspec gem:
|
12
|
+
gem install rspec
|
13
|
+
EOS
|
14
|
+
exit(0)
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Run the specs under spec/models"
|
18
|
+
Spec::Rake::SpecTask.new do |t|
|
19
|
+
t.spec_opts = ["-c"]
|
20
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: something_and_nothing
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robert Oles
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-02-08 00:00:00 +00:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Helps display array results in action view
|
17
|
+
email: robertoles@me.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- lib/something_and_nothing.rb
|
24
|
+
- lib/something_and_nothing/list_display_helper.rb
|
25
|
+
- lib/something_and_nothing/view_helper.rb
|
26
|
+
- tasks/rspec.rake
|
27
|
+
files:
|
28
|
+
- Rakefile
|
29
|
+
- lib/something_and_nothing.rb
|
30
|
+
- lib/something_and_nothing/list_display_helper.rb
|
31
|
+
- lib/something_and_nothing/view_helper.rb
|
32
|
+
- spec/something_and_nothing/list_display_helper_spec.rb
|
33
|
+
- spec/something_and_nothing/view_helper_spec.rb
|
34
|
+
- tasks/rspec.rake
|
35
|
+
- Manifest
|
36
|
+
- something_and_nothing.gemspec
|
37
|
+
has_rdoc: true
|
38
|
+
homepage: http://github.com/robertoles/something_and_nothing
|
39
|
+
licenses: []
|
40
|
+
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options:
|
43
|
+
- --line-numbers
|
44
|
+
- --inline-source
|
45
|
+
- --title
|
46
|
+
- Something_and_nothing
|
47
|
+
- --main
|
48
|
+
- README.rdoc
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
version:
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "1.2"
|
62
|
+
version:
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
rubyforge_project: something_and_nothing
|
66
|
+
rubygems_version: 1.3.5
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: Helps display array results in action view
|
70
|
+
test_files: []
|
71
|
+
|